Example usage for com.liferay.portal.kernel.util PortalUtil getPlidFromFriendlyURL

List of usage examples for com.liferay.portal.kernel.util PortalUtil getPlidFromFriendlyURL

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PortalUtil getPlidFromFriendlyURL.

Prototype

public static long getPlidFromFriendlyURL(long companyId, String friendlyURL) 

Source Link

Usage

From source file:com.liferay.blogs.internal.util.PingbackMethodImpl.java

License:Open Source License

protected BlogsEntry getBlogsEntry(long companyId) throws Exception {
    BlogsEntry entry = null;//from w  ww .  j ava 2s  . co  m

    URL url = new URL(_targetURI);

    String friendlyURL = url.getPath();

    int end = friendlyURL.indexOf(Portal.FRIENDLY_URL_SEPARATOR);

    if (end != -1) {
        friendlyURL = friendlyURL.substring(0, end);
    }

    long plid = PortalUtil.getPlidFromFriendlyURL(companyId, friendlyURL);
    long groupId = PortalUtil.getScopeGroupId(plid);

    Map<String, String[]> params = new HashMap<>();

    FriendlyURLMapperThreadLocal.setPRPIdentifiers(new HashMap<String, String>());

    String portletId = PortletProviderUtil.getPortletId(BlogsEntry.class.getName(),
            PortletProvider.Action.VIEW);

    Portlet portlet = _portletLocalService.getPortletById(portletId);

    FriendlyURLMapper friendlyURLMapper = portlet.getFriendlyURLMapperInstance();

    friendlyURL = url.getPath();

    end = friendlyURL.indexOf(Portal.FRIENDLY_URL_SEPARATOR);

    if (end != -1) {
        friendlyURL = friendlyURL.substring(end + Portal.FRIENDLY_URL_SEPARATOR.length() - 1);
    }

    Map<String, Object> requestContext = new HashMap<>();

    friendlyURLMapper.populateParams(friendlyURL, params, requestContext);

    String param = getParam(params, "entryId");

    if (Validator.isNotNull(param)) {
        long entryId = GetterUtil.getLong(param);

        entry = _blogsEntryLocalService.getEntry(entryId);
    } else {
        String urlTitle = getParam(params, "urlTitle");

        entry = _blogsEntryLocalService.getEntry(groupId, urlTitle);
    }

    return entry;
}

From source file:com.liferay.journal.service.impl.JournalFeedLocalServiceImpl.java

License:Open Source License

protected void validate(long companyId, long groupId, String name, String ddmStructureKey,
        String targetLayoutFriendlyUrl, String contentField) throws PortalException {

    if (Validator.isNull(name)) {
        throw new FeedNameException("Name is null");
    }/*from w w w  . java 2 s. c  o m*/

    long plid = PortalUtil.getPlidFromFriendlyURL(companyId, targetLayoutFriendlyUrl);

    if (plid <= 0) {
        StringBundler sb = new StringBundler(4);

        sb.append("No layout exists for company ");
        sb.append(companyId);
        sb.append(" and friendly URL ");
        sb.append(targetLayoutFriendlyUrl);

        throw new FeedTargetLayoutFriendlyUrlException(sb.toString());
    }

    if (contentField.equals(JournalFeedConstants.RENDERED_WEB_CONTENT)
            || contentField.equals(JournalFeedConstants.WEB_CONTENT_DESCRIPTION)) {

        return;
    }

    DDMStructure ddmStructure = ddmStructureLocalService.getStructure(groupId,
            classNameLocalService.getClassNameId(JournalArticle.class), ddmStructureKey, true);

    DDMForm ddmForm = ddmStructure.getDDMForm();

    Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(true);

    if (ddmFormFieldsMap.containsKey(contentField)) {
        return;
    }

    if (!isValidStructureOptionValue(ddmFormFieldsMap, contentField)) {
        throw new FeedContentFieldException("Invalid content field " + contentField);
    }
}