public TemplateContext getTemplateContext() { if (templateEngineContext == null) { templateEngineContext = new TemplateContextDefault(staticClassOperatorMap); } return templateEngineContext; }
public boolean exist(String name) { boolean exist = super.exist(name); if (exist) { return true; } Context parentContext = getParent(); if (parentContext != null) { return parentContext.exist(name); } return false; }
public void renderTemplate(Template Template) throws TemplateException { renderTemplate(Template, new TemplateContextDefault(), System.out); }
public <T> T get(String name) { T result = super.get(name); if (result != null) { return result; } Context parentContext = getParent(); if (parentContext != null) { return (T) parentContext.get(name); } return null; }
public void render() throws TemplateException { render(new TemplateContextDefault(), System.out); }
public void renderTemplate(String path) throws TemplateException { renderTemplate(path, new TemplateContextDefault(), System.out); }
private void generate(Template template, Context context, OutputStream writer) { try { if (context instanceof TemplateContext) { templateGenerater.renderTemplate(template, (TemplateContext) context, writer); } else { TemplateContext newContext = new TemplateContextDefault(); newContext.setParent(context); templateGenerater.renderTemplate(template, newContext, writer); } } catch (Exception e) { throw new RuntimeException(e); } }
public Object process(TemplateInterpreter interpreter, TemplateFromContext templateFromContext, TinyTemplateParser.Include_directiveContext parseTree, TemplateContext pageContext, TemplateContext context, TemplateEngineDefault engine, OutputStream outputStream, String fileName) throws Exception { String path = interpreter.interpretTree(engine, templateFromContext, parseTree.expression(), pageContext, context, outputStream, fileName).toString(); if (!path.startsWith("/")) { //如果不是绝对路径 URL url = new URL("file:" + templateFromContext.getPath()); URL newUrl = new URL(url, path); path = newUrl.getPath(); } if (parseTree.hash_map_entry_list() != null) { Map map = (Map) interpreter.interpretTree(engine, templateFromContext, parseTree.hash_map_entry_list(), pageContext, context, outputStream, fileName); TemplateContext newContext = new TemplateContextDefault(map); engine.renderTemplateWithOutLayout(path, newContext, outputStream); } else { engine.renderTemplateWithOutLayout(path, context, outputStream); } // context.put(key,value); return null; } }
public void doExecute(Context context) throws Exception { boolean isPagelet = false; if (path.endsWith(template)) { isPagelet = true; path = path.substring(0, path.length() - template.length()) + templeteWithLayout; } FileObject fileObject = fullContextFileRepository.getFileObject(path); WebContext webContent = null; if (context instanceof WebContext) webContent = (WebContext) context; else return; if (fileObject != null && fileObject.isExist()) { TemplateContext templateContext = new TemplateContextDefault(context.getItemMap()); if (isPagelet) { engine.renderTemplateWithOutLayout(path, templateContext, webContent.getResponse().getOutputStream()); } else { engine.renderTemplate(path, templateContext, webContent.getResponse().getOutputStream()); } return; } else { webContent.getResponse() .sendError(HttpServletResponse.SC_NOT_FOUND); } }
public Object execute(Template template, TemplateContext context, Object... parameters) throws TemplateException { String macroName = parameters[0].toString(); Macro macro = getTemplateEngine().findMacro(macroName, template, context); TemplateContext newTemplateContext = null; newTemplateContext = new TemplateContextDefault(); newTemplateContext.setParent(context); List paraList = new ArrayList(); newTemplateContext.put(parameters[0] + "ParameterList", paraList); for (int i = 1; i < parameters.length; i++) { paraList.add(parameters[i]); } for (int i = 0; i < macro.getParameterNames().size(); i++) { if (i + 1 >= parameters.length) { continue; } newTemplateContext.put(macro.getParameterNames().get(i), parameters[i + 1]); } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); macro.render(template, context, newTemplateContext, byteArrayOutputStream); try { return new String(byteArrayOutputStream.toByteArray(), template.getTemplateEngine().getEncode()); } catch (UnsupportedEncodingException e) { throw new TemplateException(e); } } }
for (int i = layoutPaths.size() - 1; i >= 0; i--) { TemplateContext tempContext = new TemplateContextDefault(); tempContext.setParent(layoutContext); layoutContext = tempContext;
public Object executeRule(Object customObj, String customRule, ScriptContext context) throws ScriptException { TemplateEngine engine = (TemplateEngine) customObj; TemplateRender render = new TemplateRenderDefault(); render.setTemplateEngine(engine); TemplateContext templateContext = new TemplateContextDefault(); templateContext.setParent(context); try { return render.renderTemplateContent(customRule, templateContext); } catch (TemplateException e) { throw new ScriptException( ResourceBundleUtil.getResourceMessage("template", "template.render.error", customRule), e); } }
TemplateContext context = new TemplateContextDefault();
public LuceneConfig getFullTextConfig(String userId, String configId) { LuceneConfig config = getLuceneConfig(configId); if (config == null) { throw new FullTextException(String.format("获取动态配置失败:根据[%s]没有找到对应的动态Lucene配置", configId)); } //原始config不能修改 LuceneConfig newConfig = (LuceneConfig) config.clone(); TemplateContext context = new TemplateContextDefault(); context.put("userId", userId); //目前只需要渲染路径属性 try { String s = templateRender.renderTemplateContent(newConfig.getDirectory(), context); newConfig.setDirectory(s); } catch (TemplateException e) { throw new FullTextException("获取动态配置失败:模板渲染发生异常", e); } return newConfig; }
public void callBlockMacro(TemplateEngineDefault engine, TemplateFromContext templateFromContext, String name, TinyTemplateParser.BlockContext block, TinyTemplateParser.Para_expression_listContext paraList, TemplateContext pageContext, OutputStream outputStream, TemplateContext context) throws Exception { Macro macro = engine.findMacro(name, templateFromContext, context); try { TemplateContext newContext = new TemplateContextDefault(); newContext.setParent(context); if (paraList != null) {