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 IconListTag 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-list:icon-count");
53
54 Boolean singleIcon = (Boolean)request.getAttribute(
55 "liferay-ui:icon-list: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-list: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-list:icon-count");
79
80 request.removeAttribute("liferay-ui:icon-list:icon-count");
81
82 Boolean singleIcon = (Boolean)request.getAttribute(
83 "liferay-ui:icon-list:single-icon");
84
85 request.removeAttribute("liferay-ui:icon-list: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-list:showWhenSingleIcon");
102
103 return EVAL_PAGE;
104 }
105 catch (Exception e) {
106 throw new JspException(e);
107 }
108 finally {
109 if (!ServerDetector.isResin()) {
110 _bodyContentString = StringPool.BLANK;
111 _endPage = null;
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(
123 "liferay-ui:icon-list:icon-count", new IntegerWrapper());
124 request.setAttribute(
125 "liferay-ui:icon-list:showWhenSingleIcon",
126 String.valueOf(_showWhenSingleIcon));
127
128 return EVAL_BODY_BUFFERED;
129 }
130
131 public String getEndPage() {
132 if (Validator.isNull(_endPage)) {
133 return _END_PAGE;
134 }
135 else {
136 return _endPage;
137 }
138 }
139
140 public String getStartPage() {
141 if (Validator.isNull(_startPage)) {
142 return _START_PAGE;
143 }
144 else {
145 return _startPage;
146 }
147 }
148
149 public void setEndPage(String endPage) {
150 _endPage = endPage;
151 }
152
153 public void setShowWhenSingleIcon(boolean showWhenSingleIcon) {
154 _showWhenSingleIcon = showWhenSingleIcon;
155 }
156
157 public void setStartPage(String startPage) {
158 _startPage = startPage;
159 }
160
161 private static final String _END_PAGE = "/html/taglib/ui/icon_list/end.jsp";
162
163 private static final String _START_PAGE =
164 "/html/taglib/ui/icon_list/start.jsp";
165
166 private String _bodyContentString = StringPool.BLANK;
167 private String _endPage;
168 private boolean _showWhenSingleIcon = false;
169 private String _startPage;
170
171 }