KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > jforum > view > admin > CacheAction


1 /*
2  * Copyright (c) Rafael Steil
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms,
6  * with or without modification, are permitted provided
7  * that the following conditions are met:
8  *
9  * 1) Redistributions of source code must retain the above
10  * copyright notice, this list of conditions and the
11  * following disclaimer.
12  * 2) Redistributions in binary form must reproduce the
13  * above copyright notice, this list of conditions and
14  * the following disclaimer in the documentation and/or
15  * other materials provided with the distribution.
16  * 3) Neither the name of "Rafael Steil" nor
17  * the names of its contributors may be used to endorse
18  * or promote products derived from this software without
19  * specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
22  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27  * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
32  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
34  * IN CONTRACT, STRICT LIABILITY, OR TORT
35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
38  *
39  * Created on Feb 20, 2005 12:00:02 PM
40  * The JForum Project
41  * http://www.jforum.net
42  */

43 package net.jforum.view.admin;
44
45 import java.util.Collection JavaDoc;
46
47 import net.jforum.SessionFacade;
48 import net.jforum.dao.DataAccessDriver;
49 import net.jforum.repository.BBCodeRepository;
50 import net.jforum.repository.ForumRepository;
51 import net.jforum.repository.ModulesRepository;
52 import net.jforum.repository.PostRepository;
53 import net.jforum.repository.RankingRepository;
54 import net.jforum.repository.SecurityRepository;
55 import net.jforum.repository.SmiliesRepository;
56 import net.jforum.repository.TopicRepository;
57 import net.jforum.util.bbcode.BBCodeHandler;
58 import net.jforum.util.preferences.ConfigKeys;
59 import net.jforum.util.preferences.SystemGlobals;
60 import net.jforum.util.preferences.TemplateKeys;
61
62 /**
63  * @author Rafael Steil
64  * @version $Id: CacheAction.java,v 1.7 2005/09/15 00:59:44 rafaelsteil Exp $
65  */

66 public class CacheAction extends AdminCommand
67 {
68     /**
69      * @see net.jforum.Command#list()
70      */

71     public void list() throws Exception JavaDoc
72     {
73         this.setTemplateName(TemplateKeys.CACHE_LIST);
74         
75         this.context.put("bb", new BBCodeRepository());
76         this.context.put("modules", new ModulesRepository());
77         this.context.put("ranking", new RankingRepository());
78         this.context.put("smilies", new SmiliesRepository());
79         this.context.put("security", new SecurityRepository());
80         this.context.put("forum", new ForumRepository());
81         this.context.put("topic", new TopicRepository());
82         this.context.put("session", new SessionFacade());
83         this.context.put("posts", new PostRepository());
84     }
85     
86     public void bbReload() throws Exception JavaDoc
87     {
88         BBCodeRepository.setBBCollection(new BBCodeHandler().parse());
89         this.list();
90     }
91     
92     public void sessionClear() throws Exception JavaDoc
93     {
94         SessionFacade.clear();
95         this.list();
96     }
97     
98     public void modulesReload() throws Exception JavaDoc
99     {
100         ModulesRepository.init(SystemGlobals.getValue(ConfigKeys.CONFIG_DIR));
101         this.list();
102     }
103     
104     public void smiliesReload() throws Exception JavaDoc
105     {
106         SmiliesRepository.loadSmilies();
107         this.list();
108     }
109     
110     public void rankingReload() throws Exception JavaDoc
111     {
112         RankingRepository.loadRanks();
113         this.list();
114     }
115     
116     public void topicsMoreInfo() throws Exception JavaDoc
117     {
118         if (!SystemGlobals.getBoolValue(ConfigKeys.TOPIC_CACHE_ENABLED)) {
119             this.list();
120             return;
121         }
122         
123         this.setTemplateName(TemplateKeys.CACHE_TOPICS_MOREINFO);
124         
125         this.context.put("categories", ForumRepository.getAllCategories());
126     }
127     
128     public void topicsClear() throws Exception JavaDoc
129     {
130         int forumId = this.request.getIntParameter("forum_id");
131         TopicRepository.clearCache(forumId);
132         this.topicsMoreInfo();
133     }
134     
135     public void postsMoreInfo() throws Exception JavaDoc
136     {
137         if (!SystemGlobals.getBoolValue(ConfigKeys.POSTS_CACHE_ENABLED)) {
138             this.list();
139             return;
140         }
141         
142         Collection JavaDoc topics = PostRepository.cachedTopics();
143         
144         this.context.put("topics", DataAccessDriver.getInstance().newTopicDAO().selectTopicTitlesByIds(topics));
145         this.context.put("repository", new PostRepository());
146         this.setTemplateName(TemplateKeys.CACHE_POST_MOREINFO);
147     }
148     
149     public void postsClear() throws Exception JavaDoc
150     {
151         int topicId = this.request.getIntParameter("topic_id");
152         PostRepository.clearCache(topicId);
153         this.postsMoreInfo();
154     }
155 }
156
Popular Tags