1 2 package org.roller.presentation.website.actions; 3 4 import java.io.IOException ; 5 6 import javax.servlet.ServletException ; 7 import javax.servlet.http.HttpServletRequest ; 8 import javax.servlet.http.HttpServletResponse ; 9 10 import org.apache.commons.logging.Log; 11 import org.apache.commons.logging.LogFactory; 12 import org.apache.struts.action.ActionError; 13 import org.apache.struts.action.ActionErrors; 14 import org.apache.struts.action.ActionForm; 15 import org.apache.struts.action.ActionForward; 16 import org.apache.struts.action.ActionMapping; 17 import org.apache.struts.action.ActionMessage; 18 import org.apache.struts.action.ActionMessages; 19 import org.apache.struts.actions.DispatchAction; 20 import org.roller.RollerException; 21 import org.roller.RollerPermissionsException; 22 import org.roller.model.IndexManager; 23 import org.roller.model.RollerFactory; 24 import org.roller.pojos.RollerConfigData; 25 import org.roller.presentation.RollerRequest; 26 import org.roller.presentation.RollerSession; 27 import org.roller.presentation.website.formbeans.RollerConfigFormEx; 28 29 34 public final class RollerConfigAction extends DispatchAction 35 { 36 private static Log mLogger = 37 LogFactory.getFactory().getInstance(RollerConfigAction.class); 38 39 public ActionForward edit( 41 ActionMapping mapping, 42 ActionForm actionForm, 43 HttpServletRequest request, 44 HttpServletResponse response) 45 throws IOException , ServletException 46 { 47 ActionForward forward = mapping.findForward("rollerConfig.page"); 48 try 49 { 50 RollerRequest rreq = RollerRequest.getRollerRequest(request); 51 if ( rreq.isUserAuthorizedToEdit() && rreq.isAdminUser() ) 52 { 53 RollerConfigData rollerConfig = RollerFactory.getRoller().getConfigManager().getRollerConfig(); 54 RollerConfigFormEx rcForm = (RollerConfigFormEx)actionForm; 55 rcForm.copyFrom(rollerConfig, request.getLocale()); 56 } 57 else 58 { 59 forward = mapping.findForward("access-denied"); 60 } 61 } 62 catch (Exception e) 63 { 64 mLogger.error("ERROR in action",e); 65 throw new ServletException (e); 66 } 67 return forward; 68 } 69 70 public ActionForward update( 72 ActionMapping mapping, 73 ActionForm actionForm, 74 HttpServletRequest request, 75 HttpServletResponse response) 76 throws IOException , ServletException 77 { 78 ActionForward forward = mapping.findForward("rollerConfig.page"); 79 ActionErrors errors = new ActionErrors(); 80 try 81 { 82 RollerRequest rreq = RollerRequest.getRollerRequest(request); 83 if ( rreq.isUserAuthorizedToEdit() && rreq.isAdminUser() ) 84 { 85 RollerConfigFormEx rcForm = (RollerConfigFormEx)actionForm; 86 87 RollerConfigData rollerConfig = RollerFactory.getRoller().getConfigManager().getRollerConfig(); 89 rcForm.copyTo(rollerConfig, request.getLocale()); 90 91 rreq.getRoller().getConfigManager().storeRollerConfig(rollerConfig); 93 rreq.getRoller().getRefererManager().applyRefererFilters(); 94 rreq.getRoller().commit(); 95 96 ActionMessages uiMessages = new ActionMessages(); 97 uiMessages.add(null, new ActionMessage("weblogEdit.changesSaved")); 98 saveMessages(request, uiMessages); 99 } 100 else 101 { 102 forward = mapping.findForward("access-denied"); 103 } 104 } 105 catch (RollerPermissionsException e) 106 { 107 errors.add(null, new ActionError("error.permissions.deniedSave")); 108 saveErrors(request, errors); 109 forward = mapping.findForward("access-denied"); 110 } 111 catch (RollerException e) 112 { 113 mLogger.error(e); 114 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError( 115 "error.update.rollerConfig",e.getClass().getName())); 116 saveErrors(request,errors); 117 } 118 return forward; 119 } 120 121 public ActionForward index( 122 ActionMapping mapping, 123 ActionForm actionForm, 124 HttpServletRequest request, 125 HttpServletResponse response) 126 throws Exception 127 { 128 ActionForward forward = mapping.findForward("rollerConfig.page"); 129 try { 130 RollerRequest rreq = RollerRequest.getRollerRequest(request); 132 IndexManager manager = rreq.getRoller().getIndexManager(); 133 134 manager.rebuildUserIndex(); 135 request.getSession().setAttribute( 136 RollerSession.STATUS_MESSAGE, 137 "Successfully scheduled rebuild of all users' indexes"); 138 139 RollerConfigData rollerConfig = RollerFactory.getRoller().getConfigManager().getRollerConfig(); 141 RollerConfigFormEx rcForm = (RollerConfigFormEx)actionForm; 142 rcForm.copyFrom(rollerConfig, request.getLocale()); 143 } 144 catch (Exception e) 145 { 146 mLogger.error("ERROR in action",e); 147 throw new ServletException (e); 148 } 149 return forward; 150 } 151 } | Popular Tags |