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

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

Introduction

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

Prototype

public static String getQueryString(String url) 

Source Link

Usage

From source file:com.liferay.journal.web.util.JournalRSSUtil.java

License:Open Source License

public FileEntry getFileEntry(String url) {
    FileEntry fileEntry = null;//w w  w. j a  v a  2s .  co  m

    String queryString = HttpUtil.getQueryString(url);

    Map<String, String[]> parameters = HttpUtil.parameterMapFromString(queryString);

    if (url.startsWith("/documents/")) {
        String[] pathArray = StringUtil.split(url, CharPool.SLASH);

        String uuid = null;
        long groupId = GetterUtil.getLong(pathArray[2]);
        long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
        String title = null;

        if (pathArray.length == 4) {
            uuid = pathArray[3];
        } else if (pathArray.length == 5) {
            folderId = GetterUtil.getLong(pathArray[3]);
            title = HttpUtil.decodeURL(pathArray[4]);
        } else if (pathArray.length > 5) {
            uuid = pathArray[5];
        }

        try {
            if (Validator.isNotNull(uuid)) {
                fileEntry = _dlAppLocalService.getFileEntryByUuidAndGroupId(uuid, groupId);
            } else {
                fileEntry = _dlAppLocalService.getFileEntry(groupId, folderId, title);
            }
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e, e);
            }
        }
    } else if (parameters.containsKey("folderId") && parameters.containsKey("name")) {

        try {
            long fileEntryId = GetterUtil.getLong(parameters.get("fileEntryId")[0]);

            fileEntry = _dlAppLocalService.getFileEntry(fileEntryId);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e, e);
            }
        }
    } else if (parameters.containsKey("uuid") && parameters.containsKey("groupId")) {

        try {
            String uuid = parameters.get("uuid")[0];
            long groupId = GetterUtil.getLong(parameters.get("groupId")[0]);

            fileEntry = _dlAppLocalService.getFileEntryByUuidAndGroupId(uuid, groupId);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e, e);
            }
        }
    }

    return fileEntry;
}

From source file:com.liferay.journal.web.util.JournalRSSUtil.java

License:Open Source License

public Image getImage(String url) {
    Image image = null;//www  .  j  ava  2 s .  c  o  m

    String queryString = HttpUtil.getQueryString(url);

    Map<String, String[]> parameters = HttpUtil.parameterMapFromString(queryString);

    if (parameters.containsKey("image_id") || parameters.containsKey("img_id")
            || parameters.containsKey("i_id")) {

        try {
            long imageId = 0;

            if (parameters.containsKey("image_id")) {
                imageId = GetterUtil.getLong(parameters.get("image_id")[0]);
            } else if (parameters.containsKey("img_id")) {
                imageId = GetterUtil.getLong(parameters.get("img_id")[0]);
            } else if (parameters.containsKey("i_id")) {
                imageId = GetterUtil.getLong(parameters.get("i_id")[0]);
            }

            image = _imageLocalService.getImage(imageId);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e, e);
            }
        }
    }

    return image;
}

From source file:com.liferay.portlet.journal.util.JournalRSSUtil.java

License:Open Source License

public static FileEntry getFileEntry(String url) {
    FileEntry fileEntry = null;//from w ww.  j a  va2s  .  c om

    String queryString = HttpUtil.getQueryString(url);

    Map<String, String[]> parameters = HttpUtil.parameterMapFromString(queryString);

    if (url.startsWith("/documents/")) {
        String[] pathArray = StringUtil.split(url, CharPool.SLASH);

        long groupId = GetterUtil.getLong(pathArray[2]);
        long folderId = GetterUtil.getLong(pathArray[3]);
        String title = HttpUtil.decodeURL(pathArray[4], true);

        try {
            fileEntry = DLAppLocalServiceUtil.getFileEntry(groupId, folderId, title);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e, e);
            }
        }
    } else if (parameters.containsKey("folderId") && parameters.containsKey("name")) {

        try {
            long fileEntryId = GetterUtil.getLong(parameters.get("fileEntryId")[0]);

            fileEntry = DLAppLocalServiceUtil.getFileEntry(fileEntryId);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e, e);
            }
        }
    } else if (parameters.containsKey("uuid") && parameters.containsKey("groupId")) {

        try {
            String uuid = parameters.get("uuid")[0];
            long groupId = GetterUtil.getLong(parameters.get("groupId")[0]);

            fileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e, e);
            }
        }
    }

    return fileEntry;
}

From source file:com.liferay.portlet.journal.util.JournalRSSUtil.java

License:Open Source License

public static Image getImage(String url) {
    Image image = null;/*from   w  w  w  .j  ava  2 s  .c om*/

    String queryString = HttpUtil.getQueryString(url);

    Map<String, String[]> parameters = HttpUtil.parameterMapFromString(queryString);

    if (parameters.containsKey("image_id") || parameters.containsKey("img_id")
            || parameters.containsKey("i_id")) {

        try {
            long imageId = 0;

            if (parameters.containsKey("image_id")) {
                imageId = GetterUtil.getLong(parameters.get("image_id")[0]);
            } else if (parameters.containsKey("img_id")) {
                imageId = GetterUtil.getLong(parameters.get("img_id")[0]);
            } else if (parameters.containsKey("i_id")) {
                imageId = GetterUtil.getLong(parameters.get("i_id")[0]);
            }

            image = ImageLocalServiceUtil.getImage(imageId);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e, e);
            }
        }
    }

    return image;
}

From source file:com.liferay.portlet.PortletBagFactory.java

License:Open Source License

protected String getContent(String fileName) throws Exception {
    String queryString = HttpUtil.getQueryString(fileName);

    if (Validator.isNull(queryString)) {
        return StringUtil.read(_classLoader, fileName);
    }//from   w  w  w . ja  v a2  s  .com

    int pos = fileName.indexOf(StringPool.QUESTION);

    String xml = StringUtil.read(_classLoader, fileName.substring(0, pos));

    Map<String, String[]> parameterMap = HttpUtil.getParameterMap(queryString);

    if (parameterMap == null) {
        return xml;
    }

    for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
        String name = entry.getKey();
        String[] values = entry.getValue();

        if (values.length == 0) {
            continue;
        }

        String value = values[0];

        xml = StringUtil.replace(xml, "@" + name + "@", value);
    }

    return xml;
}

From source file:com.liferay.taglib.portlet.RenderURLParamsTag.java

License:Open Source License

private static String _toParamsString(PortletURL portletURL, PageContext pageContext) throws Exception {

    StringBundler sb = new StringBundler();

    String url = portletURL.toString();

    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    if (ParamUtil.getBoolean(request, "wsrp")) {
        int x = url.indexOf("/wsrp_rewrite");

        url = url.substring(0, x);/*  ww w  . j  a va2s.c o  m*/
    }

    String queryString = HttpUtil.getQueryString(url);

    String[] parameters = StringUtil.split(queryString, CharPool.AMPERSAND);

    for (String parameter : parameters) {
        if (parameter.length() > 0) {
            String[] kvp = StringUtil.split(parameter, CharPool.EQUAL);

            if ((kvp != null) && (kvp.length > 0)) {
                String key = kvp[0];
                String value = StringPool.BLANK;

                if (kvp.length > 1) {
                    value = kvp[1];
                }

                value = HttpUtil.decodeURL(value);

                sb.append("<input name=\"");
                sb.append(key);
                sb.append("\" type=\"hidden\" value=\"");
                sb.append(HtmlUtil.escapeAttribute(value));
                sb.append("\" />");
            }
        }
    }

    return sb.toString();
}

From source file:it.smartcommunitylab.platform.idea.portlet.Utils.java

License:Apache License

public static String generateRenderURL(String base, String url) {
    int indexOfBase = base.indexOf("/-/");
    int indexOfUrl = url.indexOf("/-/");
    // check whether both context paths are the same
    if (indexOfBase >= 0 && indexOfUrl >= 0) {
        if (base.substring(0, indexOfBase).equals(url.substring(0, indexOfUrl)))
            return url;
    }/*from  w ww .  j ava 2  s  .c  o  m*/
    // if derived is not friendly use the base + query string
    if (indexOfUrl < 0) {
        return base + "?" + HttpUtil.getQueryString(url);
    } else {
        // if derived is friendly and the base is friendly, replace the part
        // before /-/
        if (indexOfBase >= 0) {
            base = base.substring(0, indexOfBase);
        }
        // otherwise use base + new friendly
        return base + url.substring(indexOfUrl);
    }
}