in jelly-tags/util/src/main/java/org/apache/commons/jelly/tags/util/PropertiesTag.java [47:101]
public void doTag(final XMLOutput output) throws JellyTagException {
if (file == null && uri == null) {
throw new JellyTagException("This tag must define a 'file' or 'uri' attribute");
}
InputStream is = null;
if (file != null) {
File f = new File(file);
if (!f.exists()) {
throw new JellyTagException("file: " + file + " does not exist!");
}
try {
is = new FileInputStream(f);
} catch (FileNotFoundException e) {
throw new JellyTagException(e);
}
}
else {
is = context.getResourceAsStream(uri);
if (is == null) {
throw new JellyTagException( "Could not find: " + uri );
}
}
Properties props = new Properties();
try {
props.load(is);
} catch (IOException e) {
throw new JellyTagException("properties tag could not load from file",e);
}
finally {
if (is != null) {
try {
is.close();
} catch (IOException ioe) {
;
}
}
}
if (var != null) {
context.setVariable(var, props);
}
else {
Enumeration propsEnum = props.propertyNames();
while (propsEnum.hasMoreElements()) {
String key = (String) propsEnum.nextElement();
String value = props.getProperty(key);
// @todo we should parse the value in case its an Expression
context.setVariable(key, value);
}
}
}