Example usage for com.liferay.portal.kernel.util HttpUtil getDomain

List of usage examples for com.liferay.portal.kernel.util HttpUtil getDomain

Introduction

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

Prototype

public static String getDomain(String url) 

Source Link

Usage

From source file:com.beorn.paypalpaymentplugin.util.PayPalUtil.java

License:Open Source License

public static String getReturnUrl(ServletContext servletContext, String successUrl, String errorUrl) {
    String returnUrl = HttpUtil.getProtocol(successUrl) + "://" + HttpUtil.getDomain(successUrl);
    returnUrl += servletContext.getContextPath() + _returnServletPath;
    returnUrl = HttpUtil.addParameter(returnUrl, "successUrl", successUrl);
    returnUrl = HttpUtil.addParameter(returnUrl, "errorUrl", errorUrl);
    return returnUrl;
}

From source file:com.liferay.rss.web.internal.util.RSSFeed.java

License:Open Source License

public RSSFeed(RSSWebCacheConfiguration rssWebCacheConfiguration, String url, String title) {

    _rssWebCacheConfiguration = rssWebCacheConfiguration;
    _url = url;/*from   w  ww  .java  2s  . c om*/

    SyndFeed syndFeed = getSyndFeed();

    if (syndFeed == null) {
        _baseURL = StringPool.BLANK;
        _syndFeedImageLink = StringPool.BLANK;
        _syndFeedImageURL = StringPool.BLANK;
        _syndFeedLink = StringPool.BLANK;
        _title = title;

        return;
    }

    if (Validator.isNull(title)) {
        title = syndFeed.getTitle();
    }

    String baseURL = StringPool.BLANK;
    String syndFeedImageLink = StringPool.BLANK;
    String syndFeedImageURL = StringPool.BLANK;
    String syndFeedLink = syndFeed.getLink();

    if (Validator.isNull(syndFeedLink) || !HttpUtil.hasDomain(syndFeedLink)) {

        baseURL = HttpUtil.getProtocol(_url).concat(Http.PROTOCOL_DELIMITER).concat(HttpUtil.getDomain(_url));

        if (Validator.isNotNull(syndFeedLink)) {
            syndFeedLink = baseURL.concat(syndFeedLink);
        } else {
            syndFeedLink = baseURL;
        }
    } else {
        baseURL = HttpUtil.getProtocol(syndFeedLink).concat(Http.PROTOCOL_DELIMITER)
                .concat(HttpUtil.getDomain(syndFeedLink));
    }

    SyndImage syndImage = syndFeed.getImage();

    if (syndImage != null) {
        syndFeedImageLink = syndImage.getLink();

        if (!HttpUtil.hasDomain(syndFeedImageLink)) {
            syndFeedImageLink = baseURL + syndFeedImageLink;
        }

        syndFeedImageURL = syndImage.getUrl();

        if (!HttpUtil.hasDomain(syndFeedImageURL)) {
            syndFeedImageURL = baseURL + syndFeedImageURL;
        }
    }

    _baseURL = baseURL;
    _syndFeedImageLink = syndFeedImageLink;
    _syndFeedImageURL = syndFeedImageURL;
    _syndFeedLink = syndFeedLink;
    _title = title;
}

From source file:com.liferay.so.activities.hook.social.BookmarksActivityInterpreter.java

License:Open Source License

protected String getBookmarkLink(String className, long classPK, ServiceContext serviceContext)
        throws Exception {

    BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);

    String faviconUrl = HttpUtil.getDomain(entry.getUrl()) + "/favicon.ico";

    AssetRenderer assetRenderer = getAssetRenderer(className, classPK);

    LiferayPortletRequest liferayPortletRequest = serviceContext.getLiferayPortletRequest();

    if (ping(faviconUrl)) {
        return wrapLink(entry.getUrl(), faviconUrl, entry.getName());
    } else if (Validator.isNotNull(assetRenderer.getIconPath(liferayPortletRequest))) {

        return wrapLink(entry.getUrl(), assetRenderer.getIconPath(liferayPortletRequest),
                HtmlUtil.escape(assetRenderer.getTitle(serviceContext.getLocale())));
    }//from w w  w . jav a  2 s .c  o m

    return wrapLink(entry.getUrl(), entry.getName());
}

From source file:com.liferay.wsrp.servlet.ProxyServlet.java

License:Open Source License

protected boolean isAllowedURL(String url) throws Exception {
    String[] allowedIps = PortletPropsValues.PROXY_URL_IPS_ALLOWED;

    if (allowedIps.length == 0) {
        return true;
    }/*w  ww .j ava 2s .com*/

    String domain = HttpUtil.getDomain(url);

    int pos = domain.indexOf(CharPool.COLON);

    if (pos != -1) {
        domain = domain.substring(0, pos);
    }

    InetAddress inetAddress = InetAddress.getByName(domain);

    String hostAddress = inetAddress.getHostAddress();

    String serverIp = PortalUtil.getComputerAddress();

    boolean serverIpIsHostAddress = serverIp.equals(hostAddress);

    for (String ip : allowedIps) {
        if ((serverIpIsHostAddress && ip.equals("SERVER_IP")) || ip.equals(hostAddress)) {

            return true;
        }
    }

    return false;
}