Example usage for com.liferay.portal.kernel.theme ThemeDisplay getLanguageId

List of usage examples for com.liferay.portal.kernel.theme ThemeDisplay getLanguageId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.theme ThemeDisplay getLanguageId.

Prototype

public String getLanguageId() 

Source Link

Document

Returns the current language's code.

Usage

From source file:com.liferay.asset.browser.web.internal.display.context.AssetBrowserDisplayContext.java

License:Open Source License

public AssetBrowserSearch getAssetBrowserSearch() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    AssetBrowserSearch assetBrowserSearch = new AssetBrowserSearch(_renderRequest, getPortletURL());

    if (Validator.isNull(getKeywords())) {
        if (Validator.isNotNull(getAddButtonURL())) {
            assetBrowserSearch//from  w w  w  .  j a va  2  s  .  co m
                    .setEmptyResultsMessageCssClass("taglib-empty-result-message-header-has-plus-btn");
        }
    } else {
        assetBrowserSearch.setSearch(true);
    }

    AssetRendererFactory assetRendererFactory = getAssetRendererFactory();

    int total = getTotal();

    assetBrowserSearch.setTotal(total);

    if (AssetBrowserWebConfigurationValues.SEARCH_WITH_DATABASE) {
        List<AssetEntry> assetEntries = AssetEntryLocalServiceUtil.getEntries(getFilterGroupIds(),
                new long[] { assetRendererFactory.getClassNameId() }, getKeywords(), getKeywords(),
                getKeywords(), getKeywords(), getListable(), false, false, assetBrowserSearch.getStart(),
                assetBrowserSearch.getEnd(), "modifiedDate", StringPool.BLANK, getOrderByType(),
                StringPool.BLANK);

        assetBrowserSearch.setResults(assetEntries);
    } else {
        Sort sort = null;

        boolean orderByAsc = false;

        if (Objects.equals(getOrderByType(), "asc")) {
            orderByAsc = true;
        }

        if (Objects.equals(getOrderByCol(), "modified-date")) {
            sort = new Sort(Field.MODIFIED_DATE, Sort.LONG_TYPE, orderByAsc);
        } else if (Objects.equals(getOrderByCol(), "title")) {
            String sortFieldName = DocumentImpl
                    .getSortableFieldName("localized_title_".concat(themeDisplay.getLanguageId()));

            sort = new Sort(sortFieldName, Sort.STRING_TYPE, orderByAsc);
        }

        Hits hits = AssetEntryLocalServiceUtil.search(themeDisplay.getCompanyId(), getFilterGroupIds(),
                themeDisplay.getUserId(), assetRendererFactory.getClassName(), getSubtypeSelectionId(),
                getKeywords(), isShowNonindexable(), getStatuses(), assetBrowserSearch.getStart(),
                assetBrowserSearch.getEnd(), sort);

        List<AssetEntry> assetEntries = _assetHelper.getAssetEntries(hits);

        assetBrowserSearch.setResults(assetEntries);
    }

    return assetBrowserSearch;
}

From source file:com.liferay.asset.categories.navigation.web.internal.display.context.AssetCategoriesNavigationDisplayContext.java

License:Open Source License

protected String getTitle(AssetVocabulary assetVocabulary) {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    String title = HtmlUtil.escape(assetVocabulary.getTitle(themeDisplay.getLanguageId()));

    if (assetVocabulary.getGroupId() == themeDisplay.getCompanyGroupId()) {
        title += " (" + LanguageUtil.get(_request, "global") + ")";
    }/*from   w  w w .  ja v  a 2 s .c om*/

    return title;
}

From source file:com.liferay.configuration.admin.web.internal.portlet.action.BindConfigurationMVCActionCommand.java

License:Open Source License

@Override
public boolean processAction(ActionRequest actionRequest, ActionResponse actionResponse)
        throws PortletException {

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

    String factoryPid = ParamUtil.getString(actionRequest, "factoryPid");

    String pid = ParamUtil.getString(actionRequest, "pid", factoryPid);

    if (_log.isDebugEnabled()) {
        _log.debug("Binding attributes for service " + pid);
    }/*w  w w  .j a v a  2  s  .  c o m*/

    ConfigurationModel configurationModel = null;

    Map<String, ConfigurationModel> configurationModels = _configurationModelRetriever
            .getConfigurationModels(themeDisplay.getLanguageId());

    if (Validator.isNotNull(factoryPid)) {
        configurationModel = configurationModels.get(factoryPid);
    } else {
        configurationModel = configurationModels.get(pid);
    }

    Configuration configuration = _configurationModelRetriever.getConfiguration(pid);

    ResourceBundleLoader resourceBundleLoader = _resourceBundleLoaderProvider
            .getResourceBundleLoader(configurationModel.getBundleSymbolicName());

    ResourceBundle resourceBundle = resourceBundleLoader.loadResourceBundle(themeDisplay.getLocale());

    ConfigurationModelToDDMFormConverter configurationModelToDDMFormConverter = new ConfigurationModelToDDMFormConverter(
            configurationModel, themeDisplay.getLocale(), resourceBundle);

    DDMForm ddmForm = configurationModelToDDMFormConverter.getDDMForm();

    DDMFormValues ddmFormValues = getDDMFormValues(actionRequest, ddmForm);

    DDMFormValuesToPropertiesConverter ddmFormValuesToPropertiesConverter = new DDMFormValuesToPropertiesConverter(
            configurationModel, ddmFormValues, _jsonFactory, themeDisplay.getLocale());

    Dictionary<String, Object> properties = ddmFormValuesToPropertiesConverter.getProperties();

    properties.put(Constants.SERVICE_PID, pid);

    if (Validator.isNotNull(factoryPid)) {
        properties.put(ConfigurationAdmin.SERVICE_FACTORYPID, factoryPid);
    }

    try {
        configureTargetService(configurationModel, configuration, properties);
    } catch (ConfigurationModelListenerException cmle) {
        SessionErrors.add(actionRequest, ConfigurationModelListenerException.class, cmle);

        actionResponse.setRenderParameter("mvcRenderCommandName", "/edit_configuration");
    }

    return true;
}

From source file:com.liferay.configuration.admin.web.internal.portlet.action.EditConfigurationMVCRenderCommand.java

License:Open Source License

@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException {

    String factoryPid = ParamUtil.getString(renderRequest, "factoryPid");

    String pid = ParamUtil.getString(renderRequest, "pid", factoryPid);

    MVCRenderCommand customRenderCommand = _renderCommands.get(pid);

    if (customRenderCommand != null) {
        return customRenderCommand.render(renderRequest, renderResponse);
    }/*from   w w w .j  a  v  a 2s .c o m*/

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

    Map<String, ConfigurationModel> configurationModels = _configurationModelRetriever
            .getConfigurationModels(themeDisplay.getLanguageId());

    ConfigurationModel configurationModel = configurationModels.get(pid);

    if ((configurationModel == null) && Validator.isNotNull(factoryPid)) {
        configurationModel = configurationModels.get(factoryPid);
    }

    if ((configurationModel != null) && !configurationModel.isCompanyFactory()) {

        Configuration configuration = _configurationModelRetriever.getConfiguration(pid);

        configurationModel = new ConfigurationModel(configurationModel.getExtendedObjectClassDefinition(),
                configuration, configurationModel.getBundleSymbolicName(),
                configurationModel.getBundleLocation(), configurationModel.isFactory());
    }

    if (configurationModel != null) {
        renderRequest.setAttribute(ConfigurationAdminWebKeys.CONFIGURATION_MODEL, configurationModel);

        DDMFormRendererHelper ddmFormRendererHelper = new DDMFormRendererHelper(renderRequest, renderResponse,
                configurationModel, _ddmFormRenderer, _resourceBundleLoaderProvider);

        renderRequest.setAttribute(ConfigurationAdminWebKeys.CONFIGURATION_MODEL_FORM_HTML,
                ddmFormRendererHelper.getDDMFormHTML());

        renderRequest.setAttribute(ConfigurationAdminWebKeys.RESOURCE_BUNDLE_LOADER_PROVIDER,
                _resourceBundleLoaderProvider);

        return "/edit_configuration.jsp";
    }

    SessionErrors.add(renderRequest, "entryInvalid");

    return "/error.jsp";
}

From source file:com.liferay.configuration.admin.web.internal.portlet.action.ExportConfigurationMVCResourceCommand.java

License:Open Source License

protected void exportAll(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {

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

    String languageId = themeDisplay.getLanguageId();

    ZipWriter zipWriter = ZipWriterFactoryUtil.getZipWriter();

    Map<String, ConfigurationModel> configurationModels = _configurationModelRetriever
            .getConfigurationModels(themeDisplay.getLanguageId());

    for (ConfigurationModel configurationModel : configurationModels.values()) {

        if (configurationModel.isFactory()) {
            String curFactoryPid = configurationModel.getFactoryPid();

            List<ConfigurationModel> factoryInstances = _configurationModelRetriever
                    .getFactoryInstances(configurationModel);

            for (ConfigurationModel factoryInstance : factoryInstances) {
                String curPid = factoryInstance.getID();

                String curFileName = getFileName(curFactoryPid, curPid);

                zipWriter.addEntry(curFileName, ConfigurationExporter
                        .getPropertiesAsBytes(getProperties(languageId, curFactoryPid, curPid)));
            }/* w w w  .  j  a va 2  s  .  c om*/
        } else if (configurationModel.hasConfiguration()) {
            String curPid = configurationModel.getID();

            String curFileName = getFileName(null, curPid);

            zipWriter.addEntry(curFileName,
                    ConfigurationExporter.getPropertiesAsBytes(getProperties(languageId, curPid, curPid)));
        }
    }

    String fileName = "liferay-system-settings.zip";

    PortletResponseUtil.sendFile(resourceRequest, resourceResponse, fileName,
            new FileInputStream(zipWriter.getFile()), ContentTypes.APPLICATION_ZIP);
}

From source file:com.liferay.configuration.admin.web.internal.portlet.action.ExportConfigurationMVCResourceCommand.java

License:Open Source License

protected void exportFactoryPid(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

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

    String languageId = themeDisplay.getLanguageId();

    ZipWriter zipWriter = ZipWriterFactoryUtil.getZipWriter();

    String factoryPid = ParamUtil.getString(resourceRequest, "factoryPid");

    Map<String, ConfigurationModel> configurationModels = _configurationModelRetriever
            .getConfigurationModels(themeDisplay.getLanguageId());

    ConfigurationModel factoryConfigurationModel = configurationModels.get(factoryPid);

    List<ConfigurationModel> factoryInstances = _configurationModelRetriever
            .getFactoryInstances(factoryConfigurationModel);

    for (ConfigurationModel factoryInstance : factoryInstances) {
        String curPid = factoryInstance.getID();

        String curFileName = getFileName(factoryPid, curPid);

        zipWriter.addEntry(curFileName,/*from  w w  w .  ja va 2 s.c  o  m*/
                ConfigurationExporter.getPropertiesAsBytes(getProperties(languageId, factoryPid, curPid)));
    }

    String fileName = "liferay-system-settings-" + factoryConfigurationModel.getFactoryPid() + ".zip";

    PortletResponseUtil.sendFile(resourceRequest, resourceResponse, fileName,
            new FileInputStream(zipWriter.getFile()), ContentTypes.APPLICATION_ZIP);
}

From source file:com.liferay.configuration.admin.web.internal.portlet.action.ExportConfigurationMVCResourceCommand.java

License:Open Source License

protected void exportPid(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception {

    String factoryPid = ParamUtil.getString(resourceRequest, "factoryPid");
    String pid = ParamUtil.getString(resourceRequest, "pid");

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

    String languageId = themeDisplay.getLanguageId();

    String fileName = getFileName(factoryPid, pid);

    PortletResponseUtil.sendFile(resourceRequest, resourceResponse, fileName,
            ConfigurationExporter.getPropertiesAsBytes(getProperties(languageId, factoryPid, pid)),
            ContentTypes.TEXT_XML_UTF8);
}

From source file:com.liferay.configuration.admin.web.internal.portlet.action.ViewFactoryInstancesMVCRenderCommand.java

License:Open Source License

@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException {

    String factoryPid = ParamUtil.getString(renderRequest, "factoryPid");

    MVCRenderCommand customRenderCommand = _renderCommands.get(factoryPid);

    if (customRenderCommand != null) {
        return customRenderCommand.render(renderRequest, renderResponse);
    }/*from w ww .  j  a  va2  s. c  om*/

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

    Map<String, ConfigurationModel> configurationModels = _configurationModelRetriever
            .getConfigurationModels(themeDisplay.getLanguageId());

    try {
        ConfigurationModel factoryConfigurationModel = configurationModels.get(factoryPid);

        List<ConfigurationModel> factoryInstances = _configurationModelRetriever
                .getFactoryInstances(factoryConfigurationModel);

        renderRequest.setAttribute(ConfigurationAdminWebKeys.CONFIGURATION_MODEL_ITERATOR,
                new ConfigurationModelIterator(factoryInstances));

        renderRequest.setAttribute(ConfigurationAdminWebKeys.FACTORY_CONFIGURATION_MODEL,
                factoryConfigurationModel);

        renderRequest.setAttribute(ConfigurationAdminWebKeys.RESOURCE_BUNDLE_LOADER_PROVIDER,
                _resourceBundleLoaderProvider);

        return "/view_factory_instances.jsp";
    } catch (IOException ioe) {
        throw new PortletException(ioe);
    }
}

From source file:com.liferay.configuration.admin.web.internal.portlet.action.ViewMVCRenderCommand.java

License:Open Source License

@Override
public String render(RenderRequest renderRequest, RenderResponse renderResponse) {

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

    Map<String, ConfigurationModel> configurationModels = _configurationModelRetriever
            .getConfigurationModels(themeDisplay.getLanguageId());

    Map<String, Set<ConfigurationModel>> categorizedConfigurationModels = _configurationModelRetriever
            .categorizeConfigurationModels(configurationModels);

    List<String> configurationCategories = _configurationModelRetriever
            .getConfigurationCategories(categorizedConfigurationModels);

    renderRequest.setAttribute(ConfigurationAdminWebKeys.CONFIGURATION_CATEGORIES, configurationCategories);

    String configurationCategory = ParamUtil.getString(renderRequest, "configurationCategory");

    if (Validator.isNull(configurationCategory)) {
        configurationCategory = configurationCategories.get(0);
    }/*  www  . ja v a  2 s .  c  om*/

    renderRequest.setAttribute(ConfigurationAdminWebKeys.CONFIGURATION_CATEGORY, configurationCategory);

    Set<ConfigurationModel> categoryConfigurationModels = categorizedConfigurationModels
            .get(configurationCategory);

    renderRequest.setAttribute(ConfigurationAdminWebKeys.CONFIGURATION_MODEL_ITERATOR,
            new ConfigurationModelIterator(categoryConfigurationModels));

    renderRequest.setAttribute(ConfigurationAdminWebKeys.RESOURCE_BUNDLE_LOADER_PROVIDER,
            _resourceBundleLoaderProvider);

    return "/view.jsp";
}

From source file:com.liferay.document.library.web.internal.display.context.DLDisplayContextProvider.java

License:Open Source License

public DLViewFileVersionDisplayContext getDLViewFileVersionDisplayContext(HttpServletRequest request,
        HttpServletResponse response, FileShortcut fileShortcut) {

    try {//w  w w  . j  a  va  2  s.  c o  m
        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

        ResourceBundle resourceBundle = _resourceBundleLoader.loadResourceBundle(themeDisplay.getLanguageId());

        DLViewFileVersionDisplayContext dlViewFileVersionDisplayContext = new DefaultDLViewFileVersionDisplayContext(
                request, response, fileShortcut, _dlMimeTypeDisplayContext, resourceBundle, _storageEngine);

        if (fileShortcut == null) {
            return dlViewFileVersionDisplayContext;
        }

        for (DLDisplayContextFactory dlDisplayContextFactory : _dlDisplayContextFactories) {

            dlViewFileVersionDisplayContext = dlDisplayContextFactory.getDLViewFileVersionDisplayContext(
                    dlViewFileVersionDisplayContext, request, response, fileShortcut);
        }

        return dlViewFileVersionDisplayContext;
    } catch (PortalException pe) {
        throw new SystemException(pe);
    }
}