freemarker.template.SimpleCollection#freemarker.template.TemplateCollectionModel源码实例Demo

下面列出了freemarker.template.SimpleCollection#freemarker.template.TemplateCollectionModel 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ogham   文件: SpringBeansTemplateHashModelEx.java
@Override
public TemplateCollectionModel keys() throws TemplateModelException {
	return new IteratorModel(new Iterator<String>() {
		private int currentIdx = 0;

		@Override
		public boolean hasNext() {
			return currentIdx < applicationContext.getBeanDefinitionCount();
		}

		@Override
		public String next() {
			if (!hasNext()) {
				throw new NoSuchElementException();
			}
			return "@" + applicationContext.getBeanDefinitionNames()[currentIdx++];
		}

	}, beansWrapper);
}
 
源代码2 项目: ogham   文件: SpringBeansTemplateHashModelEx.java
@Override
public TemplateCollectionModel values() throws TemplateModelException {
	return new IteratorModel(new Iterator<Object>() {
		private int currentIdx = 0;

		@Override
		public boolean hasNext() {
			return currentIdx < applicationContext.getBeanDefinitionCount();
		}

		@Override
		public Object next() {
			if (!hasNext()) {
				throw new NoSuchElementException();
			}
			String name = applicationContext.getBeanDefinitionNames()[currentIdx++];
			return new LazySpringBeanAccessModel(applicationContext, beansWrapper, name);
		}

	}, beansWrapper);
}
 
源代码3 项目: scipio-erp   文件: MultiVarMethod.java
@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());
    }
}
 
源代码4 项目: scipio-erp   文件: LangFtlUtil.java
/**
 * Shallow-copies map or list. Note: won't preserve order for maps.
 *
 * @param object
 * @param targetType 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");
    }
}
 
源代码5 项目: scipio-erp   文件: LangFtlUtil.java
@SuppressWarnings({ "unchecked", "unused" })
@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");
    }
}
 
源代码6 项目: scipio-erp   文件: LangFtlUtil.java
/**
 * Adds all the elements in the given collection to a new set.
 * <p>
 * NOTE: This method does NOT handle string escaping explicitly; you may want {@link #toStringSet} instead.
 */
@SuppressWarnings("unchecked")
public static <T> Set<T> toSet(TemplateModel object) throws TemplateModelException {
    if (object instanceof WrapperTemplateModel && ((WrapperTemplateModel) object).getWrappedObject() instanceof Set) {
        return (Set<T>) ((WrapperTemplateModel) object).getWrappedObject();
    } else if (object instanceof TemplateCollectionModel) {
        return toSet((TemplateCollectionModel) object);
    } else if (object instanceof TemplateSequenceModel) {
        return toSet((TemplateSequenceModel) object);
    } else {
        throw new TemplateModelException("Cannot convert object of type " + (object != null ? object.getClass() : "null") + " to set");
    }
}
 
源代码7 项目: scipio-erp   文件: LangFtlUtil.java
/**
 * Adds all the elements in the given collection to a new set.
 * <p>
 * NOTE: This method does NOT handle string escaping explicitly; you may want {@link #toStringSet} instead.
 */
public static <T> Set<T> toSet(TemplateCollectionModel object) throws TemplateModelException {
    // would be safer to let the wrapper do it, but we know it's just a BeanModel in Ofbiz so we can optimize.
    TemplateCollectionModel collModel = (TemplateCollectionModel) object;
    Set<Object> res = new HashSet<>();
    TemplateModelIterator it = collModel.iterator();
    while(it.hasNext()) {
        res.add(LangFtlUtil.unwrapAlways(it.next()));
    }
    return UtilGenerics.cast(res);
}
 
源代码8 项目: scipio-erp   文件: LangFtlUtil.java
/**
 * Adds all the elements in the given collection to a new set, as TemplateModels.
 * <p>
 * NOTE: This method does NOT handle string escaping explicitly; you may want {@link #toStringSet} instead.
 */
public static <T extends TemplateModel> Set<T> toSetNoUnwrap(TemplateCollectionModel object) throws TemplateModelException {
    // would be safer to let the wrapper do it, but we know it's just a BeanModel in Ofbiz so we can optimize.
    TemplateCollectionModel collModel = (TemplateCollectionModel) object;
    Set<Object> res = new HashSet<>();
    TemplateModelIterator it = collModel.iterator();
    while(it.hasNext()) {
        res.add(it.next());
    }
    return UtilGenerics.cast(res);
}
 
源代码9 项目: scipio-erp   文件: LangFtlUtil.java
/**
 * Adds all the elements in the given collection to a new list.
 * <p>
 * NOTE: This method does NOT handle string escaping explicitly; you may want {@link #toStringSet} instead.
 */
public static <T> List<T> toList(TemplateCollectionModel collModel) throws TemplateModelException {
    // would be safer to let the wrapper do it, but we know it's just a BeanModel in Ofbiz so we can optimize.
    List<Object> res = new ArrayList<>();
    TemplateModelIterator it = collModel.iterator();
    while(it.hasNext()) {
        res.add(LangFtlUtil.unwrapAlways(it.next()));
    }
    return UtilGenerics.cast(res);
}
 
源代码10 项目: scipio-erp   文件: LangFtlUtil.java
/**
 * Adds all the elements in the given collection to a new list, as TemplateModels.
 * <p>
 * NOTE: This method does NOT handle string escaping explicitly; you may want {@link #toStringSet} instead.
 */
public static <T extends TemplateModel> List<T> toListNoUnwrap(TemplateCollectionModel collModel) throws TemplateModelException {
    // would be safer to let the wrapper do it, but we know it's just a BeanModel in Ofbiz so we can optimize.
    List<Object> res = new ArrayList<>();
    TemplateModelIterator it = collModel.iterator();
    while(it.hasNext()) {
        res.add(it.next());
    }
    return UtilGenerics.cast(res);
}
 
源代码11 项目: scipio-erp   文件: LangFtlUtil.java
/**
 * Adds to simple hash from source map.
 * <p>
 * <em>WARN</em>: This is not BeanModel-aware (complex map).
 */
public static void addToSimpleMap(SimpleHash dest, TemplateHashModelEx source) throws TemplateModelException {
    TemplateCollectionModel keysModel = source.keys();
    TemplateModelIterator modelIt = keysModel.iterator();
    while(modelIt.hasNext()) {
        String key = getAsStringNonEscaping((TemplateScalarModel) modelIt.next());
        dest.put(key, source.get(key));
    }
}
 
源代码12 项目: scipio-erp   文件: LangFtlUtil.java
/**
 * Adds the still-wrapped TemplateModels in hash to a java Map.
 * <p>
 * <em>WARN</em>: This is not BeanModel-aware (complex map).
 */
public static void addModelsToMap(Map<String, ? super TemplateModel> dest, TemplateHashModelEx source) throws TemplateModelException {
    TemplateCollectionModel keysModel = source.keys();
    TemplateModelIterator modelIt = keysModel.iterator();
    while(modelIt.hasNext()) {
        String key = getAsStringNonEscaping((TemplateScalarModel) modelIt.next());
        dest.put(key, source.get(key));
    }
}
 
源代码13 项目: scipio-erp   文件: LangFtlUtil.java
/**
 * 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(TemplateCollectionModel collModel) throws TemplateModelException {
    Set<String> set = new HashSet<String>();
    TemplateModelIterator modelIt = collModel.iterator();
    while(modelIt.hasNext()) {
        set.add(getAsStringNonEscaping((TemplateScalarModel) modelIt.next()));
    }
    return set;
}
 
源代码14 项目: scipio-erp   文件: LangFtlUtil.java
/**
 * 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, TemplateCollectionModel collModel) throws TemplateModelException {
    TemplateModelIterator modelIt = collModel.iterator();
    while(modelIt.hasNext()) {
        dest.add(getAsStringNonEscaping((TemplateScalarModel) modelIt.next()));
    }
}
 
源代码15 项目: scipio-erp   文件: LangFtlUtil.java
/**
 * 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;
}
 
源代码16 项目: scipio-erp   文件: LangFtlUtil.java
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());
    }
}
 
@Override
public TemplateCollectionModel keys()
    throws TemplateModelException
{
    List<String> names = descriptor.state().properties()
        .map( descriptor -> descriptor.qualifiedName().name() )
        .collect( Collectors.toList() );
    return (TemplateCollectionModel) wrapper.wrap( names.iterator() );
}
 
源代码18 项目: scipio-erp   文件: LangFtlUtil.java
public static SimpleHash makeSimpleMap(TemplateHashModel map, TemplateCollectionModel keys, ObjectWrapper objectWrapper) throws TemplateModelException {
    SimpleHash res = new SimpleHash(objectWrapper);
    addToSimpleMap(res, map, LangFtlUtil.toStringSet(keys));
    return res;
}
 
源代码19 项目: scipio-erp   文件: LangFtlUtil.java
public static void addToSimpleList(SimpleSequence dest, TemplateCollectionModel source) throws TemplateModelException {
    TemplateModelIterator it = source.iterator();
    while(it.hasNext()) {
        dest.add(it.next());
    }
}
 
源代码20 项目: brooklyn-server   文件: TemplateProcessor.java
public TemplateCollectionModel keys() {
    return new SimpleCollection(map.keySet(), WRAPPER);
}
 
源代码21 项目: brooklyn-server   文件: TemplateProcessor.java
public TemplateCollectionModel values() {
    return new SimpleCollection(map.values(), WRAPPER);
}
 
源代码22 项目: vertx-web   文件: JsonObjectAdapter.java
@Override
public TemplateCollectionModel keys() {
  return new SimpleCollection(jsonObject.fieldNames(), getObjectWrapper());
}
 
源代码23 项目: vertx-web   文件: JsonObjectAdapter.java
@Override
public TemplateCollectionModel values() {
  return new SimpleCollection(jsonObject.getMap().values(), getObjectWrapper());
}