List of usage examples for com.liferay.portal.kernel.util HttpUtil decodeURL
public static String decodeURL(String url)
From source file:com.liferay.documentlibrary.hook.filter.DLRecordFilter.java
License:Open Source License
/** * Get FileEntry object by passing document download URL in array. * User will not have permission to download document then it will throw Principal Exception * @param pathArray/*w ww . jav a 2 s . com*/ * @return * @throws Exception */ protected FileEntry getFileEntry(String[] pathArray) throws Exception { if (pathArray.length == 1) { long dlFileShortcutId = GetterUtil.getLong(pathArray[0]); DLFileShortcut dlFileShortcut = DLAppServiceUtil.getFileShortcut(dlFileShortcutId); return DLAppServiceUtil.getFileEntry(dlFileShortcut.getToFileEntryId()); } else if (pathArray.length == 2) { long groupId = GetterUtil.getLong(pathArray[0]); return DLAppServiceUtil.getFileEntryByUuidAndGroupId(pathArray[1], groupId); } else if (pathArray.length == 3) { long groupId = GetterUtil.getLong(pathArray[0]); long folderId = GetterUtil.getLong(pathArray[1]); String fileName = HttpUtil.decodeURL(pathArray[2]); if (fileName.contains(StringPool.QUESTION)) { fileName = fileName.substring(0, fileName.indexOf(StringPool.QUESTION)); } return DLAppServiceUtil.getFileEntry(groupId, folderId, fileName); } else { long groupId = GetterUtil.getLong(pathArray[0]); String uuid = pathArray[3]; return DLAppServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId); } }
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;// ww w . jav a 2 s .co 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.internal.upgrade.v1_1_0.UpgradeDocumentLibraryTypeContent.java
License:Open Source License
protected String getUuidByDocumentLibraryURLWithoutUuid(String[] splitURL) throws PortalException { long groupId = GetterUtil.getLong(splitURL[2]); long folderId = GetterUtil.getLong(splitURL[3]); String title = HttpUtil.decodeURL(HtmlUtil.escape(splitURL[4])); try {// w w w . jav a2 s . c o m FileEntry fileEntry = _dlAppLocalService.getFileEntry(groupId, folderId, title); return fileEntry.getUuid(); } catch (PortalException pe) { _log.error("Unable to get file entry with group ID " + groupId + ", folder ID " + folderId + ", and title " + title, pe); throw pe; } }
From source file:com.liferay.journal.internal.util.impl.JournalConverterImpl.java
License:Open Source License
protected String decodeURL(String url) { try {/*from w ww . j ava2 s.co m*/ return HttpUtil.decodeURL(url); } catch (IllegalArgumentException iae) { return url; } }
From source file:com.liferay.journal.web.internal.portlet.JournalPortlet.java
License:Open Source License
protected void sendEditArticleRedirect(ActionRequest actionRequest, ActionResponse actionResponse, JournalArticle article, String oldUrlTitle) throws Exception { String actionName = ParamUtil.getString(actionRequest, ActionRequest.ACTION_NAME); String redirect = ParamUtil.getString(actionRequest, "redirect"); int workflowAction = ParamUtil.getInteger(actionRequest, "workflowAction", WorkflowConstants.ACTION_PUBLISH); String portletId = HttpUtil.getParameter(redirect, "p_p_id", false); String namespace = _portal.getPortletNamespace(portletId); if (Validator.isNotNull(oldUrlTitle)) { String oldRedirectParam = namespace + "redirect"; String oldRedirect = HttpUtil.getParameter(redirect, oldRedirectParam, false); if (Validator.isNotNull(oldRedirect)) { String newRedirect = HttpUtil.decodeURL(oldRedirect); newRedirect = StringUtil.replace(newRedirect, oldUrlTitle, article.getUrlTitle()); newRedirect = StringUtil.replace(newRedirect, oldRedirectParam, "redirect"); redirect = StringUtil.replace(redirect, oldRedirect, newRedirect); }/*from w w w.j av a2 s. c o m*/ } if ((actionName.equals("deleteArticle") || actionName.equals("deleteArticles")) && !ActionUtil.hasArticle(actionRequest)) { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletURL portletURL = PortletURLFactoryUtil.create(actionRequest, themeDisplay.getPpid(), PortletRequest.RENDER_PHASE); redirect = portletURL.toString(); } if ((article != null) && (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) { redirect = getSaveAndContinueRedirect(actionRequest, article, redirect); if (actionName.equals("previewArticle")) { SessionMessages.add(actionRequest, "previewRequested"); hideDefaultSuccessMessage(actionRequest); } } else { WindowState windowState = actionRequest.getWindowState(); if (windowState.equals(LiferayWindowState.POP_UP)) { redirect = _portal.escapeRedirect(redirect); if (Validator.isNotNull(redirect)) { if (actionName.equals("addArticle") && (article != null)) { redirect = HttpUtil.addParameter(redirect, namespace + "className", JournalArticle.class.getName()); redirect = HttpUtil.addParameter(redirect, namespace + "classPK", JournalArticleAssetRenderer.getClassPK(article)); } } } } actionRequest.setAttribute(WebKeys.REDIRECT, redirect); }
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 ava2 s . 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.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. jav a2 s . c o 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.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);/* w w w.j a v a2 s. c om*/ } 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:com.liferay.wsrp.consumer.portlet.ConsumerPortlet.java
License:Open Source License
protected String rewriteURLs(PortletRequest portletRequest, PortletResponse portletResponse, String content) throws Exception { Matcher rewriteMatcher = _rewritePattern.matcher(content); StringBuffer sb = new StringBuffer(); while (rewriteMatcher.find()) { String namespace = rewriteMatcher.group(1); String url = rewriteMatcher.group(2); String extensionURL1 = rewriteMatcher.group(3); String extensionURL2 = rewriteMatcher.group(4); Map<String, String> parameterMap = new HashMap<String, String>(); if (Validator.isNotNull(namespace)) { rewriteMatcher.appendReplacement(sb, portletResponse.getNamespace()); } else if (Validator.isNotNull(url)) { Matcher parameterMatcher = _parameterPattern.matcher(url); while (parameterMatcher.find()) { String name = parameterMatcher.group(1); String value = parameterMatcher.group(2); if (Validator.isNull(value) || value.equals(StringPool.DOUBLE_QUOTE)) { continue; }//w ww . j av a2 s .c o m parameterMap.put(name, HttpUtil.decodeURL(value)); } String rewrittenURL = rewriteURL(portletRequest, portletResponse, parameterMap); rewriteMatcher.appendReplacement(sb, rewrittenURL); } else if (Validator.isNotNull(extensionURL1)) { parameterMap.put("wsrp-urlType", "render"); parameterMap.put("wsrp-windowState", "wsrp:normal"); String rewrittenURL = rewriteURL(portletRequest, portletResponse, parameterMap); String replacement = "location.href = '" + rewrittenURL + "'"; rewriteMatcher.appendReplacement(sb, replacement); } else if (Validator.isNotNull(extensionURL2)) { parameterMap.put("wsrp-urlType", "render"); parameterMap.put("wsrp-windowState", "wsrp:normal"); String rewrittenURL = rewriteURL(portletRequest, portletResponse, parameterMap); String replacement = "href=\"" + rewrittenURL + "\""; rewriteMatcher.appendReplacement(sb, replacement); } } rewriteMatcher.appendTail(sb); return sb.toString(); }
From source file:com.liferay.wsrp.portlet.ConsumerPortlet.java
License:Open Source License
protected String rewriteURLs(PortletResponse portletResponse, String content) throws Exception { Matcher rewriteMatcher = _rewritePattern.matcher(content); StringBuffer sb = new StringBuffer(); while (rewriteMatcher.find()) { String namespace = rewriteMatcher.group(1); String url = rewriteMatcher.group(2); String extensionURL1 = rewriteMatcher.group(3); String extensionURL2 = rewriteMatcher.group(4); String replacement = null; Map<String, String> parameterMap = new HashMap<String, String>(); if (Validator.isNotNull(namespace)) { rewriteMatcher.appendReplacement(sb, portletResponse.getNamespace()); } else if (Validator.isNotNull(url)) { Matcher parameterMatcher = _parameterPattern.matcher(url); while (parameterMatcher.find()) { String name = parameterMatcher.group(1); String value = parameterMatcher.group(2); if (Validator.isNull(value) || value.equals(StringPool.DOUBLE_QUOTE)) { continue; }/*ww w . j a v a 2s . c om*/ parameterMap.put(name, HttpUtil.decodeURL(value)); } rewriteMatcher.appendReplacement(sb, rewriteURL(portletResponse, parameterMap)); } else if (Validator.isNotNull(extensionURL1)) { parameterMap.put("wsrp-urlType", "render"); parameterMap.put("wsrp-windowState", "wsrp:normal"); replacement = "location.href = '" + rewriteURL(portletResponse, parameterMap) + "'"; rewriteMatcher.appendReplacement(sb, replacement); } else if (Validator.isNotNull(extensionURL2)) { parameterMap.put("wsrp-urlType", "render"); parameterMap.put("wsrp-windowState", "wsrp:normal"); replacement = "href=\"" + rewriteURL(portletResponse, parameterMap) + "\""; rewriteMatcher.appendReplacement(sb, replacement); } } rewriteMatcher.appendTail(sb); return sb.toString(); }