Example usage for com.liferay.portal.util PropsValues LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING

List of usage examples for com.liferay.portal.util PropsValues LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING

Introduction

In this page you can find the example usage for com.liferay.portal.util PropsValues LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING.

Prototype

String LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING

To view the source code for com.liferay.portal.util PropsValues LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING.

Click Source Link

Usage

From source file:com.liferay.exportimport.content.processor.base.BaseTextExportImportContentProcessor.java

License:Open Source License

protected String replaceImportLayoutReferences(PortletDataContext portletDataContext, String content)
        throws Exception {

    String companyPortalURL = StringPool.BLANK;
    String privateLayoutSetPortalURL = StringPool.BLANK;
    String publicLayoutSetPortalURL = StringPool.BLANK;

    Group group = GroupLocalServiceUtil.getGroup(portletDataContext.getScopeGroupId());

    Company company = CompanyLocalServiceUtil.getCompany(group.getCompanyId());

    LayoutSet privateLayoutSet = group.getPrivateLayoutSet();
    LayoutSet publicLayoutSet = group.getPublicLayoutSet();

    int serverPort = PortalUtil.getPortalServerPort(false);

    if (serverPort != -1) {
        if (Validator.isNotNull(company.getVirtualHostname())) {
            companyPortalURL = PortalUtil.getPortalURL(company.getVirtualHostname(), serverPort, false);
        }/*from w  ww . ja  v  a  2 s.  c  o  m*/

        if (Validator.isNotNull(privateLayoutSet.getVirtualHostname())) {
            privateLayoutSetPortalURL = PortalUtil.getPortalURL(privateLayoutSet.getVirtualHostname(),
                    serverPort, false);
        }

        if (Validator.isNotNull(publicLayoutSet.getVirtualHostname())) {
            publicLayoutSetPortalURL = PortalUtil.getPortalURL(publicLayoutSet.getVirtualHostname(), serverPort,
                    false);
        }
    }

    int secureSecurePort = PortalUtil.getPortalServerPort(true);

    String companySecurePortalURL = StringPool.BLANK;
    String privateLayoutSetSecurePortalURL = StringPool.BLANK;
    String publicLayoutSetSecurePortalURL = StringPool.BLANK;

    if (secureSecurePort != -1) {
        if (Validator.isNotNull(company.getVirtualHostname())) {
            companySecurePortalURL = PortalUtil.getPortalURL(company.getVirtualHostname(), secureSecurePort,
                    true);
        }

        if (Validator.isNotNull(privateLayoutSet.getVirtualHostname())) {
            privateLayoutSetSecurePortalURL = PortalUtil.getPortalURL(privateLayoutSet.getVirtualHostname(),
                    secureSecurePort, true);
        }

        if (Validator.isNotNull(publicLayoutSet.getVirtualHostname())) {
            publicLayoutSetSecurePortalURL = PortalUtil.getPortalURL(publicLayoutSet.getVirtualHostname(),
                    secureSecurePort, true);
        }
    }

    StringBundler sb = new StringBundler(3);

    sb.append(VirtualLayoutConstants.CANONICAL_URL_SEPARATOR);
    sb.append(GroupConstants.CONTROL_PANEL_FRIENDLY_URL);
    sb.append(PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL);

    content = StringUtil.replace(content, DATA_HANDLER_COMPANY_SECURE_URL, companySecurePortalURL);
    content = StringUtil.replace(content, DATA_HANDLER_COMPANY_URL, companyPortalURL);

    // Group friendly URLs

    while (true) {
        int groupFriendlyUrlPos = content.indexOf(DATA_HANDLER_GROUP_FRIENDLY_URL);

        if (groupFriendlyUrlPos == -1) {
            break;
        }

        int groupUuidPos = groupFriendlyUrlPos + DATA_HANDLER_GROUP_FRIENDLY_URL.length();

        int endIndex = content.indexOf(StringPool.AT, groupUuidPos + 1);

        if (endIndex < (groupUuidPos + 1)) {
            content = StringUtil.replaceFirst(content, DATA_HANDLER_GROUP_FRIENDLY_URL, StringPool.BLANK,
                    groupFriendlyUrlPos);

            continue;
        }

        String groupUuid = content.substring(groupUuidPos + 1, endIndex);

        Group groupFriendlyUrlGroup = GroupLocalServiceUtil.fetchGroupByUuidAndCompanyId(groupUuid,
                portletDataContext.getCompanyId());

        if ((groupFriendlyUrlGroup == null) || groupUuid.startsWith(StringPool.SLASH)) {

            content = StringUtil.replaceFirst(content, DATA_HANDLER_GROUP_FRIENDLY_URL, group.getFriendlyURL(),
                    groupFriendlyUrlPos);
            content = StringUtil.replaceFirst(content, StringPool.AT + groupUuid + StringPool.AT,
                    StringPool.BLANK, content.indexOf(group.getFriendlyURL()));

            continue;
        }

        content = StringUtil.replaceFirst(content, DATA_HANDLER_GROUP_FRIENDLY_URL, StringPool.BLANK,
                groupFriendlyUrlPos);
        content = StringUtil.replaceFirst(content, StringPool.AT + groupUuid + StringPool.AT,
                groupFriendlyUrlGroup.getFriendlyURL(), groupFriendlyUrlPos);
    }

    content = StringUtil.replace(content, DATA_HANDLER_PATH_CONTEXT, PortalUtil.getPathContext());
    content = StringUtil.replace(content, DATA_HANDLER_PRIVATE_GROUP_SERVLET_MAPPING,
            PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING);
    content = StringUtil.replace(content, DATA_HANDLER_PRIVATE_LAYOUT_SET_SECURE_URL,
            privateLayoutSetSecurePortalURL);
    content = StringUtil.replace(content, DATA_HANDLER_PRIVATE_LAYOUT_SET_URL, privateLayoutSetPortalURL);
    content = StringUtil.replace(content, DATA_HANDLER_PRIVATE_USER_SERVLET_MAPPING,
            PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING);
    content = StringUtil.replace(content, DATA_HANDLER_PUBLIC_LAYOUT_SET_SECURE_URL,
            publicLayoutSetSecurePortalURL);
    content = StringUtil.replace(content, DATA_HANDLER_PUBLIC_LAYOUT_SET_URL, publicLayoutSetPortalURL);
    content = StringUtil.replace(content, DATA_HANDLER_PUBLIC_SERVLET_MAPPING,
            PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING);
    content = StringUtil.replace(content, DATA_HANDLER_SITE_ADMIN_URL, sb.toString());

    return content;
}

From source file:com.liferay.exportimport.internal.content.processor.LayoutReferencesExportImportContentProcessor.java

License:Open Source License

protected String replaceImportLayoutReferences(PortletDataContext portletDataContext, String content)
        throws Exception {

    String companyPortalURL = StringPool.BLANK;
    String privateLayoutSetPortalURL = StringPool.BLANK;
    String publicLayoutSetPortalURL = StringPool.BLANK;

    Group group = _groupLocalService.getGroup(portletDataContext.getScopeGroupId());

    Company company = _companyLocalService.getCompany(group.getCompanyId());

    LayoutSet privateLayoutSet = group.getPrivateLayoutSet();
    LayoutSet publicLayoutSet = group.getPublicLayoutSet();

    int serverPort = _portal.getPortalServerPort(false);

    if (serverPort != -1) {
        if (Validator.isNotNull(company.getVirtualHostname())) {
            companyPortalURL = _portal.getPortalURL(company.getVirtualHostname(), serverPort, false);
        }//from  w ww.j a  va2 s  .c o m

        if (Validator.isNotNull(privateLayoutSet.getVirtualHostname())) {
            privateLayoutSetPortalURL = _portal.getPortalURL(privateLayoutSet.getVirtualHostname(), serverPort,
                    false);
        }

        if (Validator.isNotNull(publicLayoutSet.getVirtualHostname())) {
            publicLayoutSetPortalURL = _portal.getPortalURL(publicLayoutSet.getVirtualHostname(), serverPort,
                    false);
        }
    }

    int secureSecurePort = _portal.getPortalServerPort(true);

    String companySecurePortalURL = StringPool.BLANK;
    String privateLayoutSetSecurePortalURL = StringPool.BLANK;
    String publicLayoutSetSecurePortalURL = StringPool.BLANK;

    if (secureSecurePort != -1) {
        if (Validator.isNotNull(company.getVirtualHostname())) {
            companySecurePortalURL = _portal.getPortalURL(company.getVirtualHostname(), secureSecurePort, true);
        }

        if (Validator.isNotNull(privateLayoutSet.getVirtualHostname())) {
            privateLayoutSetSecurePortalURL = _portal.getPortalURL(privateLayoutSet.getVirtualHostname(),
                    secureSecurePort, true);
        }

        if (Validator.isNotNull(publicLayoutSet.getVirtualHostname())) {
            publicLayoutSetSecurePortalURL = _portal.getPortalURL(publicLayoutSet.getVirtualHostname(),
                    secureSecurePort, true);
        }
    }

    StringBundler sb = new StringBundler(3);

    sb.append(VirtualLayoutConstants.CANONICAL_URL_SEPARATOR);
    sb.append(GroupConstants.CONTROL_PANEL_FRIENDLY_URL);
    sb.append(PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL);

    content = StringUtil.replace(content, _DATA_HANDLER_COMPANY_SECURE_URL, companySecurePortalURL);
    content = StringUtil.replace(content, _DATA_HANDLER_COMPANY_URL, companyPortalURL);

    // Group friendly URLs

    while (true) {
        int groupFriendlyUrlPos = content.indexOf(_DATA_HANDLER_GROUP_FRIENDLY_URL);

        if (groupFriendlyUrlPos == -1) {
            break;
        }

        int groupUuidPos = groupFriendlyUrlPos + _DATA_HANDLER_GROUP_FRIENDLY_URL.length();

        int endIndex = content.indexOf(StringPool.AT, groupUuidPos + 1);

        if (endIndex < (groupUuidPos + 1)) {
            content = StringUtil.replaceFirst(content, _DATA_HANDLER_GROUP_FRIENDLY_URL, StringPool.BLANK,
                    groupFriendlyUrlPos);

            continue;
        }

        String groupUuid = content.substring(groupUuidPos + 1, endIndex);

        Group groupFriendlyUrlGroup = _groupLocalService.fetchGroupByUuidAndCompanyId(groupUuid,
                portletDataContext.getCompanyId());

        if ((groupFriendlyUrlGroup == null) || groupUuid.startsWith(StringPool.SLASH)) {

            content = StringUtil.replaceFirst(content, _DATA_HANDLER_GROUP_FRIENDLY_URL, group.getFriendlyURL(),
                    groupFriendlyUrlPos);
            content = StringUtil.replaceFirst(content, StringPool.AT + groupUuid + StringPool.AT,
                    StringPool.BLANK, content.indexOf(group.getFriendlyURL()));

            continue;
        }

        content = StringUtil.replaceFirst(content, _DATA_HANDLER_GROUP_FRIENDLY_URL, StringPool.BLANK,
                groupFriendlyUrlPos);
        content = StringUtil.replaceFirst(content, StringPool.AT + groupUuid + StringPool.AT,
                groupFriendlyUrlGroup.getFriendlyURL(), groupFriendlyUrlPos);
    }

    content = StringUtil.replace(content, _DATA_HANDLER_PATH_CONTEXT, _portal.getPathContext());
    content = StringUtil.replace(content, _DATA_HANDLER_PRIVATE_GROUP_SERVLET_MAPPING,
            PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING);
    content = StringUtil.replace(content, _DATA_HANDLER_PRIVATE_LAYOUT_SET_SECURE_URL,
            privateLayoutSetSecurePortalURL);
    content = StringUtil.replace(content, _DATA_HANDLER_PRIVATE_LAYOUT_SET_URL, privateLayoutSetPortalURL);
    content = StringUtil.replace(content, _DATA_HANDLER_PRIVATE_USER_SERVLET_MAPPING,
            PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING);
    content = StringUtil.replace(content, _DATA_HANDLER_PUBLIC_LAYOUT_SET_SECURE_URL,
            publicLayoutSetSecurePortalURL);
    content = StringUtil.replace(content, _DATA_HANDLER_PUBLIC_LAYOUT_SET_URL, publicLayoutSetPortalURL);
    content = StringUtil.replace(content, _DATA_HANDLER_PUBLIC_SERVLET_MAPPING,
            PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING);
    content = StringUtil.replace(content, _DATA_HANDLER_SITE_ADMIN_URL, sb.toString());

    return content;
}

From source file:com.liferay.exportimport.internal.content.processor.test.DefaultExportImportContentProcessorTest.java

License:Open Source License

@Test
public void testExportLayoutReferencesWithContext() throws Exception {
    PortalImpl portalImpl = new PortalImpl() {

        @Override// ww w .j  av  a 2s  . co m
        public String getPathContext() {
            return "/de";
        }

    };

    PortalUtil portalUtil = new PortalUtil();

    portalUtil.setPortal(portalImpl);

    Portal originalPortal = ReflectionTestUtil
            .getAndSetFieldValue(_layoutReferencesExportImportContentProcessor, "_portal", portalImpl);

    _oldLayoutFriendlyURLPrivateUserServletMapping = PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING;

    setFinalStaticField(PropsValues.class.getField("LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING"), "/en");

    Class<?> clazz = _layoutReferencesExportImportContentProcessor.getClass();

    setFinalStaticField(clazz.getDeclaredField("_PRIVATE_USER_SERVLET_MAPPING"), "/en/");

    String content = replaceParameters(getContent("layout_references.txt"), _fileEntry);

    _exportImportContentProcessor.validateContentReferences(_stagingGroup.getGroupId(), content);

    content = _exportImportContentProcessor.replaceExportContentReferences(_portletDataContextExport,
            _referrerStagedModel, content, true, true);

    Assert.assertFalse(content, content.contains(VirtualLayoutConstants.CANONICAL_URL_SEPARATOR));
    Assert.assertFalse(content, content.contains(GroupConstants.CONTROL_PANEL_FRIENDLY_URL));
    Assert.assertFalse(content, content.contains(PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL));
    Assert.assertFalse(content,
            content.contains(PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING));
    Assert.assertFalse(content, content.contains(PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING));
    Assert.assertTrue(content,
            content.contains("@data_handler_group_friendly_url@@" + _stagingGroup.getFriendlyURL() + "@"));
    Assert.assertTrue(content, content.contains("@data_handler_path_context@/en@"));
    Assert.assertFalse(content, content.contains("@data_handler_path_context@/de@"));

    setFinalStaticField(PropsValues.class.getDeclaredField("LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING"),
            _oldLayoutFriendlyURLPrivateUserServletMapping);

    setFinalStaticField(clazz.getDeclaredField("_PRIVATE_USER_SERVLET_MAPPING"),
            PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING + StringPool.SLASH);

    portalUtil.setPortal(new PortalImpl());

    ReflectionTestUtil.setFieldValue(_layoutReferencesExportImportContentProcessor, "_portal", originalPortal);
}

From source file:com.liferay.exportimport.internal.content.processor.test.DefaultExportImportContentProcessorTest.java

License:Open Source License

@Test
public void testExportLayoutReferencesWithoutContext() throws Exception {
    _oldLayoutFriendlyURLPrivateUserServletMapping = PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING;

    setFinalStaticField(PropsValues.class.getField("LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING"), "/en");

    Class<?> clazz = _layoutReferencesExportImportContentProcessor.getClass();

    setFinalStaticField(clazz.getDeclaredField("_PRIVATE_USER_SERVLET_MAPPING"), "/en/");

    String content = replaceParameters(getContent("layout_references.txt"), _fileEntry);

    _exportImportContentProcessor.validateContentReferences(_stagingGroup.getGroupId(), content);

    content = _exportImportContentProcessor.replaceExportContentReferences(_portletDataContextExport,
            _referrerStagedModel, content, true, true);

    Assert.assertFalse(content, content.contains(VirtualLayoutConstants.CANONICAL_URL_SEPARATOR));
    Assert.assertFalse(content, content.contains(GroupConstants.CONTROL_PANEL_FRIENDLY_URL));
    Assert.assertFalse(content, content.contains(PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL));
    Assert.assertFalse(content,/*ww w.j  a va 2s .co  m*/
            content.contains(PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING));
    Assert.assertFalse(content, content.contains(PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING));
    Assert.assertTrue(content,
            content.contains("@data_handler_group_friendly_url@@" + _stagingGroup.getFriendlyURL() + "@"));
    Assert.assertFalse(content, content.contains("/en/en"));

    setFinalStaticField(PropsValues.class.getDeclaredField("LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING"),
            _oldLayoutFriendlyURLPrivateUserServletMapping);

    setFinalStaticField(clazz.getDeclaredField("_PRIVATE_USER_SERVLET_MAPPING"),
            PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING + StringPool.SLASH);
}

From source file:com.liferay.exportimport.internal.content.processor.test.DefaultExportImportContentProcessorTest.java

License:Open Source License

protected String replaceParameters(String content, FileEntry fileEntry) {
    Company company = CompanyLocalServiceUtil.fetchCompany(fileEntry.getCompanyId());

    content = replaceMultiLocaleLayoutFriendlyURLs(content);

    Map<Locale, String> livePublicLayoutFriendlyURLMap = _livePublicLayout.getFriendlyURLMap();
    Map<Locale, String> stagingPrivateLayoutFriendlyURLMap = _stagingPrivateLayout.getFriendlyURLMap();
    Map<Locale, String> stagingPublicLayoutFriendlyURLMap = _stagingPublicLayout.getFriendlyURLMap();

    content = StringUtil.replace(content, new String[] { "[$CANONICAL_URL_SEPARATOR$]",
            "[$CONTROL_PANEL_FRIENDLY_URL$]", "[$CONTROL_PANEL_LAYOUT_FRIENDLY_URL$]", "[$GROUP_FRIENDLY_URL$]",
            "[$GROUP_ID$]", "[$IMAGE_ID$]", "[$LIVE_GROUP_FRIENDLY_URL$]", "[$LIVE_GROUP_ID$]",
            "[$LIVE_PUBLIC_LAYOUT_FRIENDLY_URL$]", "[$NON_DEFAULT_LIVE_PUBLIC_LAYOUT_FRIENDLY_URL$]",
            "[$NON_DEFAULT_PRIVATE_LAYOUT_FRIENDLY_URL$]", "[$NON_DEFAULT_PUBLIC_LAYOUT_FRIENDLY_URL$]",
            "[$PATH_CONTEXT$]", "[$PATH_FRIENDLY_URL_PRIVATE_GROUP$]", "[$PATH_FRIENDLY_URL_PRIVATE_USER$]",
            "[$PATH_FRIENDLY_URL_PUBLIC$]", "[$PRIVATE_LAYOUT_FRIENDLY_URL$]", "[$PUBLIC_LAYOUT_FRIENDLY_URL$]",
            "[$TITLE$]", "[$UUID$]", "[$WEB_ID$]" },
            new String[] { VirtualLayoutConstants.CANONICAL_URL_SEPARATOR,
                    GroupConstants.CONTROL_PANEL_FRIENDLY_URL, PropsValues.CONTROL_PANEL_LAYOUT_FRIENDLY_URL,
                    _stagingGroup.getFriendlyURL(), String.valueOf(fileEntry.getGroupId()),
                    String.valueOf(fileEntry.getFileEntryId()), _liveGroup.getFriendlyURL(),
                    String.valueOf(_liveGroup.getGroupId()), _livePublicLayout.getFriendlyURL(),
                    livePublicLayoutFriendlyURLMap.get(_nonDefaultLocale),
                    stagingPrivateLayoutFriendlyURLMap.get(_nonDefaultLocale),
                    stagingPublicLayoutFriendlyURLMap.get(_nonDefaultLocale), PortalUtil.getPathContext(),
                    PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING,
                    PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING,
                    PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING,
                    _stagingPrivateLayout.getFriendlyURL(), _stagingPublicLayout.getFriendlyURL(),
                    fileEntry.getTitle(), fileEntry.getUuid(), company.getWebId() });

    if (!content.contains("[$TIMESTAMP")) {
        return content;
    }/*  w w  w . jav a  2 s  . com*/

    return replaceTimestampParameters(content);
}

From source file:com.liferay.journal.internal.exportimport.content.processor.JournalFeedExportImportContentProcessor.java

License:Open Source License

@Override
public String replaceExportContentReferences(PortletDataContext portletDataContext, StagedModel stagedModel,
        String content, boolean exportReferencedContent, boolean escapeContent) throws Exception {

    JournalFeed feed = (JournalFeed) stagedModel;

    Group group = _groupLocalService.getGroup(portletDataContext.getScopeGroupId());

    String newGroupFriendlyURL = group.getFriendlyURL();

    newGroupFriendlyURL = newGroupFriendlyURL.substring(1);

    String[] friendlyURLParts = StringUtil.split(feed.getTargetLayoutFriendlyUrl(), StringPool.FORWARD_SLASH);

    String oldGroupFriendlyURL = friendlyURLParts[2];

    if (newGroupFriendlyURL.equals(oldGroupFriendlyURL)) {
        String targetLayoutFriendlyUrl = StringUtil.replaceFirst(feed.getTargetLayoutFriendlyUrl(),
                StringPool.SLASH + newGroupFriendlyURL + StringPool.SLASH,
                StringPool.SLASH + DATA_HANDLER_GROUP_FRIENDLY_URL + StringPool.SLASH);

        feed.setTargetLayoutFriendlyUrl(targetLayoutFriendlyUrl);
    }//from   w  ww.ja va2 s.  co  m

    Group targetLayoutGroup = _groupLocalService.fetchFriendlyURLGroup(portletDataContext.getCompanyId(),
            StringPool.SLASH + oldGroupFriendlyURL);

    boolean privateLayout = false;

    if (!PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING
            .equals(StringPool.SLASH + friendlyURLParts[1])) {

        privateLayout = true;
    }

    String targetLayoutFriendlyURL = StringPool.SLASH + friendlyURLParts[3];

    Layout targetLayout = _layoutLocalService.fetchLayoutByFriendlyURL(targetLayoutGroup.getGroupId(),
            privateLayout, targetLayoutFriendlyURL);

    Element feedElement = portletDataContext.getExportDataElement(feed);

    portletDataContext.addReferenceElement(feed, feedElement, targetLayout,
            PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true);

    return content;
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java

License:Open Source License

protected Object[] extractFriendlyURLInfo(Layout layout) {
    if (!Objects.equals(layout.getType(), LayoutConstants.TYPE_URL)) {
        return null;
    }//from  ww  w  .  j  a  va  2  s. co  m

    UnicodeProperties typeSettings = layout.getTypeSettingsProperties();

    String url = GetterUtil.getString(typeSettings.getProperty("url"));

    String friendlyURLPrivateGroupPath = PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING;
    String friendlyURLPrivateUserPath = PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING;
    String friendlyURLPublicPath = PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING;

    if (!url.startsWith(friendlyURLPrivateGroupPath) && !url.startsWith(friendlyURLPrivateUserPath)
            && !url.startsWith(friendlyURLPublicPath)) {

        return null;
    }

    int x = url.indexOf(CharPool.SLASH, 1);

    if (x == -1) {
        return null;
    }

    int y = url.indexOf(CharPool.SLASH, x + 1);

    if (y == -1) {
        return null;
    }

    return new Object[] { url.substring(x, y), url, x, y };
}

From source file:com.liferay.portlet.journal.lar.JournalPortletDataHandlerImpl.java

License:Open Source License

protected static String exportLayoutFriendlyURLs(PortletDataContext portletDataContext, String content) {

    Group group = null;//  ww  w  .  j  av  a  2  s. c om

    try {
        group = GroupLocalServiceUtil.getGroup(portletDataContext.getScopeGroupId());
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(e);
        }

        return content;
    }

    StringBuilder sb = new StringBuilder(content);

    String friendlyURLPrivateGroupPath = PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING;
    String friendlyURLPrivateUserPath = PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING;
    String friendlyURLPublicPath = PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING;

    String href = "href=";

    int beginPos = content.length();

    while (true) {
        int hrefLength = href.length();

        beginPos = content.lastIndexOf(href, beginPos);

        if (beginPos == -1) {
            break;
        }

        char c = content.charAt(beginPos + hrefLength);

        if ((c == CharPool.APOSTROPHE) || (c == CharPool.QUOTE)) {
            hrefLength++;
        }

        int endPos1 = content.indexOf(CharPool.APOSTROPHE, beginPos + hrefLength);
        int endPos2 = content.indexOf(CharPool.CLOSE_BRACKET, beginPos + hrefLength);
        int endPos3 = content.indexOf(CharPool.CLOSE_CURLY_BRACE, beginPos + hrefLength);
        int endPos4 = content.indexOf(CharPool.CLOSE_PARENTHESIS, beginPos + hrefLength);
        int endPos5 = content.indexOf(CharPool.LESS_THAN, beginPos + hrefLength);
        int endPos6 = content.indexOf(CharPool.QUESTION, beginPos + hrefLength);
        int endPos7 = content.indexOf(CharPool.QUOTE, beginPos + hrefLength);
        int endPos8 = content.indexOf(CharPool.SPACE, beginPos + hrefLength);

        int endPos = endPos1;

        if ((endPos == -1) || ((endPos2 != -1) && (endPos2 < endPos))) {
            endPos = endPos2;
        }

        if ((endPos == -1) || ((endPos3 != -1) && (endPos3 < endPos))) {
            endPos = endPos3;
        }

        if ((endPos == -1) || ((endPos4 != -1) && (endPos4 < endPos))) {
            endPos = endPos4;
        }

        if ((endPos == -1) || ((endPos5 != -1) && (endPos5 < endPos))) {
            endPos = endPos5;
        }

        if ((endPos == -1) || ((endPos6 != -1) && (endPos6 < endPos))) {
            endPos = endPos6;
        }

        if ((endPos == -1) || ((endPos7 != -1) && (endPos7 < endPos))) {
            endPos = endPos7;
        }

        if ((endPos == -1) || ((endPos8 != -1) && (endPos8 < endPos))) {
            endPos = endPos8;
        }

        if (endPos == -1) {
            beginPos--;

            continue;
        }

        String url = content.substring(beginPos + hrefLength, endPos);

        if (!url.startsWith(friendlyURLPrivateGroupPath) && !url.startsWith(friendlyURLPrivateUserPath)
                && !url.startsWith(friendlyURLPublicPath)) {

            beginPos--;

            continue;
        }

        int beginGroupPos = content.indexOf(CharPool.SLASH, beginPos + hrefLength + 1);

        if (beginGroupPos == -1) {
            beginPos--;

            continue;
        }

        int endGroupPos = content.indexOf(CharPool.SLASH, beginGroupPos + 1);

        if (endGroupPos == -1) {
            beginPos--;

            continue;
        }

        String groupFriendlyURL = content.substring(beginGroupPos, endGroupPos);

        if (groupFriendlyURL.equals(group.getFriendlyURL())) {
            sb.replace(beginGroupPos, endGroupPos, "@data_handler_group_friendly_url@");
        }

        beginPos--;
    }

    return sb.toString();
}