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