001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/categorytree/impl/RSSImpl.java,v 1.16 2007/12/17 09:09:40 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.16 $
005: * $Date: 2007/12/17 09:09:40 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Minh Nguyen
039: * @author: Mai Nguyen
040: */
041: package com.mvnforum.categorytree.impl;
042:
043: import java.io.IOException;
044: import java.util.*;
045:
046: import org.apache.commons.logging.Log;
047: import org.apache.commons.logging.LogFactory;
048:
049: import net.myvietnam.mvncore.exception.DatabaseException;
050: import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
051: import net.myvietnam.mvncore.service.URLResolverService;
052: import net.myvietnam.mvncore.util.I18nUtil;
053: import net.myvietnam.mvncore.web.*;
054:
055: import com.mvnforum.MVNForumResourceBundle;
056: import com.mvnforum.MyUtil;
057: import com.mvnforum.auth.*;
058: import com.mvnforum.categorytree.CategoryTreeEvent;
059: import com.mvnforum.db.CategoryBean;
060: import com.mvnforum.db.ForumBean;
061:
062: import freemarker.cache.ClassTemplateLoader;
063: import freemarker.cache.TemplateLoader;
064: import freemarker.template.*;
065:
066: public class RSSImpl extends FtlCategoryTreeListener {
067:
068: private static Log log = LogFactory.getLog(RSSImpl.class);
069:
070: private GenericRequest request;
071: private GenericResponse response;
072: private String sort;
073: private String order;
074:
075: private OnlineUser onlineUser;
076: private MVNForumPermission permission;
077: private static URLResolverService urlResolver = MvnCoreServiceFactory
078: .getMvnCoreService().getURLResolverService();
079: private static Template template;
080: private CategoryBean categoryBean;
081:
082: private int categoryID;
083: private static int rowIndex;
084: private Locale locale;
085: static {
086: Configuration conf = new Configuration();
087: TemplateLoader loader = new ClassTemplateLoader(RSSImpl.class);
088: conf.setTemplateLoader(loader);
089: try {
090: template = conf.getTemplate("rss.ftl");
091: } catch (IOException e) {
092: log.error("Cannot load template for RSS", e);
093: }
094: }
095:
096: public RSSImpl(GenericRequest request)
097: throws AuthenticationException, DatabaseException {
098:
099: this .request = request;
100: onlineUser = OnlineUserManager.getInstance().getOnlineUser(
101: request);
102: permission = onlineUser.getPermission();
103: locale = I18nUtil.getLocaleInRequest(request);
104: super .init(template);
105: }
106:
107: public RSSImpl(GenericRequest request, GenericResponse response,
108: String sort, String order) throws AuthenticationException,
109: DatabaseException {
110:
111: this .request = request;
112: this .response = response;
113: this .sort = sort;
114: this .order = order;
115: onlineUser = OnlineUserManager.getInstance().getOnlineUser(
116: request);
117: permission = onlineUser.getPermission();
118: locale = I18nUtil.getLocaleInRequest(request);
119: super .init(template);
120: }
121:
122: public String drawHeader(CategoryTreeEvent event) {
123:
124: SimpleHash subRoot = new SimpleHash();
125:
126: subRoot.put("name", "header");
127: rows.add(subRoot);
128:
129: return "";
130: }
131:
132: public String drawFooter(CategoryTreeEvent event) {
133:
134: SimpleHash subRoot = new SimpleHash();
135:
136: subRoot.put("name", "footer");
137:
138: boolean checkNoCategory = (event.getDepth() == 0);
139: subRoot.put("checkNoCategory", checkNoCategory);
140: if (checkNoCategory) {
141: String no_category = MVNForumResourceBundle.getString(
142: locale,
143: "mvnforum.user.listforums.table.no_category");
144: subRoot.put("no_category", no_category);
145: }
146:
147: rows.add(subRoot);
148:
149: return "";
150: }
151:
152: public String drawCategory(CategoryTreeEvent event) {
153:
154: SimpleHash subRoot = new SimpleHash();
155: rowIndex = 0;
156:
157: categoryBean = (CategoryBean) event.getSource();
158:
159: categoryID = categoryBean.getCategoryID();
160: subRoot.put("categoryId", String.valueOf(categoryID));
161: subRoot.put("categoryName", categoryBean.getCategoryName());
162: subRoot.put("name", "category");
163:
164: if (MyUtil.canViewAnyForumInCategory(categoryBean
165: .getCategoryID(), permission) == false)
166: return "";
167:
168: rows.add(subRoot);
169:
170: return "";
171: }
172:
173: public String drawForum(CategoryTreeEvent event) {
174:
175: SimpleHash subRoot = new SimpleHash();
176: ForumBean forum = (ForumBean) event.getSource();
177:
178: subRoot.put("forumName", forum.getForumName());
179:
180: int forumID = forum.getForumID();
181: subRoot.put("forumID", String.valueOf(forumID));
182:
183: subRoot.put("ContextPath", request.getContextPath());
184:
185: if (forum.getCategoryID() != categoryID) {
186: return "";
187: }
188:
189: boolean check_permission = permission.canReadPost(forumID)
190: && (forum.getForumStatus() != ForumBean.FORUM_STATUS_DISABLED);
191: subRoot.put("check_permission", check_permission);
192:
193: subRoot.put("forumCountInCurrentCategory",
194: new Integer(rowIndex));
195: rowIndex++;
196:
197: subRoot.put("name", "forum");
198: subRoot.put("urlRSS091", urlResolver.encodeURL(request,
199: response, "rss?forum=" + forumID + "&sort=" + sort
200: + "&order=" + order,
201: URLResolverService.ACTION_URL));
202: subRoot.put("urlRSS20", urlResolver.encodeURL(request,
203: response, "rss2?forum=" + forumID + "&sort=" + sort
204: + "&order=" + order,
205: URLResolverService.ACTION_URL));
206: subRoot.put("urlATOM", urlResolver.encodeURL(request, response,
207: "atom?forum=" + forumID + "&sort=" + sort
208: + "&order=" + order,
209: URLResolverService.ACTION_URL));
210: subRoot.put("forum_specific_feed", MVNForumResourceBundle
211: .getString(locale,
212: "mvnforum.common.forum_specific_feed"));
213:
214: rows.add(subRoot);
215:
216: return "";
217: }
218:
219: public String drawSeparator(CategoryTreeEvent event) {
220: return "";
221: }
222:
223: public void setDepthTree(int depth) {
224: //this.depth = depth;
225: }
226: }
|