Java Code Examples for freemarker.template.ObjectWrapper#wrap()
The following examples show how to use
freemarker.template.ObjectWrapper#wrap() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 6 votes |
/** * 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 */ @SuppressWarnings("unused") @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"); } }
Example 2
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 6 votes |
/** * 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 */ @SuppressWarnings("unused") @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"); } }
Example 3
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 2 votes |
/** * Scipio wrapper around ObjectWrapper.wrap in case extra logic is needed. * <p> * Currently leaving all to object wrapper, but may change... */ public static TemplateModel wrap(Object object, ObjectWrapper objectWrapper) throws TemplateModelException { return objectWrapper.wrap(object); }