/** * Get template. * * @param name - template name * @return template instance * @throws IOException - If an I/O error occurs * @throws ParseException - If the template cannot be parsed * @see #getEngine() */ public Template getTemplate(String name) throws IOException, ParseException { return getTemplate(name, null, null, null); }
/** * Tests whether the resource denoted by this abstract pathname exists. * * @param name - template name * @return exists * @see #getEngine() */ public boolean hasResource(String name) { return hasResource(name, null); }
/** * Get template engine singleton. * * @param configPath - config path * @return template engine */ public static Engine getEngine(String configPath) { return getEngine(configPath, null); }
try { if (WebEngine.getEngine().hasResource(templateName)) { template = WebEngine.getEngine().getTemplate(templateName); break;
/** * Get config value. * * @param key - config key * @return config value * @see #getEngine() */ public Object getProperty(String key) { return getProperty(key, Object.class); }
private String findMessageByLocale(String key, Locale locale) { String file = messageBasename + (locale == null ? "" : "_" + locale) + messageSuffix; EncodingProperties properties = messageCache.get(file); if ((properties == null || reloadable) && engine.hasResource(file)) { if (properties == null) { properties = new EncodingProperties(); Resource resource = engine.getResource(file); if (properties.getLastModified() < resource.getLastModified()) { String encoding = (StringUtils.isEmpty(messageEncoding) ? "UTF-8" : messageEncoding);
public HttlScriptEngineFactory() { String config = System.getProperty("httl.properties"); this.engine = StringUtils.isEmpty(config) ? Engine.getEngine() : Engine.getEngine(config); List<String> extensions = new ArrayList<String>(); extensions.add("httl"); List<String> mimeTypes = new ArrayList<String>(); mimeTypes.add("text/httl"); mimeTypes.add("text/html"); for (String suffix : engine.getProperty("template.suffix", new String[] { ".httl" })) { if (suffix.startsWith(".")) { suffix = suffix.substring(1); } if (! "httl".equals(suffix)) { extensions.add(suffix); } if (! "httl".equals(suffix) && ! "html".equals(suffix)) { mimeTypes.add("text/" + suffix); } } this.extensions = Collections.unmodifiableList(extensions); this.mimeTypes = Collections.unmodifiableList(mimeTypes); }
/** * Parse string template. * * @param source - template source * @return template instance * @throws ParseException - If the template cannot be parsed * @see #getEngine() */ public Template parseTemplate(String source) throws ParseException { return parseTemplate(source, null); }
private static void logConfigPath(Engine engine, ServletContext servletContext, String path) { if (engine != null && servletContext != null && path != null) { Logger logger = engine.getProperty("logger", Logger.class); if (logger != null && logger.isInfoEnabled()) { String name = engine.getName(); try { if (name != null && name.startsWith("/") && servletContext.getResource(name) != null) { logger.info("Load httl config form " + servletContext.getRealPath(name) + " in webapp."); } } catch (IOException e) { // ignore } } } }
/** * Get config value. * * @see #getEngine() * @param key - config key * @return config value */ public Object getProperty(String key) { return getProperty(key, Object.class); }
private String findMessageByLocale(String key, Locale locale) { String file = messageBasename + (locale == null ? "" : "_" + locale) + messageSuffix; EncodingProperties properties = messageCache.get(file); if ((properties == null || reloadable) && engine.hasResource(file)) { if (properties == null) { properties = new EncodingProperties(); Resource resource = engine.getResource(file); if (properties.getLastModified() < resource.getLastModified()) { String encoding = (StringUtils.isEmpty(messageEncoding) ? "UTF-8" : messageEncoding);
/** * Parse string template. * * @see #getEngine() * @param source - template source * @return template instance * @throws ParseException - If the template cannot be parsed */ public Template parseTemplate(String source) throws ParseException { return parseTemplate(source, null); }
private static void logConfigPath(Engine engine, ServletContext servletContext, String path) { if (engine != null && servletContext != null && path != null) { Logger logger = engine.getProperty("logger", Logger.class); if (logger != null && logger.isInfoEnabled()) { String name = engine.getName(); try { if (name != null && name.startsWith("/") && servletContext.getResource(name) != null) { logger.info("Load httl config form " + servletContext.getRealPath(name) + " in webapp."); } } catch (IOException e) { // ignore } } } }
/** * Get template. * * @see #getEngine() * @param name - template name * @return template instance * @throws IOException - If an I/O error occurs * @throws ParseException - If the template cannot be parsed */ public Template getTemplate(String name) throws IOException, ParseException { return getTemplate(name, null, null, null); }
/** * Tests whether the resource denoted by this abstract pathname exists. * * @see #getEngine() * @param name - template name * @return exists */ public boolean hasResource(String name) { return hasResource(name, null); }
public Object getParameter(String key) { return engine.getProperty(key); }
/** * Get template engine singleton. * * @param configPath - config path * @return template engine */ public static Engine getEngine(String configPath) { return getEngine(configPath, null); }
public CompiledScript compile(String script) throws ScriptException { try { return new HttlScript(this, engine.parseTemplate(script)); } catch (ParseException e) { throw new ScriptException(e.getMessage()); } }
/** * Get template. * * @param name - template name * @param encoding - template encoding * @return template instance * @throws IOException - If an I/O error occurs * @throws ParseException - If the template cannot be parsed * @see #getEngine() */ public Template getTemplate(String name, String encoding, Object args) throws IOException, ParseException { return getTemplate(name, null, encoding, args); }
public boolean exists(String templateName) { if (WebEngine.getServletContext() == null) { return templateName.endsWith(getTemplateSuffix()); } return WebEngine.getEngine().hasResource(getTemplatePath(templateName)); }