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.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 extends SearchContainerColumnTag {
32  
33      private static final String DEFAULT_NAME = "score";
34  
35      public int doEndTag() {
36          try {
37              SearchContainerRowTag parentTag =
38                  (SearchContainerRowTag)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 parentRowTag =
62              (SearchContainerRowTag)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  }