/** * A hook that Jython uses. */ public void __setitem__(String key, Object o) throws TemplateException { setGlobalVariable(key, getObjectWrapper().wrap(o)); }
static FreeMarkerPageContext getCurrentPageContext() throws TemplateModelException { Environment env = Environment.getCurrentEnvironment(); TemplateModel pageContextModel = env.getGlobalVariable(PageContext.PAGECONTEXT); if (pageContextModel instanceof FreeMarkerPageContext) { return (FreeMarkerPageContext) pageContextModel; } try { FreeMarkerPageContext pageContext = (FreeMarkerPageContext) pageContextImpl.newInstance(); env.setGlobalVariable(PageContext.PAGECONTEXT, pageContext); return pageContext; } catch (IllegalAccessException e) { throw new IllegalAccessError(e.getMessage()); } catch (InstantiationException e) { throw new UndeclaredThrowableException(e); } }
@Override public void close() throws IOException { SimpleScalar result = new SimpleScalar(buf.toString()); try { if (localVar) { env.setLocalVariable(varName, result); } else if (globalVar) { env.setGlobalVariable(varName, result); } else { if (nsModel == null) { env.setVariable(varName, result); } else { ((Environment.Namespace) nsModel).put(varName, result); } } } catch (java.lang.IllegalStateException ise) { // if somebody uses 'local' outside a macro throw new IOException("Could not set variable " + varName + ": " + ise.getMessage()); } } };
@Override public void setAttribute(String name, Object value, int scope) { switch(scope) { case PAGE_SCOPE: { try { environment.setGlobalVariable(name, wrapper.wrap(value)); break; } catch (TemplateModelException e) { throw new UndeclaredThrowableException(e); } } case REQUEST_SCOPE: { getRequest().setAttribute(name, value); break; } case SESSION_SCOPE: { getSession(true).setAttribute(name, value); break; } case APPLICATION_SCOPE: { getServletContext().setAttribute(name, value); break; } default: { throw new IllegalArgumentException("Invalid scope " + scope); } } }
@Override TemplateElement[] accept(Environment env) throws TemplateException, IOException { TemplateElement[] children = getChildBuffer(); TemplateModel value; if (children != null) { StringWriter out = new StringWriter(); env.visit(children, out); value = capturedStringToModel(out.toString()); } else { value = capturedStringToModel(""); } if (namespaceExp != null) { ((Environment.Namespace) namespaceExp.eval(env)).put(varName, value); } else if (scope == Assignment.NAMESPACE) { env.setVariable(varName, value); } else if (scope == Assignment.GLOBAL) { env.setGlobalVariable(varName, value); } else if (scope == Assignment.LOCAL) { env.setLocalVariable(varName, value); } else { throw new BugException("Unhandled scope"); } return null; }
/** * A hook that Jython uses. */ public void __setitem__(String key, Object o) throws TemplateException { setGlobalVariable(key, getObjectWrapper().wrap(o)); }
/** * A hook that Jython uses. */ public void __setitem__(String key, Object o) throws TemplateException { setGlobalVariable(key, getObjectWrapper().wrap(o)); }
/** * A hook that Jython uses. */ public void __setitem__(String key, Object o) throws TemplateException { setGlobalVariable(key, getObjectWrapper().wrap(o)); }
static FreeMarkerPageContext getCurrentPageContext() throws TemplateModelException { Environment env = Environment.getCurrentEnvironment(); TemplateModel pageContextModel = env.getGlobalVariable(PageContext.PAGECONTEXT); if (pageContextModel instanceof FreeMarkerPageContext) { return (FreeMarkerPageContext) pageContextModel; } try { FreeMarkerPageContext pageContext = (FreeMarkerPageContext) pageContextImpl.newInstance(); env.setGlobalVariable(PageContext.PAGECONTEXT, pageContext); return pageContext; } catch (IllegalAccessException e) { throw new IllegalAccessError(e.getMessage()); } catch (InstantiationException e) { throw new UndeclaredThrowableException(e); } }
static FreeMarkerPageContext getCurrentPageContext() throws TemplateModelException { Environment env = Environment.getCurrentEnvironment(); TemplateModel pageContextModel = env.getGlobalVariable(PageContext.PAGECONTEXT); if (pageContextModel instanceof FreeMarkerPageContext) { return (FreeMarkerPageContext) pageContextModel; } try { FreeMarkerPageContext pageContext = (FreeMarkerPageContext) pageContextImpl.newInstance(); env.setGlobalVariable(PageContext.PAGECONTEXT, pageContext); return pageContext; } catch (IllegalAccessException e) { throw new IllegalAccessError(e.getMessage()); } catch (InstantiationException e) { throw new UndeclaredThrowableException(e); } }
static FreeMarkerPageContext getCurrentPageContext() throws TemplateModelException { Environment env = Environment.getCurrentEnvironment(); TemplateModel pageContextModel = env.getGlobalVariable(PageContext.PAGECONTEXT); if(pageContextModel instanceof FreeMarkerPageContext) { return (FreeMarkerPageContext)pageContextModel; } try { FreeMarkerPageContext pageContext = (FreeMarkerPageContext)constructor.invoke(null, (Object[]) null); env.setGlobalVariable(PageContext.PAGECONTEXT, pageContext); return pageContext; } catch(IllegalAccessException e) { throw new IllegalAccessError(e.getMessage()); } catch(InvocationTargetException e) { if(e.getTargetException() instanceof TemplateModelException) { throw (TemplateModelException)e.getTargetException(); } throw new UndeclaredThrowableException(e); } }
/** * Get the data from a DataGetter, and store it in global variables in the * Freemarker environment. */ private static void applyDataGetter(DataGetter dg, Environment env, Map<String, Object> dataMap) throws TemplateModelException { Map<String, Object> moreData = dg.getData(dataMap); ObjectWrapper wrapper = env.getObjectWrapper(); if (moreData != null) { for (String key : moreData.keySet()) { Object value = moreData.get(key); env.setGlobalVariable(key, wrapper.wrap(value)); log.debug("Stored in environment: '" + key + "' = '" + value + "'"); } } }
public void close() throws IOException { SimpleScalar result = new SimpleScalar(buf.toString()); try { if (localVar) { env.setLocalVariable(varName, result); } else if (globalVar) { env.setGlobalVariable(varName, result); } else { if (nsModel == null) { env.setVariable(varName, result); } else { ((Environment.Namespace) nsModel).put(varName, result); } } } catch (java.lang.IllegalStateException ise) { // if somebody uses 'local' outside a macro throw new IOException("Could not set variable " + varName + ": " + ise.getMessage()); } } };
@Override public void close() throws IOException { SimpleScalar result = new SimpleScalar(buf.toString()); try { if (localVar) { env.setLocalVariable(varName, result); } else if (globalVar) { env.setGlobalVariable(varName, result); } else { if (nsModel == null) { env.setVariable(varName, result); } else { ((Environment.Namespace) nsModel).put(varName, result); } } } catch (java.lang.IllegalStateException ise) { // if somebody uses 'local' outside a macro throw new IOException("Could not set variable " + varName + ": " + ise.getMessage()); } } };
@Override public void close() throws IOException { SimpleScalar result = new SimpleScalar(buf.toString()); try { if (localVar) { env.setLocalVariable(varName, result); } else if (globalVar) { env.setGlobalVariable(varName, result); } else { if (nsModel == null) { env.setVariable(varName, result); } else { ((Environment.Namespace) nsModel).put(varName, result); } } } catch (java.lang.IllegalStateException ise) { // if somebody uses 'local' outside a macro throw new IOException("Could not set variable " + varName + ": " + ise.getMessage()); } } };
@Override public void setAttribute(String name, Object value, int scope) { switch(scope) { case PAGE_SCOPE: { try { environment.setGlobalVariable(name, wrapper.wrap(value)); break; } catch (TemplateModelException e) { throw new UndeclaredThrowableException(e); } } case REQUEST_SCOPE: { getRequest().setAttribute(name, value); break; } case SESSION_SCOPE: { getSession(true).setAttribute(name, value); break; } case APPLICATION_SCOPE: { getServletContext().setAttribute(name, value); break; } default: { throw new IllegalArgumentException("Invalid scope " + scope); } } }
public void close() { SimpleScalar result = new SimpleScalar(toString()); switch(scope) { case Assignment.NAMESPACE: { if(fnsModel != null) { fnsModel.put(varName, result); } else { env.setVariable(varName, result); } break; } case Assignment.LOCAL: { env.setLocalVariable(varName, result); break; } case Assignment.GLOBAL: { env.setGlobalVariable(varName, result); break; } } } };
@Override TemplateElement[] accept(Environment env) throws TemplateException, IOException { TemplateElement[] children = getChildBuffer(); TemplateModel value; if (children != null) { StringWriter out = new StringWriter(); env.visit(children, out); value = capturedStringToModel(out.toString()); } else { value = capturedStringToModel(""); } if (namespaceExp != null) { ((Environment.Namespace) namespaceExp.eval(env)).put(varName, value); } else if (scope == Assignment.NAMESPACE) { env.setVariable(varName, value); } else if (scope == Assignment.GLOBAL) { env.setGlobalVariable(varName, value); } else if (scope == Assignment.LOCAL) { env.setLocalVariable(varName, value); } else { throw new BugException("Unhandled scope"); } return null; }
@Override TemplateElement[] accept(Environment env) throws TemplateException, IOException { TemplateElement[] children = getChildBuffer(); TemplateModel value; if (children != null) { StringWriter out = new StringWriter(); env.visit(children, out); value = capturedStringToModel(out.toString()); } else { value = capturedStringToModel(""); } if (namespaceExp != null) { ((Environment.Namespace) namespaceExp.eval(env)).put(varName, value); } else if (scope == Assignment.NAMESPACE) { env.setVariable(varName, value); } else if (scope == Assignment.GLOBAL) { env.setGlobalVariable(varName, value); } else if (scope == Assignment.LOCAL) { env.setLocalVariable(varName, value); } else { throw new BugException("Unhandled scope"); } return null; }
void accept(Environment env) throws TemplateException, IOException { if (nestedBlock != null) { env.visit(nestedBlock, new CaptureOutput(env), null); } else { TemplateModel value = new SimpleScalar(""); if (namespaceExp != null) { Environment.Namespace ns = (Environment.Namespace) namespaceExp.getAsTemplateModel(env); ns.put(varName, value); } else if (scope == Assignment.NAMESPACE) { env.setVariable(varName, value); } else if (scope == Assignment.GLOBAL) { env.setGlobalVariable(varName, value); } else if (scope == Assignment.LOCAL) { env.setLocalVariable(varName, value); } } }