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


Java WrapperTemplateModel类代码示例

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


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


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