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