Example usage for com.liferay.portal.template TemplateContextHelper getTemplateVariableGroups

List of usage examples for com.liferay.portal.template TemplateContextHelper getTemplateVariableGroups

Introduction

In this page you can find the example usage for com.liferay.portal.template TemplateContextHelper getTemplateVariableGroups.

Prototype

public static Map<String, TemplateVariableGroup> getTemplateVariableGroups(long classNameId, long classPK,
            String language, Locale locale) throws Exception 

Source Link

Usage

From source file:com.liferay.dynamic.data.mapping.internal.util.DDMTemplateHelperImpl.java

License:Open Source License

protected List<TemplateVariableDefinition> getAutocompleteTemplateVariableDefinitions(
        HttpServletRequest request, String language) throws Exception {

    if (!isAutocompleteEnabled(language)) {
        return Collections.emptyList();
    }/*from w w  w  . j  a  va  2s.com*/

    Set<TemplateVariableDefinition> templateVariableDefinitions = new LinkedHashSet<>();

    // Declared variables

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    DDMTemplate ddmTemplate = (DDMTemplate) request.getAttribute(DDMWebKeys.DYNAMIC_DATA_MAPPING_TEMPLATE);

    long classPK = BeanParamUtil.getLong(ddmTemplate, request, "classPK");
    long classNameId = BeanParamUtil.getLong(ddmTemplate, request, "classNameId");

    if (classPK > 0) {
        DDMStructure ddmStructure = _ddmStructureService.getStructure(classPK);

        classNameId = ddmStructure.getClassNameId();
    } else if (ddmTemplate != null) {
        classNameId = ddmTemplate.getClassNameId();
    }

    Map<String, TemplateVariableGroup> templateVariableGroups = TemplateContextHelper
            .getTemplateVariableGroups(classNameId, classPK, language, themeDisplay.getLocale());

    for (TemplateVariableGroup templateVariableGroup : templateVariableGroups.values()) {

        if (!templateVariableGroup.isAutocompleteEnabled()) {
            continue;
        }

        templateVariableDefinitions.addAll(templateVariableGroup.getTemplateVariableDefinitions());
    }

    // Other variables

    TemplateResource templateResource = new StringTemplateResource(_TEMPLATE_ID, _TEMPLATE_CONTENT);

    Template template = TemplateManagerUtil.getTemplate(language, templateResource, false);

    for (String key : template.getKeys()) {
        Object value = template.get(key);

        if (value == null) {
            continue;
        }

        TemplateVariableDefinition variableDefinition = new TemplateVariableDefinition(key, value.getClass(),
                key, (String) null);

        templateVariableDefinitions.add(variableDefinition);
    }

    return new ArrayList<>(templateVariableDefinitions);
}