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.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 extends SearchContainerColumnTag {
37  
38      public int doEndTag() {
39          try {
40              SearchContainerRowTag parentTag =
41                  (SearchContainerRowTag)findAncestorWithClass(
42                      this, SearchContainerRowTag.class);
43  
44              ResultRow row = parentTag.getRow();
45  
46              if (index <= -1) {
47                  index = row.getEntries().size();
48              }
49  
50              row.addButton(
51                  index, getAlign(), getValign(), getColspan(), getName(),
52                  (String)getHref());
53  
54              return EVAL_PAGE;
55          }
56          finally {
57              if (!ServerDetector.isResin()) {
58                  align = SearchEntry.DEFAULT_ALIGN;
59                  colspan = SearchEntry.DEFAULT_COLSPAN;
60                  _href = null;
61                  index = -1;
62                  name = StringPool.BLANK;
63                  valign = SearchEntry.DEFAULT_VALIGN;
64              }
65          }
66      }
67  
68      public int doStartTag() throws JspException {
69          SearchContainerRowTag parentRowTag =
70              (SearchContainerRowTag)findAncestorWithClass(
71                  this, SearchContainerRowTag.class);
72  
73          if (parentRowTag == null) {
74              throw new JspTagException(
75                  "Requires liferay-ui:search-container-row");
76          }
77  
78          if (!parentRowTag.isHeaderNamesAssigned()) {
79              List<String> headerNames = parentRowTag.getHeaderNames();
80  
81              headerNames.add(StringPool.BLANK);
82          }
83  
84          return EVAL_BODY_INCLUDE;
85      }
86  
87      public Object getHref() {
88          if (Validator.isNotNull(_href) && (_href instanceof PortletURL)) {
89              _href = _href.toString();
90          }
91  
92          return _href;
93      }
94  
95      public void setHref(Object href) {
96          _href = href;
97      }
98  
99      private Object _href;
100 
101 }