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.DateSearchEntry;
019 import com.liferay.portal.kernel.dao.search.ResultRow;
020 import com.liferay.portal.kernel.dao.search.SearchEntry;
021 import com.liferay.portal.kernel.util.ServerDetector;
022 import com.liferay.portal.kernel.util.Validator;
023
024 import java.util.Date;
025 import java.util.List;
026 import java.util.Map;
027
028 import javax.portlet.PortletURL;
029
030 import javax.servlet.jsp.JspException;
031 import javax.servlet.jsp.JspTagException;
032
033
036 public class SearchContainerColumnDateTag<R> extends SearchContainerColumnTag {
037
038 @Override
039 public int doEndTag() {
040 try {
041 SearchContainerRowTag<R> searchContainerRowTag =
042 (SearchContainerRowTag<R>)findAncestorWithClass(
043 this, SearchContainerRowTag.class);
044
045 ResultRow resultRow = searchContainerRowTag.getRow();
046
047 if (Validator.isNotNull(_property)) {
048 _value = (Date)BeanPropertiesUtil.getObject(
049 resultRow.getObject(), _property);
050 }
051
052 if (index <= -1) {
053 List<SearchEntry> searchEntries = resultRow.getEntries();
054
055 index = searchEntries.size();
056 }
057
058 if (resultRow.isRestricted()) {
059 _href = null;
060 }
061
062 DateSearchEntry dateSearchEntry = new DateSearchEntry();
063
064 dateSearchEntry.setAlign(getAlign());
065 dateSearchEntry.setColspan(getColspan());
066 dateSearchEntry.setCssClass(getCssClass());
067 dateSearchEntry.setDate(_value);
068 dateSearchEntry.setHref((String)getHref());
069 dateSearchEntry.setValign(getValign());
070
071 resultRow.addSearchEntry(index, dateSearchEntry);
072
073 return EVAL_PAGE;
074 }
075 finally {
076 index = -1;
077 _value = null;
078
079 if (!ServerDetector.isResin()) {
080 align = SearchEntry.DEFAULT_ALIGN;
081 colspan = SearchEntry.DEFAULT_COLSPAN;
082 cssClass = SearchEntry.DEFAULT_CSS_CLASS;
083 _href = null;
084 name = null;
085 _orderable = false;
086 _orderableProperty = null;
087 _property = null;
088 valign = SearchEntry.DEFAULT_VALIGN;
089 }
090 }
091 }
092
093 @Override
094 public int doStartTag() throws JspException {
095 if (_orderable && Validator.isNull(_orderableProperty)) {
096 _orderableProperty = name;
097 }
098
099 SearchContainerRowTag<R> searchContainerRowTag =
100 (SearchContainerRowTag<R>)findAncestorWithClass(
101 this, SearchContainerRowTag.class);
102
103 if (searchContainerRowTag == null) {
104 throw new JspTagException(
105 "Requires liferay-ui:search-container-row");
106 }
107
108 if (!searchContainerRowTag.isHeaderNamesAssigned()) {
109 List<String> headerNames = searchContainerRowTag.getHeaderNames();
110
111 String name = getName();
112
113 if (Validator.isNull(name) && Validator.isNotNull(_property)) {
114 name = _property;
115 }
116
117 headerNames.add(name);
118
119 if (_orderable) {
120 Map<String, String> orderableHeaders =
121 searchContainerRowTag.getOrderableHeaders();
122
123 if (Validator.isNotNull(_orderableProperty)) {
124 orderableHeaders.put(name, _orderableProperty);
125 }
126 else if (Validator.isNotNull(_property)) {
127 orderableHeaders.put(name, _property);
128 }
129 else if (Validator.isNotNull(name)) {
130 orderableHeaders.put(name, name);
131 }
132 }
133 }
134
135 return EVAL_BODY_INCLUDE;
136 }
137
138 public Object getHref() {
139 if (Validator.isNotNull(_href) && (_href instanceof PortletURL)) {
140 _href = _href.toString();
141 }
142
143 return _href;
144 }
145
146 public String getOrderableProperty() {
147 return _orderableProperty;
148 }
149
150 public String getProperty() {
151 return _property;
152 }
153
154 public Date getValue() {
155 return _value;
156 }
157
158 public boolean isOrderable() {
159 return _orderable;
160 }
161
162 public void setHref(Object href) {
163 _href = href;
164 }
165
166 public void setOrderable(boolean orderable) {
167 _orderable = orderable;
168 }
169
170 public void setOrderableProperty(String orderableProperty) {
171 _orderableProperty = orderableProperty;
172 }
173
174 public void setProperty(String property) {
175 _property = property;
176 }
177
178 public void setValue(Date value) {
179 _value = value;
180 }
181
182 private Object _href;
183 private boolean _orderable;
184 private String _orderableProperty;
185 private String _property;
186 private Date _value;
187
188 }