当前位置: 首页>>代码示例>>Java>>正文


Java DeepUnwrap.unwrap方法代码示例

本文整理汇总了Java中freemarker.template.utility.DeepUnwrap.unwrap方法的典型用法代码示例。如果您正苦于以下问题:Java DeepUnwrap.unwrap方法的具体用法?Java DeepUnwrap.unwrap怎么用?Java DeepUnwrap.unwrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在freemarker.template.utility.DeepUnwrap的用法示例。


在下文中一共展示了DeepUnwrap.unwrap方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exec

import freemarker.template.utility.DeepUnwrap; //导入方法依赖的package包/类
@Override
public Object exec(@SuppressWarnings("rawtypes") List list) throws TemplateModelException
{
	RenderContext info = getSectionWriter();

	Object wrapped = DeepUnwrap.unwrap((TemplateModel) list.get(0));
	String type = list.get(1).toString();
	SectionRenderable renderable = getSectionRenderable(info, wrapped, type, factory);
	if( renderable == null )
	{
		return TemplateModel.NOTHING;
	}
	return renderable;
}
 
开发者ID:equella,项目名称:Equella,代码行数:15,代码来源:ChooseRenderer.java

示例2: exec

import freemarker.template.utility.DeepUnwrap; //导入方法依赖的package包/类
@Override
public Object exec(List list) throws TemplateModelException
{
	if( list.size() != 2 )
	{
		throw new RuntimeException("Needs a key and a value"); //$NON-NLS-1$
	}

	String key = (String) DeepUnwrap.unwrap((TemplateModel) list.get(0));
	map.put(key, (TemplateModel) list.get(1));
	return TemplateModel.NOTHING;
}
 
开发者ID:equella,项目名称:Equella,代码行数:13,代码来源:MutableMapModel.java

示例3: unwrap

import freemarker.template.utility.DeepUnwrap; //导入方法依赖的package包/类
/**
 * Unwraps template model; if cannot, throws exception. If null, returns null.
 * <p>
 * NOTE: This automatically bypasses the auto-escaping done by wrappers implementing the <code>EscapingModel</code> interface
 * (such as Ofbiz special widget wrappers).
 */
public static Object unwrap(TemplateModel templateModel) throws TemplateModelException {
    if (templateModel != null) {
        return DeepUnwrap.unwrap(templateModel); // will throw exception if improper type
    }
    else {
        return null;
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:15,代码来源:LangFtlUtil.java

示例4: unwrapAlways

import freemarker.template.utility.DeepUnwrap; //导入方法依赖的package包/类
/**
 * Unwraps value if template model and unwrappable; else exception.
 * <p>
 * Interpretation of null depends on the ObjectWrapper.
 * <p>
 * NOTE: This automatically bypasses the auto-escaping done by wrappers implementing the <code>EscapingModel</code> interface
 * (such as Ofbiz special widget wrappers).
 */
public static Object unwrapAlways(Object value) throws TemplateModelException {
    if (value instanceof TemplateModel || value == null) {
        return DeepUnwrap.unwrap((TemplateModel) value);
    }
    else {
        throw new TemplateModelException("Cannot unwrap non-TemplateModel value (type " + value.getClass().getName() + ")");
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:17,代码来源:LangFtlUtil.java

示例5: unwrapAlwaysUnlessNull

import freemarker.template.utility.DeepUnwrap; //导入方法依赖的package包/类
/**
 * Unwraps template model; if cannot, throws exception. Special case where null accepted.
 * <p>
 * Interpretation of null depends on the ObjectWrapper.
 * <p>
 * NOTE: This automatically bypasses the auto-escaping done by wrappers implementing the <code>EscapingModel</code> interface
 * (such as Ofbiz special widget wrappers).
 */
public static Object unwrapAlwaysUnlessNull(TemplateModel templateModel) throws TemplateModelException {
    if (templateModel == null) {
        return null;
    }
    else {
        return DeepUnwrap.unwrap(templateModel); // will throw exception if improper type
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:17,代码来源:LangFtlUtil.java

示例6: getParameter

import freemarker.template.utility.DeepUnwrap; //导入方法依赖的package包/类
/**
 * 获取参数
 * 
 * @param name
 *            名称
 * @param type
 *            类型
 * @param params
 *            参数
 * @return 参数,若不存在则返回null
 */
public static <T> T getParameter(String name, Class<T> type, Map<String, TemplateModel> params) throws TemplateModelException {
	Assert.hasText(name);
	Assert.notNull(type);
	Assert.notNull(params);
	TemplateModel templateModel = params.get(name);
	if (templateModel == null) {
		return null;
	}
	Object value = DeepUnwrap.unwrap(templateModel);
	return (T) convertUtils.convert(value, type);
}
 
开发者ID:justinbaby,项目名称:my-paper,代码行数:23,代码来源:FreemarkerUtils.java

示例7: execute

import freemarker.template.utility.DeepUnwrap; //导入方法依赖的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

示例8: exec

import freemarker.template.utility.DeepUnwrap; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public Object exec(List arguments) throws TemplateModelException {
	Stub stub = (Stub) DeepUnwrap.unwrap((TemplateModel) arguments.get(0));
	String parentPath = (String) DeepUnwrap.unwrap((TemplateModel) arguments.get(1));
	if (parentPath == null || StringUtils.isEmpty(parentPath)) {
		return getStubNameConsideringMultiple(stub);
	}
	return parentPath + "." + getStubNameConsideringMultiple(stub);
}
 
开发者ID:chenjianjx,项目名称:wsdl2html,代码行数:11,代码来源:FreemarkerWebServiceDisplayer.java

示例9: execute

import freemarker.template.utility.DeepUnwrap; //导入方法依赖的package包/类
@Override
public void execute(Environment env, Map args, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
    Map<String, TemplateModel> params = UtilGenerics.checkMap(args);
    String productId = (String) DeepUnwrap.unwrap(params.get("productId"));
    String currentCategoryId = (String) DeepUnwrap.unwrap(params.get("currentCategoryId"));
    String previousCategoryId = (String) DeepUnwrap.unwrap(params.get("previousCategoryId"));

    BeanModel req = (BeanModel) env.getVariable("request");

    if (req != null) {
        HttpServletRequest request = (HttpServletRequest) req.getWrappedObject();
        env.getOut().write(CatalogUrlServlet.makeCatalogUrl(request, productId, currentCategoryId, previousCategoryId));
    }
}
 
开发者ID:gildaslemoal,项目名称:elpi,代码行数:15,代码来源:CatalogUrlDirective.java

示例10: getObjectParameter

import freemarker.template.utility.DeepUnwrap; //导入方法依赖的package包/类
/**
 * 获取Object类型的参数值
 * 
 * @return 参数值
 */
public static Object getObjectParameter(String name, Map<String, TemplateModel> params) throws TemplateModelException {
	TemplateModel templateModel = params.get(name);
	if (templateModel == null) {
		return null;
	}
	try {
		 return DeepUnwrap.unwrap(templateModel);
	} catch (TemplateModelException e) {
		throw new TemplateModelException("The \"" + name + "\" parameter " + "must be a object.");
	}
}
 
开发者ID:wangko27,项目名称:SelfSoftShop,代码行数:17,代码来源:DirectiveUtil.java

示例11: execute

import freemarker.template.utility.DeepUnwrap; //导入方法依赖的package包/类
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
        throws TemplateException, IOException {
    if (!params.containsKey("of")) {
        throw new TemplateModelException("LocalizedNameDirective directive expects 'of'.");
    }

    if (params.size() != 1) {
        throw new TemplateModelException("TeamDirective directive expects the only parameter named 'of'.");
    }

    Object obj = DeepUnwrap.unwrap((TemplateModel) params.get("of"));

    if (obj instanceof Localized) {
        Localized localized = (Localized) obj;
        String name;

        if (LocaleUtil.isRussian(ApplicationContext.getInstance().getLocale())) {
            name = StringUtil.isEmpty(localized.getRussianName())
                    ? localized.getEnglishName()
                    : localized.getRussianName();
        } else {
            name = StringUtil.isEmpty(localized.getEnglishName())
                    ? localized.getRussianName()
                    : localized.getEnglishName();
        }

        name = StringEscapeUtils.escapeHtml(name);

        name = Patterns.LINE_BREAK_PATTERN.matcher(name).replaceAll("<br/>");

        env.getOut().write(name);
    }
}
 
开发者ID:MikeMirzayanov,项目名称:pbox,代码行数:35,代码来源:LocalizedNameDirective.java

示例12: getParameter

import freemarker.template.utility.DeepUnwrap; //导入方法依赖的package包/类
public static <T> T getParameter(String name, Class<T> type, Map<String, TemplateModel> params) throws TemplateModelException
{
  Assert.hasText(name);
  Assert.notNull(type);
  Assert.notNull(params);
  TemplateModel model = (TemplateModel)params.get(name);
  if (model == null)
    return null;
  Object obj = DeepUnwrap.unwrap(model);
  return (T) convertUtilsBean.convert(obj, type);
}
 
开发者ID:zhanggh,项目名称:mtools,代码行数:12,代码来源:FreemarkerUtils.java

示例13: execute

import freemarker.template.utility.DeepUnwrap; //导入方法依赖的package包/类
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
    throws TemplateException, IOException {
    TemplateModel pItem = (TemplateModel) params.get("item");
    SimpleScalar pVar = (SimpleScalar) params.get("var");

    App app = App.get();
    List<NavigationItem> navItems = app.registryGet(NavigationConstant.NAV_ITEMS);
    List<Id> navItemIds = app.registryGet(NavigationConstant.NAV_ITEM_IDS);

    boolean isActive = false;
    String var = null;

    if (pVar != null)
        var = pVar.getAsString();

    if (pItem != null && navItems != null) {
        Object navItem = null;

        if (pItem instanceof SimpleScalar) {
            navItem = ((SimpleScalar) pItem).getAsString();
        } else if (pItem instanceof SimpleNumber) {
            navItem = Id.valueOf(((SimpleNumber) pItem).getAsNumber());
        } else if (pItem instanceof StringModel) {
            navItem = ((StringModel) pItem).getWrappedObject();
        } else {
            navItem = DeepUnwrap.unwrap(pItem);
        }

        if (navItem instanceof String) {
            for (NavigationItem navigationItem : navItems) {
                if ((navigationItem.getLabel() != null
                    && Str.trimEqualsIgnoreCase((String) navItem, navigationItem.getLabel().str()))
                    || Str.trimEqualsIgnoreCase((String) navItem, navigationItem.getDisplayURI())) {
                    isActive = true;
                    break;
                }
            }
        } else if (navItem instanceof Id) {
            isActive = navItemIds.contains(navItem);
        } else if (navItem instanceof NavigationItem) {
            isActive = navItemIds.contains(((NavigationItem) navItem).getId());
        }
    }

    if (isActive && Str.isEmpty(var)) {
        body.render(env.getOut());
    } else {
        env.setVariable(var, DefaultObjectWrapper.getDefaultInstance().wrap(isActive));
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:52,代码来源:IsActiveDirective.java

示例14: execute

import freemarker.template.utility.DeepUnwrap; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
    throws TemplateException, IOException {
    SimpleScalar pPath = (SimpleScalar) params.get("path");
    TemplateModel pTarget = (TemplateModel) params.get("target");
    SimpleScalar pVar = (SimpleScalar) params.get("var");

    String path = null;
    String varName = null;

    App app = App.get();

    // String path has precedence.
    if (pPath != null) {
        path = pPath.getAsString();

        if (!Str.isEmpty(path) && !Str.SLASH.equals(path.trim())) {
            UrlRewrite urlRewrite = urlRewrites.forTargetURI(path);

            if (urlRewrite != null) {
                String requestPath = ContextObjects.findCurrentLanguage(urlRewrite.getRequestURI());

                if (!Str.isEmpty(requestPath))
                    path = requestPath;
            }
        }
    }

    // If no path was set, attempt other objects.
    if (path == null && pTarget != null) {
        Object target = DeepUnwrap.unwrap(pTarget);

        if (target instanceof TargetSupport) {
            path = app.helper(TargetSupportHelper.class).findURI((TargetSupport) target);
        } else if (target instanceof ContextObject) {
            path = ContextObjects.findCurrentLanguageOrGlobal((ContextObject<String>) target);
        } else {
            path = target.toString();
        }
    }

    // Optionally put the result into a parameters map instead of outputting
    // it.
    if (pVar != null)
        varName = pVar.getAsString();

    if (path != null) {
        HttpServletResponse response = app.servletResponse();

        if (varName != null) {
            // Sets the result into the current template as if using
            // <#assign name=model>.
            env.setVariable(varName, DefaultObjectWrapper.getDefaultInstance().wrap(response.encodeURL(path)));
        } else {
            // Simply writes the result to the template.
            env.getOut().write(response.encodeURL(path));
        }
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:61,代码来源:URLDirective.java


注:本文中的freemarker.template.utility.DeepUnwrap.unwrap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。