1
22
23 package com.liferay.taglib.ui;
24
25 import com.liferay.portal.kernel.servlet.PortalIncludeUtil;
26 import com.liferay.portal.kernel.util.IntegerWrapper;
27 import com.liferay.portal.kernel.util.ServerDetector;
28 import com.liferay.portal.kernel.util.StringPool;
29 import com.liferay.portal.kernel.util.Validator;
30
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.jsp.JspException;
33 import javax.servlet.jsp.tagext.BodyContent;
34 import javax.servlet.jsp.tagext.BodyTagSupport;
35
36
41 public class IconMenuTag extends BodyTagSupport {
42
43 public int doAfterBody() {
44 BodyContent bodyContent = getBodyContent();
45
46 _bodyContentString = bodyContent.getString();
47
48 HttpServletRequest request =
49 (HttpServletRequest)pageContext.getRequest();
50
51 IntegerWrapper iconCount = (IntegerWrapper)request.getAttribute(
52 "liferay-ui:icon-menu:icon-count");
53
54 Boolean singleIcon = (Boolean)request.getAttribute(
55 "liferay-ui:icon-menu:single-icon");
56
57 if ((iconCount != null) && (iconCount.getValue() == 1) &&
58 (singleIcon == null)) {
59
60 bodyContent.clearBody();
61
62 request.setAttribute(
63 "liferay-ui:icon-menu:single-icon", Boolean.TRUE);
64
65 return EVAL_BODY_AGAIN;
66 }
67 else {
68 return SKIP_BODY;
69 }
70 }
71
72 public int doEndTag() throws JspException {
73 try {
74 HttpServletRequest request =
75 (HttpServletRequest)pageContext.getRequest();
76
77 IntegerWrapper iconCount = (IntegerWrapper)request.getAttribute(
78 "liferay-ui:icon-menu:icon-count");
79
80 request.removeAttribute("liferay-ui:icon-menu:icon-count");
81
82 Boolean singleIcon = (Boolean)request.getAttribute(
83 "liferay-ui:icon-menu:single-icon");
84
85 request.removeAttribute("liferay-ui:icon-menu:single-icon");
86
87 if ((iconCount != null) && (iconCount.getValue() >= 1) &&
88 ((singleIcon == null) || _showWhenSingleIcon)) {
89
90 PortalIncludeUtil.include(pageContext, getStartPage());
91 }
92
93 pageContext.getOut().print(_bodyContentString);
94
95 if ((iconCount != null) && (iconCount.getValue() >= 1) &&
96 ((singleIcon == null) || _showWhenSingleIcon)) {
97
98 PortalIncludeUtil.include(pageContext, getEndPage());
99 }
100
101 request.removeAttribute("liferay-ui:icon-menu:align");
102 request.removeAttribute("liferay-ui:icon-menu:cssClass");
103 request.removeAttribute("liferay-ui:icon-menu:message");
104 request.removeAttribute("liferay-ui:icon-menu:showExpanded");
105 request.removeAttribute("liferay-ui:icon-menu:showWhenSingleIcon");
106
107 return EVAL_PAGE;
108 }
109 catch (Exception e) {
110 throw new JspException(e);
111 }
112 finally {
113 if (!ServerDetector.isResin()) {
114 _align = "right";
115 _bodyContentString = StringPool.BLANK;
116 _cssClass = null;
117 _endPage = null;
118 _message = "actions";
119 _showExpanded = false;
120 _showWhenSingleIcon = false;
121 _startPage = null;
122 }
123 }
124 }
125
126 public int doStartTag() {
127 HttpServletRequest request =
128 (HttpServletRequest)pageContext.getRequest();
129
130 request.setAttribute("liferay-ui:icon-menu:align", _align);
131 request.setAttribute("liferay-ui:icon-menu:cssClass", _cssClass);
132 request.setAttribute(
133 "liferay-ui:icon-menu:icon-count", new IntegerWrapper());
134 request.setAttribute("liferay-ui:icon-menu:message", _message);
135 request.setAttribute(
136 "liferay-ui:icon-menu:showExpanded",String.valueOf(_showExpanded));
137 request.setAttribute(
138 "liferay-ui:icon-menu:showWhenSingleIcon",
139 String.valueOf(_showWhenSingleIcon));
140
141 return EVAL_BODY_BUFFERED;
142 }
143
144 public String getEndPage() {
145 if (Validator.isNull(_endPage)) {
146 return _END_PAGE;
147 }
148 else {
149 return _endPage;
150 }
151 }
152
153 public String getStartPage() {
154 if (Validator.isNull(_startPage)) {
155 return _START_PAGE;
156 }
157 else {
158 return _startPage;
159 }
160 }
161
162 public void setAlign(String align) {
163 _align = align;
164 }
165
166 public void setCssClass(String cssClass) {
167 _cssClass = cssClass;
168 }
169
170 public void setEndPage(String endPage) {
171 _endPage = endPage;
172 }
173
174 public void setMessage(String message) {
175 _message = message;
176 }
177
178 public void setShowExpanded(boolean showExpanded) {
179 _showExpanded = showExpanded;
180 }
181
182 public void setShowWhenSingleIcon(boolean showWhenSingleIcon) {
183 _showWhenSingleIcon = showWhenSingleIcon;
184 }
185
186 public void setStartPage(String startPage) {
187 _startPage = startPage;
188 }
189
190 private static final String _END_PAGE = "/html/taglib/ui/icon_menu/end.jsp";
191
192 private static final String _START_PAGE =
193 "/html/taglib/ui/icon_menu/start.jsp";
194
195 private String _align = "right";
196 private String _bodyContentString = StringPool.BLANK;
197 private String _cssClass;
198 private String _endPage;
199 private String _message = "actions";
200 private boolean _showExpanded;
201 private boolean _showWhenSingleIcon;
202 private String _startPage;
203
204 }