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 index = -1;
050
051 if (!ServerDetector.isResin()) {
052 _name = DEFAULT_NAME;
053 _score = 0;
054 }
055 }
056 }
057
058 public int doStartTag() throws JspException {
059 SearchContainerRowTag parentRowTag =
060 (SearchContainerRowTag)findAncestorWithClass(
061 this, SearchContainerRowTag.class);
062
063 if (parentRowTag == null) {
064 throw new JspTagException(
065 "Requires liferay-ui:search-container-row");
066 }
067
068 if (!parentRowTag.isHeaderNamesAssigned()) {
069 List<String> headerNames = parentRowTag.getHeaderNames();
070
071 headerNames.add(_name);
072 }
073
074 return EVAL_BODY_INCLUDE;
075 }
076
077 public float getScore() {
078 return _score;
079 }
080
081 public void setScore(float score) {
082 _score = score;
083 }
084
085 private String _name = DEFAULT_NAME;
086 private float _score;
087
088 }