@Override protected void visit(Element element, ExecutionContext executionContext) { // First thing we do is clone the template for this transformation... // Commented out as due to https://github.com/antlr/stringtemplate4/issues/100 // ST transform = new ST(template); ST transform = templateGroupDir.getInstanceOf(templateName); Map<String, Object> beans = executionContext.getBeanContext().getBeanMap(); // Set the document data beans on the template and apply it... for (Map.Entry<String, Object> entry : beans.entrySet()) { transform.add(entry.getKey(), entry.getValue()); } String templatingResult = transform.render().trim(); Node resultNode = TextSerializationUnit.createTextElement(element, templatingResult); // Process the templating action, supplying the templating result... processTemplateAction(element, resultNode, executionContext); }
@Override protected void visit(Element element, ExecutionContext executionContext) { // First thing we do is clone the template for this transformation... // Commented out as due to https://github.com/antlr/stringtemplate4/issues/100 // ST transform = new ST(template); ST transform = templateGroupDir.getInstanceOf(templateName); Map<String, Object> beans = executionContext.getBeanContext().getBeanMap(); // Set the document data beans on the template and apply it... for (Map.Entry<String, Object> entry : beans.entrySet()) { transform.add(entry.getKey(), entry.getValue()); } String templatingResult = transform.render().trim(); Node resultNode = TextSerializationUnit.createTextElement(element, templatingResult); // Process the templating action, supplying the templating result... processTemplateAction(element, resultNode, executionContext); }
private void applyTemplate(Template template, Element element, ExecutionContext executionContext) throws SmooksException { // Apply the template... String templatingResult; try { Writer writer = new StringWriter(); Map<String, Object> model = FreeMarkerUtils.getMergedModel(executionContext); template.process(model, writer); writer.flush(); templatingResult = writer.toString(); } catch (TemplateException e) { throw new SmooksException("Failed to apply FreeMarker template to fragment '" + DomUtils.getXPath(element) + "'. Resource: " + config, e); } catch (IOException e) { throw new SmooksException("Failed to apply FreeMarker template to fragment '" + DomUtils.getXPath(element) + "'. Resource: " + config, e); } // Create the replacement DOM text node containing the applied template... Node resultNode = TextSerializationUnit.createTextElement(element, templatingResult); // Process the templating action, supplying the templating result... processTemplateAction(element, resultNode, executionContext); }
private void applyTemplate(Template template, Element element, ExecutionContext executionContext) throws SmooksException { // Apply the template... String templatingResult; try { Writer writer = new StringWriter(); Map<String, Object> model = FreeMarkerUtils.getMergedModel(executionContext); template.process(model, writer); writer.flush(); templatingResult = writer.toString(); } catch (TemplateException e) { throw new SmooksException("Failed to apply FreeMarker template to fragment '" + DomUtils.getXPath(element) + "'. Resource: " + config, e); } catch (IOException e) { throw new SmooksException("Failed to apply FreeMarker template to fragment '" + DomUtils.getXPath(element) + "'. Resource: " + config, e); } // Create the replacement DOM text node containing the applied template... Node resultNode = TextSerializationUnit.createTextElement(element, templatingResult); // Process the templating action, supplying the templating result... processTemplateAction(element, resultNode, executionContext); }
@Override protected void visit(Element element, ExecutionContext executionContext) { // First thing we do is clone the template for this transformation... StringTemplate thisTransTemplate = template.getInstanceOf(); Map<String, Object> beans = executionContext.getBeanContext().getBeanMap(); String templatingResult; Node resultNode; // Set the document data beans on the template and apply it... thisTransTemplate.setAttributes(beans); templatingResult = thisTransTemplate.toString(); resultNode = TextSerializationUnit.createTextElement(element, templatingResult); // Process the templating action, supplying the templating result... processTemplateAction(element, resultNode, executionContext); }
@Override protected void visit(Element element, ExecutionContext executionContext) { // First thing we do is clone the template for this transformation... StringTemplate thisTransTemplate = template.getInstanceOf(); Map<String, Object> beans = executionContext.getBeanContext().getBeanMap(); String templatingResult; Node resultNode; // Set the document data beans on the template and apply it... thisTransTemplate.setAttributes(beans); templatingResult = thisTransTemplate.toString(); resultNode = TextSerializationUnit.createTextElement(element, templatingResult); // Process the templating action, supplying the templating result... processTemplateAction(element, resultNode, executionContext); }