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