1
19
20 package com.liferay.taglib.portletext;
21
22 import com.liferay.portal.kernel.servlet.StringServletResponse;
23 import com.liferay.taglib.util.IncludeTag;
24
25 import java.io.IOException;
26
27 import javax.servlet.RequestDispatcher;
28 import javax.servlet.ServletContext;
29 import javax.servlet.ServletException;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import javax.servlet.jsp.JspException;
33
34
40 public class PreviewTag extends IncludeTag {
41
42 public static void doTag(
43 String portletName, String queryString, String width,
44 ServletContext servletContext, HttpServletRequest request,
45 HttpServletResponse response)
46 throws IOException, ServletException {
47
48 doTag(
49 _PAGE, portletName, queryString, width, servletContext, request,
50 response);
51 }
52
53 public static void doTag(
54 String page, String portletName, String queryString, String width,
55 ServletContext servletContext, HttpServletRequest request,
56 HttpServletResponse response)
57 throws IOException, ServletException {
58
59 request.setAttribute(
60 "liferay-portlet:preview:portletName", portletName);
61 request.setAttribute(
62 "liferay-portlet:preview:queryString", queryString);
63 request.setAttribute("liferay-portlet:preview:width", width);
64
65 RequestDispatcher requestDispatcher =
66 servletContext.getRequestDispatcher(page);
67
68 requestDispatcher.include(request, response);
69 }
70
71 public int doEndTag() throws JspException {
72 try {
73 ServletContext servletContext = getServletContext();
74 HttpServletRequest request = getServletRequest();
75 StringServletResponse response = getServletResponse();
76
77 doTag(
78 getPage(), _portletName, _queryString, _width, servletContext,
79 request, response);
80
81 pageContext.getOut().print(response.getString());
82
83 return EVAL_PAGE;
84 }
85 catch (Exception e) {
86 throw new JspException(e);
87 }
88 }
89
90 public void setPortletName(String portletName) {
91 _portletName = portletName;
92 }
93
94 public void setQueryString(String queryString) {
95 _queryString = queryString;
96 }
97
98 public void setWidth(String width) {
99 _width = width;
100 }
101
102 protected String getDefaultPage() {
103 return _PAGE;
104 }
105
106 private static final String _PAGE = "/html/taglib/portlet/preview/page.jsp";
107
108 private String _portletName;
109 private String _queryString;
110 private String _width;
111
112 }