1
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
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 }