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


Java ObjectWrapper类代码示例

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


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

示例1: initialValue

import freemarker.template.ObjectWrapper; //导入依赖的package包/类
@Override
protected ObjectWrapper initialValue()
{
    return new DefaultObjectWrapper()
    {
        /* (non-Javadoc)
         * @see freemarker.template.DefaultObjectWrapper#wrap(java.lang.Object)
         */
        @Override
        public TemplateModel wrap(Object obj) throws TemplateModelException
        {
            if (obj instanceof QNameMap)
            {
                return new QNameHash((QNameMap)obj, this);
            }
            else
            {
                return super.wrap(obj);
            }
        }
    };
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:23,代码来源:QNameAwareObjectWrapper.java

示例2: getRequestStackAsList

import freemarker.template.ObjectWrapper; //导入依赖的package包/类
/**
 * Gets the request stack as a list. The stack cannot be modified using this list.
 * It may be TemplateModel-wrapped or unwrapped as may be the individual values.
 *
 * @param name
 * @param request
 * @param context
 * @param env
 * @param copyTargetType target type for list copy. if null, does not copy (should be avoided in most cases!).
 * @return
 * @throws TemplateModelException
 */
static Object getRequestStackAsList(String name, HttpServletRequest request, 
        Map<String, Object> context, Environment env, ObjectWrapper objectWrapper, TemplateValueTargetType copyTargetType) throws TemplateModelException {
    if (request != null) {
        return getStackAsList(getRequestVarMapFromReqAttribs(request), name, copyTargetType, objectWrapper, "request attributes");
    }
    else {
        Map<String, Object> globalContext = getGlobalContext(context, env);
        if (globalContext != null) {  
            return getStackAsList(getRequestVarMapFromGlobalContext(globalContext), name, copyTargetType, objectWrapper, "globalContext");
        }
        else if (env != null) {
            return getStackAsList(getRequestVarMapFromFtlGlobals(env), name, copyTargetType, objectWrapper, "FTL globals");
        }
        else {
            throw new IllegalArgumentException("No request, context or ftl environment to get request scope stack (name: " + name + ")");
        }
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:31,代码来源:ContextFtlUtil.java

示例3: getStackAsList

import freemarker.template.ObjectWrapper; //导入依赖的package包/类
private static Object getStackAsList(Map<String, Object> varMap, String name, TemplateValueTargetType copyTargetType, ObjectWrapper objectWrapper, String desc) throws TemplateModelException {
    List<Object> stack = null;
    Object stackObj = varMap.get(name);
    if (stackObj instanceof List) {
        stack = UtilGenerics.checkList(stackObj);
    }
    if (stack != null) {
        if (copyTargetType == null) {
            return Collections.unmodifiableList(stack);
        }
        else {
            return LangFtlUtil.copyList(stack, copyTargetType, objectWrapper);
        }
    }
    else {
        return null;
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:19,代码来源:ContextFtlUtil.java

示例4: exec

import freemarker.template.ObjectWrapper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object exec(List args) throws TemplateModelException {
    if (args == null || args.size() != 1) {
        throw new TemplateModelException("Invalid number of arguments (expected: 1)");
    }
    TemplateModel nameModel = (TemplateModel) args.get(0);
    if (!(nameModel instanceof TemplateScalarModel)) {
        throw new TemplateModelException("First argument not an instance of TemplateScalarModel (string)");
    }

    Environment env = CommonFtlUtil.getCurrentEnvironment();
    Object res = ContextFtlUtil.getRequestVar(LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) nameModel)), env);
    
    ObjectWrapper objectWrapper = getResultObjectWrapper(env);
    return LangFtlUtil.wrap(res, objectWrapper);
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:18,代码来源:GetRequestVarMethod.java

示例5: execRead

import freemarker.template.ObjectWrapper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected Object execRead(List args, boolean pop) throws TemplateModelException {
    if (args == null || args.size() != 1) {
        throw new TemplateModelException("Invalid number of arguments (expected: 1)");
    }
    TemplateModel nameModel = (TemplateModel) args.get(0);
    if (!(nameModel instanceof TemplateScalarModel)) {
        throw new TemplateModelException("First argument not an instance of TemplateScalarModel (string)");
    }

    Environment env = CommonFtlUtil.getCurrentEnvironment();
    Object res = ContextFtlUtil.readRequestStack(LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) nameModel)), pop, env);
 
    ObjectWrapper objectWrapper = GetRequestVarMethod.getResultObjectWrapper(env);
    return LangFtlUtil.wrap(res, objectWrapper);
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:17,代码来源:RequestStackMethod.java

示例6: exec

import freemarker.template.ObjectWrapper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object exec(List args) throws TemplateModelException {
    if (args == null || args.size() != 2) {
        throw new TemplateModelException("Invalid number of arguments (expected: 2)");
    }
    String styleString = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) args.get(0)));
    styleString = TemplateFtlUtil.getPlainClassArgNames(styleString);
    
    String prefix = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) args.get(1)));
    
    String[] names = StringUtils.split(styleString, ' ');
    // NOTE: For emergency/safety reasons, use the current wrapper, which MAY be escaping.
    // style strings contain only simple characters anyway.
    ObjectWrapper objectWrapper = LangFtlUtil.getCurrentObjectWrapper();
    SimpleSequence res = new SimpleSequence(names.length, objectWrapper);

    for(String name : names) {
        if (name.startsWith(prefix)) {
            res.add(name);
        }
    }
    
    // redundant
    //return LangFtlUtil.wrap(res, objectWrapper);
    return res;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:28,代码来源:GetStyleNamesByPrefixMethod.java

示例7: wrap

import freemarker.template.ObjectWrapper; //导入依赖的package包/类
/**
     * Wraps the TemplateInvoker in an appropriate TemplateModel, using explicit model type.
     * Can be called manually as this logic may not be present in <code>ObjectWrapper.wrap</code>.
     */
    @SuppressWarnings("unchecked")
    public static <T extends TemplateModel> T wrap(TemplateInvoker invoker, WrapperModel targetModel, ObjectWrapper objectWrapper) throws TemplateModelException {
        if (targetModel == null || targetModel == WrapperModel.HYBRID) {
            return (T) new HybridInvokerWrapper(invoker);
        } else if (targetModel == null || targetModel == WrapperModel.SCALAR) {
            // 2017-03-31: just avoid the bean wrapper as much as possible, even though may not entirely be able to
//            if (invoker instanceof StringTemplateInvoker && objectWrapper != null) {
//                return (T) objectWrapper.wrap(invoker);
//            } else {
            return (T) new ScalarInvokerWrapper(invoker);
//            }
        } else if (targetModel == WrapperModel.DIRECTIVE) {
            return (T) new DirectiveInvokerWrapper(invoker);
        }
        throw new UnsupportedOperationException("Unsupported template invoker FTL wrapper model: " + targetModel);
    }
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:21,代码来源:TemplateInvoker.java

示例8: makeOptions

import freemarker.template.ObjectWrapper; //导入依赖的package包/类
public static WrappingOptions makeOptions(String wrapper, String mode, Environment env) throws TemplateModelException {
    ObjectWrapper targetWrapper = ObjectWrapperUtil.getObjectWrapperByName(wrapper, env);
    if (targetWrapper == null) {
        throw new TemplateModelException("Unrecognized wrapper name: " + wrapper);
    }
    if (wrapper == null) {
        wrapper = "";
    }
    
    RewrapMode rewrapMode = RewrapMode.ALWAYS_DEEP;
    if (mode != null && !mode.isEmpty()) {
        rewrapMode = RewrapMode.fromString(mode);
        if (rewrapMode == null) {
            throw new TemplateModelException("Unrecognized rewrapping mode: " + mode);
        }
    }
    
    return new WrappingOptions(wrapper, ObjectWrapperUtil.getObjectWrapperByName(wrapper, env), 
            rewrapMode, env.getObjectWrapper());
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:21,代码来源:WrappingOptions.java

示例9: exec

import freemarker.template.ObjectWrapper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object exec(List args) throws TemplateModelException {
    if (args == null || args.size() < 0 || args.size() > 1) {
        throw new TemplateModelException("Invalid number of arguments (expected: 0-1)");
    }
    Environment env = CommonFtlUtil.getCurrentEnvironment();
    
    if (args.size() > 0) {
        TemplateModel object = (TemplateModel) args.get(0);

        ObjectWrapper objectWrapper = LangFtlUtil.getCurrentObjectWrapper(env);
        return LangFtlUtil.toSet(object, objectWrapper);
    }
    else {
        return new HashSet<Object>();
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:19,代码来源:ToSetMethod.java

示例10: copyMap

import freemarker.template.ObjectWrapper; //导入依赖的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

示例11: toSimpleMap

import freemarker.template.ObjectWrapper; //导入依赖的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

示例12: makeSimpleMapAdapter

import freemarker.template.ObjectWrapper; //导入依赖的package包/类
/**
 * Adapts a map to a TemplateHashModelEx using an appropriate simple adapter, normally 
 * DefaultMapAdapter (or SimpleMapModel for BeansWrapper compatibility).
 * <p>
 * The ObjectWrapper is expected to implement at least ObjectWrapperWithAPISupport.
 * <p>
 * WARN: If impossible, it will duplicate the map using SimpleHash; but because this may result
 * in loss of ordering, a log warning will be printed.
 */
public static TemplateHashModelEx makeSimpleMapAdapter(Map<?, ?> map, ObjectWrapper objectWrapper, boolean permissive) throws TemplateModelException {
    // COMPATIBILITY MODE: check if exactly BeansWrapper, or a class that we know extends it WITHOUT extending DefaultObjectWrapper
    if (objectWrapper instanceof ScipioBeansWrapper || BeansWrapper.class.equals(objectWrapper.getClass())) {
        return new SimpleMapModel(map, (BeansWrapper) objectWrapper);
    } else if (objectWrapper instanceof ObjectWrapperWithAPISupport) {
        return DefaultMapAdapter.adapt(map, (ObjectWrapperWithAPISupport) objectWrapper);
    } else {
        if (permissive) {
            Debug.logWarning("Scipio: adaptSimpleMap: Unsupported Freemarker object wrapper (expected to implement ObjectWrapperWithAPISupport or BeansWrapper); forced to adapt map"
                    + " using SimpleHash; this could cause loss of map insertion ordering; please switch renderer setup to a different ObjectWrapper", module);
            return new SimpleHash(map, objectWrapper);
        } else {
            throw new TemplateModelException("Tried to wrap a Map using an adapter class,"
                    + " but our ObjectWrapper does not implement ObjectWrapperWithAPISupport or BeansWrapper"
                    + "; please switch renderer setup to a different ObjectWrapper");
        }
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:28,代码来源:LangFtlUtil.java

示例13: toSimpleMapRewrapAdapters

import freemarker.template.ObjectWrapper; //导入依赖的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

示例14: toSimpleMapRewrapAny

import freemarker.template.ObjectWrapper; //导入依赖的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

示例15: combineMaps

import freemarker.template.ObjectWrapper; //导入依赖的package包/类
/**
 * Combines two maps with the given operator into a new hash.
 */
public static TemplateHashModelEx combineMaps(TemplateHashModelEx first, TemplateHashModelEx second, SetOperations ops, 
        ObjectWrapper objectWrapper) throws TemplateModelException {
    SimpleHash res = new SimpleHash(objectWrapper);
    if (ops == null || ops == SetOperations.UNION) {
        // this is less efficient than freemarker + operator, but provides the "alternative" implementation, so have choice
        addToSimpleMap(res, first);
        addToSimpleMap(res, second);
    }
    else if (ops == SetOperations.INTERSECT) {
        Set<String> intersectKeys = toStringSet(second.keys());
        intersectKeys.retainAll(toStringSet(first.keys()));
        addToSimpleMap(res, second, intersectKeys);
    }
    else if (ops == SetOperations.DIFFERENCE) {
        Set<String> diffKeys = toStringSet(first.keys());
        diffKeys.removeAll(toStringSet(second.keys()));
        addToSimpleMap(res, first, diffKeys);
    }
    else {
        throw new TemplateModelException("Unsupported combineMaps operation");
    }
    return res;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:27,代码来源:LangFtlUtil.java


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