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