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