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 IconListTag 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-list:icon-count");
45
46 Boolean singleIcon = (Boolean)request.getAttribute(
47 "liferay-ui:icon-list: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-list: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-list:icon-count");
71
72 request.removeAttribute("liferay-ui:icon-list:icon-count");
73
74 Boolean singleIcon = (Boolean)request.getAttribute(
75 "liferay-ui:icon-list:single-icon");
76
77 request.removeAttribute("liferay-ui:icon-list: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-list:showWhenSingleIcon");
94
95 return EVAL_PAGE;
96 }
97 catch (Exception e) {
98 throw new JspException(e);
99 }
100 finally {
101 if (!ServerDetector.isResin()) {
102 _bodyContentString = StringPool.BLANK;
103 _endPage = null;
104 _showWhenSingleIcon = false;
105 _startPage = null;
106 }
107 }
108 }
109
110 public int doStartTag() {
111 HttpServletRequest request =
112 (HttpServletRequest)pageContext.getRequest();
113
114 request.setAttribute(
115 "liferay-ui:icon-list:icon-count", new IntegerWrapper());
116 request.setAttribute(
117 "liferay-ui:icon-list:showWhenSingleIcon",
118 String.valueOf(_showWhenSingleIcon));
119
120 return EVAL_BODY_BUFFERED;
121 }
122
123 public String getEndPage() {
124 if (Validator.isNull(_endPage)) {
125 return _END_PAGE;
126 }
127 else {
128 return _endPage;
129 }
130 }
131
132 public String getStartPage() {
133 if (Validator.isNull(_startPage)) {
134 return _START_PAGE;
135 }
136 else {
137 return _startPage;
138 }
139 }
140
141 public void setEndPage(String endPage) {
142 _endPage = endPage;
143 }
144
145 public void setShowWhenSingleIcon(boolean showWhenSingleIcon) {
146 _showWhenSingleIcon = showWhenSingleIcon;
147 }
148
149 public void setStartPage(String startPage) {
150 _startPage = startPage;
151 }
152
153 private static final String _END_PAGE = "/html/taglib/ui/icon_list/end.jsp";
154
155 private static final String _START_PAGE =
156 "/html/taglib/ui/icon_list/start.jsp";
157
158 private String _bodyContentString = StringPool.BLANK;
159 private String _endPage;
160 private boolean _showWhenSingleIcon = false;
161 private String _startPage;
162
163 }