freemarker.template.TemplateCollectionModel#iterator ( )源码实例Demo

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

源代码1 项目: 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");
    }
}
 
源代码2 项目: 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);
}
 
源代码3 项目: 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);
}
 
源代码4 项目: 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);
}
 
源代码5 项目: 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);
}
 
源代码6 项目: 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));
    }
}
 
源代码7 项目: 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));
    }
}
 
源代码8 项目: 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;
}
 
源代码9 项目: 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()));
    }
}
 
源代码10 项目: 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());
    }
}