Hello
Could someone point out what I need to change in the code I have so far? I would like to use XML format in a properties file.
The original .properties worked but this will not load the new formatted .properties.
I have an app that loads properties in ModelUtils.java where I access ModelResources.properties in my src
model.res.ModelResources
public static final String RESOURCES = ModelUtils.class.getPackage().getName()
+ ".res.ModelResources";
I would like to change the format on this file to xml.
can this be done by simply changing the structure to XML and load it the same way?
This would allow me the '.' seperated path of
sys.out
run:
RESOURCES: model.res.ModelResources
to use a FileInputStream I think I need seperator "/"
public class ModelUtils {
private static ResourceBundle resources;
public static final String RESOURCES = ModelUtils.class.getPackage().getName()
+ ".res.ModelResources";
private static StudentDAO studentDAO;
private static InstructorDAO instructorDAO;
private static AdminDAO adminDAO;
private static PayeeDAO payeeDAO;
private Properties prop;
private String SUFFIX=".properties";
public static void log(Throwable x) {
Logger.global.log(Level.SEVERE, x.getMessage(), x);
}
//To load the original .properties "not used now"
public static synchronized ResourceBundle getResources() {
if (resources == null) {
try {
resources = ResourceBundle.getBundle(RESOURCES);
} catch (MissingResourceException x) {
log(x);
throw new InternalError(x.getMessage());
}
System.out.println("RESOURCES: "+RESOURCES);
System.out.println("resources: "+resources);
}
return resources;
}
//first thing called from main
public void findXMLResource() throws FileNotFoundException, IOException{
String path=replaceSeparator(RESOURCES);
loadXML(path);
}
public String replaceSeparator(String path){
path = path.replace ('.', '/');
path=path.concat(SUFFIX);
System.out.println("The path sent to loadXML: "+path);
return path;
}
public static void loadXML(String path) throws FileNotFoundException, IOException{
Properties prop=new Properties();
FileInputStream fis=new FileInputStream(path);
prop.loadFromXML(fis);
}
//used to retrieve properties on request.
public String getXMLProperty(String key){
key=prop.getProperty(key);
return key;
}
sys.out
run:
The path sent to loadXML: model/res/ModelResources.properties
Exception in thread "main" java.io.FileNotFoundException: \model\res\ModelResources.properties (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at model.ModelUtils.loadXML(ModelUtils.java:71)
at model.ModelUtils.findXMLResource(ModelUtils.java:57)
at view.Main.main(Main.java:36)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
basic .properties in XML Format I ommitted the majority of the file
# Document : temp_properties.xml
# Created on : May 5, 2010, 1:01 AM
# Author : depot
# Description:
# Purpose of the document follows.
<?xml version"1.0" encoding"UTF-8"?>
<!DOCTYPE properties SYSTEM modelresourcsDTD>
<properties>
<dao>
<JDBCDAO>model.dao.JDBCSchoolofdbDAO</JDBCDAO>
<studentDAO>model.dao.ConnectStudentDAO</studentDAO>
<instructorDAO>model.dao.ConnectPayeeDAO</instructorDAO>
<adminDAO>model.dao.ConnectAdminDAO</adminDAO>
<payeeDAO>model.dao.ConnectPayeeDAO</payeeDAO>
</dao>
</properties>