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.portal.wsrp;
022:
023: import com.liferay.portal.kernel.util.StringPool;
024: import com.liferay.portal.util.PortalUtil;
025: import com.liferay.portal.wsrp.util.WSRPUtil;
026: import com.liferay.portlet.ActionRequestImpl;
027: import com.liferay.portlet.PortletURLImpl;
028: import com.liferay.portlet.RenderRequestImpl;
029:
030: import java.util.HashMap;
031: import java.util.Iterator;
032: import java.util.Map;
033:
034: import javax.portlet.PortletMode;
035: import javax.portlet.WindowState;
036:
037: import oasis.names.tc.wsrp.v1.types.GetMarkup;
038: import oasis.names.tc.wsrp.v1.types.PerformBlockingInteraction;
039: import oasis.names.tc.wsrp.v1.types.PortletContext;
040: import oasis.names.tc.wsrp.v1.types.RuntimeContext;
041: import oasis.names.tc.wsrp.v1.types.UserContext;
042:
043: import org.apache.wsrp4j.producer.provider.Provider;
044: import org.apache.wsrp4j.producer.provider.URLComposer;
045: import org.apache.wsrp4j.producer.util.Base64;
046: import org.apache.wsrp4j.producer.util.ObjectSerializer;
047:
048: /**
049: * <a href="WSRPPortletURLImpl.java.html"><b><i>View Source</i></b></a>
050: *
051: * @author Michael Young
052: *
053: */
054: public class WSRPPortletURLImpl extends PortletURLImpl {
055:
056: public WSRPPortletURLImpl(PerformBlockingInteraction pbo,
057: Provider wsrpProvider, ActionRequestImpl req,
058: String portletName, long plid, boolean action) {
059:
060: super (req, portletName, plid, action);
061:
062: _init(pbo, wsrpProvider);
063: }
064:
065: public WSRPPortletURLImpl(GetMarkup getMarkup,
066: Provider wsrpProvider, RenderRequestImpl req,
067: String portletName, long plid, boolean action) {
068:
069: super (req, portletName, plid, action);
070:
071: _init(getMarkup, wsrpProvider);
072: }
073:
074: public String toString() {
075: PortletMode portletMode = getPortletMode();
076: WindowState windowState = getWindowState();
077: boolean action = isAction();
078: boolean secure = isSecure();
079:
080: if (portletMode == null) {
081: portletMode = PortletMode.VIEW;
082: }
083:
084: if (windowState == null) {
085: windowState = WindowState.NORMAL;
086: }
087:
088: URLComposer urlComposer = _wsrpProvider.getURLComposer();
089: String encodedParams = _getEncodedParameters();
090: String url = StringPool.BLANK;
091:
092: if (action) {
093: url = urlComposer.createBlockingActionURL(WSRPUtil
094: .toWsrpMode(portletMode.toString()), null,
095: encodedParams, WSRPUtil
096: .toWsrpWindowState(windowState.toString()),
097: secure, _runtimeContext, _portletContext,
098: _userContext);
099: } else {
100: url = urlComposer.createRenderURL(WSRPUtil
101: .toWsrpMode(portletMode.toString()), encodedParams,
102: WSRPUtil.toWsrpWindowState(windowState.toString()),
103: secure, _runtimeContext, _portletContext,
104: _userContext);
105: }
106: return url;
107: }
108:
109: private void _init(GetMarkup getMarkup, Provider wsrpProvider) {
110: _runtimeContext = getMarkup.getRuntimeContext();
111: _portletContext = getMarkup.getPortletContext();
112: _userContext = getMarkup.getUserContext();
113: _wsrpProvider = wsrpProvider;
114: }
115:
116: private void _init(PerformBlockingInteraction pbo,
117: Provider wsrpProvider) {
118: _runtimeContext = pbo.getRuntimeContext();
119: _portletContext = pbo.getPortletContext();
120: _userContext = pbo.getUserContext();
121: _wsrpProvider = wsrpProvider;
122: }
123:
124: private String _getEncodedParameters() {
125: Map renderParams = getParameterMap();
126: Map params = new HashMap();
127:
128: String[] plid = { String.valueOf(getPlid()) };
129: params.put("p_l_id", plid);
130:
131: String[] portletId = { getPortletId() };
132: params.put("p_p_id", portletId);
133:
134: String[] action = { isAction() ? "1" : "0" };
135: params.put("p_p_action", action);
136:
137: WindowState windowState = getWindowState();
138: if (getWindowState() != null) {
139: String[] stateStr = { windowState.toString() };
140: params.put("p_p_state", stateStr);
141: }
142:
143: PortletMode portletMode = getPortletMode();
144: if (getPortletMode() != null) {
145: String[] modeStr = { portletMode.toString() };
146: params.put("p_p_mode", modeStr);
147: }
148:
149: Iterator itr = renderParams.entrySet().iterator();
150:
151: while (itr.hasNext()) {
152: Map.Entry entry = (Map.Entry) itr.next();
153:
154: String name = PortalUtil.getPortletNamespace(portletId[0])
155: + (String) entry.getKey();
156: String[] values = (String[]) entry.getValue();
157:
158: for (int i = 0; i < values.length; i++) {
159: params.put(name, values);
160: }
161: }
162:
163: String encodedParams = null;
164:
165: try {
166: encodedParams = Base64.encode(ObjectSerializer
167: .serialize(params));
168: } catch (Exception e) {
169: }
170:
171: return encodedParams;
172: }
173:
174: private RuntimeContext _runtimeContext;
175: private PortletContext _portletContext;
176: private UserContext _userContext;
177: private Provider _wsrpProvider;
178:
179: }
|