Utility functions
1. How to load a resource like (1) XML File (2) Properties file, dynamically in a web application at runtime?
(a) DocumentBuilder builder = factory.newDocumentBuilder();
InputStream is = this.getClass().getResourceAsStream("ABCXMLFile.xml");
doc = builder.parse(is);
(b) Properties p = new Properties();
InputStream is = this.getClass().getResourceAsStream("log4j.properties");
p.load(is);
PropertyConfigurator.configure(p);
2. Code to convert boolean (‘Y’/’N’) value to String (‘Yes’/’No’) value.
public static String booleanToString(String booleanCharacter)
{
String returnStringValue = null;
if(booleanCharacter.compareToIgnoreCase("Y") == 0) {
returnStringValue = "Yes";
} else{
returnStringValue = "No";
}
return returnStringValue;
}
3. Code to convert String (‘Yes’/’No’) value to boolean (‘Y’/’N’) value.
public static String stringToBoolean(String booleanString)
{
String returnBooleanValue = null;
if(booleanString.compareToIgnoreCase("Yes") == 0) {
returnBooleanValue = "Y";
} else {
returnBooleanValue = "N";
}
return returnBooleanValue;
}


