001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet;
022:
023: import com.liferay.portal.kernel.portlet.LiferayPortletURL;
024:
025: import java.util.Enumeration;
026:
027: import javax.portlet.PortletException;
028: import javax.portlet.PortletMode;
029: import javax.portlet.PortletURL;
030: import javax.portlet.RenderRequest;
031: import javax.portlet.RenderResponse;
032: import javax.portlet.WindowState;
033:
034: /**
035: * <a href="PortletURLUtil.java.html"><b><i>View Source</i></b></a>
036: *
037: * @author Brian Wing Shun Chan
038: *
039: */
040: public class PortletURLUtil {
041:
042: public static PortletURL getCurrent(RenderRequest req,
043: RenderResponse res) {
044: PortletURL portletURL = res.createRenderURL();
045:
046: Enumeration enu = req.getParameterNames();
047:
048: while (enu.hasMoreElements()) {
049: String param = (String) enu.nextElement();
050: String[] values = req.getParameterValues(param);
051:
052: boolean addParam = true;
053:
054: // Don't set paramter values that are over 32 kb. See LEP-1755.
055:
056: for (int i = 0; i < values.length; i++) {
057: if (values[i].length() > _CURRENT_URL_PARAMETER_THRESHOLD) {
058: addParam = false;
059:
060: break;
061: }
062: }
063:
064: if (addParam) {
065: portletURL.setParameter(param, values);
066: }
067: }
068:
069: return portletURL;
070: }
071:
072: public static PortletURL clone(PortletURL portletURL,
073: RenderResponse res) throws PortletException {
074:
075: LiferayPortletURL liferayPortletURL = (LiferayPortletURL) portletURL;
076:
077: return clone(liferayPortletURL, liferayPortletURL.isAction(),
078: res);
079: }
080:
081: public static PortletURL clone(PortletURL portletURL,
082: boolean action, RenderResponse res) throws PortletException {
083:
084: LiferayPortletURL liferayPortletURL = (LiferayPortletURL) portletURL;
085:
086: return clone(liferayPortletURL, action, res);
087: }
088:
089: public static PortletURL clone(LiferayPortletURL liferayPortletURL,
090: boolean action, RenderResponse res) throws PortletException {
091:
092: LiferayPortletURL newURLImpl = null;
093:
094: if (action) {
095: newURLImpl = (LiferayPortletURL) res.createActionURL();
096: } else {
097: newURLImpl = (LiferayPortletURL) res.createRenderURL();
098: }
099:
100: newURLImpl.setPortletId(liferayPortletURL.getPortletId());
101:
102: WindowState windowState = liferayPortletURL.getWindowState();
103:
104: if (windowState != null) {
105: newURLImpl.setWindowState(windowState);
106: }
107:
108: PortletMode portletMode = liferayPortletURL.getPortletMode();
109:
110: if (portletMode != null) {
111: newURLImpl.setPortletMode(portletMode);
112: }
113:
114: newURLImpl.setParameters(liferayPortletURL.getParameterMap());
115:
116: return newURLImpl;
117: }
118:
119: private static final int _CURRENT_URL_PARAMETER_THRESHOLD = 32768;
120:
121: }
|