Example usage for com.liferay.portal.kernel.model LayoutTypePortletConstants DEFAULT_ASSET_PUBLISHER_PORTLET_ID

List of usage examples for com.liferay.portal.kernel.model LayoutTypePortletConstants DEFAULT_ASSET_PUBLISHER_PORTLET_ID

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model LayoutTypePortletConstants DEFAULT_ASSET_PUBLISHER_PORTLET_ID.

Prototype

String DEFAULT_ASSET_PUBLISHER_PORTLET_ID

To view the source code for com.liferay.portal.kernel.model LayoutTypePortletConstants DEFAULT_ASSET_PUBLISHER_PORTLET_ID.

Click Source Link

Usage

From source file:com.liferay.asset.publisher.layout.prototype.internal.instance.lifecycle.AddLayoutPrototypePortalInstanceLifecycleListener.java

License:Open Source License

protected void addWebContentPage(long companyId, long defaultUserId, List<LayoutPrototype> layoutPrototypes)
        throws Exception {

    ResourceBundleLoader resourceBundleLoader = new AggregateResourceBundleLoader(
            ResourceBundleUtil.getResourceBundleLoader("content.Language", getClassLoader()),
            LanguageResources.RESOURCE_BUNDLE_LOADER);

    Map<Locale, String> nameMap = ResourceBundleUtil.getLocalizationMap(resourceBundleLoader,
            "layout-prototype-web-content-title");
    Map<Locale, String> descriptionMap = ResourceBundleUtil.getLocalizationMap(resourceBundleLoader,
            "layout-prototype-web-content-description");

    Layout layout = DefaultLayoutPrototypesUtil.addLayoutPrototype(companyId, defaultUserId, nameMap,
            descriptionMap, "2_columns_ii", layoutPrototypes);

    if (layout == null) {
        return;//from   ww  w . j ava 2s.  co m
    }

    DefaultLayoutPrototypesUtil.addPortletId(layout, AssetTagsNavigationPortletKeys.ASSET_TAGS_NAVIGATION,
            "column-1");

    DefaultLayoutPrototypesUtil.addPortletId(layout,
            AssetCategoriesNavigationPortletKeys.ASSET_CATEGORIES_NAVIGATION, "column-1");

    String portletId = DefaultLayoutPrototypesUtil.addPortletId(layout,
            AssetPublisherPortletKeys.ASSET_PUBLISHER, "column-2");

    Map<String, String> preferences = new HashMap<>();

    preferences.put("showOnlyLayoutAssets", Boolean.TRUE.toString());

    DefaultLayoutPrototypesUtil.updatePortletSetup(layout, portletId, preferences);

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    typeSettingsProperties.setProperty(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID,
            portletId);

    _layoutLocalService.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
            layout.getTypeSettings());
}

From source file:com.liferay.asset.publisher.portlet.test.DisplayPageFriendlyURLResolverTest.java

License:Open Source License

@Test
public void testJournalArticleFriendlyURL() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext();

    LayoutLocalServiceUtil.addLayout(TestPropsValues.getUserId(), _group.getGroupId(), false,
            LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "Home", StringPool.BLANK, StringPool.BLANK,
            LayoutConstants.TYPE_PORTLET, false, StringPool.BLANK, serviceContext);

    Layout layout = LayoutLocalServiceUtil.addLayout(TestPropsValues.getUserId(), _group.getGroupId(), false,
            LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "Test " + RandomTestUtil.nextInt(), StringPool.BLANK,
            StringPool.BLANK, LayoutConstants.TYPE_PORTLET, false, StringPool.BLANK, serviceContext);

    LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

    String portletId = layoutTypePortlet.addPortletId(TestPropsValues.getUserId(),
            AssetPublisherPortletKeys.ASSET_PUBLISHER, "column-1", 0);

    layoutTypePortlet.setTypeSettingsProperty(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID,
            portletId);//from  w ww  . j a v a2 s .  c  o  m

    layout = LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(),
            layout.getLayoutId(), layout.getTypeSettings());

    Map<Locale, String> titleMap = new HashMap<>();

    titleMap.put(LocaleUtil.US, "Test Journal Article");

    Map<Locale, String> contentMap = new HashMap<>();

    contentMap.put(LocaleUtil.US, "This test content is in English.");

    JournalTestUtil.addArticle(_group.getGroupId(), JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            JournalArticleConstants.CLASSNAME_ID_DEFAULT, titleMap, titleMap, contentMap, layout.getUuid(),
            LocaleUtil.US, null, false, false, serviceContext);

    String actualURL = PortalUtil.getActualURL(_group.getGroupId(), false, Portal.PATH_MAIN,
            "/-/test-journal-article", new HashMap<String, String[]>(), getRequestContext());

    Assert.assertNotNull(actualURL);

    try {
        PortalUtil.getActualURL(_group.getGroupId(), false, Portal.PATH_MAIN,
                "/-/nonexistent-test-journal-article", new HashMap<String, String[]>(), getRequestContext());

        Assert.fail();
    } catch (NoSuchLayoutException nsle) {
    }
}

From source file:com.liferay.asset.publisher.web.AssetPublisherPortletLayoutListener.java

License:Open Source License

@Override
public void updatePropertiesOnRemoveFromLayout(String portletId, UnicodeProperties typeSettingsProperties)
        throws PortletLayoutListenerException {

    String defaultAssetPublisherPortletId = typeSettingsProperties
            .getProperty(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID);

    if (portletId.equals(defaultAssetPublisherPortletId)) {
        typeSettingsProperties.setProperty(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID,
                StringPool.BLANK);//from   ww w .j  a v a 2  s  . c  om
    }
}

From source file:com.liferay.asset.publisher.web.internal.util.AssetPublisherWebUtil.java

License:Open Source License

public String getDefaultAssetPublisherId(Layout layout) {
    return layout.getTypeSettingsProperty(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID,
            StringPool.BLANK);
}

From source file:com.liferay.asset.publisher.web.portlet.action.AssetPublisherConfigurationAction.java

License:Open Source License

protected void updateDefaultAssetPublisher(ActionRequest actionRequest) throws Exception {

    boolean defaultAssetPublisher = ParamUtil.getBoolean(actionRequest, "defaultAssetPublisher");

    Layout layout = (Layout) actionRequest.getAttribute(WebKeys.LAYOUT);

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

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    if (defaultAssetPublisher) {
        typeSettingsProperties.setProperty(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID,
                portletResource);//www.j av a  2  s  . co  m
    } else {
        String defaultAssetPublisherPortletId = typeSettingsProperties
                .getProperty(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID);

        if (Validator.isNotNull(defaultAssetPublisherPortletId)
                && defaultAssetPublisherPortletId.equals(portletResource)) {

            typeSettingsProperties.setProperty(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID,
                    StringPool.BLANK);
        }
    }

    layout = layoutLocalService.updateLayout(layout.getGroupId(), layout.isPrivateLayout(),
            layout.getLayoutId(), layout.getTypeSettings());

    if (LayoutStagingUtil.isBranchingLayout(layout)) {
        HttpServletRequest request = portal.getHttpServletRequest(actionRequest);

        LayoutSetBranch layoutSetBranch = LayoutStagingUtil.getLayoutSetBranch(layout.getLayoutSet());

        long layoutSetBranchId = layoutSetBranch.getLayoutSetBranchId();

        long layoutRevisionId = staging.getRecentLayoutRevisionId(request, layoutSetBranchId, layout.getPlid());

        LayoutRevision layoutRevision = layoutRevisionLocalService.getLayoutRevision(layoutRevisionId);

        PortletPreferencesImpl portletPreferences = (PortletPreferencesImpl) actionRequest.getPreferences();

        if (layoutRevision != null) {
            portletPreferences.setPlid(layoutRevision.getLayoutRevisionId());
        }
    }
}

From source file:com.liferay.asset.publisher.web.portlet.DisplayPageFriendlyURLResolver.java

License:Open Source License

@Override
public String getActualURL(long companyId, long groupId, boolean privateLayout, String mainPath,
        String friendlyURL, Map<String, String[]> params, Map<String, Object> requestContext)
        throws PortalException {

    String urlTitle = friendlyURL.substring(JournalArticleConstants.CANONICAL_URL_SEPARATOR.length());

    JournalArticle journalArticle = _journalArticleLocalService.getArticleByUrlTitle(groupId, urlTitle);

    Layout layout = getJournalArticleLayout(groupId, privateLayout, friendlyURL);

    String layoutActualURL = _portal.getLayoutActualURL(layout, mainPath);

    InheritableMap<String, String[]> actualParams = new InheritableMap<>();

    if (params != null) {
        actualParams.setParentMap(params);
    }// w w  w.ja v  a2 s  . c  o  m

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    String defaultAssetPublisherPortletId = typeSettingsProperties
            .get(LayoutTypePortletConstants.DEFAULT_ASSET_PUBLISHER_PORTLET_ID);

    String currentDefaultAssetPublisherPortletId = defaultAssetPublisherPortletId;

    if (Validator.isNull(defaultAssetPublisherPortletId)) {
        defaultAssetPublisherPortletId = PortletIdCodec.encode(AssetPublisherPortletKeys.ASSET_PUBLISHER);
    }

    HttpServletRequest request = (HttpServletRequest) requestContext.get("request");

    if (Validator.isNull(currentDefaultAssetPublisherPortletId)) {
        String actualPortletAuthenticationToken = AuthTokenUtil.getToken(request, layout.getPlid(),
                defaultAssetPublisherPortletId);

        actualParams.put("p_p_auth", new String[] { actualPortletAuthenticationToken });
    }

    actualParams.put("p_p_id", new String[] { defaultAssetPublisherPortletId });
    actualParams.put("p_p_lifecycle", new String[] { "0" });

    if (Validator.isNull(currentDefaultAssetPublisherPortletId)) {
        actualParams.put("p_p_state", new String[] { WindowState.MAXIMIZED.toString() });
    }

    actualParams.put("p_p_mode", new String[] { "view" });
    actualParams.put("p_j_a_id", new String[] { String.valueOf(journalArticle.getId()) });

    String namespace = _portal.getPortletNamespace(defaultAssetPublisherPortletId);

    actualParams.put(namespace + "mvcPath", new String[] { "/view_content.jsp" });

    AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil
            .getAssetRendererFactoryByClassName(JournalArticle.class.getName());

    actualParams.put(namespace + "type", new String[] { assetRendererFactory.getType() });

    actualParams.put(namespace + "urlTitle", new String[] { journalArticle.getUrlTitle() });

    String queryString = _http.parameterMapToString(actualParams, false);

    if (layoutActualURL.contains(StringPool.QUESTION)) {
        layoutActualURL = layoutActualURL + StringPool.AMPERSAND + queryString;
    } else {
        layoutActualURL = layoutActualURL + StringPool.QUESTION + queryString;
    }

    Locale locale = _portal.getLocale(request);

    _portal.addPageSubtitle(journalArticle.getTitle(locale), request);
    _portal.addPageDescription(journalArticle.getDescription(locale), request);

    List<AssetTag> assetTags = _assetTagLocalService.getTags(JournalArticle.class.getName(),
            journalArticle.getPrimaryKey());

    if (!assetTags.isEmpty()) {
        _portal.addPageKeywords(ListUtil.toString(assetTags, AssetTag.NAME_ACCESSOR), request);
    }

    return layoutActualURL;
}