1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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.StringPool;
20  import com.liferay.portal.kernel.util.Validator;
21  
22  import java.util.List;
23  
24  import javax.portlet.PortletURL;
25  
26  import javax.servlet.jsp.JspException;
27  import javax.servlet.jsp.JspTagException;
28  
29  /**
30   * <a href="SearchContainerColumnButtonTag.java.html"><b><i>View Source</i></b>
31   * </a>
32   *
33   * @author Raymond Augé
34   */
35  public class SearchContainerColumnButtonTag extends SearchContainerColumnTag {
36  
37      public int doEndTag() {
38          try {
39              SearchContainerRowTag parentTag =
40                  (SearchContainerRowTag)findAncestorWithClass(
41                      this, SearchContainerRowTag.class);
42  
43              ResultRow row = parentTag.getRow();
44  
45              if (index <= -1) {
46                  index = row.getEntries().size();
47              }
48  
49              row.addButton(
50                  index, getAlign(), getValign(), getColspan(), getName(),
51                  (String)getHref());
52  
53              return EVAL_PAGE;
54          }
55          finally {
56              align = SearchEntry.DEFAULT_ALIGN;
57              colspan = SearchEntry.DEFAULT_COLSPAN;
58              _href = null;
59              index = -1;
60              name = StringPool.BLANK;
61              valign = SearchEntry.DEFAULT_VALIGN;
62          }
63      }
64  
65      public int doStartTag() throws JspException {
66          SearchContainerRowTag parentRowTag =
67              (SearchContainerRowTag)findAncestorWithClass(
68                  this, SearchContainerRowTag.class);
69  
70          if (parentRowTag == null) {
71              throw new JspTagException(
72                  "Requires liferay-ui:search-container-row");
73          }
74  
75          if (!parentRowTag.isHeaderNamesAssigned()) {
76              List<String> headerNames = parentRowTag.getHeaderNames();
77  
78              headerNames.add(StringPool.BLANK);
79          }
80  
81          return EVAL_BODY_INCLUDE;
82      }
83  
84      public Object getHref() {
85          if (Validator.isNotNull(_href) && (_href instanceof PortletURL)) {
86              _href = _href.toString();
87          }
88  
89          return _href;
90      }
91  
92      public void setHref(Object href) {
93          _href = href;
94      }
95  
96      private Object _href;
97  
98  }