KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > cmstool > actions > UpdateCacheAction


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24
25 package org.infoglue.cms.applications.cmstool.actions;
26
27 import org.apache.log4j.Logger;
28 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
29 import org.infoglue.cms.applications.common.actions.SimpleXmlServiceAction;
30 import org.infoglue.cms.entities.content.impl.simple.ContentImpl;
31 import org.infoglue.cms.entities.content.impl.simple.SmallContentImpl;
32 import org.infoglue.cms.entities.management.impl.simple.ContentTypeDefinitionImpl;
33 import org.infoglue.cms.entities.management.impl.simple.InterceptionPointImpl;
34 import org.infoglue.cms.entities.management.impl.simple.InterceptorImpl;
35 import org.infoglue.cms.entities.management.impl.simple.RepositoryImpl;
36 import org.infoglue.deliver.util.CacheController;
37
38
39 /**
40  * This is the action that takes care of all incoming update-calls. This action is
41  * called by either the system or by replication-program and the class the distibutes the
42  * update-call to all the listeners which have registered earlier.
43  *
44  * @author Mattias Bogeblad
45  */

46
47 public class UpdateCacheAction extends InfoGlueAbstractAction
48 {
49     private final static Logger logger = Logger.getLogger(UpdateCacheAction.class.getName());
50
51     private static final long serialVersionUID = -1669612689042389758L;
52     
53     private String JavaDoc className = null;
54     private String JavaDoc objectId = null;
55     private String JavaDoc objectName = null;
56     private String JavaDoc typeId = null;
57
58     private String JavaDoc repositoryName = null;
59     private Integer JavaDoc languageId = null;
60     private Integer JavaDoc siteNodeId = null;
61     
62     private static boolean cachingInProgress = false;
63     
64     /**
65      * The constructor for this action - contains nothing right now.
66      */

67     
68     public UpdateCacheAction()
69     {
70     
71     }
72     
73     /**
74      * This method will just reply to a testcall.
75      */

76          
77     public String JavaDoc doTest() throws Exception JavaDoc
78     {
79         this.getResponse().getWriter().println("test ok - cache action available");
80         return NONE;
81     }
82
83     /**
84      * This method is the application entry-point. The parameters has been set through the setters
85      * and now we just have to render the appropriate output.
86      */

87          
88     public String JavaDoc doExecute() throws Exception JavaDoc
89     {
90         try
91         {
92             CacheController.clearCaches(className, objectId, null);
93             
94             logger.info("Updating className with id:" + className + ":" + objectId);
95             
96             if(className != null)
97             {
98                 Class JavaDoc types = Class.forName(className);
99                 Object JavaDoc[] ids = {new Integer JavaDoc(objectId)};
100                 
101                 CacheController.clearCache(types, ids);
102                                      
103                 //If it's an contentVersion we should delete all images it might have generated from attributes.
104
/*
105                 if(Class.forName(className).getName().equals(ContentVersionImpl.class.getName()))
106                 {
107                     logger.info("We should delete all images with contentVersionId " + objectId);
108                     DigitalAssetDeliveryController.getDigitalAssetDeliveryController().deleteContentVersionAssets(new Integer(objectId));
109                 }
110                 */

111                 
112                 //If it's an ContentImpl we update SmallContentImpl as well.
113
if(Class.forName(className).getName().equals(ContentImpl.class.getName()))
114                 {
115                     CacheController.clearCache(SmallContentImpl.class, new Object JavaDoc[]{new Integer JavaDoc(objectId)});
116                 }
117                 
118                 if(Class.forName(className).getClass().getName().equals(RepositoryImpl.class.getName()))
119                 {
120                     CacheController.clearCache("repositoryCache");
121                 }
122                 else if(Class.forName(className).getClass().getName().equals(InterceptionPointImpl.class.getName()))
123                 {
124                     CacheController.clearCache("interceptionPointCache");
125                     CacheController.clearCache("interceptorsCache");
126                 }
127                 else if(Class.forName(className).getClass().getName().equals(InterceptorImpl.class.getName()))
128                 {
129                     CacheController.clearCache("interceptionPointCache");
130                     CacheController.clearCache("interceptorsCache");
131                 }
132                 else if(Class.forName(className).getClass().getName().equals(ContentTypeDefinitionImpl.class.getName()))
133                 {
134                     CacheController.clearCache("contentTypeDefinitionCache");
135                 }
136                 else if(Class.forName(className).getClass().getName().equals(ContentImpl.class.getName()))
137                 {
138                     CacheController.clearCache("childContentCache");
139                 }
140                 /*
141                 else if(Class.forName(className).getClass().getName().equals(ContentImpl.class.getName()))
142                 {
143                     CacheController.clearCache("childContentCache");
144                 }
145                 */

146             }
147         }
148         catch(Exception JavaDoc e)
149         {
150             logger.error(e.getMessage(), e);
151         }
152                 
153         return "success";
154     }
155     
156
157     /**
158      * This method is for letting users update cache manually.
159      */

160          
161     public String JavaDoc doInput() throws Exception JavaDoc
162     {
163         return "input";
164     }
165     
166
167     /**
168      * Setters and getters for all things sent to the page in the request
169      */

170             
171     public void setClassName(String JavaDoc className)
172     {
173         this.className = className;
174     }
175         
176     public void setObjectId(String JavaDoc objectId)
177     {
178         this.objectId = objectId;
179     }
180
181     public void setObjectName(String JavaDoc objectName)
182     {
183         this.objectName = objectName;
184     }
185
186     public void setTypeId(String JavaDoc typeId)
187     {
188         this.typeId = typeId;
189     }
190     
191 }
192
Popular Tags