001    /**
002     * Copyright (c) 2000-2010 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.portlet.ratings.model.RatingsEntry;
018    import com.liferay.portlet.ratings.model.RatingsStats;
019    import com.liferay.taglib.util.IncludeTag;
020    
021    import javax.servlet.http.HttpServletRequest;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     * @author Shuyang Zhou
026     */
027    public class RatingsTag extends IncludeTag {
028    
029            public void setClassName(String className) {
030                    _className = className;
031            }
032    
033            public void setClassPK(long classPK) {
034                    _classPK = classPK;
035            }
036    
037            public void setNumberOfStars(int numberOfStars) {
038                    _numberOfStars = numberOfStars;
039            }
040    
041            public void setRatingsEntry(RatingsEntry ratingsEntry) {
042                    _ratingsEntry = ratingsEntry;
043    
044                    _setRatingsEntry = true;
045            }
046    
047            public void setRatingsStats(RatingsStats ratingsStats) {
048                    _ratingsStats = ratingsStats;
049    
050                    _setRatingsStats = true;
051            }
052    
053            public void setType(String type) {
054                    _type = type;
055            }
056    
057            public void setUrl(String url) {
058                    _url = url;
059            }
060    
061            protected void cleanUp() {
062                    _className = null;
063                    _classPK = 0;
064                    _numberOfStars = 5;
065                    _ratingsEntry = null;
066                    _ratingsStats = null;
067                    _setRatingsEntry = false;
068                    _setRatingsStats = false;
069                    _type = "stars";
070                    _url = null;
071            }
072    
073            protected String getPage() {
074                    return _PAGE;
075            }
076    
077            protected boolean isCleanUpSetAttributes() {
078                    return _CLEAN_UP_SET_ATTRIBUTES;
079            }
080    
081            protected void setAttributes(HttpServletRequest request) {
082                    request.setAttribute("liferay-ui:ratings:className", _className);
083                    request.setAttribute(
084                            "liferay-ui:ratings:classPK", String.valueOf(_classPK));
085                    request.setAttribute(
086                            "liferay-ui:ratings:numberOfStars", String.valueOf(_numberOfStars));
087                    request.setAttribute("liferay-ui:ratings:ratingsEntry", _ratingsEntry);
088                    request.setAttribute("liferay-ui:ratings:ratingsStats", _ratingsStats);
089                    request.setAttribute(
090                            "liferay-ui:ratings:setRatingsEntry",
091                            String.valueOf(_setRatingsEntry));
092                    request.setAttribute(
093                            "liferay-ui:ratings:setRatingsStats",
094                            String.valueOf(_setRatingsStats));
095                    request.setAttribute("liferay-ui:ratings:type", _type);
096                    request.setAttribute("liferay-ui:ratings:url", _url);
097            }
098    
099            private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
100    
101            private static final String _PAGE = "/html/taglib/ui/ratings/page.jsp";
102    
103            private String _className;
104            private long _classPK;
105            private int _numberOfStars = 5;
106            private RatingsEntry _ratingsEntry;
107            private RatingsStats _ratingsStats;
108            private boolean _setRatingsEntry;
109            private boolean _setRatingsStats;
110            private String _type = "stars";
111            private String _url;
112    
113    }