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

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

Introduction

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

Prototype

public static String getPortalURL(String serverName, int serverPort, boolean secure) 

Source Link

Usage

From source file:com.liferay.dynamic.data.mapping.model.impl.DDMStructureImpl.java

License:Open Source License

/**
 * Returns the WebDAV URL to access the structure.
 *
 * @param  themeDisplay the theme display needed to build the URL. It can
 *         set HTTPS access, the server name, the server port, the path
 *         context, and the scope group.
 * @param  webDAVToken the WebDAV token for the URL
 * @return the WebDAV URL//from www . j  ava  2s.  c om
 */
@Override
public String getWebDavURL(ThemeDisplay themeDisplay, String webDAVToken) {
    StringBundler sb = new StringBundler(11);

    boolean secure = false;

    if (themeDisplay.isSecure() || PropsValues.WEBDAV_SERVLET_HTTPS_REQUIRED) {

        secure = true;
    }

    String portalURL = PortalUtil.getPortalURL(themeDisplay.getServerName(), themeDisplay.getServerPort(),
            secure);

    sb.append(portalURL);

    sb.append(themeDisplay.getPathContext());
    sb.append(StringPool.SLASH);
    sb.append("webdav");

    Group group = themeDisplay.getScopeGroup();

    sb.append(group.getFriendlyURL());

    sb.append(StringPool.SLASH);
    sb.append(webDAVToken);
    sb.append(StringPool.SLASH);
    sb.append("Structures");
    sb.append(StringPool.SLASH);
    sb.append(getStructureId());

    return sb.toString();
}

From source file:com.liferay.dynamic.data.mapping.model.impl.DDMTemplateImpl.java

License:Open Source License

/**
 * Returns the WebDAV URL to access the template.
 *
 * @param  themeDisplay the theme display needed to build the URL. It can
 *         set HTTPS access, the server name, the server port, the path
 *         context, and the scope group.
 * @param  webDAVToken the WebDAV token for the URL
 * @return the WebDAV URL/*from www . ja va 2 s. c  o  m*/
 */
@Override
public String getWebDavURL(ThemeDisplay themeDisplay, String webDAVToken) {
    StringBundler sb = new StringBundler(11);

    boolean secure = false;

    if (themeDisplay.isSecure() || PropsValues.WEBDAV_SERVLET_HTTPS_REQUIRED) {

        secure = true;
    }

    String portalURL = PortalUtil.getPortalURL(themeDisplay.getServerName(), themeDisplay.getServerPort(),
            secure);

    sb.append(portalURL);

    sb.append(themeDisplay.getPathContext());
    sb.append(StringPool.SLASH);
    sb.append("webdav");

    Group group = themeDisplay.getScopeGroup();

    sb.append(group.getFriendlyURL());

    sb.append(StringPool.SLASH);
    sb.append(webDAVToken);
    sb.append(StringPool.SLASH);
    sb.append("Templates");
    sb.append(StringPool.SLASH);
    sb.append(getTemplateId());

    return sb.toString();
}

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  a  v  a 2s.  c o  m

    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);
        }/*  ww w  . ja v  a 2  s. co  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;
}