/** * @return The template file name this directive was defined in, or null if not * defined in a file. */ public String getTemplateName() { return template.getName(); }
public String getTemplateName() { return template.getName(); }
public String getName() { if (directive != null) { return directive.getName(); } if (template != null) { return template.getName(); } return null; }
public String getTemplate() { if (directive != null) { return directive.getTemplateName(); } if (template != null) { return template.getName(); } return null; }
public String getTemplate() { if (directive != null) { return directive.getTemplateName(); } if (template != null) { return template.getName(); } return null; }
@Override public Optional<Template> getTemplate(String name) { try { Optional<Template> t = Optional.of(velocityEngine.getTemplate(name)); if (t.isPresent()) { registeredTemplates.add(t.get().getName()); } return t; } catch (ResourceNotFoundException e) { return Optional.empty(); } catch (ParseErrorException e) { //WARN!!! return Optional.empty(); } }
public String getName() { if (directive != null) { return directive.getName(); } if (template != null) { return template.getName(); } return null; }
public void generate(Properties context, File outputFile) throws Exception { VelocityContext vcontext = new VelocityContext(); // Note: properties that contain dots will not be properly parsed by // Velocity. Should we replace dots with underscores ? addPropertiesToContext(System.getProperties(), vcontext); addPropertiesToContext(mavenProject.getProperties(), vcontext); addPropertiesToContext(context, vcontext); vcontext.put("project", mavenProject.getModel()); vcontext.put("outputFile", outputFile.getName()); FileWriter writer = new FileWriter(outputFile); try { velocityTemplate.merge(vcontext, writer); writer.flush(); } catch (Exception e) { throw new Exception( "Could not generate the template " + velocityTemplate.getName() + ": " + e.getMessage(), e); } finally { writer.close(); } }
/** * Applies a template to an object. * * @param template the template * @param source the source object */ public <T> void merge(final Template<T> template, final T source) { // Prepare the velocity template and context final org.apache.velocity.Template velocityTemplate = velocityEngine.getTemplate(template.getVelocityTemplate()); final VelocityContext velocityContext = buildVelocityContext(source); // Prepare the macro libraries final List<String> macroLibraries = new ArrayList<>(); macroLibraries.add(macroLibrary.getName()); LOGGER.debug("Generating file using template " + velocityTemplate.getName()); // Merge and write the template final StringWriter writer = new StringWriter(); velocityTemplate.merge(velocityContext, writer, macroLibraries); templateWriter.write(context, template, source, writer.toString()); }
public void generate(Properties context, Writer writer) throws Exception { VelocityContext vcontext = new VelocityContext(); // Note: properties that contain dots will not be properly parsed by // Velocity. Should we replace dots with underscores ? addPropertiesToContext(System.getProperties(), vcontext); addPropertiesToContext(mavenProject.getProperties(), vcontext); addPropertiesToContext(context, vcontext); vcontext.put("project", mavenProject.getModel()); try { velocityTemplate.merge(vcontext, writer); writer.flush(); } catch (Exception e) { throw new Exception( "Could not generate the template " + velocityTemplate.getName() + ": " + e.getMessage(), e); } finally { writer.close(); } }
public void generate(Properties context, File outputFile) throws Exception { VelocityContext vcontext = new VelocityContext(); // Note: properties that contain dots will not be properly parsed by // Velocity. Should we replace dots with underscores ? addPropertiesToContext(System.getProperties(), vcontext); addPropertiesToContext(mavenProject.getProperties(), vcontext); addPropertiesToContext(context, vcontext); vcontext.put("project", mavenProject.getModel()); vcontext.put("outputFile", outputFile.getName()); FileWriter writer = new FileWriter(outputFile); try { velocityTemplate.merge(vcontext, writer); writer.flush(); } catch (Exception e) { throw new Exception( "Could not generate the template " + velocityTemplate.getName() + ": " + e.getMessage(), e); } finally { writer.close(); } }
public void generate(Properties context, Writer writer) throws Exception { VelocityContext vcontext = new VelocityContext(); // Note: properties that contain dots will not be properly parsed by // Velocity. Should we replace dots with underscores ? addPropertiesToContext(System.getProperties(), vcontext); addPropertiesToContext(mavenProject.getProperties(), vcontext); addPropertiesToContext(context, vcontext); vcontext.put("project", mavenProject.getModel()); try { velocityTemplate.merge(vcontext, writer); writer.flush(); } catch (Exception e) { throw new Exception( "Could not generate the template " + velocityTemplate.getName() + ": " + e.getMessage(), e); } finally { writer.close(); } }
if( macroLibVec.contains(definingTemplate.getName()) ) return true;
/** * Creates the method body * * @param context * @return */ protected String createMethodBody(VelocityContext context) { context.put("inflector", Inflector.class); context.put("path", resourcePath.getNodePath()); context.put("param_names", getRoutePattern().getParameterNames()); Template template = getTemplate(); StringWriter writer = new StringWriter(); logger.debug("Creating the method body with context {} and template {} for the resource path {} and method {}", context, template.getName(), resourcePath, getHttpMethod()); template.merge(context, writer); return writer.toString(); }
throw new VelocityException("Null AST for "+vmName+" in " + definingTemplate.getName()); MacroEntry me = new MacroEntry(vmName, macroBody, macroArgs, definingTemplate.getName(), rsvc); libraries.put(definingTemplate.getName(), definingTemplate); isLib = libraries.containsKey(definingTemplate.getName());
log.error("{}: {}", template.getName(), mee.getMessage(), mee); throw mee; log.error("{}: {}", currentTemplate.getName(), pe.getMessage()); throw new TemplateParseException (pe.currentToken, pe.expectedTokenSequences, pe.tokenImage, currentTemplate.getName()); String msg = template.getName() + ": " + e.getMessage(); log.error(msg, e); throw new VelocityException(msg, e);
log.debug("Applying decorator " + velocityDecorator.getName());
+getName(), e); throw errorCondition;
+getName(), e); throw errorCondition;