Dienstag, 5. Mai 2009
from the 3zlCAP projekt
short example to create XML configuration file:


public class Cap {

String version="1.007d",
subvers="subv",
hostURL="http://192.168.0.1", // trizonia
port="8082",
fileXferDoc="/",
hsUsersDoc="/",
adminUserName="admin",
adminPassw="PPPPP",
operatorName="AnyName",
operatorPassw="yourpassword",
logFileName="caplog.txt"; // full path ?


public String getVersion(){
return(version+"."+subvers);
}
public String gethostURL(){
return (hostURL);
}
public void sethostURL(String url){
hostURL=url;
}



public void setXML(){
String testString="TEST";

XMLConfiguration xml_config = new XMLConfiguration();
xml_config.setRootElementName("Cap");
xml_config.setProperty("Class", this.getClass().getName());
xml_config.setProperty("logFileName", testString);
xml_config.setProperty("version", getVersion());
xml_config.setProperty("hostURL", gethostURL());

try {
String file_name="cap.XML";
xml_config.save(new File(file_name));
} catch (ConfigurationException ex) {
Logger.getLogger(Cap.class.getName()).log(Level.SEVERE, null, ex);
}
/*
* this creates the file "cap.XML" holding following

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

desktopapplication2.Cap
TEST
1.007d.subv
http://192.168.1.11


*/
}

}


*fin




Mittwoch, 29. April 2009
http://blog.dotkam.com/2007/06/09/convert-date-to-string-in-java/
import java.util.Date;
import java.text.SimpleDateFormat;
... ... ... ...

public void testConvertDateToString() {

// Allocates a Date object and initializes it so that it represents the time
// at which it was allocated, measured to the nearest millisecond.
Date dateNow = new Date ();

SimpleDateFormat dateformatYYYYMMDD = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat dateformatMMDDYYYY = new SimpleDateFormat("MMddyyyy");

StringBuilder nowYYYYMMDD = new StringBuilder( dateformatYYYYMMDD.format( dateNow ) );
StringBuilder nowMMDDYYYY = new StringBuilder( dateformatMMDDYYYY.format( dateNow ) );

System.out.println( "DEBUG: Today in YYYYMMDD: '" + nowYYYYMMDD + "'");
System.out.println( "DEBUG: Today in MMDDYYYY: '" + nowMMDDYYYY + "'");

}