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.StringPool;
28 import com.liferay.portal.kernel.util.Validator;
29
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.jsp.JspException;
32 import javax.servlet.jsp.tagext.BodyContent;
33 import javax.servlet.jsp.tagext.BodyTagSupport;
34
35
41 public class IconListTag extends BodyTagSupport {
42
43 public int doStartTag() {
44 HttpServletRequest request =
45 (HttpServletRequest)pageContext.getRequest();
46
47 request.setAttribute(
48 "liferay-ui:icon-list:icon-count", new IntegerWrapper());
49
50 return EVAL_BODY_BUFFERED;
51 }
52
53 public int doAfterBody() {
54 BodyContent bodyContent = getBodyContent();
55
56 _bodyContentString = bodyContent.getString();
57
58 HttpServletRequest request =
59 (HttpServletRequest)pageContext.getRequest();
60
61 IntegerWrapper iconCount = (IntegerWrapper)request.getAttribute(
62 "liferay-ui:icon-list:icon-count");
63
64 Boolean singleIcon = (Boolean)request.getAttribute(
65 "liferay-ui:icon-list:single-icon");
66
67 if ((iconCount != null) && (iconCount.getValue() == 1) &&
68 (singleIcon == null)) {
69
70 bodyContent.clearBody();
71
72 request.setAttribute(
73 "liferay-ui:icon-list:single-icon", Boolean.TRUE);
74
75 return EVAL_BODY_AGAIN;
76 }
77 else {
78 return SKIP_BODY;
79 }
80 }
81
82 public int doEndTag() throws JspException {
83 try {
84 HttpServletRequest request =
85 (HttpServletRequest)pageContext.getRequest();
86
87 IntegerWrapper iconCount = (IntegerWrapper)request.getAttribute(
88 "liferay-ui:icon-list:icon-count");
89
90 request.removeAttribute("liferay-ui:icon-list:icon-count");
91
92 Boolean singleIcon = (Boolean)request.getAttribute(
93 "liferay-ui:icon-list:single-icon");
94
95 request.removeAttribute("liferay-ui:icon-list:single-icon");
96
97 if ((iconCount != null) && (iconCount.getValue() > 1) &&
98 (singleIcon == null)) {
99
100 PortalIncludeUtil.include(pageContext, getStartPage());
101 }
102
103 pageContext.getOut().print(_bodyContentString);
104
105 if ((iconCount != null) && (iconCount.getValue() > 1) &&
106 (singleIcon == null)) {
107
108 PortalIncludeUtil.include(pageContext, getEndPage());
109 }
110
111 return EVAL_PAGE;
112 }
113 catch (Exception e) {
114 throw new JspException(e);
115 }
116 }
117
118 public String getStartPage() {
119 if (Validator.isNull(_startPage)) {
120 return _START_PAGE;
121 }
122 else {
123 return _startPage;
124 }
125 }
126
127 public void setStartPage(String startPage) {
128 _startPage = startPage;
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 void setEndPage(String endPage) {
141 _endPage = endPage;
142 }
143
144 private static final String _START_PAGE =
145 "/html/taglib/ui/icon_list/start.jsp";
146
147 private static final String _END_PAGE = "/html/taglib/ui/icon_list/end.jsp";
148
149 private String _startPage;
150 private String _endPage;
151 private String _bodyContentString = StringPool.BLANK;
152
153 }