freemarker.template.ObjectWrapper Java Examples
The following examples show how to use
freemarker.template.ObjectWrapper.
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: WrappingOptions.java From scipio-erp with Apache License 2.0 | 6 votes |
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()); }
Example #3
Source File: GetStyleNamesByPrefixMethod.java From scipio-erp with Apache License 2.0 | 6 votes |
@Override public Object exec(@SuppressWarnings("rawtypes") 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; }
Example #4
Source File: ObjectWrapperUtil.java From scipio-erp with Apache License 2.0 | 6 votes |
@Override public ObjectWrapper getWrapper(Environment env) { ObjectWrapper curr = env.getObjectWrapper(); if (curr instanceof ScipioExtendedObjectWrapper) { if (curr instanceof ScipioBeansWrapper) { if (((BeansWrapper) curr).isSimpleMapWrapper()) { return FreeMarkerWorker.getDefaultOfbizSimpleMapWrapper(); } else { return FreeMarkerWorker.getDefaultOfbizWrapper(); } } else { return FreeMarkerWorker.getDefaultOfbizSimpleMapWrapper(); } } else { return curr; } }
Example #5
Source File: RequestStackMethod.java From scipio-erp with Apache License 2.0 | 6 votes |
protected Object execGetAsList(@SuppressWarnings("rawtypes") List args) throws TemplateModelException { if (args == null || args.size() < 1 || args.size() > 2) { throw new TemplateModelException("Invalid number of arguments (expected: 1-2)"); } TemplateModel nameModel = (TemplateModel) args.get(0); if (!(nameModel instanceof TemplateScalarModel)) { throw new TemplateModelException("First argument not an instance of TemplateScalarModel (string)"); } String stackName = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) nameModel)); boolean origList = false; if (args.size() >= 2) { TemplateModel listTypeModel = (TemplateModel) args.get(1); String listType = LangFtlUtil.getAsStringNonEscaping(((TemplateScalarModel) listTypeModel)); if ("orig".equals(listType)) { origList = true; } } Environment env = CommonFtlUtil.getCurrentEnvironment(); ObjectWrapper objectWrapper = GetRequestVarMethod.getResultObjectWrapper(env); Object res = ContextFtlUtil.getRequestStackAsList(stackName, (origList ? null : LangFtlUtil.TemplateValueTargetType.SIMPLEMODEL), env, objectWrapper); return LangFtlUtil.wrap(res, objectWrapper); }
Example #6
Source File: GetRequestVarMethod.java From scipio-erp with Apache License 2.0 | 6 votes |
@Override public Object exec(@SuppressWarnings("rawtypes") 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); }
Example #7
Source File: ContextFtlUtil.java From scipio-erp with Apache License 2.0 | 6 votes |
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; } }
Example #8
Source File: ContextFtlUtil.java From scipio-erp with Apache License 2.0 | 6 votes |
/** * 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 + ")"); } } }
Example #9
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 6 votes |
/** * 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; }
Example #10
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 6 votes |
/** * 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()); }
Example #11
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 6 votes |
/** * 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"); } }
Example #12
Source File: QNameAwareObjectWrapper.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@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); } } }; }
Example #13
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 #14
Source File: FreeMarkerInlineRenderBootstrap.java From rice with Educational Community License v2.0 | 6 votes |
/** * Initialize FreeMarker elements after servlet context and FreeMarker configuration have both * been populated. */ private static void finishConfig() { if (freeMarkerConfig != null && servletContext != null) { taglibFactory = new TaglibFactory(servletContext); objectWrapper = freeMarkerConfig.getObjectWrapper(); if (objectWrapper == null) { objectWrapper = ObjectWrapper.DEFAULT_WRAPPER; } GenericServlet servlet = new ServletAdapter(); try { servlet.init(new DelegatingServletConfig()); } catch (ServletException ex) { throw new BeanInitializationException("Initialization of GenericServlet adapter failed", ex); } servletContextHashModel = new ServletContextHashModel(servlet, ObjectWrapper.DEFAULT_WRAPPER); LOG.info("Freemarker configuration complete"); } }
Example #15
Source File: Freemarker.java From freeacs with MIT License | 6 votes |
/** * Inits the freemarker. * * @return the configuration */ public static Configuration initFreemarker() { try { Configuration config = new Configuration(); config.setTemplateLoader(new ClassTemplateLoader(Freemarker.class, "/templates")); config.setTemplateUpdateDelay(0); config.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER); config.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER); config.setDefaultEncoding("ISO-8859-1"); config.setOutputEncoding("ISO-8859-1"); config.setNumberFormat("0"); config.setSetting("url_escaping_charset", "ISO-8859-1"); config.setLocale(Locale.ENGLISH); setAutoImport(config); setSharedVariables(config); return config; } catch (Throwable e) { throw new RuntimeException("Could not initialise Freemarker configuration", e); } }
Example #16
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 6 votes |
/** * 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"); } } }
Example #17
Source File: AbstractTestExecutorService.java From entando-core with GNU Lesser General Public License v3.0 | 6 votes |
protected TemplateModel createModel(ObjectWrapper wrapper) throws Throwable { HttpServletRequest request = super.getRequestContext().getRequest(); HttpServletResponse response = super.getRequestContext().getResponse(); ServletContext servletContext = request.getSession().getServletContext(); AllHttpScopesHashModel hashModel = new AllHttpScopesHashModel(wrapper, servletContext, request); //super.createModel(wrapper, servletContext, request, response); ControllerServlet servlet = new ControllerServlet(); MockServletConfig config = new MockServletConfig(servletContext); servlet.init(config); ServletContextHashModel newServletContextModel = new ServletContextHashModel(servlet, wrapper); ServletContextHashModel servletContextModel = new ServletContextHashModel(servlet, wrapper); servletContext.setAttribute(ATTR_APPLICATION_MODEL, servletContextModel); TaglibFactory taglibs = new TaglibFactory(servletContext); servletContext.setAttribute(ATTR_JSP_TAGLIBS_MODEL, taglibs); hashModel.putUnlistedModel(FreemarkerServlet.KEY_APPLICATION, newServletContextModel); hashModel.putUnlistedModel(FreemarkerServlet.KEY_APPLICATION_PRIVATE, newServletContextModel); hashModel.putUnlistedModel(FreemarkerServlet.KEY_JSP_TAGLIBS, taglibs); HttpRequestHashModel requestModel = new HttpRequestHashModel(request, response, wrapper); request.setAttribute(ATTR_REQUEST_MODEL, requestModel); hashModel.putUnlistedModel(FreemarkerServlet.KEY_REQUEST_PRIVATE, requestModel); return hashModel; }
Example #18
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
/** * Checks if the wrapper is a special escaping wrapper, and if so, * returns a non-escaping one. */ public static ObjectWrapper getNonEscapingObjectWrapper(ObjectWrapper objectWrapper) { if (objectWrapper instanceof ScipioExtendedObjectWrapper) { return FreeMarkerWorker.getDefaultOfbizWrapper(); } else { return objectWrapper; } }
Example #19
Source File: FreemarkerConfigurationBuilder.java From ogham with Apache License 2.0 | 5 votes |
private static BeansWrapper getBeansWrapper(Configuration configuration) { ObjectWrapper objectWrapper = configuration.getObjectWrapper(); if (objectWrapper instanceof BeansWrapper) { return (BeansWrapper) objectWrapper; } return new BeansWrapperBuilder(configuration.getIncompatibleImprovements()).build(); }
Example #20
Source File: ExportUtilities.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
/** * Returns an ObjectWrapper of sufficiently high version for pcgen */ public static ObjectWrapper getObjectWrapper() { DefaultObjectWrapperBuilder defaultObjectWrapperBuilder = new DefaultObjectWrapperBuilder( new Version("2.3.28")); return defaultObjectWrapperBuilder.build(); }
Example #21
Source File: WrappingOptions.java From scipio-erp with Apache License 2.0 | 5 votes |
public WrappingOptions(String targetWrapperName, ObjectWrapper targetWrapper, RewrapMode rewrapMode, ObjectWrapper curObjectWrapper) { super(); this.targetWrapperName = targetWrapperName; this.targetWrapper = targetWrapper; this.rewrapMode = rewrapMode; this.curObjectWrapper = curObjectWrapper; }
Example #22
Source File: ObjectWrapperUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
@Override public ObjectWrapper getWrapper(Environment env) { ObjectWrapper wrapper = env.getObjectWrapper(); // FIXME: Support for extended ScipioDefaultObjectWrapper: it is currently ditched by this code if (wrapper instanceof ScipioExtendedBeansWrapper && ((BeansWrapper) wrapper).isSimpleMapWrapper() == simpleMap) { return wrapper; } else { // semi-reliable way to get the language Object simpleEncoder = null; try { simpleEncoder = LangFtlUtil.unwrapOrNull(env.getGlobalVariable("simpleEncoder")); } catch (TemplateModelException e) { ; } if (simpleEncoder != null) { if (simpleEncoder instanceof UtilCodec.HtmlEncoder) { // heuristic return simpleMap ? defaultHtmlExtendedWrapper : defaultHtmlExtendedSimpleMapWrapper; } else { // TODO: REVIEW: what is this doing for non-html?? HtmlWidget was missing other lang support, // that's why not doing it here... return simpleMap ? FreeMarkerWorker.getDefaultOfbizWrapper() : FreeMarkerWorker.getDefaultOfbizSimpleMapWrapper(); } } else { // FIXME: if we don't know the lang, we have to play it safe and use html return simpleMap ? defaultHtmlExtendedWrapper : defaultHtmlExtendedSimpleMapWrapper; } } }
Example #23
Source File: ToSimpleMapMethod.java From scipio-erp with Apache License 2.0 | 5 votes |
@Override public Object exec(@SuppressWarnings("rawtypes") List args) throws TemplateModelException { if (args == null || args.size() != 1) { throw new TemplateModelException("Invalid number of arguments (expected: 1)"); } Environment env = CommonFtlUtil.getCurrentEnvironment(); TemplateModel object = (TemplateModel) args.get(0); ObjectWrapper objectWrapper = LangFtlUtil.getCurrentObjectWrapper(env); return LangFtlUtil.toSimpleMap(object, null, objectWrapper); }
Example #24
Source File: CopyObjectMethod.java From scipio-erp with Apache License 2.0 | 5 votes |
@Override public Object exec(@SuppressWarnings("rawtypes") List args) throws TemplateModelException { if (args == null || args.size() < 1 || args.size() > 2) { throw new TemplateModelException("Invalid number of arguments (expected: 1-2)"); } Environment env = CommonFtlUtil.getCurrentEnvironment(); TemplateModel object = (TemplateModel) args.get(0); ObjectWrapper objectWrapper = LangFtlUtil.getCurrentObjectWrapper(env); return LangFtlUtil.copyObject(object, null, objectWrapper); }
Example #25
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
/** * Checks if the current env wrapper is a special escaping wrapper, and if so, * returns a non-escaping one. */ public static ObjectWrapper getNonEscapingObjectWrapper(Environment env) { ObjectWrapper objectWrapper = env.getObjectWrapper(); if (objectWrapper instanceof ScipioExtendedObjectWrapper) { return FreeMarkerWorker.getDefaultOfbizWrapper(); } else { return objectWrapper; } }
Example #26
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
/** * Checks if the current env wrapper is a special escaping wrapper, and if so, * returns a non-escaping one. */ public static ObjectWrapper getNonEscapingObjectWrapper() { Environment env = FreeMarkerWorker.getCurrentEnvironment(); ObjectWrapper objectWrapper = env.getObjectWrapper(); if (objectWrapper instanceof ScipioExtendedObjectWrapper) { return FreeMarkerWorker.getDefaultOfbizWrapper(); } else { return objectWrapper; } }
Example #27
Source File: AllHttpScopesAndAppContextHashModel.java From engine with GNU General Public License v3.0 | 5 votes |
public AllHttpScopesAndAppContextHashModel(ObjectWrapper wrapper, ApplicationContextAccessor applicationContextAccessor, ServletContext context, HttpServletRequest request, boolean disableVariableRestrictions) { super(wrapper); this.applicationContextAccessor = applicationContextAccessor; this.context = context; this.request = request; this.disableVariableRestrictions = disableVariableRestrictions; }
Example #28
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
/** * Copies a list to a target model/raw list type. In general does not wrap/unwrap individual values. */ public static Object copyList(Object object, TemplateValueTargetType targetType, ObjectWrapper objectWrapper) throws TemplateModelException { if (targetType == null) { targetType = TemplateValueTargetType.PRESERVE; } if (object instanceof Iterable) { return LangFtlUtil.copyList(UtilGenerics.<Iterable<Object>>cast(object), targetType, objectWrapper); } else if (object instanceof TemplateModel) { return LangFtlUtil.copyList((TemplateModel) object, targetType, objectWrapper); } throw new TemplateModelException("Cannot copy list of type " + object.getClass().toString() + " to target type: " + targetType.toString()); }
Example #29
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
@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"); } }
Example #30
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
/** * 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"); } }