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  
19  import java.util.List;
20  
21  import javax.servlet.jsp.JspException;
22  import javax.servlet.jsp.JspTagException;
23  
24  /**
25   * <a href="SearchContainerColumnScoreTag.java.html"><b><i>View Source</i></b>
26   * </a>
27   *
28   * @author Raymond Augé
29   */
30  public class SearchContainerColumnScoreTag extends SearchContainerColumnTag {
31  
32      private static final String DEFAULT_NAME = "score";
33  
34      public int doEndTag() {
35          try {
36              SearchContainerRowTag parentTag =
37                  (SearchContainerRowTag)findAncestorWithClass(
38                      this, SearchContainerRowTag.class);
39  
40              ResultRow row = parentTag.getRow();
41  
42              if (index <= -1) {
43                  index = row.getEntries().size();
44              }
45  
46              row.addScore(index, getScore());
47  
48              return EVAL_PAGE;
49          }
50          finally {
51              index = -1;
52              _name = DEFAULT_NAME;
53              _score = 0;
54          }
55      }
56  
57      public int doStartTag() throws JspException {
58          SearchContainerRowTag parentRowTag =
59              (SearchContainerRowTag)findAncestorWithClass(
60                  this, SearchContainerRowTag.class);
61  
62          if (parentRowTag == null) {
63              throw new JspTagException(
64                  "Requires liferay-ui:search-container-row");
65          }
66  
67          if (!parentRowTag.isHeaderNamesAssigned()) {
68              List<String> headerNames = parentRowTag.getHeaderNames();
69  
70              headerNames.add(_name);
71          }
72  
73          return EVAL_BODY_INCLUDE;
74      }
75  
76      public float getScore() {
77          return _score;
78      }
79  
80      public void setScore(float score) {
81          _score = score;
82      }
83  
84      private String _name = DEFAULT_NAME;
85      private float _score;
86  
87  }