1 18 19 package org.apache.roller.ui.authoring.struts.actions; 20 21 import java.io.IOException ; 22 import java.util.Date ; 23 import javax.servlet.ServletException ; 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.apache.struts.action.ActionForm; 29 import org.apache.struts.action.ActionForward; 30 import org.apache.struts.action.ActionMapping; 31 import org.apache.struts.action.ActionMessage; 32 import org.apache.struts.action.ActionMessages; 33 import org.apache.struts.actions.DispatchAction; 34 import org.apache.roller.RollerException; 35 import org.apache.roller.model.IndexManager; 36 import org.apache.roller.model.RollerFactory; 37 import org.apache.roller.model.UserManager; 38 import org.apache.roller.pojos.WebsiteData; 39 import org.apache.roller.ui.core.BasePageModel; 40 import org.apache.roller.ui.core.RollerRequest; 41 import org.apache.roller.ui.core.RollerSession; 42 import org.apache.roller.util.cache.CacheManager; 43 44 45 54 public class MaintenanceAction extends DispatchAction { 55 56 private static Log mLogger = LogFactory.getLog(MaintenanceAction.class); 57 58 59 66 protected ActionForward unspecified( 67 ActionMapping mapping, 68 ActionForm actionForm, 69 HttpServletRequest request, 70 HttpServletResponse response) 71 throws ServletException { 72 73 request.setAttribute("model", new BasePageModel( 74 "maintenance.title", request, response, mapping)); 75 return mapping.findForward("maintenance.page"); 76 } 77 78 79 82 public ActionForward index( 83 ActionMapping mapping, 84 ActionForm actionForm, 85 HttpServletRequest request, 86 HttpServletResponse response) 87 throws IOException , ServletException { 88 89 try { 90 RollerRequest rreq = RollerRequest.getRollerRequest(request); 91 WebsiteData website = rreq.getWebsite(); 92 RollerSession rses = RollerSession.getRollerSession(request); 93 94 if (rses.isUserAuthorizedToAdmin(website) ) { 95 IndexManager manager = 96 RollerFactory.getRoller().getIndexManager(); 97 manager.rebuildWebsiteIndex(website); 98 99 ActionMessages messages = new ActionMessages(); 100 messages.add(null, new ActionMessage("maintenance.message.indexed")); 101 saveMessages(request, messages); 102 } 103 104 request.setAttribute("model", new BasePageModel( 105 "maintenance.title", request, response, mapping)); 106 107 } catch (RollerException re) { 108 mLogger.error("Unexpected exception",re.getRootCause()); 109 throw new ServletException (re); 110 } catch (Exception e) { 111 mLogger.error("Unexpected exception",e); 112 throw new ServletException (e); 113 } 114 115 return mapping.findForward("maintenance.page"); 116 } 117 118 119 122 public ActionForward flushCache( 123 ActionMapping mapping, 124 ActionForm actionForm, 125 HttpServletRequest request, 126 HttpServletResponse response) 127 throws IOException , ServletException { 128 129 try { 130 RollerRequest rreq = RollerRequest.getRollerRequest(request); 131 WebsiteData website = rreq.getWebsite(); 132 RollerSession rses = RollerSession.getRollerSession(request); 133 134 if ( rses.isUserAuthorizedToAdmin(website) ) { 135 136 website.setLastModified(new Date ()); 138 139 try { 140 UserManager umgr = RollerFactory.getRoller().getUserManager(); 141 umgr.saveWebsite(website); 142 RollerFactory.getRoller().flush(); 143 } catch (RollerException ex) { 144 mLogger.error("Error saving website", ex); 145 } 146 147 CacheManager.invalidate(website); 149 150 ActionMessages messages = new ActionMessages(); 151 messages.add(null, new ActionMessage("maintenance.message.flushed")); 152 saveMessages(request, messages); 153 154 } 155 156 request.setAttribute("model", new BasePageModel( 157 "maintenance.title", request, response, mapping)); 158 159 } catch (Exception e) { 160 throw new ServletException (e); 161 } 162 163 return mapping.findForward("maintenance.page"); 164 } 165 166 } 167 | Popular Tags |