1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.taglib.ui;
16  
17  import com.liferay.portal.kernel.dao.search.ResultRow;
18  import com.liferay.portal.kernel.dao.search.SearchEntry;
19  import com.liferay.portal.kernel.util.ServerDetector;
20  import com.liferay.portal.kernel.util.StringPool;
21  import com.liferay.portal.kernel.util.Validator;
22  
23  import java.util.List;
24  
25  import javax.portlet.PortletURL;
26  
27  import javax.servlet.jsp.JspException;
28  import javax.servlet.jsp.JspTagException;
29  
30  /**
31   * <a href="SearchContainerColumnButtonTag.java.html"><b><i>View Source</i></b>
32   * </a>
33   *
34   * @author Raymond Augé
35   */
36  public class SearchContainerColumnButtonTag<R>
37      extends SearchContainerColumnTag {
38  
39      public int doEndTag() {
40          try {
41              SearchContainerRowTag<R> parentTag =
42                  (SearchContainerRowTag<R>)findAncestorWithClass(
43                      this, SearchContainerRowTag.class);
44  
45              ResultRow row = parentTag.getRow();
46  
47              if (index <= -1) {
48                  index = row.getEntries().size();
49              }
50  
51              row.addButton(
52                  index, getAlign(), getValign(), getColspan(), getName(),
53                  (String)getHref());
54  
55              return EVAL_PAGE;
56          }
57          finally {
58              if (!ServerDetector.isResin()) {
59                  align = SearchEntry.DEFAULT_ALIGN;
60                  colspan = SearchEntry.DEFAULT_COLSPAN;
61                  _href = null;
62                  index = -1;
63                  name = StringPool.BLANK;
64                  valign = SearchEntry.DEFAULT_VALIGN;
65              }
66          }
67      }
68  
69      public int doStartTag() throws JspException {
70          SearchContainerRowTag<R> parentRowTag =
71              (SearchContainerRowTag<R>)findAncestorWithClass(
72                  this, SearchContainerRowTag.class);
73  
74          if (parentRowTag == null) {
75              throw new JspTagException(
76                  "Requires liferay-ui:search-container-row");
77          }
78  
79          if (!parentRowTag.isHeaderNamesAssigned()) {
80              List<String> headerNames = parentRowTag.getHeaderNames();
81  
82              headerNames.add(StringPool.BLANK);
83          }
84  
85          return EVAL_BODY_INCLUDE;
86      }
87  
88      public Object getHref() {
89          if (Validator.isNotNull(_href) && (_href instanceof PortletURL)) {
90              _href = _href.toString();
91          }
92  
93          return _href;
94      }
95  
96      public void setHref(Object href) {
97          _href = href;
98      }
99  
100     private Object _href;
101 
102 }