1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.taglib.ui;
16  
17  import com.liferay.portlet.ratings.model.RatingsEntry;
18  import com.liferay.portlet.ratings.model.RatingsStats;
19  import com.liferay.portlet.ratings.model.impl.RatingsEntryImpl;
20  import com.liferay.taglib.util.IncludeTag;
21  
22  import javax.servlet.http.HttpServletRequest;
23  
24  /**
25   * <a href="RatingsTag.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Brian Wing Shun Chan
28   * @author Shuyang Zhou
29   */
30  public class RatingsTag extends IncludeTag {
31  
32      public void setClassName(String className) {
33          _className = className;
34      }
35  
36      public void setClassPK(long classPK) {
37          _classPK = classPK;
38      }
39  
40      public void setNumberOfStars(int numberOfStars) {
41          _numberOfStars = numberOfStars;
42      }
43  
44      public void setRatingsEntry(RatingsEntry ratingsEntry) {
45          if (ratingsEntry == null) {
46              _ratingsEntry = _nullRatingsEntry;
47          }
48          else {
49              _ratingsEntry = ratingsEntry;
50          }
51      }
52  
53      public void setRatingsStats(RatingsStats ratingsStats) {
54          _ratingsStats = ratingsStats;
55      }
56  
57      public void setType(String type) {
58          _type = type;
59      }
60  
61      public void setUrl(String url) {
62          _url = url;
63      }
64  
65      protected void cleanUp() {
66          _className = null;
67          _classPK = 0;
68          _numberOfStars = 5;
69          _ratingsEntry = null;
70          _ratingsStats = null;
71          _type = "stars";
72          _url = null;
73      }
74  
75      protected String getPage() {
76          return _PAGE;
77      }
78  
79      protected boolean isCleanUpSetAttributes() {
80          return _CLEAN_UP_SET_ATTRIBUTES;
81      }
82  
83      protected void setAttributes(HttpServletRequest request) {
84          request.setAttribute("liferay-ui:ratings:className", _className);
85          request.setAttribute(
86              "liferay-ui:ratings:classPK", String.valueOf(_classPK));
87          request.setAttribute(
88              "liferay-ui:ratings:numberOfStars", String.valueOf(_numberOfStars));
89          request.setAttribute("liferay-ui:ratings:ratingsEntry", _ratingsEntry);
90          request.setAttribute("liferay-ui:ratings:ratingsStats", _ratingsStats);
91          request.setAttribute("liferay-ui:ratings:type", _type);
92          request.setAttribute("liferay-ui:ratings:url", _url);
93      }
94  
95      private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;
96  
97      private static final String _PAGE = "/html/taglib/ui/ratings/page.jsp";
98  
99      private static RatingsEntry _nullRatingsEntry = new RatingsEntryImpl();
100 
101     private String _className;
102     private long _classPK;
103     private int _numberOfStars = 5;
104     private RatingsEntry _ratingsEntry;
105     private RatingsStats _ratingsStats;
106     private String _type = "stars";
107     private String _url;
108 
109 }