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

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

Introduction

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

Prototype

public long getScopeGroupId() 

Source Link

Document

Returns the ID of the scoped or sub-scoped active group (e.g.

Usage

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);
    }/*from  ww w .j  a  v  a2 s . com*/

    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

public static long getPreviewPlid(JournalArticle article, ThemeDisplay themeDisplay) throws Exception {

    if (article != null) {
        Layout layout = article.getLayout();

        if (layout != null) {
            return layout.getPlid();
        }//from  ww w.  j a  v a2s. c  o m
    }

    Layout layout = LayoutLocalServiceUtil.fetchFirstLayout(themeDisplay.getScopeGroupId(), false,
            LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

    if (layout == null) {
        layout = LayoutLocalServiceUtil.fetchFirstLayout(themeDisplay.getScopeGroupId(), true,
                LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
    }

    if (layout != null) {
        return layout.getPlid();
    }

    return themeDisplay.getPlid();
}

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 . ja  v  a  2s  .  com*/
        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 getFoldersJSON() throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY);

    JSONArray jsonArray = _getFoldersJSONArray(themeDisplay.getScopeGroupId(),
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("children", jsonArray);
    jsonObject.put("icon", "folder");
    jsonObject.put("id", JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID);
    jsonObject.put("name", LanguageUtil.get(themeDisplay.getLocale(), "home"));

    return jsonObject.toString();
}

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

License:Open Source License

public List<ManagementBarFilterItem> getManagementBarStatusFilterItems()
        throws PortalException, PortletException {

    List<ManagementBarFilterItem> managementBarFilterItems = new ArrayList<>();

    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_ANY));
    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_DRAFT));

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

    int workflowDefinitionLinksCount = WorkflowDefinitionLinkLocalServiceUtil.getWorkflowDefinitionLinksCount(
            themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(), JournalFolder.class.getName());

    if (workflowDefinitionLinksCount > 0) {
        managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_PENDING));
        managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_DENIED));
    }/*from   www .  java2s.c  o m*/

    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_SCHEDULED));
    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_APPROVED));
    managementBarFilterItems.add(getManagementBarFilterItem(WorkflowConstants.STATUS_EXPIRED));

    return managementBarFilterItems;
}

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

License:Open Source License

public SearchContainer getSearchContainer(boolean showVersions) throws PortalException {

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

    SearchContainer articleSearchContainer = new SearchContainer(_liferayPortletRequest, getPortletURL(), null,
            null);//w  w w.j a  v  a2 s.c o  m

    if (!isSearch()) {
        articleSearchContainer
                .setEmptyResultsMessageCssClass("taglib-empty-result-message-header-has-plus-btn");
    } else {
        articleSearchContainer.setSearch(true);
    }

    OrderByComparator<JournalArticle> orderByComparator = JournalPortletUtil
            .getArticleOrderByComparator(getOrderByCol(), getOrderByType());

    articleSearchContainer.setOrderByCol(getOrderByCol());
    articleSearchContainer.setOrderByComparator(orderByComparator);
    articleSearchContainer.setOrderByType(getOrderByType());

    EntriesChecker entriesChecker = new EntriesChecker(_liferayPortletRequest, _liferayPortletResponse);

    entriesChecker.setCssClass("entry-selector");
    entriesChecker.setRememberCheckBoxStateURLRegex(
            "^(?!.*" + _liferayPortletResponse.getNamespace() + "redirect).*(folderId=" + getFolderId() + ")");

    articleSearchContainer.setRowChecker(entriesChecker);

    EntriesMover entriesMover = new EntriesMover(themeDisplay.getScopeGroupId());

    articleSearchContainer.setRowMover(entriesMover);

    if (isNavigationMine() || isNavigationRecent()) {
        boolean includeOwner = true;

        if (isNavigationMine()) {
            includeOwner = false;
        }

        if (isNavigationRecent()) {
            articleSearchContainer.setOrderByCol("create-date");
            articleSearchContainer.setOrderByType(getOrderByType());
        }

        int total = JournalArticleServiceUtil.getGroupArticlesCount(themeDisplay.getScopeGroupId(),
                themeDisplay.getUserId(), getFolderId(), getStatus(), includeOwner);

        articleSearchContainer.setTotal(total);

        List results = JournalArticleServiceUtil.getGroupArticles(themeDisplay.getScopeGroupId(),
                themeDisplay.getUserId(), getFolderId(), getStatus(), includeOwner,
                articleSearchContainer.getStart(), articleSearchContainer.getEnd(),
                articleSearchContainer.getOrderByComparator());

        articleSearchContainer.setResults(results);
    } else if (Validator.isNotNull(getDDMStructureKey())) {
        int total = JournalArticleServiceUtil.getArticlesCountByStructureId(themeDisplay.getScopeGroupId(),
                getDDMStructureKey(), getStatus());

        articleSearchContainer.setTotal(total);

        List results = JournalArticleServiceUtil.getArticlesByStructureId(themeDisplay.getScopeGroupId(),
                getDDMStructureKey(), getStatus(), articleSearchContainer.getStart(),
                articleSearchContainer.getEnd(), articleSearchContainer.getOrderByComparator());

        articleSearchContainer.setResults(results);
    } else if (Validator.isNotNull(getDDMTemplateKey())) {
        List<Long> folderIds = new ArrayList<>(1);

        if (getFolderId() != JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

            folderIds.add(getFolderId());
        }

        int total = JournalArticleServiceUtil.searchCount(themeDisplay.getCompanyId(),
                themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT,
                getKeywords(), -1.0, getDDMStructureKey(), getDDMTemplateKey(), null, null, getStatus(), null);

        articleSearchContainer.setTotal(total);

        List results = JournalArticleServiceUtil.search(themeDisplay.getCompanyId(),
                themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT,
                getKeywords(), -1.0, getDDMStructureKey(), getDDMTemplateKey(), null, null, getStatus(), null,
                articleSearchContainer.getStart(), articleSearchContainer.getEnd(),
                articleSearchContainer.getOrderByComparator());

        articleSearchContainer.setResults(results);
    } else if (isSearch()) {
        List<Long> folderIds = new ArrayList<>(1);

        if (getFolderId() != JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

            folderIds.add(getFolderId());
        }

        JournalWebConfiguration journalWebConfiguration = (JournalWebConfiguration) _request
                .getAttribute(JournalWebConfiguration.class.getName());

        if (journalWebConfiguration.journalArticlesSearchWithIndex()) {
            boolean orderByAsc = false;

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

            Sort sort = null;

            if (Objects.equals(getOrderByCol(), "display-date")) {
                sort = new Sort("displayDate", Sort.LONG_TYPE, orderByAsc);
            } else if (Objects.equals(getOrderByCol(), "id")) {
                sort = new Sort(DocumentImpl.getSortableFieldName(Field.ARTICLE_ID), Sort.STRING_TYPE,
                        !orderByAsc);
            } else if (Objects.equals(getOrderByCol(), "modified-date")) {
                sort = new Sort(Field.MODIFIED_DATE, Sort.LONG_TYPE, orderByAsc);
            } else if (Objects.equals(getOrderByCol(), "title")) {
                sort = new Sort("title", Sort.STRING_TYPE, !orderByAsc);
            }

            LinkedHashMap<String, Object> params = new LinkedHashMap<>();

            params.put("expandoAttributes", getKeywords());

            Indexer indexer = JournalSearcher.getInstance();

            SearchContext searchContext = buildSearchContext(themeDisplay.getCompanyId(),
                    themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT,
                    getDDMStructureKey(), getDDMTemplateKey(), getKeywords(), params,
                    articleSearchContainer.getStart(), articleSearchContainer.getEnd(), sort, showVersions);

            Hits hits = indexer.search(searchContext);

            int total = hits.getLength();

            articleSearchContainer.setTotal(total);

            List results = new ArrayList<>();

            Document[] documents = hits.getDocs();

            for (int i = 0; i < documents.length; i++) {
                Document document = documents[i];

                JournalArticle article = null;
                JournalFolder folder = null;

                String className = document.get(Field.ENTRY_CLASS_NAME);
                long classPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

                if (className.equals(JournalArticle.class.getName())) {
                    if (!showVersions) {
                        article = JournalArticleLocalServiceUtil.fetchLatestArticle(classPK,
                                WorkflowConstants.STATUS_ANY, false);
                    } else {
                        String articleId = document.get(Field.ARTICLE_ID);
                        long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID));
                        double version = GetterUtil.getDouble(document.get(Field.VERSION));

                        article = JournalArticleLocalServiceUtil.fetchArticle(groupId, articleId, version);
                    }

                    results.add(article);
                } else if (className.equals(JournalFolder.class.getName())) {
                    folder = JournalFolderLocalServiceUtil.getFolder(classPK);

                    results.add(folder);
                }
            }

            articleSearchContainer.setResults(results);
        } else {
            int total = JournalArticleServiceUtil.searchCount(themeDisplay.getCompanyId(),
                    themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT,
                    getKeywords(), -1.0, getDDMStructureKey(), getDDMTemplateKey(), null, null, getStatus(),
                    null);

            articleSearchContainer.setTotal(total);

            List results = JournalArticleServiceUtil.search(themeDisplay.getCompanyId(),
                    themeDisplay.getScopeGroupId(), folderIds, JournalArticleConstants.CLASSNAME_ID_DEFAULT,
                    getKeywords(), -1.0, getDDMStructureKey(), getDDMTemplateKey(), null, null, getStatus(),
                    null, articleSearchContainer.getStart(), articleSearchContainer.getEnd(),
                    articleSearchContainer.getOrderByComparator());

            articleSearchContainer.setResults(results);
        }
    } else {
        int total = JournalFolderServiceUtil.getFoldersAndArticlesCount(themeDisplay.getScopeGroupId(), 0,
                getFolderId(), getStatus());

        articleSearchContainer.setTotal(total);

        OrderByComparator<Object> folderOrderByComparator = null;

        boolean orderByAsc = false;

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

        if (Objects.equals(getOrderByCol(), "display-date")) {
            folderOrderByComparator = new FolderArticleDisplayDateComparator(orderByAsc);
        } else if (Objects.equals(getOrderByCol(), "id")) {
            folderOrderByComparator = new FolderArticleArticleIdComparator(orderByAsc);
        } else if (Objects.equals(getOrderByCol(), "modified-date")) {
            folderOrderByComparator = new FolderArticleModifiedDateComparator(orderByAsc);
        } else if (Objects.equals(getOrderByCol(), "title")) {
            folderOrderByComparator = new FolderArticleTitleComparator(orderByAsc);
        }

        List results = JournalFolderServiceUtil.getFoldersAndArticles(themeDisplay.getScopeGroupId(), 0,
                getFolderId(), getStatus(), themeDisplay.getLocale(), articleSearchContainer.getStart(),
                articleSearchContainer.getEnd(), folderOrderByComparator);

        articleSearchContainer.setResults(results);
    }

    return articleSearchContainer;
}

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

License:Open Source License

public int getStatus() {
    if (_status != null) {
        return _status;
    }//ww w.  j  a va  2 s. c o  m

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

    int defaultStatus = WorkflowConstants.STATUS_APPROVED;

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    if (permissionChecker.isContentReviewer(themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId())
            || isNavigationMine()) {

        defaultStatus = WorkflowConstants.STATUS_ANY;
    }

    _status = ParamUtil.getInteger(_request, "status", defaultStatus);

    return _status;
}

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

License:Open Source License

public List<JournalArticle> getMoveArticles() throws PortalException {
    ThemeDisplay themeDisplay = (ThemeDisplay) _liferayPortletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    List<JournalArticle> articles = new ArrayList<>();

    String[] articleIds = ParamUtil.getStringValues(_liferayPortletRequest, "rowIdsJournalArticle");

    for (String articleId : articleIds) {
        JournalArticle article = JournalArticleServiceUtil.fetchArticle(themeDisplay.getScopeGroupId(),
                articleId);// ww w .j a  v  a  2  s .c o m

        if (article != null) {
            articles.add(article);
        }
    }

    return articles;
}

From source file:com.liferay.journal.web.internal.portlet.action.ActionUtil.java

License:Open Source License

public static JournalArticle getArticle(HttpServletRequest request) throws PortalException {

    String actionName = ParamUtil.getString(request, ActionRequest.ACTION_NAME);

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

    long resourcePrimKey = ParamUtil.getLong(request, "resourcePrimKey");
    long groupId = ParamUtil.getLong(request, "groupId", themeDisplay.getScopeGroupId());
    long classNameId = ParamUtil.getLong(request, "classNameId");
    long classPK = ParamUtil.getLong(request, "classPK");
    String articleId = ParamUtil.getString(request, "articleId");
    String ddmStructureKey = ParamUtil.getString(request, "ddmStructureKey");
    int status = ParamUtil.getInteger(request, "status", WorkflowConstants.STATUS_ANY);

    JournalArticle article = null;//from w w w.ja v a 2 s.  c  o  m

    if (actionName.equals("addArticle") && (resourcePrimKey != 0)) {
        article = JournalArticleLocalServiceUtil.getLatestArticle(resourcePrimKey, status, false);
    } else if (!actionName.equals("addArticle") && Validator.isNotNull(articleId)) {

        article = JournalArticleServiceUtil.getLatestArticle(groupId, articleId, status);
    } else if ((classNameId > 0) && (classPK > JournalArticleConstants.CLASSNAME_ID_DEFAULT)) {

        String className = PortalUtil.getClassName(classNameId);

        try {
            article = JournalArticleServiceUtil.getLatestArticle(groupId, className, classPK);
        } catch (NoSuchArticleException nsae) {
            return null;
        }
    } else {
        DDMStructure ddmStructure = DDMStructureServiceUtil.fetchStructure(groupId,
                PortalUtil.getClassNameId(JournalArticle.class), ddmStructureKey, true);

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

        try {
            article = JournalArticleServiceUtil.getArticle(ddmStructure.getGroupId(),
                    DDMStructure.class.getName(), ddmStructure.getStructureId());

            article.setNew(true);

            article.setId(0);
            article.setGroupId(groupId);
            article.setClassNameId(JournalArticleConstants.CLASSNAME_ID_DEFAULT);
            article.setClassPK(0);
            article.setArticleId(null);
            article.setVersion(0);
        } catch (NoSuchArticleException nsae) {
            return null;
        }
    }

    return article;
}

From source file:com.liferay.journal.web.internal.portlet.action.ActionUtil.java

License:Open Source License

public static JournalFolder getFolder(HttpServletRequest request) throws PortalException {

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

    long folderId = ParamUtil.getLong(request, "folderId");

    JournalFolder folder = null;/*from w  w  w. j a  va 2  s.  c  o m*/

    if ((folderId > 0) && (folderId != JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {

        folder = JournalFolderServiceUtil.fetchFolder(folderId);
    } else {
        JournalPermission.check(themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(),
                ActionKeys.VIEW);
    }

    return folder;
}