1
14
15 package com.liferay.taglib.aui;
16
17 import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
18 import com.liferay.portal.kernel.util.ServerDetector;
19 import com.liferay.portal.kernel.util.Validator;
20 import com.liferay.taglib.util.IncludeTag;
21 import com.liferay.util.PwdGenerator;
22 import com.liferay.util.TextFormatter;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import javax.servlet.http.HttpServletRequest;
28 import javax.servlet.jsp.JspException;
29
30
36 public class PanelTag extends IncludeTag {
37
38 public void addToolTag(ToolTag toolTag) {
39 if (_toolTags == null) {
40 _toolTags = new ArrayList<ToolTag>();
41 }
42
43 _toolTags.add(toolTag);
44 }
45
46 public int doEndTag() throws JspException {
47 try{
48 HttpServletRequest request =
49 (HttpServletRequest)pageContext.getRequest();
50
51 request.setAttribute(
52 "aui:panel:collapsible", String.valueOf(_collapsible));
53 request.setAttribute("aui:panel:id", _id);
54 request.setAttribute("aui:panel:label", _label);
55 request.setAttribute("aui:panel:toolTags", _toolTags);
56
57 PortalIncludeUtil.include(pageContext, getEndPage());
58
59 return EVAL_PAGE;
60 }
61 catch (Exception e) {
62 throw new JspException(e);
63 }
64 finally {
65 if (!ServerDetector.isResin()) {
66 _collapsible = false;
67 _endPage = null;
68 _id = null;
69 _label = null;
70 _startPage = null;
71 _toolTags = null;
72 }
73 }
74 }
75
76 public int doStartTag() throws JspException {
77 try{
78 HttpServletRequest request =
79 (HttpServletRequest)pageContext.getRequest();
80
81 if (_label == null) {
82 _label = TextFormatter.format(_id, TextFormatter.K);
83 }
84
85 if (Validator.isNull(_id)) {
86 _id = PwdGenerator.getPassword(PwdGenerator.KEY3, 4);
87 }
88
89 request.setAttribute(
90 "aui:panel:collapsible", String.valueOf(_collapsible));
91 request.setAttribute("aui:panel:id", _id);
92 request.setAttribute("aui:panel:label", _label);
93 request.setAttribute("aui:panel:toolTags", _toolTags);
94
95 PortalIncludeUtil.include(pageContext, getStartPage());
96
97 return EVAL_BODY_INCLUDE;
98 }
99 catch (Exception e) {
100 throw new JspException(e);
101 }
102 }
103
104 public String getEndPage() {
105 if (Validator.isNull(_endPage)) {
106 return _END_PAGE;
107 }
108 else {
109 return _endPage;
110 }
111 }
112
113 public String getStartPage() {
114 if (Validator.isNull(_startPage)) {
115 return _START_PAGE;
116 }
117 else {
118 return _startPage;
119 }
120 }
121
122 public List<ToolTag> getToolTags() {
123 return _toolTags;
124 }
125
126 public void setCollapsible(boolean collapsible) {
127 _collapsible = collapsible;
128 }
129
130 public void setEndPage(String endPage) {
131 _endPage = endPage;
132 }
133
134 public void setId(String id) {
135 _id = id;
136 }
137
138 public void setLabel(String label) {
139 _label = label;
140 }
141
142 public void setStartPage(String startPage) {
143 _startPage = startPage;
144 }
145
146 private static final String _END_PAGE = "/html/taglib/aui/panel/end.jsp";
147
148 private static final String _START_PAGE =
149 "/html/taglib/aui/panel/start.jsp";
150
151 private boolean _collapsible;
152 private String _endPage;
153 private String _id;
154 private String _label;
155 private String _startPage;
156 private List<ToolTag> _toolTags;
157
158 }