/** * Constructs a new {@link TemplateEngine} object, and initializes it. This * constructor will throw a {@link RuntimeException} if initializing fails. * * @param path The path containing all the templates. * @param executor */ public TemplateEngine(Path path, ExecutorService executor) { this.executor = executor; try { this.path = path; this.modificationTimes = Maps.newHashMap(); this.engine = new VelocityEngine(); engine.setProperty("resource.loader", "string"); engine.setProperty("runtime.log.logsystem.class", getPath(NullLogChute.class)); engine.setProperty("string.resource.loader.class", getPath(StringResourceLoader.class)); engine.setProperty("string.resource.loader.description", "Velocity StringResource loader"); engine.setProperty("string.resource.loader.repository.class", getPath(StringResourceRepositoryImpl.class)); engine.init(); updateTemplates(); } catch (Exception e) { LOG.error(e.getLocalizedMessage(), e); throw new DevHubException("Could not initialize the TemplateEngine", e); } }
private StringResourceRepository initStringResourceRepository(Map<String, String> pathToTempalteMapping) throws IOException { StringResourceRepository result = new StringResourceRepositoryImpl(); StringResourceLoader.setRepository(StringResourceLoader.REPOSITORY_NAME_DEFAULT, result); registerResource(result, RuntimeConstants.VM_LIBRARY_DEFAULT, RuntimeConstants.VM_LIBRARY_DEFAULT); for (Map.Entry<String, String> pathToTempalteMappingItem : pathToTempalteMapping.entrySet()) { registerResource(result, pathToTempalteMappingItem.getKey(), pathToTempalteMappingItem.getValue()); } return result; }
public PnResourceLoader() { repo = new StringResourceRepositoryImpl(); StringResourceLoader.setRepository(REPOSITORY_NAME_DEFAULT, repo); }