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.struts;
022:
023: import com.liferay.portal.kernel.util.StringPool;
024: import com.liferay.portal.model.Portlet;
025: import com.liferay.portlet.ActionResponseImpl;
026: import com.liferay.portlet.PortletURLImplWrapper;
027: import com.liferay.portlet.RenderResponseImpl;
028:
029: import java.util.Iterator;
030: import java.util.Map;
031:
032: /**
033: * <a href="StrutsActionPortletURL.java.html"><b><i>View Source</i></b></a>
034: *
035: * @author Brian Wing Shun Chan
036: *
037: */
038: public class StrutsActionPortletURL extends PortletURLImplWrapper {
039:
040: public StrutsActionPortletURL(ActionResponseImpl res, boolean action) {
041: super (res, action);
042:
043: _portlet = res.getPortlet();
044: _strutsPath = StringPool.SLASH + _portlet.getStrutsPath()
045: + StringPool.SLASH;
046: }
047:
048: public StrutsActionPortletURL(RenderResponseImpl res, boolean action) {
049: super (res, action);
050:
051: _portlet = res.getPortlet();
052: _strutsPath = StringPool.SLASH + _portlet.getStrutsPath()
053: + StringPool.SLASH;
054: }
055:
056: public void setParameter(String name, String value) {
057: if (name.equals("struts_action")) {
058: if (!value.startsWith(_strutsPath)) {
059: int pos = value.lastIndexOf(StringPool.SLASH);
060:
061: value = _strutsPath
062: + value.substring(pos + 1, value.length());
063: }
064: }
065:
066: super .setParameter(name, value);
067: }
068:
069: public void setParameters(Map params) {
070: Iterator itr = params.entrySet().iterator();
071:
072: while (itr.hasNext()) {
073: Map.Entry entry = (Map.Entry) itr.next();
074:
075: String name = (String) entry.getKey();
076: String[] values = (String[]) entry.getValue();
077:
078: if (name.equals("struts_action")) {
079: for (int i = 0; i < values.length; i++) {
080: String value = values[i];
081:
082: if (!value.startsWith(_strutsPath)) {
083: int pos = value.lastIndexOf(StringPool.SLASH);
084:
085: value = _strutsPath
086: + value.substring(pos + 1, value
087: .length());
088:
089: values[i] = value;
090: }
091: }
092: }
093: }
094:
095: super .setParameters(params);
096: }
097:
098: private Portlet _portlet;
099: private String _strutsPath;
100:
101: }
|