1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.layoutconfiguration.util.xml;
21  
22  import com.liferay.portal.kernel.util.Validator;
23  import com.liferay.portal.kernel.xml.Document;
24  import com.liferay.portal.kernel.xml.Element;
25  import com.liferay.portal.kernel.xml.SAXReaderUtil;
26  import com.liferay.portal.model.PortletConstants;
27  import com.liferay.portlet.layoutconfiguration.util.RuntimePortletUtil;
28  
29  import javax.portlet.RenderRequest;
30  import javax.portlet.RenderResponse;
31  
32  import javax.servlet.ServletContext;
33  import javax.servlet.http.HttpServletRequest;
34  import javax.servlet.http.HttpServletResponse;
35  
36  /**
37   * <a href="PortletLogic.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class PortletLogic extends RuntimeLogic {
43  
44      public static final String OPEN_TAG = "<runtime-portlet";
45  
46      public static final String CLOSE_1_TAG = "</runtime-portlet>";
47  
48      public static final String CLOSE_2_TAG = "/>";
49  
50      public PortletLogic(
51          ServletContext servletContext, HttpServletRequest request,
52          HttpServletResponse response, RenderRequest renderRequest,
53          RenderResponse renderResponse) {
54  
55          _servletContext = servletContext;
56          _request = request;
57          _response = response;
58          _renderRequest = renderRequest;
59          _renderResponse = renderResponse;
60      }
61  
62      public String getOpenTag() {
63          return OPEN_TAG;
64      }
65  
66      public String getClose1Tag() {
67          return CLOSE_1_TAG;
68      }
69  
70      public void processXML(StringBuilder sb, String xml) throws Exception {
71          Document doc = SAXReaderUtil.read(xml);
72  
73          Element root = doc.getRootElement();
74  
75          String rootPortletId = root.attributeValue("name");
76          String instanceId = root.attributeValue("instance");
77          String queryString = root.attributeValue("queryString");
78  
79          String portletId = rootPortletId;
80  
81          if (Validator.isNotNull(instanceId)) {
82              portletId += PortletConstants.INSTANCE_SEPARATOR + instanceId;
83          }
84  
85          RuntimePortletUtil.processPortlet(
86              sb, _servletContext, _request, _response, _renderRequest,
87              _renderResponse, portletId, queryString);
88      }
89  
90      private ServletContext _servletContext;
91      private HttpServletRequest _request;
92      private HttpServletResponse _response;
93      private RenderRequest _renderRequest;
94      private RenderResponse _renderResponse;
95  
96  }