private Map<String, TemplateModel> reduce() throws TemplateModelException { Map<String, TemplateModel> reduceMap = new LinkedHashMap<>(); ObjectWrapper objectWrapper = environment.getObjectWrapper(); Namespace namespace = environment.getCurrentNamespace(); Iterator<Entry<String, Object>> iterator = map.entrySet().iterator(); for (int i = 0; iterator.hasNext(); i++) { Entry<String, Object> entry = iterator.next(); if (i < loopVars.length) { loopVars[i] = objectWrapper.wrap(entry.getValue()); } else { String key = entry.getKey(); reduceMap.put(key, namespace.get(key)); namespace.put(key, objectWrapper.wrap(entry.getValue())); } } return reduceMap; }
setVariable(targetNsVarName, existingNamespace); if (isIcI2324OrLater() && currentNamespace == mainNamespace) { globalNamespace.put(targetNsVarName, existingNamespace); = lazyImport ? new LazilyInitializedNamespace(templateName) : new Namespace(loadedTemplate); loadedLibs.put(templateName, newNamespace); setVariable(targetNsVarName, newNamespace); if (currentNamespace == mainNamespace) { globalNamespace.put(targetNsVarName, newNamespace);
for (int i = 0; i < paramNames.length; ++i) { String argName = paramNames[i]; if (localVars.get(argName) == null) { Expression valueExp = (Expression) paramDefaults.get(argName); if (valueExp != null) { localVars.put(argName, tm); resolvedAnArg = true; boolean argWasSpecified = localVars.containsKey(argName); throw new _MiscTemplateException(env, new _ErrorDescriptionBuilder(
for (int i = 0; i < paramNames.length; ++i) { String argName = paramNames[i]; if (localVars.get(argName) == null) { Expression valueExp = (Expression) paramDefaults.get(argName); if (valueExp != null) { localVars.put(argName, tm); resolvedAnArg = true; boolean argWasSpecified = localVars.containsKey(argName); throw new _MiscTemplateException(env, new _ErrorDescriptionBuilder(
setVariable(targetNsVarName, existingNamespace); if (isIcI2324OrLater() && currentNamespace == mainNamespace) { globalNamespace.put(targetNsVarName, existingNamespace); = lazyImport ? new LazilyInitializedNamespace(templateName) : new Namespace(loadedTemplate); loadedLibs.put(templateName, newNamespace); setVariable(targetNsVarName, newNamespace); if (currentNamespace == mainNamespace) { globalNamespace.put(targetNsVarName, newNamespace);
setVariable(targetNsVarName, existingNamespace); if (isIcI2324OrLater() && currentNamespace == mainNamespace) { globalNamespace.put(targetNsVarName, existingNamespace); = lazyImport ? new LazilyInitializedNamespace(templateName) : new Namespace(loadedTemplate); loadedLibs.put(templateName, newNamespace); setVariable(targetNsVarName, newNamespace); if (currentNamespace == mainNamespace) { globalNamespace.put(targetNsVarName, newNamespace);
public Writer pipeline(String pipeTemplates[],Object rootMap,Writer writer) throws PipeException { try { Map globalContext = new HashMap(); for(int i = 0; i < pipeTemplates.length; i++) { String templateName = pipeTemplates[i]; boolean isLastTemplate = i == pipeTemplates.length - 1; try { Template template = conf.getTemplate(templateName); if(isLastTemplate) { Environment env = template.createProcessingEnvironment(rootMap, writer); env.getCurrentNamespace().putAll(globalContext); env.process(); }else { Writer tempOutput = new StringWriter(bufferSize); Environment env = template.createProcessingEnvironment(rootMap, tempOutput); env.getCurrentNamespace().putAll(globalContext); env.process(); globalContext.putAll(env.getCurrentNamespace().toMap()); globalContext.put(Pipeline.PIPELINE_CONTENT_VAR_NAME, tempOutput.toString()); } }catch(Exception e){ handleException(e,templateName,isLastTemplate); } } return writer; }catch(Exception e) { throw new PipeException("process FreeMarker template occer exception,pipeTemplates:"+StringUtils.join(pipeTemplates," | "),e); } }
@Override public void removeAttribute(String name, int scope) { switch(scope) { case PAGE_SCOPE: { environment.getGlobalNamespace().remove(name); break; } case REQUEST_SCOPE: { getRequest().removeAttribute(name); break; } case SESSION_SCOPE: { HttpSession session = getSession(false); if (session != null) { session.removeAttribute(name); } break; } case APPLICATION_SCOPE: { getServletContext().removeAttribute(name); break; } default: { throw new IllegalArgumentException("Invalid scope: " + scope); } } }
public void removeAttribute(String name, int scope) { switch(scope) { case PAGE_SCOPE: { environment.getGlobalNamespace().remove(name); break; } case REQUEST_SCOPE: { getRequest().removeAttribute(name); break; } case SESSION_SCOPE: { HttpSession session = getSession(false); if(session != null) { session.removeAttribute(name); } break; } case APPLICATION_SCOPE: { getServletContext().removeAttribute(name); break; } default: { throw new IllegalArgumentException("Invalid scope: " + scope); } } }
@Override public void removeAttribute(String name, int scope) { switch(scope) { case PAGE_SCOPE: { environment.getGlobalNamespace().remove(name); break; } case REQUEST_SCOPE: { getRequest().removeAttribute(name); break; } case SESSION_SCOPE: { HttpSession session = getSession(false); if (session != null) { session.removeAttribute(name); } break; } case APPLICATION_SCOPE: { getServletContext().removeAttribute(name); break; } default: { throw new IllegalArgumentException("Invalid scope: " + scope); } } }
@Override protected boolean preprocessRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Environment environment = Environment.getCurrentEnvironment(); if (environment != null) { try { Namespace namespace = environment.getCurrentNamespace(); TemplateCollectionModel collectionModel = namespace.keys(); TemplateModelIterator iterator = collectionModel.iterator(); Map<String, Object> sharedVariables = new HashMap<>(); while (iterator.hasNext()) { SimpleScalar scalar = (SimpleScalar) iterator.next(); TemplateModel value = namespace.get(scalar.getAsString()); sharedVariables.put(scalar.getAsString(), value); } addSharedVariables(getConfiguration(), sharedVariables); } catch (TemplateModelException e) { throw new ServletException(e); } } return false; }
Context(Environment env) throws TemplateException { invokingMacroContext = env.getCurrentMacroContext(); List bodyParameterNames = invokingMacroContext.bodyParameterNames; if (bodyParameters != null) { for (int i=0; i<bodyParameters.size(); i++) { Expression exp = (Expression) bodyParameters.get(i); TemplateModel tm = exp.getAsTemplateModel(env); if (bodyParameterNames != null && i < bodyParameterNames.size()) { String bodyParameterName = (String) bodyParameterNames.get(i); if (bodyVars == null) { bodyVars = env.new Namespace(); } bodyVars.put(bodyParameterName, tm); } } } }
Context(Environment env) throws TemplateException { invokingMacroContext = env.getCurrentMacroContext(); List bodyParameterNames = invokingMacroContext.nestedContentParameterNames; if (bodyParameters != null) { for (int i = 0; i < bodyParameters.size(); i++) { Expression exp = (Expression) bodyParameters.get(i); TemplateModel tm = exp.eval(env); if (bodyParameterNames != null && i < bodyParameterNames.size()) { String bodyParameterName = (String) bodyParameterNames.get(i); if (bodyVars == null) { bodyVars = env.new Namespace(); } bodyVars.put(bodyParameterName, tm); } } } }
Context(Environment env) throws TemplateException { invokingMacroContext = env.getCurrentMacroContext(); List bodyParameterNames = invokingMacroContext.nestedContentParameterNames; if (bodyParameters != null) { for (int i = 0; i < bodyParameters.size(); i++) { Expression exp = (Expression) bodyParameters.get(i); TemplateModel tm = exp.eval(env); if (bodyParameterNames != null && i < bodyParameterNames.size()) { String bodyParameterName = (String) bodyParameterNames.get(i); if (bodyVars == null) { bodyVars = env.new Namespace(); } bodyVars.put(bodyParameterName, tm); } } } }
public String getPrefixForNamespace(String nsURI) { return currentNamespace.getTemplate().getPrefixForNamespace(nsURI); }