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

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

Introduction

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

Prototype

public static int getPortalServerPort(boolean secure) 

Source Link

Usage

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

License:Open Source License

protected String replaceExportHostname(long groupId, String url, StringBundler urlSB) throws PortalException {

    if (!HttpUtil.hasProtocol(url)) {
        return url;
    }//from  w  ww.j  ava  2s . c om

    boolean secure = HttpUtil.isSecure(url);

    int serverPort = PortalUtil.getPortalServerPort(secure);

    if (serverPort == -1) {
        return url;
    }

    Group group = GroupLocalServiceUtil.getGroup(groupId);

    LayoutSet publicLayoutSet = group.getPublicLayoutSet();

    String publicLayoutSetVirtualHostname = publicLayoutSet.getVirtualHostname();

    String portalUrl = StringPool.BLANK;

    if (Validator.isNotNull(publicLayoutSetVirtualHostname)) {
        portalUrl = PortalUtil.getPortalURL(publicLayoutSetVirtualHostname, serverPort, secure);

        if (url.startsWith(portalUrl)) {
            if (secure) {
                urlSB.append(DATA_HANDLER_PUBLIC_LAYOUT_SET_SECURE_URL);
            } else {
                urlSB.append(DATA_HANDLER_PUBLIC_LAYOUT_SET_URL);
            }

            return url.substring(portalUrl.length());
        }
    }

    LayoutSet privateLayoutSet = group.getPrivateLayoutSet();

    String privateLayoutSetVirtualHostname = privateLayoutSet.getVirtualHostname();

    if (Validator.isNotNull(privateLayoutSetVirtualHostname)) {
        portalUrl = PortalUtil.getPortalURL(privateLayoutSetVirtualHostname, serverPort, secure);

        if (url.startsWith(portalUrl)) {
            if (secure) {
                urlSB.append(DATA_HANDLER_PRIVATE_LAYOUT_SET_SECURE_URL);
            } else {
                urlSB.append(DATA_HANDLER_PRIVATE_LAYOUT_SET_URL);
            }

            return url.substring(portalUrl.length());
        }
    }

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

    String companyVirtualHostname = company.getVirtualHostname();

    if (Validator.isNotNull(companyVirtualHostname)) {
        portalUrl = PortalUtil.getPortalURL(companyVirtualHostname, serverPort, secure);

        if (url.startsWith(portalUrl)) {
            if (secure) {
                urlSB.append(DATA_HANDLER_COMPANY_SECURE_URL);
            } else {
                urlSB.append(DATA_HANDLER_COMPANY_URL);
            }

            return url.substring(portalUrl.length());
        }
    }

    portalUrl = PortalUtil.getPortalURL("localhost", serverPort, secure);

    if (url.startsWith(portalUrl)) {
        return url.substring(portalUrl.length());
    }

    return url;
}

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);
        }/* w w  w.  j  a 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.system.event.test.SystemEventTest.java

License:Open Source License

public long doTestRemoteStaging() throws Exception {
    setPortalProperty("TUNNELING_SERVLET_SHARED_SECRET", "F0E1D2C3B4A5968778695A4B3C2D1E0F");

    setPortalProperty("TUNNELING_SERVLET_SHARED_SECRET_HEX", true);

    _stagingGroup = GroupTestUtil.addGroup();

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setScopeGroupId(_stagingGroup.getGroupId());

    Map<String, Serializable> attributes = serviceContext.getAttributes();

    attributes.putAll(ExportImportConfigurationParameterMapFactory.buildParameterMap());

    attributes.put(PortletDataHandlerKeys.PORTLET_CONFIGURATION_ALL, new String[] { Boolean.FALSE.toString() });
    attributes.put(PortletDataHandlerKeys.PORTLET_DATA_ALL, new String[] { Boolean.FALSE.toString() });

    int serverPort = PortalUtil.getPortalServerPort(false);
    String pathContext = PortalUtil.getPathContext();

    ServiceTestUtil.setUser(TestPropsValues.getUser());

    StagingLocalServiceUtil.enableRemoteStaging(TestPropsValues.getUserId(), _stagingGroup, false, false,
            "localhost", serverPort, pathContext, false, _liveGroup.getGroupId(), serviceContext);

    _exportImportConfiguration = ExportImportConfigurationFactory
            .buildDefaultRemotePublishingExportImportConfiguration(TestPropsValues.getUser(),
                    _stagingGroup.getGroupId(), false, "localhost", serverPort, pathContext, false,
                    _liveGroup.getGroupId());

    JournalArticle journalArticle = JournalTestUtil.addArticle(_stagingGroup.getGroupId(),
            JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID);

    StagingUtil.publishLayouts(TestPropsValues.getUserId(), _exportImportConfiguration);

    List<JournalArticle> articles = JournalArticleLocalServiceUtil.getArticles(_liveGroup.getGroupId());

    Assert.assertEquals(articles.toString(), 1, articles.size());

    JournalArticleLocalServiceUtil.deleteArticle(_stagingGroup.getGroupId(), journalArticle.getArticleId(),
            new ServiceContext());

    SystemEvent systemEvent = SystemEventLocalServiceUtil.fetchSystemEvent(_stagingGroup.getGroupId(),
            ClassNameLocalServiceUtil.getClassNameId(JournalArticle.class), journalArticle.getResourcePrimKey(),
            SystemEventConstants.TYPE_DELETE);

    Assert.assertNotNull(systemEvent);// ww w .j  a va  2  s. co  m

    GroupUtil.clearCache();

    StagingUtil.publishLayouts(TestPropsValues.getUserId(), _exportImportConfiguration);

    Assert.assertEquals(0, JournalArticleLocalServiceUtil.getArticlesCount(_liveGroup.getGroupId()));

    journalArticle = articles.get(0);

    return journalArticle.getResourcePrimKey();
}