001
014
015 package com.liferay.taglib.ui;
016
017 import com.liferay.portal.kernel.bean.BeanPropertiesUtil;
018 import com.liferay.portal.kernel.dao.search.ResultRow;
019 import com.liferay.portal.kernel.dao.search.SearchEntry;
020 import com.liferay.portal.kernel.language.LanguageUtil;
021 import com.liferay.portal.kernel.util.ServerDetector;
022 import com.liferay.portal.kernel.util.StringBundler;
023 import com.liferay.portal.kernel.util.Validator;
024 import com.liferay.taglib.search.TextSearchEntry;
025
026 import java.util.List;
027 import java.util.Map;
028
029 import javax.portlet.PortletURL;
030
031 import javax.servlet.jsp.JspException;
032 import javax.servlet.jsp.JspTagException;
033 import javax.servlet.jsp.tagext.BodyContent;
034 import javax.servlet.jsp.tagext.BodyTag;
035
036
039 public class SearchContainerColumnTextTag<R>
040 extends SearchContainerColumnTag implements BodyTag {
041
042 @Override
043 public int doEndTag() {
044 try {
045 SearchContainerRowTag<R> searchContainerRowTag =
046 (SearchContainerRowTag<R>)findAncestorWithClass(
047 this, SearchContainerRowTag.class);
048
049 ResultRow resultRow = searchContainerRowTag.getRow();
050
051 if (Validator.isNotNull(_property)) {
052 _value = String.valueOf(
053 BeanPropertiesUtil.getObject(
054 resultRow.getObject(), _property));
055 }
056 else if (Validator.isNotNull(_buffer)) {
057 _value = _sb.toString();
058 }
059 else if (_value == null) {
060 BodyContent bodyContent = getBodyContent();
061
062 if (bodyContent != null) {
063 _value = bodyContent.getString();
064 }
065 else {
066 Object object = BeanPropertiesUtil.getObject(
067 resultRow.getObject(), getName());
068
069 _value = String.valueOf(object);
070 }
071 }
072
073 if (_translate) {
074 _value = LanguageUtil.get(request, _value);
075 }
076
077 if (index <= -1) {
078 List<SearchEntry> searchEntries = resultRow.getEntries();
079
080 index = searchEntries.size();
081 }
082
083 if (resultRow.isRestricted()) {
084 _href = null;
085 }
086
087 TextSearchEntry textSearchEntry = new TextSearchEntry();
088
089 textSearchEntry.setAlign(getAlign());
090 textSearchEntry.setColspan(getColspan());
091 textSearchEntry.setCssClass(getCssClass());
092 textSearchEntry.setHref(String.valueOf(getHref()));
093 textSearchEntry.setName(getValue());
094 textSearchEntry.setTarget(getTarget());
095 textSearchEntry.setTitle(getTitle());
096 textSearchEntry.setTruncate(getTruncate());
097 textSearchEntry.setValign(getValign());
098
099 resultRow.addSearchEntry(index, textSearchEntry);
100
101 return EVAL_PAGE;
102 }
103 finally {
104 index = -1;
105 _value = null;
106
107 if (!ServerDetector.isResin()) {
108 align = SearchEntry.DEFAULT_ALIGN;
109 _buffer = null;
110 colspan = SearchEntry.DEFAULT_COLSPAN;
111 cssClass = SearchEntry.DEFAULT_CSS_CLASS;
112 _href = null;
113 name = null;
114 _orderable = false;
115 _orderableProperty = null;
116 _property = null;
117 _sb = null;
118 _target = null;
119 _title = null;
120 _translate = false;
121 valign = SearchEntry.DEFAULT_VALIGN;
122 }
123 }
124 }
125
126 @Override
127 public int doStartTag() throws JspException {
128 if (_orderable && Validator.isNull(_orderableProperty)) {
129 _orderableProperty = name;
130 }
131
132 SearchContainerRowTag<R> searchContainerRowTag =
133 (SearchContainerRowTag<R>)findAncestorWithClass(
134 this, SearchContainerRowTag.class);
135
136 if (searchContainerRowTag == null) {
137 throw new JspTagException(
138 "Requires liferay-ui:search-container-row");
139 }
140
141 if (!searchContainerRowTag.isHeaderNamesAssigned()) {
142 List<String> headerNames = searchContainerRowTag.getHeaderNames();
143
144 String name = getName();
145
146 if (Validator.isNull(name) && Validator.isNotNull(_property)) {
147 name = _property;
148 }
149
150 headerNames.add(name);
151
152 if (_orderable) {
153 Map<String, String> orderableHeaders =
154 searchContainerRowTag.getOrderableHeaders();
155
156 if (Validator.isNotNull(_orderableProperty)) {
157 orderableHeaders.put(name, _orderableProperty);
158 }
159 else if (Validator.isNotNull(_property)) {
160 orderableHeaders.put(name, _property);
161 }
162 else if (Validator.isNotNull(name)) {
163 orderableHeaders.put(name, name);
164 }
165 }
166 }
167
168 if (Validator.isNotNull(_property)) {
169 return SKIP_BODY;
170 }
171 else if (Validator.isNotNull(_buffer)) {
172 _sb = new StringBundler();
173
174 pageContext.setAttribute(_buffer, _sb);
175
176 return EVAL_BODY_INCLUDE;
177 }
178 else if (Validator.isNull(_value)) {
179 return EVAL_BODY_BUFFERED;
180 }
181 else {
182 return SKIP_BODY;
183 }
184 }
185
186 public String getBuffer() {
187 return _buffer;
188 }
189
190 public Object getHref() {
191 if (_href instanceof PortletURL) {
192 _href = _href.toString();
193 }
194
195 return _href;
196 }
197
198 public String getOrderableProperty() {
199 return _orderableProperty;
200 }
201
202 public String getProperty() {
203 return _property;
204 }
205
206 public String getTarget() {
207 return _target;
208 }
209
210 public String getTitle() {
211 return _title;
212 }
213
214 public String getValue() {
215 return _value;
216 }
217
218 public boolean isOrderable() {
219 return _orderable;
220 }
221
222 public void setBuffer(String buffer) {
223 _buffer = buffer;
224 }
225
226 public void setHref(Object href) {
227 _href = href;
228 }
229
230 public void setOrderable(boolean orderable) {
231 _orderable = orderable;
232 }
233
234 public void setOrderableProperty(String orderableProperty) {
235 _orderableProperty = orderableProperty;
236 }
237
238 public void setProperty(String property) {
239 _property = property;
240 }
241
242 public void setTarget(String target) {
243 _target = target;
244 }
245
246 public void setTitle(String title) {
247 _title = title;
248 }
249
250 public void setTranslate(boolean translate) {
251 _translate = translate;
252 }
253
254 public void setValue(String value) {
255 _value = value;
256 }
257
258 private String _buffer;
259 private Object _href;
260 private boolean _orderable;
261 private String _orderableProperty;
262 private String _property;
263 private StringBundler _sb;
264 private String _target;
265 private String _title;
266 private boolean _translate;
267 private String _value;
268
269 }