001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.taglib.ui;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.util.PropsKeys;
019    import com.liferay.portal.kernel.util.PropsUtil;
020    import com.liferay.portlet.ratings.model.RatingsEntry;
021    import com.liferay.portlet.ratings.model.RatingsStats;
022    import com.liferay.taglib.util.IncludeTag;
023    
024    import javax.servlet.http.HttpServletRequest;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     * @author Shuyang Zhou
029     */
030    public class RatingsTag extends IncludeTag {
031    
032            public void setClassName(String className) {
033                    _className = className;
034            }
035    
036            public void setClassPK(long classPK) {
037                    _classPK = classPK;
038            }
039    
040            public void setNumberOfStars(int numberOfStars) {
041                    _numberOfStars = numberOfStars;
042            }
043    
044            public void setRatingsEntry(RatingsEntry ratingsEntry) {
045                    _ratingsEntry = ratingsEntry;
046    
047                    _setRatingsEntry = true;
048            }
049    
050            public void setRatingsStats(RatingsStats ratingsStats) {
051                    _ratingsStats = ratingsStats;
052    
053                    _setRatingsStats = true;
054            }
055    
056            public void setRound(boolean round) {
057                    _round = round;
058            }
059    
060            public void setType(String type) {
061                    _type = type;
062            }
063    
064            public void setUrl(String url) {
065                    _url = url;
066            }
067    
068            @Override
069            protected void cleanUp() {
070                    _className = null;
071                    _classPK = 0;
072                    _numberOfStars = _DEFAULT_NUMBER_OF_STARS;
073                    _ratingsEntry = null;
074                    _ratingsStats = null;
075                    _round = true;
076                    _setRatingsEntry = false;
077                    _setRatingsStats = false;
078                    _type = "stars";
079                    _url = null;
080            }
081    
082            @Override
083            protected String getPage() {
084                    return _PAGE;
085            }
086    
087            @Override
088            protected boolean isCleanUpSetAttributes() {
089                    return _CLEAN_UP_SET_ATTRIBUTES;
090            }
091    
092            @Override
093            protected void setAttributes(HttpServletRequest request) {
094                    request.setAttribute("liferay-ui:ratings:className", _className);
095                    request.setAttribute(
096                            "liferay-ui:ratings:classPK", String.valueOf(_classPK));
097                    request.setAttribute(
098                            "liferay-ui:ratings:numberOfStars", String.valueOf(_numberOfStars));
099                    request.setAttribute("liferay-ui:ratings:ratingsEntry", _ratingsEntry);
100                    request.setAttribute("liferay-ui:ratings:ratingsStats", _ratingsStats);
101                    request.setAttribute(
102                            "liferay-ui:ratings:round", String.valueOf(_round));
103                    request.setAttribute(
104                            "liferay-ui:ratings:setRatingsEntry",
105                            String.valueOf(_setRatingsEntry));
106                    request.setAttribute(
107                            "liferay-ui:ratings:setRatingsStats",
108                            String.valueOf(_setRatingsStats));
109                    request.setAttribute("liferay-ui:ratings:type", _type);
110                    request.setAttribute("liferay-ui:ratings:url", _url);
111            }
112    
113            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
114    
115            private static final int _DEFAULT_NUMBER_OF_STARS = GetterUtil.getInteger(
116                    PropsUtil.get(PropsKeys.RATINGS_DEFAULT_NUMBER_OF_STARS));
117    
118            private static final String _PAGE = "/html/taglib/ui/ratings/page.jsp";
119    
120            private String _className;
121            private long _classPK;
122            private int _numberOfStars = _DEFAULT_NUMBER_OF_STARS;
123            private RatingsEntry _ratingsEntry;
124            private RatingsStats _ratingsStats;
125            private boolean _round;
126            private boolean _setRatingsEntry;
127            private boolean _setRatingsStats;
128            private String _type = "stars";
129            private String _url;
130    
131    }