freemarker.template.TemplateHashModel Java Examples

The following examples show how to use freemarker.template.TemplateHashModel. 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: FreemarkerStaticModels.java    From cms with Apache License 2.0 6 votes vote down vote up
public static TemplateHashModel useStaticPackage(String packageName) {
	try {
		// BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
		// Create the builder:
	    BeansWrapperBuilder builder = new BeansWrapperBuilder(Configuration.VERSION_2_3_23);
	    // Set desired BeansWrapper configuration properties:
	    builder.setUseModelCache(true);
	    builder.setExposeFields(true);
	    
	    // Get the singleton:
	    BeansWrapper wrapper = builder.build();
	    // You don't need the builder anymore.
		TemplateHashModel staticModels = wrapper.getStaticModels();
		TemplateHashModel fileStatics = (TemplateHashModel) staticModels.get(packageName);
		return fileStatics;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
Example #2
Source File: TransformUtil.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a deep-unwrapped map.
 * FIXME: nonEscaping bool is currently not handled... it may bypass escaping in some cases but not others...
 */
public static <K,V> Map<K, V> getMapArg(TemplateModel obj, Map<K, V> defaultValue, boolean useDefaultWhenEmpty, boolean nonEscaping) throws TemplateModelException {
    if (!nonEscaping) {
        throw new UnsupportedOperationException("getMapArg currently only supports escaping-bypassing (nonEscaping true)");
    }
    Map<K, V> result = null;
    if (obj instanceof TemplateHashModel) {
        result = UtilGenerics.checkMap(LangFtlUtil.unwrapAlways(obj));
    } else if (obj == null) {
        return defaultValue;
    } else {
        throw new TemplateModelException("Expected hash/map model or something coercible to map, but got a " +
                obj.getClass() + " instead");
    }
    if (useDefaultWhenEmpty && result.isEmpty()) {
        return defaultValue;
    }
    return result;
}
 
Example #3
Source File: TemplateProcessor.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
/** Processes template contents against the given {@link TemplateHashModel}. */
public static String processTemplateContents(String templateContents, final TemplateHashModel substitutions) {
    try {
        Configuration cfg = new Configuration();
        StringTemplateLoader templateLoader = new StringTemplateLoader();
        templateLoader.putTemplate("config", templateContents);
        cfg.setTemplateLoader(templateLoader);
        Template template = cfg.getTemplate("config");

        // TODO could expose CAMP '$brooklyn:' style dsl, based on template.createProcessingEnvironment
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Writer out = new OutputStreamWriter(baos);
        template.process(substitutions, out);
        out.flush();

        return new String(baos.toByteArray());
    } catch (Exception e) {
        log.warn("Error processing template (propagating): "+e, e);
        log.debug("Template which could not be parsed (causing "+e+") is:"
            + (Strings.isMultiLine(templateContents) ? "\n"+templateContents : templateContents));
        throw Exceptions.propagate(e);
    }
}
 
Example #4
Source File: LangFtlUtil.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #5
Source File: LangFtlUtil.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #6
Source File: LangFtlUtil.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #7
Source File: LangFtlUtil.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #8
Source File: Java8ObjectWrapper.java    From freemarker-java-8 with Apache License 2.0 5 votes vote down vote up
@Override
protected TemplateModel handleUnknownType(Object obj) throws TemplateModelException {
    TemplateModel delegate = _handleUnknownType(obj);
    return obj instanceof Temporal && delegate instanceof TemplateHashModel
            ? new TemporalDialerAdapter((Temporal) obj, this, (TemplateHashModel) delegate)
            : delegate;
}
 
Example #9
Source File: ItemFacetModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public TemplateModel get(String arg0) throws TemplateModelException
{
	TemplateHashModel model = getInternalHashModel();
	if (model == null)
	{
		return null;
	}
	return model.get(arg0);
}
 
Example #10
Source File: FtlUtil.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
public static TemplateHashModel generateStaticModel(String packageName) {
    try {
        TemplateHashModel staticModels = wrapper.getStaticModels();
        TemplateHashModel fileStatics = (TemplateHashModel) staticModels.get(packageName);
        return fileStatics;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
    return null;
}
 
Example #11
Source File: ItemFacetModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
private TemplateHashModel getInternalHashModel() throws TemplateModelException
{
	if (!cacheSet)
	{
		T obj = facet.get(id);
		TemplateModel wrapped = WRAPPER_FACET.wrap(id, obj);
		if (wrapped instanceof TemplateHashModel)
		{
			cache = (TemplateHashModel) wrapped;
			cacheSet = true;
		}
	}
	return cache;
}
 
Example #12
Source File: CDOMObjectWrapper.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public TemplateHashModel wrap(CharID id, Object o) throws TemplateModelException
{
	if (o instanceof CDOMObject)
	{
		return new CDOMObjectModel(id, (CDOMObject) o);
	}
	throw new TemplateModelException("Object was not a CDOMObject");
}
 
Example #13
Source File: TemplateProcessor.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/** Processes template contents using the given map, passed to freemarker,
 * with dot handling as per {@link DotSplittingTemplateModel}. */
public static String processTemplateContents(String templateContents, final Map<String, ? extends Object> substitutions) {
    TemplateHashModel root;
    try {
        root = substitutions != null
            ? (TemplateHashModel)wrapAsTemplateModel(substitutions)
            : null;
    } catch (TemplateModelException e) {
        throw new IllegalStateException("Unable to set up TemplateHashModel to parse template, given "+substitutions+": "+e, e);
    }
    
    return processTemplateContents(templateContents, root);
}
 
Example #14
Source File: ItemFacetModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public TemplateModel get(String arg0) throws TemplateModelException
{
	TemplateHashModel model = getInternalHashModel();
	if (model == null)
	{
		return null;
	}
	return model.get(arg0);
}
 
Example #15
Source File: ItemFacetModel.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
private TemplateHashModel getInternalHashModel() throws TemplateModelException
{
	if (!cacheSet)
	{
		T obj = facet.get(id);
		TemplateModel wrapped = WRAPPER_FACET.wrap(id, obj);
		if (wrapped instanceof TemplateHashModel)
		{
			cache = (TemplateHashModel) wrapped;
			cacheSet = true;
		}
	}
	return cache;
}
 
Example #16
Source File: CDOMObjectWrapper.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public TemplateHashModel wrap(CharID id, Object o) throws TemplateModelException
{
	if (o instanceof CDOMObject)
	{
		return new CDOMObjectModel(id, (CDOMObject) o);
	}
	throw new TemplateModelException("Object was not a CDOMObject");
}
 
Example #17
Source File: EntityTemplateModel.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public EntityTemplateModel(Entity entity) {
//        logger().debug("model for: " + entity.simpleClassName() + ", r: " + entity.getRepresentation().getClass().getSimpleName());
        try {
            Validate.notNull(entity);
            this.entity = entity;
            this.entityModel = (TemplateHashModel) DEFAULT_OBJECT_WRAPPER.wrap(entity);
            this.representationModel = (TemplateHashModel) DEFAULT_OBJECT_WRAPPER.wrap(entity.getRepresentation());
        } catch (TemplateModelException ex) {
            throw new RuntimeException(ex);
        }
    }
 
Example #18
Source File: FtlUtil.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
public static TemplateHashModel generateStaticModel(String packageName) {
    try {
        BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
        TemplateHashModel staticModels = wrapper.getStaticModels();
        TemplateHashModel fileStatics = (TemplateHashModel) staticModels.get(packageName);
        return fileStatics;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #19
Source File: MakeSectionsRendererMethod.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public Object execTyped(List<TemplateModel> args) throws TemplateModelException {
    if (args.size() != 2) {
        throw new TemplateModelException("Invalid number of arguments (expected: 2)");
    }

    Environment env = FreeMarkerWorker.getCurrentEnvironment();

    TemplateModel arg1 = args.get(0);
    if (!(arg1 instanceof TemplateScalarModel)) {
        throw new TemplateModelException("First argument (type) was not a string");
    }
    String type = LangFtlUtil.getAsStringNonEscaping((TemplateScalarModel) arg1);

    TemplateModel arg2 = args.get(1);
    if (!(arg2 instanceof TemplateHashModel)) {
        throw new TemplateModelException("Second argument (sectionsMap) was not a map");
    }
    TemplateHashModelEx sectionsMapModel = (TemplateHashModelEx) LangFtlUtil.toSimpleMap(arg2, false, env.getObjectWrapper());

    if ("ftl".equals(type)) {
        FtlSectionsRenderer sections = FtlSectionsRenderer.create(sectionsMapModel);
        return sections;
    } else if ("screen".equals(type)) {
        // TODO: "screen": WARN: due to build dependencies we won't be able to invoke widget renderer from here
        // may be forced to use reflection (dirty)...
        throw new TemplateModelException("First argument (type) currently only supports: ftl (screen type not yet implemented)");
    } else {
        throw new TemplateModelException("First argument (type) currently only supports: ftl");
    }
}
 
Example #20
Source File: FtlUtil.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
public static TemplateHashModel generateStaticModel(String packageName) {
    try {
        TemplateHashModel staticModels = wrapper.getStaticModels();
        TemplateHashModel fileStatics = (TemplateHashModel) staticModels.get(packageName);
        return fileStatics;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #21
Source File: FtlUtil.java    From xmfcn-spring-cloud with Apache License 2.0 5 votes vote down vote up
public static TemplateHashModel generateStaticModel(String packageName) {
    try {
        BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
        TemplateHashModel staticModels = wrapper.getStaticModels();
        TemplateHashModel fileStatics = (TemplateHashModel) staticModels.get(packageName);
        return fileStatics;
    } catch (Exception e) {

    }
    return null;
}
 
Example #22
Source File: FreemarkerConfig.java    From TrackRay with GNU General Public License v3.0 5 votes vote down vote up
static TemplateHashModel useStaticPackage(String packageName) {
    try {
        BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
        TemplateHashModel staticModels = wrapper.getStaticModels();
        return (TemplateHashModel) staticModels.get(packageName);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #23
Source File: FtlUtil.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
public static TemplateHashModel generateStaticModel(String packageName) {
    try {
        TemplateHashModel staticModels = wrapper.getStaticModels();
        TemplateHashModel fileStatics = (TemplateHashModel) staticModels.get(packageName);
        return fileStatics;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #24
Source File: FtlUtil.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
public static TemplateHashModel generateStaticModel(String packageName) {
    try {
        TemplateHashModel staticModels = wrapper.getStaticModels();
        TemplateHashModel fileStatics = (TemplateHashModel) staticModels.get(packageName);
        return fileStatics;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #25
Source File: CrafterFreeMarkerView.java    From engine with GNU General Public License v3.0 4 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
protected SimpleHash buildTemplateModel(final Map<String, Object> model, final HttpServletRequest request,
                                        final HttpServletResponse response) {
    AllHttpScopesAndAppContextHashModel templateModel = new AllHttpScopesAndAppContextHashModel(
        getObjectWrapper(), applicationContextAccessor, getServletContext(), request, disableVariableRestrictions);
    HttpSessionHashModel sessionModel = createSessionModel(request, response);
    HttpRequestHashModel requestModel = new HttpRequestHashModel(request, response, getObjectWrapper());
    HttpRequestParametersHashModel requestParamsModel = new HttpRequestParametersHashModel(request);
    Map<String, String> cookies = createCookieMap(request);

    if (disableVariableRestrictions) {
        templateModel.put(KEY_APPLICATION_CAP, servletContextHashModel);
        templateModel.put(KEY_APPLICATION, servletContextHashModel);
        templateModel.put(KEY_APP_CONTEXT_CAP, applicationContextAccessor);
        templateModel.put(KEY_APP_CONTEXT, applicationContextAccessor);
    }

    templateModel.put(KEY_SESSION_CAP, sessionModel);
    templateModel.put(KEY_SESSION, sessionModel);
    templateModel.put(KEY_REQUEST_CAP, requestModel);
    templateModel.put(KEY_REQUEST, requestModel);
    templateModel.put(KEY_REQUEST_PARAMS_CAP, requestParamsModel);
    templateModel.put(KEY_REQUEST_PARAMS, requestParamsModel);

    templateModel.put(KEY_COOKIES_CAP, cookies);
    templateModel.put(KEY_COOKIES, cookies);

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (auth != null) {
        templateModel.put(KEY_AUTH_TOKEN, auth);

        // for backwards compatibility with Profile ...

        if (auth.getPrincipal() instanceof ProfileUser) {
            ProfileUser details = (ProfileUser) auth.getPrincipal();
            templateModel.put(KEY_AUTH_CAP, details.getAuthentication());
            templateModel.put(KEY_AUTH, details.getAuthentication());
            templateModel.put(KEY_PROFILE_CAP, details.getProfile());
            templateModel.put(KEY_PROFILE, details.getProfile());
        }
    }

    SiteContext siteContext = SiteContext.getCurrent();
    Configuration siteConfig = siteContext.getConfig();
    Locale locale = LocaleContextHolder.getLocale();
    Object siteContextObject = disableVariableRestrictions?
            siteContext : new SiteContextHashModel(getObjectWrapper());
    TemplateHashModel staticModels = BeansWrapper.getDefaultInstance().getStaticModels();
    TemplateHashModel enumModels = BeansWrapper.getDefaultInstance().getEnumModels();

    templateModel.put(KEY_STATICS_CAP, staticModels);
    templateModel.put(KEY_STATICS, staticModels);
    templateModel.put(KEY_ENUMS_CAP, enumModels);
    templateModel.put(KEY_ENUMS, enumModels);
    templateModel.put(KEY_SITE_CONTEXT_CAP, siteContextObject);
    templateModel.put(KEY_SITE_CONTEXT, siteContextObject);
    templateModel.put(KEY_LOCALE_CAP, locale);
    templateModel.put(KEY_LOCALE, locale);

    if (siteConfig != null) {
        templateModel.put(KEY_SITE_CONFIG, siteConfig);
        templateModel.put(KEY_SITE_CONFIG_CAP, siteConfig);
    }

    templateModel.putAll(model);

    ObjectFactory<SimpleHash> componentModelFactory = new ObjectFactory<SimpleHash>() {
        public SimpleHash getObject() {
            return buildTemplateModel(model, request, response);
        }
    };

    RenderComponentDirective renderComponentDirective = new RenderComponentDirective();
    renderComponentDirective.setSiteItemService(siteItemService);
    renderComponentDirective.setModelFactory(componentModelFactory);
    renderComponentDirective.setTemplateXPathQuery(componentTemplateXPathQuery);
    renderComponentDirective.setTemplateNamePrefix(componentTemplateNamePrefix);
    renderComponentDirective.setTemplateNameSuffix(componentTemplateNameSuffix);
    renderComponentDirective.setIncludeElementName(componentIncludeElementName);
    renderComponentDirective.setComponentElementName(componentEmbeddedElementName);
    renderComponentDirective.setScriptResolver(componentScriptResolver);
    renderComponentDirective.setServletContext(getServletContext());

    ExecuteControllerDirective executeControllerDirective = new ExecuteControllerDirective();
    executeControllerDirective.setServletContext(getServletContext());

    templateModel.put(RENDER_COMPONENT_DIRECTIVE_NAME, renderComponentDirective);
    templateModel.put(EXECUTE_CONTROLLER_DIRECTIVE_NAME, executeControllerDirective);

    return templateModel;
}
 
Example #26
Source File: FreeMarkerDirectiveBase.java    From cms with Apache License 2.0 4 votes vote down vote up
public void copyParams(Environment env, Map params) throws TemplateModelException
{
	TemplateHashModel dataModel = env.getDataModel();

	TemplateModel localeCountry = dataModel.get(WPBModel.LOCALE_COUNTRY_KEY);
	TemplateModel localeLanguage = dataModel.get(WPBModel.LOCALE_LANGUAGE_KEY);
	params.put(WPBModel.LOCALE_LANGUAGE_KEY, localeLanguage);
	params.put(WPBModel.LOCALE_COUNTRY_KEY, localeCountry);
	
	TemplateModel resourceBundle = dataModel.get(WPBModel.LOCALE_MESSAGES);
	if (resourceBundle != null)
	{
		params.put(WPBModel.LOCALE_MESSAGES, resourceBundle);
	}
	TemplateModel pageParams = dataModel.get(WPBModel.PAGE_PARAMETERS_KEY);
	if (pageParams != null)
	{
		params.put(WPBModel.PAGE_PARAMETERS_KEY, pageParams);
	}
	TemplateModel uriParams = dataModel.get(WPBModel.URI_PARAMETERS_KEY);
	if (uriParams != null)
	{
		params.put(WPBModel.URI_PARAMETERS_KEY, uriParams);
	}
	
	params.put(WPBModel.FORMAT_TEXT_METHOD, dataModel.get(WPBModel.FORMAT_TEXT_METHOD));
	
	TemplateModel globals = dataModel.get(WPBModel.GLOBALS_KEY);
	if (globals != null) 
	{
		params.put(WPBModel.GLOBALS_KEY, globals);
	}
	TemplateModel locale = dataModel.get(WPBModel.LOCALE_KEY);
	if (locale != null) 
	{
		params.put(WPBModel.LOCALE_KEY, locale);
	}

	TemplateModel request = dataModel.get(WPBModel.REQUEST_KEY);
	if (request != null) 
	{
		params.put(WPBModel.REQUEST_KEY, request);
	}

	TemplateModel appModel = dataModel.get(WPBModel.APPLICATION_CONTROLLER_MODEL_KEY);
	if (appModel != null) 
	{
		params.put(WPBModel.APPLICATION_CONTROLLER_MODEL_KEY, appModel);
	}
	
}
 
Example #27
Source File: TemporalDialerAdapter.java    From freemarker-java-8 with Apache License 2.0 4 votes vote down vote up
public TemporalDialerAdapter(Temporal obj, BeansWrapper wrapper, TemplateHashModel delegate) {
    super(obj, wrapper);
    this.delegate = delegate;
}
 
Example #28
Source File: LangFtlUtil.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #29
Source File: LangFtlUtil.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #30
Source File: LangFtlUtil.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
/**
 * Makes a simple hash from source map; only specified keys.
 * <p>
 * <em>WARN</em>: This is not BeanModel-aware (complex map).
 */
public static SimpleHash makeSimpleMap(TemplateHashModel map, Set<String> keys, ObjectWrapper objectWrapper) throws TemplateModelException {
    SimpleHash res = new SimpleHash(objectWrapper);
    addToSimpleMap(res, map, keys);
    return res;
}