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

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

Introduction

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

Prototype

public long getSiteGroupId() 

Source Link

Usage

From source file:com.liferay.journal.content.web.internal.display.context.JournalContentDisplayContext.java

License:Open Source License

public long[] getSelectedGroupIds() throws PortalException {
    ThemeDisplay themeDisplay = (ThemeDisplay) _portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Group scopeGroup = themeDisplay.getScopeGroup();

    if (scopeGroup.isStagingGroup() && !scopeGroup.isInStagingPortlet(JournalPortletKeys.JOURNAL)) {

        return new long[] { scopeGroup.getLiveGroupId() };
    }/*from w  w  w. j av  a  2 s . c  om*/

    if (themeDisplay.getScopeGroupId() == themeDisplay.getSiteGroupId()) {
        return PortalUtil.getSharedContentSiteGroupIds(themeDisplay.getCompanyId(),
                themeDisplay.getScopeGroupId(), themeDisplay.getUserId());
    }

    return new long[] { themeDisplay.getScopeGroupId() };
}

From source file:com.liferay.journal.transformer.JournalTransformer.java

License:Open Source License

protected String doTransform(ThemeDisplay themeDisplay, Map<String, Object> contextObjects,
        Map<String, String> tokens, String viewMode, String languageId, Document document,
        PortletRequestModel portletRequestModel, String script, String langType, boolean propagateException)
        throws Exception {

    // Setup listeners

    if (_log.isDebugEnabled()) {
        _log.debug("Language " + languageId);
    }//w  w  w .j a  va  2s.c om

    if (Validator.isNull(viewMode)) {
        viewMode = Constants.VIEW;
    }

    if (_logTokens.isDebugEnabled()) {
        String tokensString = PropertiesUtil.list(tokens);

        _logTokens.debug(tokensString);
    }

    if (_logTransformBefore.isDebugEnabled()) {
        _logTransformBefore.debug(document);
    }

    List<TransformerListener> transformerListeners = JournalTransformerListenerRegistryUtil
            .getTransformerListeners();

    for (TransformerListener transformerListener : transformerListeners) {

        // Modify XML

        if (_logXmlBeforeListener.isDebugEnabled()) {
            _logXmlBeforeListener.debug(document);
        }

        if (transformerListener != null) {
            document = transformerListener.onXml(document, languageId, tokens);

            if (_logXmlAfterListener.isDebugEnabled()) {
                _logXmlAfterListener.debug(document);
            }
        }

        // Modify script

        if (_logScriptBeforeListener.isDebugEnabled()) {
            _logScriptBeforeListener.debug(script);
        }

        if (transformerListener != null) {
            script = transformerListener.onScript(script, document, languageId, tokens);

            if (_logScriptAfterListener.isDebugEnabled()) {
                _logScriptAfterListener.debug(script);
            }
        }
    }

    // Transform

    String output = null;

    if (Validator.isNull(langType)) {
        output = LocalizationUtil.getLocalization(document.asXML(), languageId);
    } else {
        long companyId = 0;
        long companyGroupId = 0;
        long articleGroupId = 0;
        long classNameId = 0;

        if (tokens != null) {
            companyId = GetterUtil.getLong(tokens.get("company_id"));
            companyGroupId = GetterUtil.getLong(tokens.get("company_group_id"));
            articleGroupId = GetterUtil.getLong(tokens.get("article_group_id"));
            classNameId = GetterUtil.getLong(tokens.get(TemplateConstants.CLASS_NAME_ID));
        }

        long scopeGroupId = 0;
        long siteGroupId = 0;

        if (themeDisplay != null) {
            companyId = themeDisplay.getCompanyId();
            companyGroupId = themeDisplay.getCompanyGroupId();
            scopeGroupId = themeDisplay.getScopeGroupId();
            siteGroupId = themeDisplay.getSiteGroupId();
        }

        String templateId = tokens.get("template_id");

        templateId = getTemplateId(templateId, companyId, companyGroupId, articleGroupId);

        Template template = getTemplate(templateId, tokens, languageId, document, script, langType);

        if (contextObjects != null) {
            template.putAll(contextObjects);
        }

        UnsyncStringWriter unsyncStringWriter = new UnsyncStringWriter();

        try {
            if (document != null) {
                Element rootElement = document.getRootElement();

                List<TemplateNode> templateNodes = getTemplateNodes(themeDisplay, rootElement,
                        Long.valueOf(tokens.get("ddm_structure_id")));

                if (templateNodes != null) {
                    for (TemplateNode templateNode : templateNodes) {
                        template.put(templateNode.getName(), templateNode);
                    }
                }

                if (portletRequestModel != null) {
                    template.put("request", portletRequestModel.toMap());

                    if (langType.equals(TemplateConstants.LANG_TYPE_XSL)) {
                        Document requestDocument = SAXReaderUtil.read(portletRequestModel.toXML());

                        Element requestElement = requestDocument.getRootElement();

                        template.put("xmlRequest", requestElement.asXML());
                    }
                } else {
                    Element requestElement = rootElement.element("request");

                    template.put("request", insertRequestVariables(requestElement));

                    if (langType.equals(TemplateConstants.LANG_TYPE_XSL)) {
                        template.put("xmlRequest", requestElement.asXML());
                    }
                }
            }

            template.put("articleGroupId", articleGroupId);
            template.put("company", getCompany(themeDisplay, companyId));
            template.put("companyId", companyId);
            template.put("device", getDevice(themeDisplay));

            String templatesPath = getTemplatesPath(companyId, articleGroupId, classNameId);

            Locale locale = LocaleUtil.fromLanguageId(languageId);

            template.put("locale", locale);

            template.put("permissionChecker", PermissionThreadLocal.getPermissionChecker());
            template.put("randomNamespace", StringUtil.randomId() + StringPool.UNDERLINE);
            template.put("scopeGroupId", scopeGroupId);
            template.put("siteGroupId", siteGroupId);
            template.put("templatesPath", templatesPath);
            template.put("viewMode", viewMode);

            if (themeDisplay != null) {
                TemplateManager templateManager = TemplateManagerUtil.getTemplateManager(langType);

                HttpServletRequest request = themeDisplay.getRequest();

                templateManager.addTaglibSupport(template, request, themeDisplay.getResponse());
                templateManager.addTaglibTheme(template, "taglibLiferay", request,
                        new PipingServletResponse(themeDisplay.getResponse(), unsyncStringWriter));
            }

            // Deprecated variables

            template.put("groupId", articleGroupId);
            template.put("journalTemplatesPath", templatesPath);

            mergeTemplate(template, unsyncStringWriter, propagateException);
        } catch (Exception e) {
            if (e instanceof DocumentException) {
                throw new TransformException("Unable to read XML document", e);
            } else if (e instanceof IOException) {
                throw new TransformException("Error reading template", e);
            } else if (e instanceof TransformException) {
                throw (TransformException) e;
            } else {
                throw new TransformException("Unhandled exception", e);
            }
        }

        output = unsyncStringWriter.toString();
    }

    // Postprocess output

    for (TransformerListener transformerListener : transformerListeners) {

        // Modify output

        if (_logOutputBeforeListener.isDebugEnabled()) {
            _logOutputBeforeListener.debug(output);
        }

        output = transformerListener.onOutput(output, languageId, tokens);

        if (_logOutputAfterListener.isDebugEnabled()) {
            _logOutputAfterListener.debug(output);
        }
    }

    if (_logTransfromAfter.isDebugEnabled()) {
        _logTransfromAfter.debug(output);
    }

    return output;
}

From source file:com.liferay.journal.util.impl.JournalUtil.java

License:Open Source License

private static void _populateTokens(Map<String, String> tokens, long articleGroupId, ThemeDisplay themeDisplay)
        throws PortalException {

    Layout layout = themeDisplay.getLayout();

    Group group = layout.getGroup();

    LayoutSet layoutSet = layout.getLayoutSet();

    String friendlyUrlCurrent = null;

    if (layout.isPublicLayout()) {
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPublic();
    } else if (group.isUserGroup()) {
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPrivateUser();
    } else {/*from  w  w w. j av  a2s.co  m*/
        friendlyUrlCurrent = themeDisplay.getPathFriendlyURLPrivateGroup();
    }

    String layoutSetFriendlyUrl = themeDisplay.getI18nPath();

    String virtualHostname = layoutSet.getVirtualHostname();

    if (Validator.isNull(virtualHostname) || !virtualHostname.equals(themeDisplay.getServerName())) {

        layoutSetFriendlyUrl = friendlyUrlCurrent + group.getFriendlyURL();
    }

    tokens.put("article_group_id", String.valueOf(articleGroupId));
    tokens.put("cdn_host", themeDisplay.getCDNHost());
    tokens.put("company_id", String.valueOf(themeDisplay.getCompanyId()));
    tokens.put("friendly_url_current", friendlyUrlCurrent);
    tokens.put("friendly_url_private_group", themeDisplay.getPathFriendlyURLPrivateGroup());
    tokens.put("friendly_url_private_user", themeDisplay.getPathFriendlyURLPrivateUser());
    tokens.put("friendly_url_public", themeDisplay.getPathFriendlyURLPublic());
    tokens.put("group_friendly_url", group.getFriendlyURL());
    tokens.put("image_path", themeDisplay.getPathImage());
    tokens.put("layout_set_friendly_url", layoutSetFriendlyUrl);
    tokens.put("main_path", themeDisplay.getPathMain());
    tokens.put("portal_ctx", themeDisplay.getPathContext());
    tokens.put("portal_url", HttpUtil.removeProtocol(themeDisplay.getURLPortal()));
    tokens.put("protocol", HttpUtil.getProtocol(themeDisplay.getURLPortal()));
    tokens.put("root_path", themeDisplay.getPathContext());
    tokens.put("scope_group_id", String.valueOf(themeDisplay.getScopeGroupId()));
    tokens.put("site_group_id", String.valueOf(themeDisplay.getSiteGroupId()));
    tokens.put("theme_image_path", themeDisplay.getPathThemeImages());

    _populateCustomTokens(tokens, themeDisplay.getCompanyId());

    // Deprecated tokens

    tokens.put("friendly_url", themeDisplay.getPathFriendlyURLPublic());
    tokens.put("friendly_url_private", themeDisplay.getPathFriendlyURLPrivateGroup());
    tokens.put("group_id", String.valueOf(articleGroupId));
    tokens.put("page_url", themeDisplay.getPathFriendlyURLPublic());
}

From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

public String getDDMStructureName() throws PortalException {
    if (_ddmStructureName != null) {
        return _ddmStructureName;
    }/*www . ja  v  a2  s.c om*/

    _ddmStructureName = LanguageUtil.get(_request, "basic-web-content");

    if (Validator.isNull(getDDMStructureKey())) {
        return _ddmStructureName;
    }

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

    DDMStructure ddmStructure = DDMStructureLocalServiceUtil.fetchStructure(themeDisplay.getSiteGroupId(),
            PortalUtil.getClassNameId(JournalArticle.class), getDDMStructureKey(), true);

    if (ddmStructure != null) {
        _ddmStructureName = ddmStructure.getName(themeDisplay.getLocale());
    }

    return _ddmStructureName;
}

From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java

License:Open Source License

public long getDDMStructurePrimaryKey() throws PortalException {
    String ddmStructureKey = getDDMStructureKey();

    if (Validator.isNull(ddmStructureKey)) {
        return 0;
    }/*from  w w w .  j  a v a 2s.  co  m*/

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

    DDMStructure ddmStructure = DDMStructureLocalServiceUtil.fetchStructure(themeDisplay.getSiteGroupId(),
            PortalUtil.getClassNameId(JournalArticle.class), getDDMStructureKey(), true);

    if (ddmStructure == null) {
        return 0;
    }

    return ddmStructure.getPrimaryKey();
}

From source file:com.liferay.journal.web.internal.display.context.util.JournalWebRequestHelper.java

License:Open Source License

public JournalGroupServiceConfiguration getJournalGroupServiceConfiguration() {

    try {/*from  w  ww .j a v  a2  s  . c o m*/
        if (_journalGroupServiceConfiguration == null) {
            ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

            PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

            if (Validator.isNotNull(portletDisplay.getPortletResource())) {
                _journalGroupServiceConfiguration = ConfigurationProviderUtil.getConfiguration(
                        JournalGroupServiceConfiguration.class,
                        new ParameterMapSettingsLocator(_request.getParameterMap(),
                                new GroupServiceSettingsLocator(themeDisplay.getSiteGroupId(),
                                        JournalConstants.SERVICE_NAME)));
            } else {
                _journalGroupServiceConfiguration = ConfigurationProviderUtil.getConfiguration(
                        JournalGroupServiceConfiguration.class, new GroupServiceSettingsLocator(
                                themeDisplay.getSiteGroupId(), JournalConstants.SERVICE_NAME));
            }
        }

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

From source file:com.liferay.layout.admin.web.internal.control.menu.ToggleControlsProductNavigationControlMenuEntry.java

License:Open Source License

protected boolean hasPortletConfigurationPermission(ThemeDisplay themeDisplay) throws PortalException {

    return PortletPermissionUtil.hasConfigurationPermission(themeDisplay.getPermissionChecker(),
            themeDisplay.getSiteGroupId(), themeDisplay.getLayout(), ActionKeys.CONFIGURATION);
}

From source file:com.liferay.layout.admin.web.internal.display.context.LayoutPageTemplateDisplayContext.java

License:Open Source License

public boolean isShowAddButton(String actionId) {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    if (LayoutPageTemplatePermission.contains(themeDisplay.getPermissionChecker(),
            themeDisplay.getSiteGroupId(), actionId)) {

        return true;
    }//from   w  w w.j  av a  2  s .c o  m

    return false;
}

From source file:com.liferay.map.taglib.servlet.taglib.MapDisplayTag.java

License:Open Source License

private String _getMapProviderKey() {
    String mapProdiverKey = _mapProviderKey;

    if (Validator.isNull(mapProdiverKey)) {
        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

        MapProviderHelper mapProviderHelper = ServletContextUtil.getMapProviderHelper();

        mapProdiverKey = mapProviderHelper.getMapProviderKey(themeDisplay.getCompanyId(),
                themeDisplay.getSiteGroupId());
    }//w ww.  j  av a  2 s .c  o  m

    return mapProdiverKey;
}

From source file:com.liferay.mentions.web.internal.portlet.MentionsPortlet.java

License:Open Source License

@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) {

    try {//  ww w  .  j a  v a  2  s. com
        ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

        if (!MentionsUtil.isMentionsEnabled(themeDisplay.getSiteGroupId())) {

            return;
        }

        HttpServletRequest request = _portal.getHttpServletRequest(resourceRequest);

        JSONArray jsonArray = getJSONArray(request);

        HttpServletResponse response = _portal.getHttpServletResponse(resourceResponse);

        response.setContentType(ContentTypes.APPLICATION_JSON);

        ServletResponseUtil.write(response, jsonArray.toString());
    } catch (Exception e) {
        _log.error(e, e);
    }
}