Search in sources :

Example 21 with PortletURL

use of javax.portlet.PortletURL in project liferay-ide by liferay.

the class FindKBArticleAction method getKBArticleURL.

protected PortletURL getKBArticleURL(long plid, boolean privateLayout, KBArticle kbArticle, HttpServletRequest request) throws Exception {
    PortletURL firstMatchPortletURL = null;
    List<Layout> layouts = getCandidateLayouts(plid, privateLayout, kbArticle);
    for (Layout layout : layouts) {
        LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
        List<Portlet> portlets = layoutTypePortlet.getAllPortlets();
        for (Portlet portlet : portlets) {
            String rootPortletId = PortletConstants.getRootPortletId(portlet.getPortletId());
            if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_DISPLAY)) {
                PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup(layout, portlet.getPortletId(), StringPool.BLANK);
                long kbFolderClassNameId = PortalUtil.getClassNameId(KBFolderConstants.getClassName());
                long resourceClassNameId = GetterUtil.getLong(portletPreferences.getValue("resourceClassNameId", null), kbFolderClassNameId);
                long resourcePrimKey = GetterUtil.getLong(portletPreferences.getValue("resourcePrimKey", null), KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);
                if (resourceClassNameId == kbFolderClassNameId) {
                    if (isParentFolder(resourcePrimKey, kbArticle.getKbFolderId())) {
                        return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                    }
                } else if (resourcePrimKey == kbArticle.getResourcePrimKey()) {
                    return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
                if (firstMatchPortletURL == null) {
                    firstMatchPortletURL = getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
            }
            if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_SECTION)) {
                PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup(layout, portlet.getPortletId(), StringPool.BLANK);
                String[] kbArticlesSections = portletPreferences.getValues("kbArticlesSections", new String[0]);
                KBArticle rootKBArticle = KBArticleLocalServiceUtil.fetchLatestKBArticle(kbArticle.getRootResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);
                if (rootKBArticle == null) {
                    continue;
                }
                String[] sections = AdminUtil.unescapeSections(rootKBArticle.getSections());
                for (String section : sections) {
                    if (!ArrayUtil.contains(kbArticlesSections, section)) {
                        continue;
                    }
                    return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
            }
            if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_ARTICLE)) {
                PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup(layout, portlet.getPortletId(), StringPool.BLANK);
                long resourcePrimKey = GetterUtil.getLong(portletPreferences.getValue("resourcePrimKey", null));
                KBArticle selKBArticle = KBArticleLocalServiceUtil.fetchLatestKBArticle(resourcePrimKey, WorkflowConstants.STATUS_APPROVED);
                if (selKBArticle == null) {
                    continue;
                }
                long rootResourcePrimKey = kbArticle.getRootResourcePrimKey();
                long selRootResourcePrimKey = selKBArticle.getRootResourcePrimKey();
                if (rootResourcePrimKey == selRootResourcePrimKey) {
                    return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
                if (firstMatchPortletURL == null) {
                    firstMatchPortletURL = getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
            }
        }
    }
    return firstMatchPortletURL;
}
Also used : LayoutTypePortlet(com.liferay.portal.model.LayoutTypePortlet) LayoutTypePortlet(com.liferay.portal.model.LayoutTypePortlet) Portlet(com.liferay.portal.model.Portlet) KBArticle(com.liferay.knowledgebase.model.KBArticle) Layout(com.liferay.portal.model.Layout) PortletPreferences(javax.portlet.PortletPreferences) PortletURL(javax.portlet.PortletURL)

Example 22 with PortletURL

use of javax.portlet.PortletURL in project liferay-ide by liferay.

the class FindKBArticleAction method getKBArticleURL.

protected PortletURL getKBArticleURL(long plid, String portletId, KBArticle kbArticle, HttpServletRequest request) throws Exception {
    long resourcePrimKey = ParamUtil.getLong(request, "resourcePrimKey");
    String mvcPath = null;
    String rootPortletId = PortletConstants.getRootPortletId(portletId);
    if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_ARTICLE)) {
        mvcPath = "/article/view_article.jsp";
    } else if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_SECTION)) {
        mvcPath = "/section/view_article.jsp";
    }
    PortletURL portletURL = PortletURLFactoryUtil.create(request, portletId, plid, PortletRequest.RENDER_PHASE);
    if (mvcPath != null) {
        portletURL.setParameter("mvcPath", mvcPath);
    }
    if ((kbArticle == null) || Validator.isNull(kbArticle.getUrlTitle())) {
        portletURL.setParameter("resourcePrimKey", String.valueOf(resourcePrimKey));
    } else {
        portletURL.setParameter("urlTitle", kbArticle.getUrlTitle());
        if (kbArticle.getKbFolderId() != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
            KBFolder kbFolder = KBFolderLocalServiceUtil.getKBFolder(kbArticle.getKbFolderId());
            portletURL.setParameter("kbFolderUrlTitle", String.valueOf(kbFolder.getUrlTitle()));
        }
    }
    portletURL.setPortletMode(PortletMode.VIEW);
    portletURL.setWindowState(LiferayWindowState.NORMAL);
    if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_SECTION)) {
        portletURL.setWindowState(LiferayWindowState.MAXIMIZED);
    }
    return portletURL;
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) PortletURL(javax.portlet.PortletURL)

Example 23 with PortletURL

use of javax.portlet.PortletURL in project liferay-ide by liferay.

the class AdminPortlet method buildEditURL.

@Override
protected String buildEditURL(ActionRequest actionRequest, ActionResponse actionResponse, KBArticle kbArticle) throws PortalException, SystemException {
    try {
        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
        PortletURL portletURL = PortletURLFactoryUtil.create(actionRequest, PortletKeys.KNOWLEDGE_BASE_ADMIN, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);
        portletURL.setParameter("mvcPath", templatePath + "edit_article.jsp");
        portletURL.setParameter("redirect", getRedirect(actionRequest, actionResponse));
        portletURL.setParameter("resourcePrimKey", String.valueOf(kbArticle.getResourcePrimKey()));
        portletURL.setWindowState(actionRequest.getWindowState());
        return portletURL.toString();
    } catch (WindowStateException wse) {
        throw new PortalException(wse);
    }
}
Also used : WindowStateException(javax.portlet.WindowStateException) PortalException(com.liferay.portal.kernel.exception.PortalException) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay) PortletURL(javax.portlet.PortletURL)

Example 24 with PortletURL

use of javax.portlet.PortletURL in project liferay-ide by liferay.

the class KnowledgeBaseUtil method addPortletBreadcrumbEntries.

protected static void addPortletBreadcrumbEntries(Map<String, Object> parameters, HttpServletRequest request, RenderResponse renderResponse) throws PortalException, SystemException {
    PortletURL portletURL = renderResponse.createRenderURL();
    for (Map.Entry<String, Object> entry : parameters.entrySet()) {
        Object value = entry.getValue();
        portletURL.setParameter(entry.getKey(), value.toString());
    }
    long kbFolderClassNameId = PortalUtil.getClassNameId(KBFolderConstants.getClassName());
    long parentResourceClassNameId = (Long) parameters.get("parentResourceClassNameId");
    long parentResourcePrimKey = (Long) parameters.get("parentResourcePrimKey");
    String mvcPath = (String) parameters.get("mvcPath");
    if (parentResourcePrimKey == KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
        PortalUtil.addPortletBreadcrumbEntry(request, themeDisplay.translate("home"), portletURL.toString());
    } else if (parentResourceClassNameId == kbFolderClassNameId) {
        KBFolder kbFolder = KBFolderServiceUtil.getKBFolder(parentResourcePrimKey);
        addPortletBreadcrumbEntries(kbFolder.getClassNameId(), kbFolder.getParentKBFolderId(), mvcPath, request, renderResponse);
        PortalUtil.addPortletBreadcrumbEntry(request, kbFolder.getName(), portletURL.toString());
    } else {
        KBArticle kbArticle = KBArticleServiceUtil.getLatestKBArticle(parentResourcePrimKey, WorkflowConstants.STATUS_ANY);
        addPortletBreadcrumbEntries(kbArticle.getParentResourceClassNameId(), kbArticle.getParentResourcePrimKey(), mvcPath, request, renderResponse);
        PortalUtil.addPortletBreadcrumbEntry(request, kbArticle.getTitle(), portletURL.toString());
    }
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) KBArticle(com.liferay.knowledgebase.model.KBArticle) JSONObject(com.liferay.portal.kernel.json.JSONObject) PortletURL(javax.portlet.PortletURL) Map(java.util.Map) HashMap(java.util.HashMap) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Example 25 with PortletURL

use of javax.portlet.PortletURL in project liferay-ide by liferay.

the class JournalArticleAssetRendererFactory method getURLAdd.

@Override
public PortletURL getURLAdd(LiferayPortletRequest liferayPortletRequest, LiferayPortletResponse liferayPortletResponse) throws PortalException, SystemException {
    ThemeDisplay themeDisplay = (ThemeDisplay) liferayPortletRequest.getAttribute(WebKeys.THEME_DISPLAY);
    if (!JournalPermission.contains(themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), ActionKeys.ADD_ARTICLE)) {
        return null;
    }
    long classTypeId = GetterUtil.getLong(liferayPortletRequest.getAttribute(WebKeys.ASSET_RENDERER_FACTORY_CLASS_TYPE_ID));
    if ((classTypeId > 0) && !DDMStructurePermission.contains(themeDisplay.getPermissionChecker(), classTypeId, ActionKeys.VIEW)) {
        return null;
    }
    PortletURL portletURL = liferayPortletResponse.createRenderURL(PortletKeys.JOURNAL);
    portletURL.setParameter("struts_action", "/journal/edit_article");
    return portletURL;
}
Also used : ThemeDisplay(com.liferay.portal.theme.ThemeDisplay) PortletURL(javax.portlet.PortletURL) LiferayPortletURL(com.liferay.portal.kernel.portlet.LiferayPortletURL)

Aggregations

PortletURL (javax.portlet.PortletURL)26 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)6 KBArticle (com.liferay.knowledgebase.model.KBArticle)5 PortalException (com.liferay.portal.kernel.exception.PortalException)5 KBFolder (com.liferay.knowledgebase.model.KBFolder)4 SystemException (com.liferay.portal.kernel.exception.SystemException)3 WindowStateException (javax.portlet.WindowStateException)3 PortletPreferences (javax.portlet.PortletPreferences)2 Album (org.liferay.jukebox.model.Album)2 Song (org.liferay.jukebox.model.Song)2 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 LiferayPortletURL (com.liferay.portal.kernel.portlet.LiferayPortletURL)1 FileEntry (com.liferay.portal.kernel.repository.model.FileEntry)1 FileVersion (com.liferay.portal.kernel.repository.model.FileVersion)1 ThemeDisplay (com.liferay.portal.kernel.theme.ThemeDisplay)1 Layout (com.liferay.portal.model.Layout)1 LayoutTypePortlet (com.liferay.portal.model.LayoutTypePortlet)1 Portlet (com.liferay.portal.model.Portlet)1 PortalPreferences (com.liferay.portlet.PortalPreferences)1 BlogsEntry (com.liferay.portlet.blogs.model.BlogsEntry)1