};
String[] templates = themedir.list(filter);
// go through each .vm file and read in its contents to a ThemeTemplate
String template_name = null;
ThemeTemplate theme_template = null;
for (int i=0; i < templates.length; i++) {
// strip off the .vm part
template_name = templates[i].substring(0, templates[i].length() - 3);
File template_file = new File(themepath + File.separator + templates[i]);
// Continue reading theme even if problem encountered with one file
String msg = "read theme template file ["+template_file+"]";
if(!template_file.exists() && !template_file.canRead()) {
log.error("Couldn't " + msg);
continue;
}
char[] chars = null;
int length;
try {
// FileReader reader = new FileReader(template_file);
chars = new char[(int) template_file.length()];
FileInputStream stream = new FileInputStream(template_file);
InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
length = reader.read(chars);
} catch (Exception noprob) {
log.error("Exception while attempting to " + msg);
if (log.isDebugEnabled()) log.debug(noprob);
continue;
}
// Strip "_" from name to form link
boolean navbar = true;
String template_link = template_name;
if (template_name.startsWith("_") && template_name.length() > 1) {
navbar = false;
template_link = template_link.substring(1);
log.debug("--- " + template_link);
}
String decorator = "_decorator";
if("_decorator".equals(template_name)) {
decorator = null;
}
// construct ThemeTemplate representing this file
// a few restrictions for now:
// - we only allow "velocity" for the template language
// - decorator is always "_decorator" or null
// - all theme templates are considered not hidden
theme_template = new ThemeTemplate(
theme,
theme_name+":"+template_name,
template_name,
template_name,
new String(chars, 0, length),
template_link,
new Date(template_file.lastModified()),
"velocity",
false,
navbar,
decorator);
// add it to the theme
theme.setTemplate(template_name, theme_template);
}
// use the last mod date of the last template file
// as the last mod date of the theme
theme.setLastModified(theme_template.getLastModified());
return theme;
}