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.layoutconfiguration.util.xml;
022:
023: import com.liferay.portal.kernel.portlet.LiferayPortletURL;
024: import com.liferay.portal.kernel.util.StringMaker;
025: import com.liferay.portal.util.PortalUtil;
026: import com.liferay.portlet.RenderResponseImpl;
027:
028: import java.io.StringReader;
029:
030: import javax.portlet.RenderResponse;
031:
032: import org.dom4j.Document;
033: import org.dom4j.Element;
034: import org.dom4j.io.SAXReader;
035:
036: /**
037: * <a href="ActionURLLogic.java.html"><b><i>View Source</i></b></a>
038: *
039: * @author Brian Wing Shun Chan
040: *
041: */
042: public class ActionURLLogic extends RuntimeLogic {
043:
044: public static final String OPEN_TAG = "<runtime-action-url";
045:
046: public static final String CLOSE_1_TAG = "</runtime-action-url>";
047:
048: public static final String CLOSE_2_TAG = "/>";
049:
050: public ActionURLLogic(RenderResponse res) {
051: _res = (RenderResponseImpl) res;
052: }
053:
054: public String getOpenTag() {
055: return OPEN_TAG;
056: }
057:
058: public String getClose1Tag() {
059: return CLOSE_1_TAG;
060: }
061:
062: public void processXML(StringMaker sm, String xml) throws Exception {
063: SAXReader reader = new SAXReader();
064:
065: Document doc = reader.read(new StringReader(xml));
066:
067: Element root = doc.getRootElement();
068:
069: LiferayPortletURL portletURL = (LiferayPortletURL) _res
070: .createPortletURL(isAction());
071:
072: String portletId = root.attributeValue("portlet-name");
073:
074: if (portletId != null) {
075: portletId = PortalUtil.getJsSafePortletId(portletId);
076:
077: portletURL.setPortletId(portletId);
078: }
079:
080: for (int i = 1;; i++) {
081: String paramName = root.attributeValue("param-name-" + i);
082: String paramValue = root.attributeValue("param-value-" + i);
083:
084: if ((paramName == null) || (paramValue == null)) {
085: break;
086: }
087:
088: portletURL.setParameter(paramName, paramValue);
089: }
090:
091: sm.append(portletURL.toString());
092: }
093:
094: public boolean isAction() {
095: return _action;
096: }
097:
098: private RenderResponseImpl _res;
099: private boolean _action = false;
100:
101: }
|