• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java WrapperTemplateModel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中freemarker.ext.util.WrapperTemplateModel的典型用法代码示例。如果您正苦于以下问题:Java WrapperTemplateModel类的具体用法?Java WrapperTemplateModel怎么用?Java WrapperTemplateModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WrapperTemplateModel类属于freemarker.ext.util包,在下文中一共展示了WrapperTemplateModel类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getContextFromEnvironment

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static MapStack<String> getContextFromEnvironment(Environment env) {
    if (env != null) {
        try {
            TemplateModel model = env.getGlobalVariable("context");
            if (model != null && model instanceof WrapperTemplateModel) {
                Object obj = ((WrapperTemplateModel) model).getWrappedObject();
                if (obj instanceof MapStack) {
                    return (MapStack<String>) obj;
                }
            }
        } catch (Exception e) {
            ;
        }
    }
    return null;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:18,代码来源:FtlContextFetcher.java


示例2: getMapKeys

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
/**
 * Gets map keys, either as collection or Set.
 * <p>
 * WARN: auto-escaping is bypassed on all keys, caller handles.
 * (e.g. the object wrapper used to rewrap the result).
 * DEV NOTE: we MUST manually bypass auto-escaping for all on this one.
 */
public static Object getMapKeys(TemplateModel object) throws TemplateModelException {
    if (OfbizFtlObjectType.COMPLEXMAP.isObjectType(object)) {
        // WARN: bypasses auto-escaping
        Map<Object, Object> wrappedObject = UtilGenerics.cast(((WrapperTemplateModel) object).getWrappedObject());
        return wrappedObject.keySet();
    }
    else if (object instanceof TemplateHashModelEx) {
        // 2016-04-20: cannot do this because we MUST trigger bypass of auto-escaping,
        // so just do a deep unwrap, which automatically bypasses the escaping,
        // and then caller handles the result, which is probably an arraylist
        //return ((TemplateHashModelEx) object).keys();
        return unwrapAlways(((TemplateHashModelEx) object).keys());
    }
    else {
        throw new TemplateModelException("object is not a map or does not support key iteration");
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:25,代码来源:LangFtlUtil.java


示例3: copyMap

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
/**
 * Copies map.
 * <p>
 * WARN: For complex maps, auto-escaping is bypassed; caller must decide how to handle.
 * (e.g. the object wrapper used to rewrap the result).
 * <p>
 * FIXME: The rewrapping objectWrapper behavior is inconsistent! may lead to auto-escape issues
 */
public static Object copyMap(TemplateModel object, Set<String> inExKeys, Boolean include, 
        TemplateValueTargetType targetType, ObjectWrapper objectWrapper) throws TemplateModelException {
    if (targetType == null) {
        targetType = TemplateValueTargetType.PRESERVE;
    }
    if (OfbizFtlObjectType.COMPLEXMAP.isObjectType(object)) {
        // WARN: bypasses auto-escaping
        Map<String, Object> wrappedObject = UtilGenerics.cast(((WrapperTemplateModel) object).getWrappedObject());
        // TODO: this only handles most urgent targetType case
        if (targetType == TemplateValueTargetType.SIMPLEMODEL) {
            return LangFtlUtil.copyMapToSimple(wrappedObject, inExKeys, include, objectWrapper);
        }
        else {
            return LangFtlUtil.copyMapToRawMap(wrappedObject, inExKeys, include);
        }
    }
    else if (object instanceof TemplateHashModel && OfbizFtlObjectType.MAP.isObjectType(object)) {
        // TODO: this ignores targetType
        return LangFtlUtil.copyMapToSimple((TemplateHashModel) object, inExKeys, include, objectWrapper);
    }
    throw new TemplateModelException("Cannot copy map of type " + object.getClass().toString() + 
            " to target type: " + targetType.toString());        
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:32,代码来源:LangFtlUtil.java


示例4: toSimpleMap

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
/**
 * Converts map to a simple wrapper, if applicable. Currently only applies to complex maps.
 * <p>
 * 2017-01-26: This has been changed so that it will by default try to wrap everything
 * with DefaultMapAdapter (or SimpleMapModel for BeansWrapper compatibility), which will always work as long as
 * the ObjectWrapper implements ObjectWrapperWithAPISupport.
 * <p>
 * WARN: Bypasses auto-escaping for complex maps; caller must decide how to handle
 * (e.g. the object wrapper used to rewrap the result).
 * Other types of maps are not altered.
 */
public static TemplateHashModel toSimpleMap(TemplateModel object, Boolean copy, ObjectWrapper objectWrapper) throws TemplateModelException {
    if (OfbizFtlObjectType.COMPLEXMAP.isObjectType(object)) {
        // WARN: bypasses auto-escaping
        Map<?, ?> wrappedObject = UtilGenerics.cast(((WrapperTemplateModel) object).getWrappedObject());
        if (Boolean.TRUE.equals(copy)) {
            return makeSimpleMapCopy(wrappedObject, objectWrapper);
        } else {
            return makeSimpleMapAdapter(wrappedObject, objectWrapper, true);
        }
    } else if (object instanceof TemplateHashModel) {
        return (TemplateHashModel) object;
    } else {
        throw new TemplateModelException("object is not a recognized map type");
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:27,代码来源:LangFtlUtil.java


示例5: toSimpleMapRewrapAdapters

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
/**
 * Converts map to a simple wrapper, if applicable, by rewrapping
 * known complex map wrappers that implement <code>WrapperTemplateModel</code>.
 * <p>
 * If the specified ObjectWrapper is a BeansWrapper, this forces rewrapping as a SimpleMapModel.
 * If it isn't we assume caller specified an objectWrapper that will rewrap the map with
 * a simple model (we have no way of knowing).
 * <p>
 * WARN: Bypasses auto-escaping for complex maps; caller must decide how to handle
 * (e.g. the object wrapper used to rewrap the result).
 * Other types of maps are not altered.
 * 
 * @deprecated don't use
 */
@Deprecated
private static TemplateHashModel toSimpleMapRewrapAdapters(TemplateModel object, ObjectWrapper objectWrapper) throws TemplateModelException {
    if (object instanceof SimpleMapModel || object instanceof BeanModel || object instanceof DefaultMapAdapter) {
        // Permissive
        Map<?, ?> wrappedObject = (Map<?, ?>) ((WrapperTemplateModel) object).getWrappedObject();
        if (objectWrapper instanceof BeansWrapper) {
            // Bypass the beanswrapper wrap method and always make simple wrapper
            return new SimpleMapModel(wrappedObject, (BeansWrapper) objectWrapper);
        } else {
            // If anything other than BeansWrapper, assume caller is aware and his wrapper will create a simple map
            return (TemplateHashModel) objectWrapper.wrap(wrappedObject);
        }
    }
    else if (object instanceof TemplateHashModel) {
        return (TemplateHashModel) object;
    }
    else {
        throw new TemplateModelException("object is not a recognized map type");
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:35,代码来源:LangFtlUtil.java


示例6: toSimpleMapRewrapAny

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
/**
 * Converts map to a simple wrapper, if applicable, by rewrapping
 * any map wrappers that implement <code>WrapperTemplateModel</code>.
 * <p>
 * This method is very permissive: anything that wraps a Map is accepted.
 * Other types of hashes are returned as-is.
 * <p>
 * If the specified ObjectWrapper is a BeansWrapper, this forces rewrapping as a SimpleMapModel.
 * If it isn't we assume caller specified an objectWrapper that will rewrap the map with
 * a simple model (we have no way of knowing).
 * <p>
 * WARN: Bypasses auto-escaping for complex maps; caller must decide how to handle
 * (e.g. the object wrapper used to rewrap the result).
 * Other types of maps are not altered.
 * 
 * @deprecated don't use
 */
@Deprecated
private static TemplateHashModel toSimpleMapRewrapAny(TemplateModel object, ObjectWrapper objectWrapper) throws TemplateModelException {
    if (object instanceof WrapperTemplateModel) {
        // Permissive
        Map<?, ?> wrappedObject = (Map<?, ?>) ((WrapperTemplateModel) object).getWrappedObject();
        if (objectWrapper instanceof BeansWrapper) {
            // Bypass the beanswrapper wrap method and always make simple wrapper
            return new SimpleMapModel(wrappedObject, (BeansWrapper) objectWrapper);
        } else {
            // If anything other than BeansWrapper, assume caller is aware and his wrapper will create a simple map
            return (TemplateHashModel) objectWrapper.wrap(wrappedObject);
        }
    }
    else if (object instanceof TemplateHashModel) {
        return (TemplateHashModel) object;
    }
    else {
        throw new TemplateModelException("object is not a recognized map type");
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:38,代码来源:LangFtlUtil.java


示例7: unwrap

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
@Override
public Object unwrap(TemplateModel dataModel) throws TemplateModelException {
    if (dataModel instanceof SimpleScalar) {
        return ((SimpleScalar) dataModel).getAsString();
    }

    if (dataModel instanceof SimpleNumber) {
        return ((SimpleNumber) dataModel).getAsNumber();
    }

    if (dataModel instanceof SimpleDate) {
        return ((SimpleDate) dataModel).getAsDate();
    }

    if (dataModel instanceof TemplateBooleanModel) {
        return ((TemplateBooleanModel) dataModel).getAsBoolean();
    }

    if (dataModel instanceof WrapperTemplateModel) {
        return ((WrapperTemplateModel) dataModel).getWrappedObject();
    }
    throw new TemplateModelException(dataModel.getClass().getCanonicalName() + " is not supported.");
}
 
开发者ID:kwon37xi,项目名称:freemarker-dynamic-ql-builder,代码行数:24,代码来源:TemplateModelObjectUnwrapperDefaultImpl.java


示例8: exec

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Object exec(List list) throws TemplateModelException {
    if (list.size() != 2) {
        throw new TemplateModelException("Wrong number of arguments for method isAssignableFrom()."
                + " Method has two required parameters: [Class, Class]. Found: " + list.size());
    }

    Object arg1 = ((WrapperTemplateModel) list.get(0)).getWrappedObject();
    if (!(arg1 instanceof Class)) {
        throw new TemplateModelException("Wrong type of the first parameter."
                + " It should be Class. Found: " + arg1.getClass());
    }

    Object arg2 = ((WrapperTemplateModel) list.get(1)).getWrappedObject();
    if (!(arg2 instanceof Class)) {
        throw new TemplateModelException("Wrong type of the second parameter."
                + " It should be Class. Found: " + arg2.getClass());
    }

    return ((Class) arg2).isAssignableFrom((Class) arg1);
}
 
开发者ID:hazelcast,项目名称:hazelcast-simulator,代码行数:23,代码来源:TimeStepRunnerCodeGenerator.java


示例9: getRenderContext

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static MapStack<String> getRenderContext(Environment env) throws TemplateModelException {
    TemplateModel pcm = env.getVariable("context");
    if (pcm != null && pcm instanceof WrapperTemplateModel) {
        Object obj = ((WrapperTemplateModel) pcm).getWrappedObject();
        if (obj instanceof MapStack) {
            return (MapStack<String>) obj;
        }
    }
    return null;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:12,代码来源:CmsRenderUtil.java


示例10: getRenderContextGeneric

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Map<String, Object> getRenderContextGeneric(Environment env) throws TemplateModelException {
    TemplateModel pcm = env.getVariable("context");
    if (pcm != null && pcm instanceof WrapperTemplateModel) {
        Object obj = ((WrapperTemplateModel) pcm).getWrappedObject();
        if (obj instanceof MapStack) {
            return (Map<String, Object>) obj;
        }
    }
    return null;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:12,代码来源:CmsRenderUtil.java


示例11: getOfbizLocaleArg

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
/**
 * Returns a Locale OR the Locale representation of the string using UtilMisc.parseLocale ofbiz utility.
 * Added 2017-11-06.
 */
public static Locale getOfbizLocaleArg(TemplateModel obj) throws TemplateModelException {
    if (obj == null) return null;
    else if (obj instanceof WrapperTemplateModel) {
        Object localeObj = ((WrapperTemplateModel) obj).getWrappedObject();
        if (localeObj == null || localeObj instanceof Locale) return (Locale) localeObj;
        else if (localeObj instanceof String) return UtilMisc.parseLocale((String) localeObj);
    } else if (obj instanceof TemplateScalarModel) {
        String localeStr = LangFtlUtil.getAsStringNonEscaping((TemplateScalarModel) obj);
        return UtilMisc.parseLocale(localeStr);
    }
    throw new IllegalArgumentException("unexpected type for locale argument: " + obj.getClass().getName());
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:17,代码来源:TransformUtil.java


示例12: getLocale

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
public static Locale getLocale(TemplateModel model) throws TemplateModelException {
    if (isNullOrEmptyString(model)) {
        return null;
    }
    if (!(model instanceof WrapperTemplateModel)) {
        throw new TemplateModelException("Invalid locale object (not WrapperTemplateModel)");
    }
    return (Locale) ((WrapperTemplateModel) model).getWrappedObject();
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:10,代码来源:LangFtlUtil.java


示例13: getTimeZone

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
public static TimeZone getTimeZone(TemplateModel model) throws TemplateModelException {
    if (isNullOrEmptyString(model)) {
        return null;
    }
    if (!(model instanceof WrapperTemplateModel)) {
        throw new TemplateModelException("Invalid locale object (not WrapperTemplateModel)");
    }
    return (TimeZone) ((WrapperTemplateModel) model).getWrappedObject();
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:10,代码来源:LangFtlUtil.java


示例14: execOneArg

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
private Object execOneArg(Object arg) throws TemplateModelException {
    if (arg instanceof WrapperTemplateModel && ((WrapperTemplateModel) arg).getWrappedObject() instanceof Map) {
        Map<String, Object> map = (Map<String, Object>) ((WrapperTemplateModel) arg).getWrappedObject();
        return markDownUtils.printIssue((Severity) (map.get("severity")), (String) map.get("message"), (String) map.get("ruleLink"), (String) map.get("url"), (String) map.get("componentKey"));
    }
    throw new TemplateModelException("Failed call accept 1 issue arg");
}
 
开发者ID:gabrie-allaigre,项目名称:sonar-gitlab-plugin,代码行数:8,代码来源:PrintTemplateMethodModelEx.java


示例15: execute

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
    throws TemplateException, IOException {
  SimpleScalar name = (SimpleScalar) params.get("name");
  if (params.containsKey("value")) {
    Object valueObject = params.get("value");
    Object value;
    if (valueObject == null) {
      value = null;
    } else if (valueObject instanceof WrapperTemplateModel) {
      value = ((WrapperTemplateModel) valueObject).getWrappedObject();
    } else if (valueObject instanceof TemplateScalarModel) {
      value = ((TemplateScalarModel) valueObject).getAsString();
    } else if (valueObject instanceof TemplateNumberModel) {
      value = ((TemplateNumberModel) valueObject).getAsNumber();
    } else if (valueObject instanceof TemplateDateModel) {
      value = ((TemplateDateModel) valueObject).getAsDate();
    } else if (valueObject instanceof TemplateBooleanModel) {
      value = ((TemplateBooleanModel) valueObject).getAsBoolean();
    } else {
      throw new UnsupportedOperationException(
          String.format("Type %s is not supported yet in this context.", valueObject.getClass().getSimpleName()));
    }

    TemplateModel generatedParamsObject = env.getGlobalVariables().get(FreeMarkerSqlSource.GENERATED_PARAMS_KEY);
    List generatedParams;
    if (generatedParamsObject instanceof DefaultListAdapter) {
      generatedParams = (List) ((DefaultListAdapter) generatedParamsObject).getWrappedObject();
    } else {
      generatedParams = ((GeneratedParamsTemplateModel) generatedParamsObject).getGeneratedParams();
    }
    String generatedParamName = "_p" + generatedParams.size();
    env.getOut().write(String.format("#{%s}", generatedParamName));
    generatedParams.add(value);
  } else {
    env.getOut().write(String.format("#{%s}", name));
  }
}
 
开发者ID:mybatis,项目名称:freemarker-scripting,代码行数:39,代码来源:MyBatisParamDirective.java


示例16: getRequest

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
public static HttpServletRequest getRequest(Environment env) throws TemplateModelException {
    WrapperTemplateModel req = (WrapperTemplateModel) env.getVariable("request");
    return (req != null) ? (HttpServletRequest) req.getWrappedObject() : null;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:5,代码来源:ContextFtlUtil.java


示例17: getResponse

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
public static HttpServletResponse getResponse(Environment env) throws TemplateModelException {
    WrapperTemplateModel req = (WrapperTemplateModel) env.getVariable("response");
    return (req != null) ? (HttpServletResponse) req.getWrappedObject() : null;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:5,代码来源:ContextFtlUtil.java


示例18: toSimpleSequence

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
/**
 * Supposed to convert to simple sequence.
 * <p>
 * WARN: Bypasses auto-escaping for complex maps, caller must decide how to handle.
 * (e.g. the object wrapper used to rewrap the result).
 * <p>
 * DEV NOTE: I stopped writing/testing this when found out most of the problems w.r.t. collections are not
 * the FTL types this time but the way they're used in Ofbiz templates.
 * FTL's CollectionModel (subclass of TemplateCollectionModel) is supposed to cover everything and
 * won't suffer from the same problems maps have.
 */
@SuppressWarnings("unchecked")
@Deprecated
private static TemplateSequenceModel toSimpleSequence(TemplateModel object, ObjectWrapper objectWrapper) throws TemplateModelException {
    if (object instanceof TemplateSequenceModel) {
        return (TemplateSequenceModel) object;
    }
    else if (object instanceof WrapperTemplateModel) {
        WrapperTemplateModel wrapperModel = (WrapperTemplateModel) object;
        // WARN: bypasses auto-escaping
        Object wrappedObject = wrapperModel.getWrappedObject();
        if (wrappedObject instanceof List) {
            return DefaultListAdapter.adapt((List<Object>) wrappedObject, (RichObjectWrapper) objectWrapper);
        }
        else if (wrappedObject instanceof Object[]) {
            return DefaultArrayAdapter.adapt((Object[]) wrappedObject, (ObjectWrapperAndUnwrapper) objectWrapper);
        }
        else if (wrappedObject instanceof Set) {
            throw new UnsupportedOperationException("Not yet implemented");
        }
        else if (wrappedObject instanceof Collection) {
            throw new UnsupportedOperationException("Not yet implemented");
        }
        else if (wrappedObject instanceof Iterable) {
            throw new UnsupportedOperationException("Not yet implemented");
        }
        else {
            throw new TemplateModelException("Cannot convert bean-wrapped object of type " + (object != null ? object.getClass() : "null") + " to simple sequence"); 
        }
    }
    else if (object instanceof TemplateCollectionModel) {
        TemplateCollectionModel collModel = (TemplateCollectionModel) object;
        SimpleSequence res = new SimpleSequence(objectWrapper);
        TemplateModelIterator it = collModel.iterator();
        while(it.hasNext()) {
            res.add(it.next());
        }
        return res;
    }
    else {
        throw new TemplateModelException("Cannot convert object of type " + (object != null ? object.getClass() : "null") + " to simple sequence"); 
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:54,代码来源:LangFtlUtil.java


示例19: getContextLocale

import freemarker.ext.util.WrapperTemplateModel; //导入依赖的package包/类
/**
 * Attempts to get the current "user" or "screen" locale normally found in screen context
 * as the simple "locale" variable.
 * TODO: REVIEW: this is currently using getGlobalVariable as most likely the fastest that
 * will avoid problems from macros - unclear if more or less reliable than trying to read
 * out of "context" map (which not guaranteed present).
 */
public static Locale getContextLocale(Environment env) throws TemplateModelException {
    WrapperTemplateModel model = (WrapperTemplateModel) env.getGlobalVariable("locale");
    if (model != null) return (Locale) ((WrapperTemplateModel) model).getWrappedObject();
    return null;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:13,代码来源:ContextFtlUtil.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NotInServiceMenu类代码示例发布时间:2022-05-22
下一篇:
Java Caverphone2类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap