KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > website > actions > MaintenanceAction


1 /*
2  * Created on May 25, 2004
3  *
4  * TODO To change the template for this generated file go to
5  * Window - Preferences - Java - Code Generation - Code and Comments
6  */

7 package org.roller.presentation.website.actions;
8
9 import java.io.IOException JavaDoc;
10
11 import javax.servlet.ServletException JavaDoc;
12 import javax.servlet.http.HttpServletRequest JavaDoc;
13 import javax.servlet.http.HttpServletResponse JavaDoc;
14
15 import org.apache.commons.logging.Log;
16 import org.apache.commons.logging.LogFactory;
17 import org.apache.struts.action.ActionForm;
18 import org.apache.struts.action.ActionForward;
19 import org.apache.struts.action.ActionMapping;
20 import org.apache.struts.action.ActionMessage;
21 import org.apache.struts.action.ActionMessages;
22 import org.apache.struts.actions.DispatchAction;
23 import org.roller.RollerException;
24 import org.roller.business.search.operations.RebuildUserIndexOperation;
25 import org.roller.model.IndexManager;
26 import org.roller.pojos.UserData;
27 import org.roller.presentation.RollerRequest;
28 import org.roller.presentation.pagecache.PageCacheFilter;
29
30 /**
31  * Allows user to perform Website maintenence operations such as flushing
32  * the website page cache or re-indexing the website search index.
33  *
34  * @struts.action path="/editor/maintenance" name="maintenanceForm" scope="request" parameter="method"
35  *
36  * @struts.action-forward name="maintenance.page" path="/website/Maintenance.jsp"
37  */

38 public class MaintenanceAction extends DispatchAction
39 {
40     private static Log mLogger =
41         LogFactory.getFactory().getInstance(MaintenanceAction.class);
42
43
44     /* (non-Javadoc)
45      * @see org.apache.struts.actions.DispatchAction#unspecified(
46      * org.apache.struts.action.ActionMapping,
47      * org.apache.struts.action.ActionForm,
48      * javax.servlet.http.HttpServletRequest,
49      * javax.servlet.http.HttpServletResponse)
50      */

51     protected ActionForward unspecified(
52             ActionMapping mapping,
53             ActionForm actionForm,
54             HttpServletRequest JavaDoc request,
55             HttpServletResponse JavaDoc response)
56             throws ServletException JavaDoc
57     {
58         return mapping.findForward("maintenance.page");
59     }
60
61     //-----------------------------------------------------------------------
62
/**
63      * Respond to user's request to rebuild search index.
64      */

65     public ActionForward index(
66         ActionMapping mapping,
67         ActionForm actionForm,
68         HttpServletRequest JavaDoc request,
69         HttpServletResponse JavaDoc response)
70         throws IOException JavaDoc, ServletException JavaDoc
71     {
72         try
73         {
74             RollerRequest rreq = RollerRequest.getRollerRequest(request);
75             if ( rreq.isUserAuthorizedToEdit() )
76             {
77                 UserData ud = rreq.getUser();
78                 IndexManager manager = rreq.getRoller().getIndexManager();
79                 manager.rebuildUserIndex();
80                 
81                 ActionMessages messages = new ActionMessages();
82                 messages.add(null, new ActionMessage("maintenance.message.indexed"));
83                 saveMessages(request, messages);
84             }
85         }
86         catch (RollerException re)
87         {
88             mLogger.error("Unexpected exception",re.getRootCause());
89             throw new ServletException JavaDoc(re);
90         }
91         catch (Exception JavaDoc e)
92         {
93             mLogger.error("Unexpected exception",e);
94             throw new ServletException JavaDoc(e);
95         }
96         return mapping.findForward("maintenance.page");
97     }
98
99     //-----------------------------------------------------------------------
100
/**
101      * Respond to request to flush a user's page cache.
102      */

103     public ActionForward flushCache(
104         ActionMapping mapping,
105         ActionForm actionForm,
106         HttpServletRequest JavaDoc request,
107         HttpServletResponse JavaDoc response)
108         throws IOException JavaDoc, ServletException JavaDoc
109     {
110         try
111         {
112             RollerRequest rreq = RollerRequest.getRollerRequest(request);
113             if ( rreq.isUserAuthorizedToEdit() )
114             {
115                 UserData user = rreq.getUser();
116                 PageCacheFilter.removeFromCache(request, user);
117
118                 ActionMessages messages = new ActionMessages();
119                 messages.add(null, new ActionMessage("maintenance.message.flushed"));
120                 saveMessages(request, messages);
121             }
122         }
123         catch (Exception JavaDoc e)
124         {
125             throw new ServletException JavaDoc(e);
126         }
127         return mapping.findForward("maintenance.page");
128     }
129 }
130
Popular Tags