1
22
23 package com.liferay.taglib.ui;
24
25 import com.liferay.portal.kernel.bean.BeanPropertiesUtil;
26 import com.liferay.portal.kernel.dao.search.ResultRow;
27 import com.liferay.portal.kernel.dao.search.SearchEntry;
28 import com.liferay.portal.kernel.dao.search.TextSearchEntry;
29 import com.liferay.portal.kernel.language.LanguageUtil;
30 import com.liferay.portal.kernel.util.ServerDetector;
31 import com.liferay.portal.kernel.util.Validator;
32
33 import java.util.List;
34 import java.util.Map;
35
36 import javax.portlet.PortletURL;
37
38 import javax.servlet.jsp.JspException;
39 import javax.servlet.jsp.JspTagException;
40 import javax.servlet.jsp.tagext.BodyContent;
41
42
48 public class SearchContainerColumnTextTag extends SearchContainerColumnTag {
49
50 public int doAfterBody() {
51 return SKIP_BODY;
52 }
53
54 public int doEndTag() {
55 try {
56 SearchContainerRowTag parentTag =
57 (SearchContainerRowTag)findAncestorWithClass(
58 this, SearchContainerRowTag.class);
59
60 ResultRow row = parentTag.getRow();
61
62 if (Validator.isNotNull(_property)) {
63 _value = String.valueOf(
64 BeanPropertiesUtil.getObject(row.getObject(), _property));
65 }
66 else if (Validator.isNotNull(_buffer)) {
67 _value = _sb.toString();
68 }
69 else if (_value == null) {
70 BodyContent bodyContent = getBodyContent();
71
72 if (bodyContent != null) {
73 _value = bodyContent.getString();
74 }
75 }
76
77 if (_translate) {
78 _value = LanguageUtil.get(pageContext, _value);
79 }
80
81 if (index <= -1) {
82 index = row.getEntries().size();
83 }
84
85 if (row.isRestricted()) {
86 _href = null;
87 }
88
89 row.addText(
90 index,
91 new TextSearchEntry(
92 getAlign(), getValign(), getColspan(), getValue(),
93 (String)getHref(), getTarget(), getTitle()));
94
95 return EVAL_PAGE;
96 }
97 finally {
98 if (!ServerDetector.isResin()) {
99 align = SearchEntry.DEFAULT_ALIGN;
100 _buffer = null;
101 colspan = SearchEntry.DEFAULT_COLSPAN;
102 _href = null;
103 index = -1;
104 name = null;
105 _orderable = false;
106 _orderableProperty = null;
107 _property = null;
108 _target = null;
109 _title = null;
110 _translate = false;
111 valign = SearchEntry.DEFAULT_VALIGN;
112 _value = null;
113 }
114 }
115 }
116
117 public int doStartTag() throws JspException {
118 if (_orderable && Validator.isNull(_orderableProperty)) {
119 _orderableProperty = name;
120 }
121
122 SearchContainerRowTag parentRowTag = (SearchContainerRowTag)
123 findAncestorWithClass(this, SearchContainerRowTag.class);
124
125 if (parentRowTag == null) {
126 throw new JspTagException(
127 "Requires liferay-ui:search-container-row");
128 }
129
130 if (!parentRowTag.isHeaderNamesAssigned()) {
131 List<String> headerNames = parentRowTag.getHeaderNames();
132
133 String name = getName();
134
135 if (Validator.isNull(name) && Validator.isNotNull(_property)) {
136 name = _property;
137 }
138
139 headerNames.add(name);
140
141 if (_orderable) {
142 Map<String,String> orderableHeaders =
143 parentRowTag.getOrderableHeaders();
144
145 if (Validator.isNotNull(_orderableProperty)) {
146 orderableHeaders.put(name, _orderableProperty);
147 }
148 else if (Validator.isNotNull(_property)) {
149 orderableHeaders.put(name, _property);
150 }
151 else if (Validator.isNotNull(name)) {
152 orderableHeaders.put(name, name);
153 }
154 }
155 }
156
157 if (Validator.isNotNull(_property)) {
158 return SKIP_BODY;
159 }
160 else if (Validator.isNotNull(_buffer)) {
161 _sb = new StringBuilder();
162
163 pageContext.setAttribute(_buffer, _sb);
164
165 return EVAL_BODY_INCLUDE;
166 }
167 else if (Validator.isNull(_value)) {
168 return EVAL_BODY_BUFFERED;
169 }
170 else {
171 return SKIP_BODY;
172 }
173 }
174
175 public String getBuffer() {
176 return _buffer;
177 }
178
179 public Object getHref() {
180 if (Validator.isNotNull(_href) && (_href instanceof PortletURL)) {
181 _href = _href.toString();
182 }
183
184 return _href;
185 }
186
187 public String getOrderableProperty() {
188 return _orderableProperty;
189 }
190
191 public String getProperty() {
192 return _property;
193 }
194
195 public String getTarget() {
196 return _target;
197 }
198
199 public String getTitle() {
200 return _title;
201 }
202
203 public String getValue() {
204 return _value;
205 }
206
207 public boolean isOrderable() {
208 return _orderable;
209 }
210
211 public void setBuffer(String buffer) {
212 _buffer = buffer;
213 }
214
215 public void setHref(Object href) {
216 _href = href;
217 }
218
219 public void setOrderable(boolean orderable) {
220 _orderable = orderable;
221 }
222
223 public void setOrderableProperty(String orderableProperty) {
224 _orderableProperty = orderableProperty;
225 }
226
227 public void setProperty(String property) {
228 _property = property;
229 }
230
231 public void setTarget(String target) {
232 _target = target;
233 }
234
235 public void setTitle(String title) {
236 _title = title;
237 }
238
239 public void setTranslate(boolean translate) {
240 _translate = translate;
241 }
242
243 public void setValue(String value) {
244 _value = value;
245 }
246
247 private String _buffer;
248 private Object _href;
249 private boolean _orderable;
250 private String _orderableProperty;
251 private String _property;
252 private StringBuilder _sb;
253 private String _target;
254 private String _title;
255 private boolean _translate;
256 private String _value;
257
258 }