
August 15th, 2004, 08:00 PM
|
|
Registered User
|
|
Join Date: Aug 2004
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
WML Index creator (1st try with Java)
Wanted to make bit easier uploading some media to my phone from my HTTP site.
This program makes WML index for files(any) in specific folder.
Though it could be usefull, at least as example for bad Java code :P
Code:
/*
* MakeTags.java
*
* Created on August 15, 2004, 10:11 PM
*/
import java.io.*;
import javax.swing.*;
/**
*
* @author Guiding5
*/
public class MakeTags
{
/** Creates a new instance of MakeTags */
public MakeTags()
{
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
File file = null ;
if (args.length > 0)
{
// allow a file to be specified via the command
// line (for testing)
file = new File(args[0]) ;
}
else
{
// allow the user to browse for a file if one was not
// specified at the command line
/*
JFileChooser jfc = new JFileChooser() ;
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int result = jfc.showOpenDialog(null) ;
if (result == jfc.CANCEL_OPTION)
{
System.exit( 0 ) ;
}
File dir = jfc.getSelectedFile();
*/
File dir = new File("D:\\nokia\\down");
if (!dir.isDirectory())
{
System.out.println("Have to be Directory !");
System.exit( 0 ) ;
}
PrintWriter pww = null;
File files[] = dir.listFiles();
try
{
pww = new PrintWriter(new FileWriter("D:\\nokia\\down\\down.wml"));
}
catch (Exception e)
{
System.out.println("Cant init output !!!");
System.exit( 0 ) ;
}
///PrintStream pww = System.out;
pww.println("<?xml version=\"1.0\"?>");
pww.println("<!DOCTYPE wml PUBLIC \"//DTD WML 1.1//EN\" \"http://www.you.org/down.wml\">");
pww.println(" <wml>");
pww.println(" <card title=\"Miscellaneous\">");
pww.println(" <p>Select file to download:</p>");
for(int i=0; i<files.length; i++)
{
File current = files[i];
if(current.isFile() && current.getName() != "down.wml")
{
pww.println(" <p><a href=\""+current.getName()+"\">"
+current.getName()+"</a></p>");
}
}
pww.println(" </card>");
pww.println("</wml>");
pww.flush();
System.out.flush();
}
}
}
|