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