1 6 7 package org.roller.presentation.website.actions; 8 9 import java.io.IOException ; 10 import java.util.Iterator ; 11 import java.util.Map ; 12 import javax.servlet.ServletException ; 13 import javax.servlet.http.HttpServletRequest ; 14 import javax.servlet.http.HttpServletResponse ; 15 import org.apache.commons.logging.Log; 16 import org.apache.commons.logging.LogFactory; 17 import org.apache.struts.action.ActionError; 18 import org.apache.struts.action.ActionErrors; 19 import org.apache.struts.action.ActionForm; 20 import org.apache.struts.action.ActionForward; 21 import org.apache.struts.action.ActionMapping; 22 import org.apache.struts.action.ActionMessage; 23 import org.apache.struts.action.ActionMessages; 24 import org.apache.struts.actions.DispatchAction; 25 import org.roller.RollerException; 26 import org.roller.RollerPermissionsException; 27 import org.roller.model.PropertiesManager; 28 import org.roller.model.Roller; 29 import org.roller.model.RollerFactory; 30 import org.roller.pojos.RollerPropertyData; 31 import org.roller.presentation.RollerRequest; 32 33 34 35 46 public class RollerPropertiesAction extends DispatchAction { 47 48 private static Log mLogger = 49 LogFactory.getFactory().getInstance(RollerPropertiesAction.class); 50 51 52 public ActionForward unspecified( 53 ActionMapping mapping, 54 ActionForm actionForm, 55 HttpServletRequest request, 56 HttpServletResponse response) 57 throws IOException , ServletException { 58 59 return this.edit(mapping, actionForm, request, response); 61 } 62 63 64 public ActionForward edit( 65 ActionMapping mapping, 66 ActionForm actionForm, 67 HttpServletRequest request, 68 HttpServletResponse response) 69 throws IOException , ServletException { 70 71 mLogger.debug("Handling edit request"); 72 73 ActionForward forward = mapping.findForward("rollerProperties.page"); 74 try { 75 RollerRequest rreq = RollerRequest.getRollerRequest(request); 76 if ( rreq.isUserAuthorizedToEdit() && rreq.isAdminUser() ) { 77 78 Roller mRoller = RollerFactory.getRoller(); 80 PropertiesManager propsManager = mRoller.getPropertiesManager(); 81 Map props = propsManager.getProperties(); 82 request.setAttribute("RollerProps", props); 83 84 } else { 85 forward = mapping.findForward("access-denied"); 86 } 87 } catch (Exception e) { 88 mLogger.error("ERROR in action",e); 89 throw new ServletException (e); 90 } 91 return forward; 92 } 93 94 95 public ActionForward update( 96 ActionMapping mapping, 97 ActionForm actionForm, 98 HttpServletRequest request, 99 HttpServletResponse response) 100 throws IOException , ServletException { 101 102 mLogger.debug("Handling update request"); 103 104 ActionForward forward = mapping.findForward("rollerProperties.page"); 105 ActionErrors errors = new ActionErrors(); 106 try { 107 RollerRequest rreq = RollerRequest.getRollerRequest(request); 108 if ( rreq.isUserAuthorizedToEdit() && rreq.isAdminUser() ) { 109 110 Roller mRoller = RollerFactory.getRoller(); 112 PropertiesManager propsManager = mRoller.getPropertiesManager(); 113 Map props = propsManager.getProperties(); 114 request.setAttribute("RollerProps", props); 115 116 String propName = null; 118 RollerPropertyData updProp = null; 119 String incomingProp = null; 120 Iterator propsIT = props.keySet().iterator(); 121 while(propsIT.hasNext()) { 122 propName = (String ) propsIT.next(); 123 updProp = (RollerPropertyData) props.get(propName); 124 incomingProp = request.getParameter(updProp.getName()); 125 126 mLogger.debug("Checking property ["+propName+"]"); 127 128 if(updProp.getValue().equals("true") || 133 updProp.getValue().equals("false")) { 134 135 if(incomingProp == null || !incomingProp.equals("on")) 136 incomingProp = "false"; 137 else 138 incomingProp = "true"; 139 } 140 141 if(incomingProp != null) { 143 mLogger.debug("Setting new value for ["+propName+"]"); 144 145 updProp.setValue(incomingProp.trim()); 147 } 148 } 149 150 propsManager.store(props); 152 mRoller.getRefererManager().applyRefererFilters(); 153 mRoller.commit(); 154 155 ActionMessages uiMessages = new ActionMessages(); 156 uiMessages.add(null, new ActionMessage("weblogEdit.changesSaved")); 157 saveMessages(request, uiMessages); 158 159 } else { 160 forward = mapping.findForward("access-denied"); 161 } 162 163 } catch (RollerPermissionsException e) { 164 errors.add(null, new ActionError("error.permissions.deniedSave")); 165 saveErrors(request, errors); 166 forward = mapping.findForward("access-denied"); 167 168 } catch (RollerException e) { 169 mLogger.error(e); 170 errors.add(ActionErrors.GLOBAL_ERROR, new ActionError( 171 "error.update.rollerConfig",e.getClass().getName())); 172 saveErrors(request,errors); 173 } 174 175 return forward; 176 } 177 178 } 179 | Popular Tags |