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

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

Introduction

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

Prototype

public static Map<String, String[]> parameterMapFromString(String queryString) 

Source Link

Usage

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

License:Open Source License

protected Map<String, String[]> getDLReferenceParameters(long groupId, String content, int beginPos,
        int endPos) {

    boolean legacyURL = true;
    char[] stopChars = DL_REFERENCE_LEGACY_STOP_CHARS;

    if (content.startsWith("/documents/", beginPos)) {
        legacyURL = false;//w  w  w  .j a  v a  2 s  . c  o  m
        stopChars = DL_REFERENCE_STOP_CHARS;
    }

    endPos = StringUtil.indexOfAny(content, stopChars, beginPos, endPos);

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

    Map<String, String[]> map = new HashMap<>();

    String dlReference = content.substring(beginPos, endPos);

    while (dlReference.contains(StringPool.AMPERSAND_ENCODED)) {
        dlReference = dlReference.replace(StringPool.AMPERSAND_ENCODED, StringPool.AMPERSAND);
    }

    if (!legacyURL) {
        String[] pathArray = dlReference.split(StringPool.SLASH);

        if (pathArray.length < 3) {
            return map;
        }

        map.put("groupId", new String[] { pathArray[2] });

        if (pathArray.length == 4) {
            map.put("uuid", new String[] { pathArray[3] });
        } else if (pathArray.length == 5) {
            map.put("folderId", new String[] { pathArray[3] });
            map.put("title", new String[] { HttpUtil.decodeURL(pathArray[4]) });
        } else if (pathArray.length > 5) {
            map.put("uuid", new String[] { pathArray[5] });
        }
    } else {
        dlReference = dlReference.substring(dlReference.indexOf(CharPool.QUESTION) + 1);

        map = HttpUtil.parameterMapFromString(dlReference);

        String[] imageIds = null;

        if (map.containsKey("img_id")) {
            imageIds = map.get("img_id");
        } else if (map.containsKey("i_id")) {
            imageIds = map.get("i_id");
        }

        imageIds = ArrayUtil.filter(imageIds, new PredicateFilter<String>() {

            @Override
            public boolean filter(String imageId) {
                if (Validator.isNotNull(imageId)) {
                    return true;
                }

                return false;
            }

        });

        if (ArrayUtil.isNotEmpty(imageIds)) {
            map.put("image_id", imageIds);
        }
    }

    map.put("endPos", new String[] { String.valueOf(endPos) });

    String groupIdString = MapUtil.getString(map, "groupId");

    if (groupIdString.equals("@group_id@")) {
        groupIdString = String.valueOf(groupId);

        map.put("groupId", new String[] { groupIdString });
    }

    return map;
}

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

License:Open Source License

public FileEntry getFileEntry(String url) {
    FileEntry fileEntry = null;/*ww w  . j a  v  a2  s.  c  o  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;//from  www  .  j  av a  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.lar.JournalPortletDataHandlerImpl.java

License:Open Source License

protected static String exportDLFileEntries(PortletDataContext portletDataContext,
        Element dlFileEntryTypesElement, Element dlFoldersElement, Element dlFileEntriesElement,
        Element dlFileRanksElement, Element dlRepositoriesElement, Element dlRepositoryEntriesElement,
        Element entityElement, String content, boolean checkDateRange) throws Exception {

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

    if (group.isStagingGroup()) {
        group = group.getLiveGroup();/*from w  w w  .ja v  a 2 s. co m*/
    }

    if (group.isStaged() && !group.isStagedRemotely() && !group.isStagedPortlet(PortletKeys.DOCUMENT_LIBRARY)) {

        return content;
    }

    StringBuilder sb = new StringBuilder(content);

    int beginPos = content.length();
    int currentLocation = -1;

    while (true) {
        currentLocation = content.lastIndexOf("/c/document_library/get_file?", beginPos);

        if (currentLocation == -1) {
            currentLocation = content.lastIndexOf("/documents/", beginPos);
        }

        if (currentLocation == -1) {
            return sb.toString();
        }

        beginPos = currentLocation;

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

        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 ((beginPos == -1) || (endPos == -1)) {
            break;
        }

        try {
            String oldParameters = content.substring(beginPos, endPos);

            while (oldParameters.contains(StringPool.AMPERSAND_ENCODED)) {
                oldParameters = oldParameters.replace(StringPool.AMPERSAND_ENCODED, StringPool.AMPERSAND);
            }

            Map<String, String[]> map = new HashMap<String, String[]>();

            if (oldParameters.startsWith("/documents/")) {
                String[] pathArray = oldParameters.split(StringPool.SLASH);

                map.put("groupId", new String[] { pathArray[2] });

                if (pathArray.length == 4) {
                    map.put("uuid", new String[] { pathArray[3] });
                } else if (pathArray.length == 5) {
                    map.put("folderId", new String[] { pathArray[3] });

                    String name = HttpUtil.decodeURL(pathArray[4]);

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

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

                    map.put("name", new String[] { name });
                } else if (pathArray.length > 5) {
                    String uuid = pathArray[5];

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

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

                    map.put("uuid", new String[] { uuid });
                }
            } else {
                oldParameters = oldParameters.substring(oldParameters.indexOf(CharPool.QUESTION) + 1);

                map = HttpUtil.parameterMapFromString(oldParameters);
            }

            FileEntry fileEntry = null;

            String uuid = MapUtil.getString(map, "uuid");

            if (Validator.isNotNull(uuid)) {
                String groupIdString = MapUtil.getString(map, "groupId");

                long groupId = GetterUtil.getLong(groupIdString);

                if (groupIdString.equals("@group_id@")) {
                    groupId = portletDataContext.getScopeGroupId();
                }

                fileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
            } else {
                String folderIdString = MapUtil.getString(map, "folderId");

                if (Validator.isNotNull(folderIdString)) {
                    long folderId = GetterUtil.getLong(folderIdString);
                    String name = MapUtil.getString(map, "name");

                    String groupIdString = MapUtil.getString(map, "groupId");

                    long groupId = GetterUtil.getLong(groupIdString);

                    if (groupIdString.equals("@group_id@")) {
                        groupId = portletDataContext.getScopeGroupId();
                    }

                    fileEntry = DLAppLocalServiceUtil.getFileEntry(groupId, folderId, name);
                }
            }

            if (fileEntry == null) {
                beginPos--;

                continue;
            }

            DLPortletDataHandlerImpl.exportFileEntry(portletDataContext, dlFileEntryTypesElement,
                    dlFoldersElement, dlFileEntriesElement, dlFileRanksElement, dlRepositoriesElement,
                    dlRepositoryEntriesElement, fileEntry, checkDateRange);

            Element dlReferenceElement = entityElement.addElement("dl-reference");

            dlReferenceElement.addAttribute("default-repository",
                    String.valueOf(fileEntry.isDefaultRepository()));

            String path = null;

            if (fileEntry.isDefaultRepository()) {
                path = DLPortletDataHandlerImpl.getFileEntryPath(portletDataContext, fileEntry);

            } else {
                path = DLPortletDataHandlerImpl.getRepositoryEntryPath(portletDataContext,
                        fileEntry.getFileEntryId());
            }

            dlReferenceElement.addAttribute("path", path);

            String dlReference = "[$dl-reference=" + path + "$]";

            sb.replace(beginPos, endPos, dlReference);
        } catch (Exception e) {
            if (_log.isDebugEnabled()) {
                _log.debug(e, e);
            } else if (_log.isWarnEnabled()) {
                _log.warn(e.getMessage());
            }
        }

        beginPos--;
    }

    return sb.toString();
}

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  w w  . j  av a2s . 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);

        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;//  ww w .  j  a  v  a  2s . co 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 = ImageLocalServiceUtil.getImage(imageId);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e, e);
            }
        }
    }

    return image;
}

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

License:Open Source License

protected void assertUrlGeneratesParameters(String url, String queryString) {

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

    Map<String, String> generatedParameters = new HashMap<String, String>();

    _routerImpl.urlToParameters(url, generatedParameters);

    assertEquals(parameters, generatedParameters);
}

From source file:com.liferay.taglib.util.VelocityTaglib.java

License:Open Source License

public void actionURL(String windowState, String portletMode, Boolean secure,
        Boolean copyCurrentRenderParameters, Boolean escapeXml, String name, long plid, long refererPlid,
        String portletName, Boolean anchor, Boolean encrypt, long doAsGroupId, long doAsUserId,
        Boolean portletConfiguration, String queryString) throws Exception {

    String var = null;
    String varImpl = null;//from  ww w .j  a v a 2  s.  c om
    String resourceID = null;
    String cacheability = null;
    Map<String, String[]> params = HttpUtil.parameterMapFromString(queryString);

    ActionURLTag.doTag(PortletRequest.ACTION_PHASE, windowState, portletMode, var, varImpl, secure,
            copyCurrentRenderParameters, escapeXml, name, resourceID, cacheability, plid, refererPlid,
            portletName, anchor, encrypt, doAsGroupId, doAsUserId, portletConfiguration, params, _pageContext);
}

From source file:com.liferay.taglib.util.VelocityTaglib.java

License:Open Source License

public void renderURL(String windowState, String portletMode, Boolean secure,
        Boolean copyCurrentRenderParameters, Boolean escapeXml, long plid, long refererPlid, String portletName,
        Boolean anchor, Boolean encrypt, long doAsGroupId, long doAsUserId, Boolean portletConfiguration,
        String queryString) throws Exception {

    String var = null;
    String varImpl = null;//from   w  w w . j a  v a2 s  . c  o m
    String name = null;
    String resourceID = null;
    String cacheability = null;
    Map<String, String[]> params = HttpUtil.parameterMapFromString(queryString);

    ActionURLTag.doTag(PortletRequest.RENDER_PHASE, windowState, portletMode, var, varImpl, secure,
            copyCurrentRenderParameters, escapeXml, name, resourceID, cacheability, plid, refererPlid,
            portletName, anchor, encrypt, doAsGroupId, doAsUserId, portletConfiguration, params, _pageContext);
}

From source file:com.liferay.wsrp.bind.MarkupServiceImpl.java

License:Open Source License

protected String getPortletId(PortletContext portletContext, NavigationalContext navigationalContext)
        throws Exception {

    String portletId = getPortletId(portletContext);

    if (navigationalContext != null) {
        String opaqueValue = navigationalContext.getOpaqueValue();

        Map<String, String[]> parameterMap = HttpUtil.parameterMapFromString(opaqueValue);

        if (parameterMap.containsKey(_STRUTS_ACTION_PORTLET_CONFIGURATION)) {

            portletId = PortletKeys.PORTLET_CONFIGURATION;
        }//from  w ww .jav  a 2s .c o m
    }

    return portletId;
}