001
014
015 package com.liferay.taglib.ui;
016
017 import com.liferay.portal.kernel.dao.search.ResultRow;
018 import com.liferay.portal.kernel.util.ServerDetector;
019
020 import java.util.List;
021
022 import javax.servlet.jsp.JspException;
023 import javax.servlet.jsp.JspTagException;
024
025
028 public class SearchContainerColumnScoreTag extends SearchContainerColumnTag {
029
030 private static final String DEFAULT_NAME = "score";
031
032 public int doEndTag() {
033 try {
034 SearchContainerRowTag parentTag =
035 (SearchContainerRowTag)findAncestorWithClass(
036 this, SearchContainerRowTag.class);
037
038 ResultRow row = parentTag.getRow();
039
040 if (index <= -1) {
041 index = row.getEntries().size();
042 }
043
044 row.addScore(index, getScore());
045
046 return EVAL_PAGE;
047 }
048 finally {
049 if (!ServerDetector.isResin()) {
050 index = -1;
051 _name = DEFAULT_NAME;
052 _score = 0;
053 }
054 }
055 }
056
057 public int doStartTag() throws JspException {
058 SearchContainerRowTag parentRowTag =
059 (SearchContainerRowTag)findAncestorWithClass(
060 this, SearchContainerRowTag.class);
061
062 if (parentRowTag == null) {
063 throw new JspTagException(
064 "Requires liferay-ui:search-container-row");
065 }
066
067 if (!parentRowTag.isHeaderNamesAssigned()) {
068 List<String> headerNames = parentRowTag.getHeaderNames();
069
070 headerNames.add(_name);
071 }
072
073 return EVAL_BODY_INCLUDE;
074 }
075
076 public float getScore() {
077 return _score;
078 }
079
080 public void setScore(float score) {
081 _score = score;
082 }
083
084 private String _name = DEFAULT_NAME;
085 private float _score;
086
087 }