Java Code Examples for freemarker.core.Environment#getOut()
The following examples show how to use
freemarker.core.Environment#getOut() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MutiLangTag.java From jeecg with Apache License 2.0 | 6 votes |
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { // 多语言key String langKey = getAttribute(params, "langKey"); if (langKey == null) { throw new TemplateException( "Can not find attribute 'name' in data tag", env); } String langArg = getAttribute(params, "langArg"); String lang_context = MutiLangUtil.getLang(langKey, langArg); Writer out = env.getOut(); out.append(lang_context); }
Example 2
Source File: FreeMarkerInlineRenderUtils.java From rice with Educational Community License v2.0 | 6 votes |
/** * Render open tags wrapping a group component. * * <p> * NOTE: Inline rendering performance is improved by *not* passing continuations for nested body * content, so the open and close methods are implemented separately. Always call * {@link #renderCloseGroupWrap(Environment, Group)} after rendering the body related to a call to * {@link #renderOpenGroupWrap(Environment, Group)}. * </p> * * <p> * This method originated as groupWrap.ftl, and supercedes the previous content of that * template. * </p> * * @param env The FreeMarker environment to use for rendering. * @param group The group to render open wrapper tags for. * @throws IOException If rendering is interrupted due to an I/O error. * @throws TemplateException If FreeMarker rendering fails. */ public static void renderOpenGroupWrap(Environment env, Group group) throws IOException, TemplateException { Writer out = env.getOut(); renderTemplate(env, group.getHeader(), null, false, false, null); if (group.isRenderLoading()) { out.write("<div id=\""); out.write(group.getId()); out.write("_disclosureContent\" data-role=\"placeholder\"> Loading... </div>"); } else { Disclosure disclosure = group.getDisclosure(); if (disclosure != null && disclosure.isRender()) { out.write("<div id=\""); out.write(group.getId() + UifConstants.IdSuffixes.DISCLOSURE_CONTENT); out.write("\" data-role=\"disclosureContent\" data-open=\""); out.write(Boolean.toString(disclosure.isDefaultOpen())); out.write("\" class=\"uif-disclosureContent\">"); } renderTemplate(env, group.getInstructionalMessage(), null, false, false, null); } }
Example 3
Source File: TextCutDirective.java From Lottery with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { String s = DirectiveUtils.getString(PARAM_S, params); Integer len = DirectiveUtils.getInt(PARAM_LEN, params); String append = DirectiveUtils.getString(PARAM_APPEND, params); if (s != null) { Writer out = env.getOut(); if (len != null) { out.append(StrUtils.textCut(s, len, append)); } else { out.append(s); } } }
Example 4
Source File: ExpTag.java From jeecg with Apache License 2.0 | 5 votes |
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { String exp = getAttribute(params, "exp"); String data = getAttribute(params, "data"); if (exp == null||data == null) { throw new TemplateException( "Can not find attribute 'name' in data tag", env); } StringBuilder resexp=new StringBuilder(); String[] ShowbyFields = exp.split("&&"); for (String ShowbyField : ShowbyFields) { int beginIndex = ShowbyField.indexOf("#"); int endIndex = ShowbyField.lastIndexOf("#"); String exptype = ShowbyField.substring(beginIndex + 1, endIndex);// 表达式类型 String field = ShowbyField.substring(0, beginIndex);// 判断显示依据字段 String[] values = ShowbyField.substring(endIndex + 1, ShowbyField.length()).split(",");// 传入字段值 String value = ""; for (int i = 0; i < values.length; i++) { value += "'" + "" + values[i] + "" + "'"; if (i < values.length - 1) { value += ","; } } if ("eq".equals(exptype)) { resexp.append("$.inArray("+data+"." + field + ",[" + value + "])>=0"); } if ("ne".equals(exptype)) { resexp.append("$.inArray("+data+"." + field + ",[" + value + "])<0"); } if ("empty".equals(exptype) && value.equals("'true'")) { resexp.append(""+data+"." + field + "==''"); } if ("empty".equals(exptype) && value.equals("'false'")) { resexp.append(""+data+"." + field + "!=''"); } } Writer out = env.getOut(); out.append(resexp); }
Example 5
Source File: RenderRuleLinkDirective.java From windup with Eclipse Public License 1.0 | 5 votes |
@Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { final Writer writer = env.getOut(); SimpleScalar ruleIDStringModel = (SimpleScalar) params.get("ruleID"); if (ruleIDStringModel == null || ruleIDStringModel.getAsString() == null) return; SimpleScalar renderTypeScalar = (SimpleScalar) params.get("renderType"); final String renderType; if (renderTypeScalar == null) renderType = RENDER_TYPE_TAG; else renderType = renderTypeScalar.getAsString(); SimpleScalar cssClassScalar = (SimpleScalar) params.get("class"); String cssClass; if (cssClassScalar == null || StringUtils.isBlank(cssClassScalar.getAsString())) { cssClass = ""; } else { cssClass = cssClassScalar.getAsString(); } String ruleID = ruleIDStringModel.getAsString(); writer.append("<a title='View Rule: " + ruleID + "' href='" + RenderRuleProviderReportRuleProvider.OUTPUT_FILENAME + "#" + ruleID + "'>"); if (RENDER_TYPE_GLYPH.equals(renderType)) writer.append("<span class='glyphicon glyphicon-link "+cssClass+"'></span>"); else if (RENDER_TYPE_TAG.equals(renderType)) writer.append("<span class='tag "+cssClass+"'><rule/></span>"); else writer.append("<span class='plain "+cssClass+"'>"+ ruleID +"</span>"); writer.append("</a>"); }
Example 6
Source File: BlockDirective.java From freemarker-template-inheritance with Apache License 2.0 | 5 votes |
@Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { String blockName = getBlockName(env, params, BLOCK_NAME_PARAMETER); PutType putType = getPutType(env, blockName); String bodyResult = getBodyResult(body); Writer out = env.getOut(); String putContents = getPutContents(env, blockName); putType.write(out, bodyResult, putContents); }
Example 7
Source File: RenderComponentDirective.java From engine with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException { TemplateModel componentParentParam = (TemplateModel) params.get(COMPONENT_PARENT_PARAM_NAME); TemplateModel componentParam = (TemplateModel) params.get(COMPONENT_PARAM_NAME); TemplateModel componentPathParam = (TemplateModel) params.get(COMPONENT_PATH_PARAM_NAME); TemplateModel additionalModelParam = (TemplateModel) params.get(ADDITIONAL_MODEL_PARAM_NAME); Map<String, Object> additionalModel = null; SiteItem component; if (componentParam == null && componentPathParam == null) { throw new TemplateException("No '" + COMPONENT_PARAM_NAME + "' or '" + COMPONENT_PATH_PARAM_NAME + "' param specified", env); } else if (componentParam != null) { component = getComponentFromNode(componentParentParam, componentParam, env); } else { component = getComponentFromPath(componentPathParam, env); } if (additionalModelParam != null) { additionalModel = unwrap(ADDITIONAL_MODEL_PARAM_NAME, additionalModelParam, Map.class, env); } Map<String, Object> templateModel = executeScripts(component, additionalModel, env); SimpleHash model = getFullModel(component, templateModel, additionalModel); Template template = getTemplate(component, env); Writer output = env.getOut(); processComponentTemplate(template, model, output, env); }
Example 8
Source File: HtmlCutDirective.java From Lottery with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { String s = DirectiveUtils.getString(PARAM_S, params); Integer len = DirectiveUtils.getInt(PARAM_LEN, params); String append = DirectiveUtils.getString(PARAM_APPEND, params); if (s != null) { Writer out = env.getOut(); if (len != null) { out.append(StrUtils.htmlCut(s, len, append)); } else { out.append(s); } } }
Example 9
Source File: ProcessTimeDirective.java From Lottery with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { long time = getStartTime(env); if (time != -1) { time = System.currentTimeMillis() - time; Writer out = env.getOut(); out.append("Processed in " + FORMAT.format(time / 1000F) + " second(s)"); } }
Example 10
Source File: VirtualSectionDirective.java From scipio-erp with Apache License 2.0 | 5 votes |
protected void executeTyped(Environment env, Map<String, TemplateModel> params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { Writer writer = env.getOut(); // NOTE: this can only work if we already had a RenderWriter. // if not, don't even bother trying. if (writer instanceof RenderWriter) { Map<String, Object> context = ContextFtlUtil.getContext(env); WidgetRenderTargetState renderTargetState = WidgetRenderTargetExpr.getRenderTargetState(context); if (renderTargetState.isEnabled()) { String name = TransformUtil.getStringNonEscapingArg(params, "name"); String containsExpr = TransformUtil.getStringNonEscapingArg(params, "contains"); String location = "unknown-location"; // FIXME ModelFtlWidget widget = new ModelVirtualSectionFtlWidget(name, location, containsExpr); WidgetRenderTargetState.ExecutionInfo execInfo = renderTargetState.handleShouldExecute(widget, writer, context, null); if (!execInfo.shouldExecute()) { return; } try { if (body != null) { body.render((Writer) execInfo.getWriterForElementRender()); } } finally { execInfo.handleFinished(context); // SCIPIO: return logic } return; } } body.render(writer); }
Example 11
Source File: FtlContextFetcher.java From scipio-erp with Apache License 2.0 | 5 votes |
public static Appendable getWriterFromEnvironment(Environment env) { if (env != null) { Writer out = env.getOut(); if (out != null) { return out; } } return null; }
Example 12
Source File: CmsPageUrlDirective.java From scipio-erp with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") @Override public void execute(Environment env, Map argsUntyped, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { String output = makeLinkFromFtl(env, UtilGenerics.<String, TemplateModel>checkMap(argsUntyped), loopVars, body, null); Writer out = env.getOut(); if (output != null) { out.write(output); } }
Example 13
Source File: TableThDirective.java From scaffold-cloud with MIT License | 4 votes |
/** * select下拉框FreeMarker自定义指令 * @param environment * @param map * @param templateModels * @param templateDirectiveBody * @throws TemplateException * @throws IOException */ @Override public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException{ TableThTag tableThTag = new TableThTag(); //校验参数 try { BeanUtils.populate(tableThTag,map); if(StringUtils.isEmpty(tableThTag.getNid()) && StringUtils.isEmpty(tableThTag.getType())){ throw new IllegalArgumentException("nid,type必须有一个不为空"); } } catch (Exception e) { log.error("数据转化异常",e); } StringBuilder html = new StringBuilder(); String title = tableThTag.getTitle(); String i18n = tableThTag.getI18n(); if(StrUtil.isNotBlank(i18n)){ String tmpTitle = I18nTransformUtil.transFormString(i18n); if(StrUtil.isNotBlank(tmpTitle)){ title = tmpTitle; } } html.append("\t\t\t\t\t<th data-options=\"field:'").append(tableThTag.getField()).append("'").append(",title:'").append(title).append("',"); if(!StringUtils.isEmpty(tableThTag.getWidth())){ html.append("width:'").append(tableThTag.getWidth()).append("',"); } ThFormatterInterface thFormatterInterface = ThFormatterFactory.createThFormatter(tableThTag.getType()); if(thFormatterInterface != null){ html.append("dict:'").append(tableThTag.getNid()).append("',"); String dictHtml = thFormatterInterface.buildFormatterHtml(tableThTag.getNid()); html.append(dictHtml); } html.append("\"></th>\n"); // 执行真正指令的执行部分: Writer out = environment.getOut(); out.write(html.toString()); if(templateDirectiveBody !=null){ templateDirectiveBody.render(environment.getOut()); } }
Example 14
Source File: FreeMarkerInlineRenderUtils.java From rice with Educational Community License v2.0 | 4 votes |
/** * Render a stacked collection inline. * * <p> * This method originated as stacked.ftl, and supercedes the previous content of that * template. * </p> * * @param env The FreeMarker environment * @param items List of items to render in a stacked layout * @param manager Layout manager for the container * @param container Container to render * @throws IOException If rendering is interrupted due to an I/O error. * @throws TemplateException If FreeMarker rendering fails. */ public static void renderStacked(Environment env, List<? extends Component> items, StackedLayoutManager manager, CollectionGroup container) throws IOException, TemplateException { String s; Writer out = env.getOut(); Pager pager = manager.getPagerWidget(); Map<String, TemplateModel> pagerTmplParms = null; if (pager != null && container.isUseServerPaging()) { pagerTmplParms = new HashMap<String, TemplateModel>(); renderTemplate(env, pager, null, false, false, pagerTmplParms); } /* out.write("<div id=\""); out.write(manager.getId()); out.write("\""); s = manager.getStyle(); if (StringUtils.hasText(s)) { out.write(" style=\""); out.write(s); out.write("\""); } s = manager.getStyleClassesAsString(); if (StringUtils.hasText(s)) { out.write(" class=\""); out.write(s); out.write("\""); } out.write(">"); */ Group wrapperGroup = manager.getWrapperGroup(); if (wrapperGroup != null) { renderTemplate(env, wrapperGroup, null, false, false, null); } else { for (Group item : manager.getStackedGroups()) { renderTemplate(env, item, null, false, false, null); } } /*out.write("</div>");*/ if (pager != null && container.isUseServerPaging()) { pagerTmplParms = new HashMap<String, TemplateModel>(); renderTemplate(env, pager, null, false, false, pagerTmplParms); } }
Example 15
Source File: FreeMarkerInlineRenderUtils.java From rice with Educational Community License v2.0 | 4 votes |
/** * Render close tags wrapping a group component. * * <p> * NOTE: Inline rendering performance is improved by *not* passing continuations for nested body * content, so the open and close methods are implemented separately. Always call * {@link #renderCloseGroupWrap(Environment, Group)} after rendering the body related to a call to * {@link #renderOpenGroupWrap(Environment, Group)}. * </p> * * <p> * This method originated as groupWrap.ftl, and supercedes the previous content of that * template. * </p> * * @param env The FreeMarker environment to use for rendering. * @param group The group to render open wrapper tags for. * @throws IOException If rendering is interrupted due to an I/O error. * @throws TemplateException If FreeMarker rendering fails. */ public static void renderCloseGroupWrap(Environment env, Group group) throws IOException, TemplateException { Writer out = env.getOut(); boolean renderLoading = group.isRenderLoading(); if (!renderLoading) { renderTemplate(env, group.getFooter(), null, false, false, null); } Disclosure disclosure = group.getDisclosure(); if (disclosure != null && disclosure.isRender()) { if (!renderLoading) { out.write("</div>"); } Map<String, TemplateModel> tmplParms = new HashMap<String, TemplateModel>(); tmplParms.put("parent", env.getObjectWrapper().wrap(group)); renderTemplate(env, disclosure, null, false, false, tmplParms); } }
Example 16
Source File: RenderTargetDirective.java From scipio-erp with Apache License 2.0 | 4 votes |
protected void executeTyped(Environment env, Map<String, TemplateModel> params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { Writer writer = env.getOut(); // NOTE: this can only work if we already had a RenderWriter. // if not, don't even bother trying. if (writer instanceof RenderWriter) { Map<String, Object> context = ContextFtlUtil.getContext(env); WidgetRenderTargetState renderTargetState = WidgetRenderTargetExpr.getRenderTargetState(context); if (renderTargetState.isEnabled()) { String dirName = TransformUtil.getStringArg(params, "dirName"); //TemplateHashModel dirArgs = (TemplateHashModel) params.get("dirArgs"); String id = null; String name = null; // TODO?: this may not work as expected if we do this... // TODO: review // if (dirArgs != null) { // TemplateScalarModel idModel = (TemplateScalarModel) dirArgs.get("id"); // if (idModel != null) { // id = LangFtlUtil.getAsStringNonEscaping(idModel); // if ("section".equals(dirName)) { // TemplateScalarModel containerIdModel = (TemplateScalarModel) dirArgs.get("containerId"); // if (containerIdModel != null) { // String containerId = LangFtlUtil.getAsStringNonEscaping(containerIdModel); // if (UtilValidate.isNotEmpty(containerId)) { // id = containerId; // } // } // } // } // } else { id = TransformUtil.getStringNonEscapingArg(params, "id"); name = TransformUtil.getStringNonEscapingArg(params, "name"); // } String location = "unknown-location"; // FIXME ModelFtlWidget widget = new ModelFtlWidget(name, dirName, location, id); WidgetRenderTargetState.ExecutionInfo execInfo = renderTargetState.handleShouldExecute(widget, writer, context, null); if (!execInfo.shouldExecute()) { return; } try { if (body != null) { body.render((Writer) execInfo.getWriterForElementRender()); } } finally { execInfo.handleFinished(context); // SCIPIO: return logic } return; } } body.render(writer); }
Example 17
Source File: RenderApplicationPieChartDirective.java From windup with Eclipse Public License 1.0 | 4 votes |
@Override public void execute(Environment env, @SuppressWarnings("rawtypes") Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { StringModel projectStringModel = (StringModel) params.get("project"); ProjectModel projectModel = null; if (projectStringModel != null) projectModel = (ProjectModel) projectStringModel.getWrappedObject(); StringModel projectTraversalStringModel = (StringModel) params.get("projectTraversal"); ProjectModelTraversal projectTraversal = null; if (projectTraversalStringModel != null) projectTraversal = (ProjectModelTraversal) projectTraversalStringModel.getWrappedObject(); if (projectModel != null && projectTraversal != null) throw new WindupException(NAME + " both 'project' and 'projectTraversal' were specified. Only one of these values should be specified."); else if (projectModel == null && projectTraversal == null) throw new WindupException(NAME + " neither 'project' nor 'projectTraversal' were specified. At least one of these must be specified."); TemplateBooleanModel recursiveBooleanModel = (TemplateBooleanModel) params.get("recursive"); boolean recursive = recursiveBooleanModel.getAsBoolean(); SimpleScalar elementIDStringModel = (SimpleScalar) params.get("elementID"); String elementID = elementIDStringModel.getAsString(); Set<String> includeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) params.get("includeTags")); Set<String> excludeTags = FreeMarkerUtil.simpleSequenceToSet((SimpleSequence) params.get("excludeTags")); TypeReferenceService typeReferenceService = new TypeReferenceService(context); Map<String, Integer> data; if (projectModel != null) data = typeReferenceService.getPackageUseFrequencies(projectModel, includeTags, excludeTags, 2, recursive); else data = typeReferenceService.getPackageUseFrequencies(projectTraversal, includeTags, excludeTags, 2, recursive); if (data.keySet().size() > 0) { drawPie(env.getOut(), data, elementID); } else { // if we aren't drawing a pie, remove the element that would have held it Writer writer = env.getOut(); writer.append("<script type='text/javascript'>"); writer.append("$('#" + elementID + "').parent().remove()"); writer.append("</script>"); } }
Example 18
Source File: RenderLinkDirective.java From windup with Eclipse Public License 1.0 | 4 votes |
@Override public void execute(Environment env, @SuppressWarnings("rawtypes") Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { final Writer writer = env.getOut(); StringModel stringModel = (StringModel) params.get(MODEL); SimpleScalar defaultTextModel = (SimpleScalar) params.get(TEXT); String defaultText = defaultTextModel == null ? null : defaultTextModel.getAsString(); if (stringModel == null || stringModel.getWrappedObject() == null) { if (StringUtils.isNotBlank(defaultText)) writer.append(defaultText); else { writer.append("unknown"); LOG.warning("Failed to resolve name or text for " + getClass().getName() + ". " + env); } return; } StringModel projectStringModel = (StringModel) params.get(PROJECT); ProjectModel project = null; if (projectStringModel != null && projectStringModel.getWrappedObject() instanceof ProjectModel) project = (ProjectModel)projectStringModel.getWrappedObject(); Object model = stringModel.getWrappedObject(); LayoutType layoutType = resolveLayoutType(params); String cssClass = resolveCssClass(params); if (model instanceof FileLocationModel) { processFileLocationModel(writer, cssClass, project, (FileLocationModel) model, defaultText); } else if (model instanceof FileModel) { processFileModel(writer, cssClass, project, (FileModel) model, defaultText); } else if (model instanceof JavaClassModel) { processJavaClassModel(writer, cssClass, project, (JavaClassModel) model, defaultText); } else if (model instanceof LinkableModel) { processLinkableModel(writer, layoutType, cssClass, project, (LinkableModel) model, defaultText); } else { throw new TemplateException("Object type not permitted: " + model.getClass().getSimpleName(), env); } }
Example 19
Source File: CmsRenderTemplate.java From scipio-erp with Apache License 2.0 | 4 votes |
public void setEnv(Environment env) { this.env = env; if (out == null && env != null) { this.out = env.getOut(); } }