use of org.walkmod.walkers.ParseException in project walkmod-core by walkmod.
the class DefaultTemplateVisitor method visit.
public synchronized void visit(Object node, VisitorContext context) throws Exception {
if (rootLabel == null) {
setRootLabel("cu");
}
if (propertiesFile == null) {
setProperties("template.properties");
}
context.put(getRootLabel(), node);
if (templateEngine == null) {
Object bean = context.getBean("org.walkmod.templates.groovy.GroovyTemplateEngine", null);
if (bean != null && bean instanceof TemplateEngine) {
templateEngine = (TemplateEngine) bean;
log.info("Applying [groovy] as a default template engine");
} else {
throw new WalkModException("Template engine not found");
}
}
templateEngine.initialize(context, node);
if (templateFiles != null && templates != null && templateFiles.size() == templates.size()) {
for (File template : templateFiles) {
String templateResult = templateEngine.applyTemplate(template, propertiesFile);
Object producedNode = null;
currentTemplate = template;
if (parser != null) {
try {
producedNode = parser.parse(templateResult, true);
} catch (ParseException e) {
log.warn("Error parsing the template " + template.getAbsolutePath() + ". Dumping contents..");
doPlainOutput(templateResult, context);
}
} else {
doPlainOutput(templateResult, context);
}
if (producedNode != null) {
log.debug("Template successfuly parsed");
context.addResultNode(producedNode);
}
}
} else {
if (!missingTemplates.isEmpty()) {
for (String missing : missingTemplates) {
log.error("The template " + missing + " is missing");
}
}
throw new WalkModException("There are missing or unexitent templates.");
}
}
Aggregations