private void customize(boolean verbose) { if (engine.resourceExists(CUSTOM_TEMPLATE)) { if (engine.getTemplate(CUSTOM_TEMPLATE).process()) { if (verbose) { logger.info("Successfully processed: {}", CUSTOM_TEMPLATE); } } else { logger.warn("Couldn't process: {}", CUSTOM_TEMPLATE); } } else if (verbose) { logger.warn( "The templates customization file '{}' wasn't found on classpath", CUSTOM_TEMPLATE); } }
/** * Returns a Velocity Resource which is a Template for the given SQL. */ public Resource getResource(String resourceName, int resourceType, String encoding) throws ResourceNotFoundException, ParseErrorException, Exception { synchronized (templateCache) { Template resource = templateCache.get(resourceName); if (resource == null) { resource = new Template(); resource.setRuntimeServices(rsvc); resource.setResourceLoader(this); resource.setName(resourceName); resource.setEncoding(encoding); resource.process(); templateCache.put(resourceName, resource); } return resource; } }
/** * Returns a Velocity Resource which is a Template for the given SQL. */ public Resource getResource(String resourceName, int resourceType, String encoding) throws ResourceNotFoundException, ParseErrorException, Exception { synchronized (templateCache) { Template resource = (Template) templateCache.get(resourceName); if (resource == null) { resource = new Template(); resource.setRuntimeServices(rsvc); resource.setResourceLoader(this); resource.setName(resourceName); resource.setEncoding(encoding); resource.process(); templateCache.put(resourceName, resource); } return resource; } }
/** * Returns a Velocity Resource which is a Template for the given SQL. */ public Resource getResource(String resourceName, int resourceType, String encoding) throws ResourceNotFoundException, ParseErrorException, Exception { synchronized (templateCache) { Template resource = (Template) templateCache.get(resourceName); if (resource == null) { resource = new Template(); resource.setRuntimeServices(rsvc); resource.setResourceLoader(this); resource.setName(resourceName); resource.setEncoding(encoding); resource.process(); templateCache.put(resourceName, resource); } return resource; } }
this.template.setResourceLoader(new RepresentationResourceLoader( templateRepresentation)); this.template.process(); this.templateName = null;
this.template.setResourceLoader(new RepresentationResourceLoader( templateRepresentation)); this.template.process(); this.templateName = null;
/** * Constructor based on a Velocity 'encoded' representation. * * @param templateRepresentation * The representation to 'decode'. * @param mediaType * The representation's media type. * @throws IOException * @throws ParseErrorException * @throws ResourceNotFoundException */ public TemplateRepresentation(Representation templateRepresentation, MediaType mediaType) throws ResourceNotFoundException, ParseErrorException, IOException { super(mediaType); this.engine = null; this.template = new Template(); CharacterSet charSet = (templateRepresentation.getCharacterSet() != null) ? templateRepresentation .getCharacterSet() : CharacterSet.DEFAULT; this.template.setEncoding(charSet.getName()); this.template.setLastModified((templateRepresentation .getModificationDate() == null) ? new Date().getTime() : templateRepresentation.getModificationDate().getTime()); this.template.setName("org.restlet.resource.representation"); this.template.setRuntimeServices(RuntimeSingleton.getRuntimeServices()); this.template.setResourceLoader(new RepresentationResourceLoader( templateRepresentation)); this.template.process(); this.templateName = null; }
/** * Compile a template * @param script template source * @return compiled template * @throws ScriptException */ public CompiledScript compile(Reader script) throws ScriptException { initVelocityEngine(null); ResourceLoader resourceLoader = new SingleResourceReader(script); Template template = new Template(); template.setRuntimeServices(velocityEngine); template.setResourceLoader(resourceLoader); try { template.process(); } catch(Exception e) { // CB TODO - exception may have line/col informations, that ScriptException can exploit throw new ScriptException(e); } return new VelocityCompiledScript(this, template); }
StringWriter writer = new StringWriter(); velocityTemplate.merge(context, writer); velocityTemplate.process(); Assert.assertEquals(resultString, writer.toString());
this.template.setResourceLoader(new RepresentationResourceLoader( templateRepresentation)); this.template.process(); this.templateName = null;