當前位置: 首頁>>代碼示例>>Java>>正文


Java TemplateDirectiveBody.render方法代碼示例

本文整理匯總了Java中freemarker.template.TemplateDirectiveBody.render方法的典型用法代碼示例。如果您正苦於以下問題:Java TemplateDirectiveBody.render方法的具體用法?Java TemplateDirectiveBody.render怎麽用?Java TemplateDirectiveBody.render使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在freemarker.template.TemplateDirectiveBody的用法示例。


在下文中一共展示了TemplateDirectiveBody.render方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars,
        TemplateDirectiveBody body) throws TemplateException, IOException {
    // Check if no parameters were given:
    if (!params.isEmpty()) {
        throw new TemplateModelException(
                getClass().getSimpleName() + " doesn't allow parameters.");
    }
    if (loopVars.length != 0) {
            throw new TemplateModelException(
                    getClass().getSimpleName() + " doesn't allow loop variables.");
    }

    // If there is non-empty nested content:
    if (body != null) {
        // Executes the nested body. Same as <#nested> in FTL, except
        // that we use our own writer instead of the current output writer.
        body.render(new JsonEscapingFilterWriter(env.getOut()));
    } else {
        throw new RuntimeException("missing body");
    }
}
 
開發者ID:kuali,項目名稱:kc-rice,代碼行數:23,代碼來源:JsonStringEscapeDirective.java

示例2: execute

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void execute(Environment env, Map params, TemplateModel[] loopVars,
		TemplateDirectiveBody body) throws TemplateException, IOException {
	CmsSite site = FrontUtils.getSite(env);
	CmsVoteTopic vote;
	Integer id = getId(params);
	if (id != null) {
		vote = cmsVoteTopicMng.findById(id);
	} else {
		Integer siteId = getSiteId(params);
		if (siteId == null) {
			siteId = site.getId();
		}
		vote = cmsVoteTopicMng.getDefTopic(siteId);
	}

	Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(
			params);
	paramWrap.put(OUT_BEAN, DEFAULT_WRAPPER.wrap(vote));
	Map<String, TemplateModel> origMap = DirectiveUtils
			.addParamsToVariable(env, paramWrap);
	body.render(env.getOut());
	DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
}
 
開發者ID:huanzhou,項目名稱:jeecms6,代碼行數:25,代碼來源:CmsVoteDirective.java

示例3: execute

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void execute(Environment env, Map params, TemplateModel[] loopVars,
		TemplateDirectiveBody body) throws TemplateException, IOException {
	Integer id = getId(params);
	Boolean next = DirectiveUtils.getBool(PRAMA_NEXT, params);
	Content content;
	if (next == null) {
		content = contentMng.findById(id);
	} else {
		CmsSite site = FrontUtils.getSite(env);
		Integer channelId = DirectiveUtils.getInt(PARAM_CHANNEL_ID, params);
		content = contentMng.getSide(id, site.getId(), channelId, next);
	}

	Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(
			params);
	paramWrap.put(OUT_BEAN, DEFAULT_WRAPPER.wrap(content));
	Map<String, TemplateModel> origMap = DirectiveUtils
			.addParamsToVariable(env, paramWrap);
	body.render(env.getOut());
	DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
}
 
開發者ID:huanzhou,項目名稱:jeecms6,代碼行數:23,代碼來源:ContentDirective.java

示例4: getBodyContent

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
protected String getBodyContent(TemplateDirectiveBody body){
		StringWriter sw = null;
		String bodyContent = "";
		try {
//			body.render(env.getOut());
			if(body!=null){
				sw = new StringWriter();
				body.render(sw);
				bodyContent = sw.toString();
			}
		} catch (Exception e) {
			LangUtils.throwBaseException("render error : " + e.getMessage(), e);
//			e.printStackTrace();
		} finally{
			LangUtils.closeIO(sw);
		}
		return bodyContent;
	}
 
開發者ID:wayshall,項目名稱:onetwo,代碼行數:19,代碼來源:AbstractDirective.java

示例5: execute

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void execute(Environment env, Map params, TemplateModel[] loopVars,
		TemplateDirectiveBody body) throws TemplateException, IOException {
	Integer id = DirectiveUtils.getInt(PARAM_ID, params);
	CmsAdvertising ad = null;
	if (id != null) {
		ad = cmsAdvertisingMng.findById(id);
	}
	Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(
			params);
	paramWrap.put(OUT_BEAN, DEFAULT_WRAPPER.wrap(ad));
	Map<String, TemplateModel> origMap = DirectiveUtils
			.addParamsToVariable(env, paramWrap);
	body.render(env.getOut());
	DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
}
 
開發者ID:huanzhou,項目名稱:jeecms6,代碼行數:17,代碼來源:CmsAdvertisingDirective.java

示例6: execute

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void execute(Environment env, Map params, TemplateModel[] loopVars,
		TemplateDirectiveBody body) throws TemplateException, IOException {
	Integer id = DirectiveUtils.getInt(PARAM_ID, params);
	CmsModel model;
	if (id != null) {
		model = modelMng.findById(id);
	} else {
		String path = DirectiveUtils.getString(PARAM_PATH, params);
		if (StringUtils.isBlank(path)) {
			// 如果path不存在,那麽id必須存在。
			throw new ParamsRequiredException(PARAM_ID);
		}
		model = modelMng.findByPath(path);
	}

	Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(
			params);
	paramWrap.put(OUT_BEAN, DEFAULT_WRAPPER.wrap(model));
	Map<String, TemplateModel> origMap = DirectiveUtils
			.addParamsToVariable(env, paramWrap);
	body.render(env.getOut());
	DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap);
}
 
開發者ID:huanzhou,項目名稱:jeecms6,代碼行數:25,代碼來源:CmsModelDirective.java

示例7: execute

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
   public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
        throws TemplateException, IOException {

	OverrideDirective.TemplateDirectiveBodyOverrideWraper current = (OverrideDirective.TemplateDirectiveBodyOverrideWraper) env
	        .getVariable(DirectiveUtils.OVERRIDE_CURRENT_NODE);
	if (current == null) {
		throw new TemplateException("<@super/> direction must be child of override", env);
	}
	TemplateDirectiveBody parent = current.parentBody;
	if (parent == null) {
		throw new TemplateException("not found parent for <@super/>", env);
	}
	parent.render(env.getOut());

}
 
開發者ID:HunanTV,項目名稱:fw,代碼行數:17,代碼來源:SuperDirective.java

示例8: executeTyped

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
protected void executeTyped(Environment env, Map<String, TemplateModel> params, TemplateModel[] loopVars, TemplateDirectiveBody body)
        throws TemplateException, IOException {
    CommonVarMaps<Map<String, Object>> varMaps = CommonVarMaps.getRawMaps(params);
    boolean restoreValues = TransformUtil.getBooleanArg(params, "restoreValues", true);
    boolean clearValues = TransformUtil.getBooleanArg(params, "clearValues", false);
    
    CommonVarMaps<Boolean> skipSet = new CommonVarMaps<>(
            TransformUtil.getBooleanArg(params, "skipSetCtxVars", false),
            TransformUtil.getBooleanArg(params, "skipSetGlobalCtxVars", false),
            TransformUtil.getBooleanArg(params, "skipSetReqAttribs", false));
    
    CommonVarMaps<Map<String, Object>> origValues = null;
    if (restoreValues && !clearValues) {
        origValues = ExtractVarsMethod.extractVars(CommonVarMaps.getRawSequences(varMaps), true, env);
    }
    
    SetVarsMethod.setVars(varMaps, skipSet, env);

    if (body != null) {
        body.render(env.getOut());
    }
    
    if (clearValues) {
        ClearVarsMethod.clearVars(CommonVarMaps.getRawSequences(varMaps), env);
    } else if (restoreValues) { 
        SetVarsMethod.setVars(origValues, env);
    }
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:29,代碼來源:VarSectionDirective.java

示例9: executeTyped

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
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);
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:33,代碼來源:VirtualSectionDirective.java

示例10: setLocalVariables

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
/**
 * 設置局部變量
 * 
 * @param variables
 *            變量
 * @param env
 *            Environment
 * @param body
 *            TemplateDirectiveBody
 */
protected void setLocalVariables(Map<String, Object> variables, Environment env, TemplateDirectiveBody body) throws TemplateException, IOException {
	Map<String, Object> sourceVariables = new HashMap<String, Object>();
	for (String name : variables.keySet()) {
		TemplateModel sourceVariable = FreemarkerUtils.getVariable(name, env);
		sourceVariables.put(name, sourceVariable);
	}
	FreemarkerUtils.setVariables(variables, env);
	body.render(env.getOut());
	FreemarkerUtils.setVariables(sourceVariables, env);
}
 
開發者ID:justinbaby,項目名稱:my-paper,代碼行數:21,代碼來源:BaseDirective.java

示例11: execute

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
    List<Map> list = categoryMapper.selectCategoryList();
    env.setVariable("list", DEFAULT_WRAPPER.wrap(list));
    System.out.println("##:"+JSON.toJSON(params));
    if (body != null) {
        body.render(env.getOut());
    } else {
        throw new RuntimeException("missing body");
    }
}
 
開發者ID:blogshun,項目名稱:ants-project,代碼行數:12,代碼來源:CategoryTag.java

示例12: execute

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
    throws TemplateException, IOException {
    if (log.isTraceEnabled()) {
        log.trace(params);
    }

    TemplateModel pProduct = (TemplateModel) params.get("product");
    SimpleScalar pType = (SimpleScalar) params.get("type");

    if (pProduct != null && pProduct instanceof BeanModel && pType != null) {
        Product product = null;
        String type = null;

        Object beanModel = ((BeanModel) pProduct).getWrappedObject();

        if (beanModel instanceof Product) {
            product = (Product) beanModel;
        } else {
            throw new IllegalArgumentException("The source-object must be of type Product");
        }

        if (pType != null)
            type = pType.getAsString();

        PriceResult result = product.getPrice();

        if (result != null && type != null) {
            Double price = result.getPrice(type);

            if (price != null && price > 0 && body != null) {
                body.render(env.getOut());
            }
        }
    }
}
 
開發者ID:geetools,項目名稱:geeCommerce-Java-Shop-Software-and-PIM,代碼行數:38,代碼來源:PriceExistsDirective.java

示例13: execute

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
    throws TemplateException, IOException {
    long start = System.currentTimeMillis();

    StringWriter sw = new StringWriter();
    body.render(sw);

    env.getOut().write(sw.toString() + "<small>" + (System.currentTimeMillis() - start) + "ms</small>");
}
 
開發者ID:geetools,項目名稱:geeCommerce-Java-Shop-Software-and-PIM,代碼行數:11,代碼來源:TimeDirective.java

示例14: execute

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
    throws TemplateException, IOException {
    TemplateModel pValue = (TemplateModel) params.get("value");
    SimpleScalar pVar = (SimpleScalar) params.get("var");

    if (pVar == null)
        throw new IllegalArgumentException("The var parameter cannot be null in set-directive");

    String var = pVar.getAsString();
    Object value = null;

    if (pValue != null) {
        if (pValue instanceof StringModel) {
            value = ((StringModel) pValue).getWrappedObject();
        } else if (pValue instanceof SimpleHash) {
            value = ((SimpleHash) pValue).toMap();
        } else {
            value = DeepUnwrap.unwrap(pValue);
        }
    } else if (body != null) {
        StringWriter sw = new StringWriter();

        try {
            body.render(sw);
            value = sw.toString().trim();
        } finally {
            IOUtils.closeQuietly(sw);
        }
    }

    env.setVariable(var, DefaultObjectWrapper.getDefaultInstance().wrap(value));
}
 
開發者ID:geetools,項目名稱:geeCommerce-Java-Shop-Software-and-PIM,代碼行數:35,代碼來源:SetDirective.java

示例15: execute

import freemarker.template.TemplateDirectiveBody; //導入方法依賴的package包/類
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars,
		TemplateDirectiveBody body) throws TemplateException, IOException 
{		
	String name = Directives.getStringParam(env, params, "name");		
	name = Overrides.BLOCK_NAME_PRE+name;
	
	TemplateModel tm = env.getCurrentNamespace().get(name);
	if(tm instanceof AdapterTemplateModel)
	{
		Object o = ((AdapterTemplateModel)tm).getAdaptedObject(null);
		if(o instanceof TemplateDirectiveBody)
		{
			((TemplateDirectiveBody)o).render(env.getOut());
			return;
		}
	}
	else if(tm instanceof TemplateDirectiveBody)
	{
		((TemplateDirectiveBody)tm).render(env.getOut());
		return;
	}
	else if(tm instanceof TemplateScalarModel)
	{
		String tpl = ((TemplateScalarModel)tm).getAsString();
		if(tpl!=null)
		{
			env.getOut().append(tpl);
			return;
		}
	}
	
	if(body!=null) body.render(env.getOut());
}
 
開發者ID:fancimage,項目名稱:tern,代碼行數:35,代碼來源:Block.java


注:本文中的freemarker.template.TemplateDirectiveBody.render方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。