Java tutorial
/** * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.portlet.layoutconfiguration.util.xml; import com.liferay.portal.kernel.portlet.LiferayPortletResponse; import com.liferay.portal.kernel.portlet.LiferayPortletURL; import com.liferay.portal.kernel.xml.Document; import com.liferay.portal.kernel.xml.Element; import com.liferay.portal.kernel.xml.SAXReaderUtil; import com.liferay.portal.util.PortalUtil; import javax.portlet.PortletRequest; import javax.portlet.RenderResponse; /** * @author Brian Wing Shun Chan */ /** * Liferay version expects that renderResponse can be cast to RenderResponseImpl but this * fails when it's instance of {@link javax.portlet.filter.RenderResponseWrapper} */ public class ActionURLLogic extends RuntimeLogic { public static final String CLOSE_1_TAG = "</runtime-action-url>"; public static final String CLOSE_2_TAG = "/>"; public static final String OPEN_TAG = "<runtime-action-url"; public ActionURLLogic(RenderResponse renderResponse) { // ======= Start of change ============ _renderResponseImpl = renderResponse; // =======end of change================ } @Override public String getClose1Tag() { return CLOSE_1_TAG; } public String getLifecycle() { return _lifecycle; } @Override public String getOpenTag() { return OPEN_TAG; } @Override public String processXML(String xml) throws Exception { Document doc = SAXReaderUtil.read(xml); Element root = doc.getRootElement(); LiferayPortletResponse liferayPortletResponse = PortalUtil.getLiferayPortletResponse(_renderResponseImpl); LiferayPortletURL liferayPortletURL = liferayPortletResponse.createLiferayPortletURL(getLifecycle()); String portletId = root.attributeValue("portlet-name"); if (portletId != null) { portletId = PortalUtil.getJsSafePortletId(portletId); liferayPortletURL.setPortletId(portletId); } for (int i = 1;; i++) { String paramName = root.attributeValue("param-name-" + i); String paramValue = root.attributeValue("param-value-" + i); if ((paramName == null) || (paramValue == null)) { break; } liferayPortletURL.setParameter(paramName, paramValue); } return liferayPortletURL.toString(); } private String _lifecycle = PortletRequest.ACTION_PHASE; private RenderResponse _renderResponseImpl; }