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.PortletURLWrapper;
024: import com.liferay.portal.kernel.util.StringMaker;
025: import com.liferay.portal.kernel.util.StringPool;
026: import com.liferay.portal.kernel.util.Validator;
027: import com.liferay.portal.util.PortalUtil;
028:
029: import java.util.HashMap;
030: import java.util.Iterator;
031: import java.util.List;
032: import java.util.Map;
033:
034: import javax.portlet.PortletURL;
035:
036: import org.springframework.web.util.HtmlUtils;
037:
038: /**
039: * <a href="MultiPortletURL.java.html"><b><i>View Source</i></b></a>
040: *
041: * @author Sergey Ponomarev
042: *
043: */
044: public class MultiPortletURL extends PortletURLWrapper {
045:
046: public MultiPortletURL(PortletURL portletURL) {
047: super (portletURL);
048: }
049:
050: public void addPortletParameters(String portletId, Map parameters) {
051: if (Validator.isNotNull(portletId)) {
052: _portletsParams.put(portletId, parameters);
053: }
054: }
055:
056: public String toString() {
057: String url = super .toString();
058:
059: if (Validator.isNull(url)) {
060: return url;
061: } else {
062: StringMaker sm = new StringMaker(url);
063:
064: if (!url.endsWith(StringPool.AMPERSAND)) {
065: sm.append(StringPool.AMPERSAND);
066: }
067:
068: String suffix = StringPool.BLANK;
069:
070: int pos = url.lastIndexOf(StringPool.POUND);
071:
072: if (pos >= 0) {
073: suffix = url.substring(pos);
074:
075: sm.delete(pos, sm.length());
076: }
077:
078: Iterator itr1 = _portletsParams.keySet().iterator();
079:
080: while (itr1.hasNext()) {
081: String portletId = (String) itr1.next();
082:
083: String namespace = PortalUtil
084: .getPortletNamespace(portletId);
085:
086: Map parameters = (Map) _portletsParams.get(portletId);
087:
088: Iterator itr2 = parameters.keySet().iterator();
089:
090: while (itr2.hasNext()) {
091: String name = (String) itr2.next();
092:
093: List values = (List) parameters.get(name);
094:
095: for (int i = 0; i < values.size(); i++) {
096: String value = (String) values.get(i);
097:
098: sm.append(namespace);
099: sm.append(name);
100: sm.append(StringPool.EQUAL);
101: sm.append(HtmlUtils.htmlEscape(value));
102: sm.append(StringPool.AMPERSAND);
103: }
104: }
105: }
106:
107: return sm.toString() + suffix;
108: }
109: }
110:
111: private Map _portletsParams = new HashMap();
112:
113: }
|