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


Java TemplateSequenceModel类代码示例

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


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

示例1: getAsRawSequence

import freemarker.template.TemplateSequenceModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static Collection<String> getAsRawSequence(TemplateModel elems) throws TemplateModelException {
    if (elems == null || elems instanceof TemplateBooleanModel) {
        return Collections.emptyList();
    } else if (elems instanceof TemplateCollectionModel || elems instanceof TemplateSequenceModel) {
        return (Collection<String>) LangFtlUtil.unwrapAlways(elems);
    } else if (elems instanceof TemplateHashModelEx) {
        return (Collection<String>) LangFtlUtil.getMapKeys(elems);
    } else {
        throw new TemplateModelException("invalid parameter type, can't interpret as sequence: " + elems.getClass());
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:13,代码来源:MultiVarMethod.java

示例2: copyObject

import freemarker.template.TemplateSequenceModel; //导入依赖的package包/类
/**
 * Shallow-copies map or list. Note: won't preserve order for maps.
 * 
 * @param object
 * @param toSimpleType if true, converts to simple FTL type instead of beans, where possible
 * @return
 * @throws TemplateModelException
 */
public static Object copyObject(TemplateModel object, TemplateValueTargetType targetType, ObjectWrapper objectWrapper) throws TemplateModelException {
    if (targetType == null) {
        targetType = TemplateValueTargetType.PRESERVE;
    }
    if (OfbizFtlObjectType.COMPLEXMAP.isObjectType(object) || (object instanceof TemplateHashModelEx && OfbizFtlObjectType.MAP.isObjectType(object))) {
        return LangFtlUtil.copyMap(object, null, null, targetType, objectWrapper);
    }
    else if (object instanceof TemplateCollectionModel || object instanceof TemplateSequenceModel) {
        return LangFtlUtil.copyList(object, targetType, objectWrapper);
    }
    else {
        throw new TemplateModelException("object is not cloneable");
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:23,代码来源:LangFtlUtil.java

示例3: toStringSet

import freemarker.template.TemplateSequenceModel; //导入依赖的package包/类
/**
 * To string set.
 * <p>
 * WARN: bypasses auto-escaping, caller handles.
 * (e.g. the object wrapper used to rewrap the result).
 */
public static Set<String> toStringSet(TemplateSequenceModel seqModel) throws TemplateModelException {
    Set<String> set = new HashSet<String>();
    for(int i=0; i < seqModel.size(); i++) {
        set.add(getAsStringNonEscaping((TemplateScalarModel) seqModel.get(i)));
    }
    return set;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:14,代码来源:LangFtlUtil.java

示例4: getAsStringSet

import freemarker.template.TemplateSequenceModel; //导入依赖的package包/类
/**
 * Gets collection as a keys.
 * <p>
 * WARN: This bypasses auto-escaping in all cases. Caller must decide how to handle.
 * (e.g. the object wrapper used to rewrap the result).
 */
public static Set<String> getAsStringSet(TemplateModel model) throws TemplateModelException {
    Set<String> exKeys = null;
    if (model != null) {
        if (model instanceof BeanModel && ((BeanModel) model).getWrappedObject() instanceof Set) {
            // WARN: bypasses auto-escaping
            exKeys = UtilGenerics.cast(((BeanModel) model).getWrappedObject());
        }
        else if (model instanceof TemplateCollectionModel) {
            exKeys = new HashSet<String>();
            TemplateModelIterator keysIt = ((TemplateCollectionModel) model).iterator();
            while(keysIt.hasNext()) {
                exKeys.add(getAsStringNonEscaping((TemplateScalarModel) keysIt.next()));
            }
        }
        else if (model instanceof TemplateSequenceModel) {
            TemplateSequenceModel seqModel = (TemplateSequenceModel) model;
            exKeys = new HashSet<String>(seqModel.size());
            for(int i=0; i < seqModel.size(); i++) {
                exKeys.add(getAsStringNonEscaping((TemplateScalarModel) seqModel.get(i)));
            }
        }
        else {
            throw new TemplateModelException("Include/exclude keys argument not a collection or set of strings");
        }
    }
    return exKeys;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:34,代码来源:LangFtlUtil.java

示例5: addToSimpleList

import freemarker.template.TemplateSequenceModel; //导入依赖的package包/类
public static void addToSimpleList(SimpleSequence dest, TemplateModel source) throws TemplateModelException {
    if (source instanceof TemplateCollectionModel) {
        addToSimpleList(dest, (TemplateCollectionModel) source);
    }
    else if (source instanceof TemplateSequenceModel) {
        addToSimpleList(dest, (TemplateSequenceModel) source);
    }
    else {
        throw new TemplateModelException("Can't add to simple list from source type (non-list type): " + source.getClass());
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:12,代码来源:LangFtlUtil.java

示例6: getChildNodes

import freemarker.template.TemplateSequenceModel; //导入依赖的package包/类
@Override
public TemplateSequenceModel getChildNodes() throws TemplateModelException {
	return new TemplateSequenceModel() {
		
		@Override
		public int size() throws TemplateModelException {
			return node.getChildren() != null ? node.getChildren().size() : 0;
		}
		
		@Override
		public TemplateModel get(int index) throws TemplateModelException {
			return node.getChildren() != null ? new TemplateNode(node.getChildren().get(index)) : null;
		}
	};
}
 
开发者ID:PayWithMyBank,项目名称:ncl,代码行数:16,代码来源:TemplateNode.java

示例7: execute

import freemarker.template.TemplateSequenceModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void execute(Environment env, Map params, TemplateModel[] loopVars,
		TemplateDirectiveBody body) throws TemplateException, IOException {
	// 此处的权限判断有可能和拦截器的不一致,有没有关系?大部分应该没有关系,因为不需要判断权限的可以不加这个标签。
	// 光一个perms可能还不够,至少还有一个是否只浏览的问题。这个是否可以不管?可以!
	// 是否控制权限这个总是要的吧?perms为null代表无需控制权限。
	String url = DirectiveUtils.getString(PARAM_URL, params);
	boolean pass = false;
	if (StringUtils.isBlank(url)) {
		// url为空,则认为有权限。
		pass = true;
	} else {
		TemplateSequenceModel perms = getPerms(env);
		if (perms == null) {
			// perms为null,则代表不需要判断权限。
			pass = true;
		} else {
			String perm;
			if(url.contains(":")){
				url="/"+url.replace(":", "/");
			}
			for (int i = 0, len = perms.size(); i < len; i++) {
				perm = ((TemplateScalarModel) perms.get(i)).getAsString();
				if (url.startsWith(perm)) {
					pass = true;
					break;
				}
			}
		}
	}
	if (pass) {
		body.render(env.getOut());
	}
}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:35,代码来源:PermistionDirective.java

示例8: getPerms

import freemarker.template.TemplateSequenceModel; //导入依赖的package包/类
private TemplateSequenceModel getPerms(Environment env)
		throws TemplateModelException {
	TemplateModel model = env.getDataModel().get(PERMISSION_MODEL);
	if (model == null) {
		return null;
	}
	if (model instanceof TemplateSequenceModel) {
		return (TemplateSequenceModel) model;
	} else {
		throw new TemplateModelException(
				"'perms' in data model not a TemplateSequenceModel");
	}

}
 
开发者ID:huanzhou,项目名称:jeecms6,代码行数:15,代码来源:PermistionDirective.java

示例9: get

import freemarker.template.TemplateSequenceModel; //导入依赖的package包/类
public static <T> T get(Map params, String paramName, Class<T> class1) {
	Object param=params.get(paramName);
	if (param!=null && param instanceof StringModel){
		StringModel criteriaModel=(StringModel)param;
		Object obj=criteriaModel.getWrappedObject();
		if (class1.isAssignableFrom(obj.getClass())){
			return (T)obj;
		}
	}else if (param!=null && !(param instanceof TemplateSequenceModel)){
		logger.error("Macro param type invalid");
	}
	return null;
}
 
开发者ID:jerolba,项目名称:funsteroid,代码行数:14,代码来源:MacroHelper.java

示例10: execute

import freemarker.template.TemplateSequenceModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void execute(Environment env, Map params, TemplateModel[] loopVars,
		TemplateDirectiveBody body) throws TemplateException, IOException {
	// 此处的权限判断有可能和拦截器的不一致,有没有关系?大部分应该没有关系,因为不需要判断权限的可以不加这个标签。
	// 光一个perms可能还不够,至少还有一个是否只浏览的问题。这个是否可以不管?可以!
	// 是否控制权限这个总是要的吧?perms为null代表无需控制权限。
	String url = DirectiveUtils.getString(PARAM_URL, params);
	boolean pass = false;
	if (StringUtils.isBlank(url)) {
		// url为空,则认为有权限。
		pass = true;
	} else {
		TemplateSequenceModel perms = getPerms(env);
		if (perms == null) {
			// perms为null,则代表不需要判断权限。
			pass = true;
		} else {
			String perm;
			for (int i = 0, len = perms.size(); i < len; i++) {
				perm = ((TemplateScalarModel) perms.get(i)).getAsString();
				if (url.startsWith(perm)) {
					pass = true;
					break;
				}
			}
		}
	}
	if (pass) {
		body.render(env.getOut());
	}
}
 
开发者ID:caipiao,项目名称:Lottery,代码行数:32,代码来源:PermistionDirective.java

示例11: toSimpleSequence

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

示例12: makeSimpleMap

import freemarker.template.TemplateSequenceModel; //导入依赖的package包/类
public static SimpleHash makeSimpleMap(TemplateHashModel map, TemplateSequenceModel keys, ObjectWrapper objectWrapper) throws TemplateModelException {
    SimpleHash res = new SimpleHash(objectWrapper);
    addToSimpleMap(res, map, LangFtlUtil.toStringSet(keys));
    return res;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:6,代码来源:LangFtlUtil.java

示例13: addToStringSet

import freemarker.template.TemplateSequenceModel; //导入依赖的package包/类
/**
 * Add to string set.
 * <p>
 * WARN: bypasses auto-escaping, caller handles.
 * (e.g. the object wrapper used to rewrap the result).
 */
public static void addToStringSet(Set<String> dest, TemplateSequenceModel seqModel) throws TemplateModelException {
    for(int i=0; i < seqModel.size(); i++) {
        dest.add(getAsStringNonEscaping(((TemplateScalarModel) seqModel.get(i))));
    }
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:12,代码来源:LangFtlUtil.java


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