Example usage for com.liferay.portal.kernel.util StringPool AMPERSAND_ENCODED

List of usage examples for com.liferay.portal.kernel.util StringPool AMPERSAND_ENCODED

Introduction

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

Prototype

String AMPERSAND_ENCODED

To view the source code for com.liferay.portal.kernel.util StringPool AMPERSAND_ENCODED.

Click Source Link

Usage

From source file:com.liferay.portlet.journal.lar.JournalPortletDataHandlerImpl.java

License:Open Source License

public static String exportReferencedContent(PortletDataContext portletDataContext,
        Element dlFileEntryTypesElement, Element dlFoldersElement, Element dlFileEntriesElement,
        Element dlFileRanksElement, Element dlRepositoriesElement, Element dlRepositoryEntriesElement,
        Element entityElement, String content) throws Exception {

    content = exportDLFileEntries(portletDataContext, dlFileEntryTypesElement, dlFoldersElement,
            dlFileEntriesElement, dlFileRanksElement, dlRepositoriesElement, dlRepositoryEntriesElement,
            entityElement, content, false);
    content = exportLayoutFriendlyURLs(portletDataContext, content);
    content = exportLinksToLayout(portletDataContext, content);

    String entityElementName = entityElement.getName();

    if (!entityElementName.equals("article")) {
        content = StringUtil.replace(content, StringPool.AMPERSAND_ENCODED, StringPool.AMPERSAND);
    }//from  ww  w .  j av a2  s .c  o  m

    return content;
}

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();/* w  w w .j av  a2 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();
}