001    /**
002     * Copyright (c) 2000-2013 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 setType(String type) {
057                    _type = type;
058            }
059    
060            public void setUrl(String url) {
061                    _url = url;
062            }
063    
064            @Override
065            protected void cleanUp() {
066                    _className = null;
067                    _classPK = 0;
068                    _numberOfStars = _DEFAULT_NUMBER_OF_STARS;
069                    _ratingsEntry = null;
070                    _ratingsStats = null;
071                    _setRatingsEntry = false;
072                    _setRatingsStats = false;
073                    _type = "stars";
074                    _url = null;
075            }
076    
077            @Override
078            protected String getPage() {
079                    return _PAGE;
080            }
081    
082            @Override
083            protected boolean isCleanUpSetAttributes() {
084                    return _CLEAN_UP_SET_ATTRIBUTES;
085            }
086    
087            @Override
088            protected void setAttributes(HttpServletRequest request) {
089                    request.setAttribute("liferay-ui:ratings:className", _className);
090                    request.setAttribute(
091                            "liferay-ui:ratings:classPK", String.valueOf(_classPK));
092                    request.setAttribute(
093                            "liferay-ui:ratings:numberOfStars", String.valueOf(_numberOfStars));
094                    request.setAttribute("liferay-ui:ratings:ratingsEntry", _ratingsEntry);
095                    request.setAttribute("liferay-ui:ratings:ratingsStats", _ratingsStats);
096                    request.setAttribute(
097                            "liferay-ui:ratings:setRatingsEntry",
098                            String.valueOf(_setRatingsEntry));
099                    request.setAttribute(
100                            "liferay-ui:ratings:setRatingsStats",
101                            String.valueOf(_setRatingsStats));
102                    request.setAttribute("liferay-ui:ratings:type", _type);
103                    request.setAttribute("liferay-ui:ratings:url", _url);
104            }
105    
106            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
107    
108            private static final int _DEFAULT_NUMBER_OF_STARS = GetterUtil.getInteger(
109                    PropsUtil.get(PropsKeys.RATINGS_DEFAULT_NUMBER_OF_STARS));
110    
111            private static final String _PAGE = "/html/taglib/ui/ratings/page.jsp";
112    
113            private String _className;
114            private long _classPK;
115            private int _numberOfStars = _DEFAULT_NUMBER_OF_STARS;
116            private RatingsEntry _ratingsEntry;
117            private RatingsStats _ratingsStats;
118            private boolean _setRatingsEntry;
119            private boolean _setRatingsStats;
120            private String _type = "stars";
121            private String _url;
122    
123    }