1 20 21 package com.methodhead.property; 22 23 import java.util.List ; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpServletResponse ; 27 28 import org.apache.struts.action.Action; 29 import org.apache.struts.action.ActionForm; 30 import org.apache.struts.action.ActionForward; 31 import org.apache.struts.action.ActionMapping; 32 import org.apache.struts.action.DynaActionForm; 33 import com.methodhead.sitecontext.SiteContext; 34 import com.methodhead.auth.AuthAction; 35 import com.methodhead.auth.AuthUser; 36 import com.methodhead.auth.AuthUtil; 37 import com.methodhead.util.OperationContext; 38 import com.methodhead.util.StrutsUtil; 39 40 102 public class PropertyAction 103 extends 104 AuthAction { 105 106 108 110 112 114 118 protected ActionForward doListProperties( 119 OperationContext op, 120 PropertyPolicy policy ) 121 throws 122 Exception { 123 124 String msg = policy.isListPropertiesAuthorized( op ); 128 if ( msg != null ) { 129 StrutsUtil.addMessage( op.request, msg, null, null, null ); 130 return op.mapping.findForward( "accessDenied" ); 131 } 132 133 op.form.set( "properties", Property.loadAll( SiteContext.getContext( op.request ) ) ); 134 135 return op.mapping.findForward( "list" ); 136 } 137 138 142 protected ActionForward doSetPropertyForm( 143 OperationContext op, 144 PropertyPolicy policy ) 145 throws 146 Exception { 147 148 String msg = policy.isSetPropertyFormAuthorized( op ); 152 if ( msg != null ) { 153 StrutsUtil.addMessage( op.request, msg, null, null, null ); 154 return op.mapping.findForward( "accessDenied" ); 155 } 156 157 Property p = new Property(); 158 p.setSiteContext( SiteContext.getContext( op.request ) ); 159 p.loadForName( ( String )op.form.get( "name" ) ); 160 161 op.form.set( "value", p.getString( "value" ) ); 162 op.form.set( "description", p.getString( "description" ) ); 163 op.form.set( "system", p.getBoolean( "system_property" ) ? "on" : "" ); 164 165 return new ActionForward( op.mapping.getInput() ); 166 } 167 168 172 protected ActionForward doSetProperty( 173 OperationContext op, 174 PropertyPolicy policy ) 175 throws 176 Exception { 177 178 String msg = policy.isSetPropertyAuthorized( op ); 182 if ( msg != null ) { 183 StrutsUtil.addMessage( op.request, msg, null, null, null ); 184 return op.mapping.findForward( "accessDenied" ); 185 } 186 187 Property.setProperty( 188 SiteContext.getContext( op.request ), 189 ( String )op.form.get( "name" ), 190 ( String )op.form.get( "value" ) ); 191 192 Property p = new Property(); 193 p.setSiteContext( SiteContext.getContext( op.request ) ); 194 p.loadForName( ( String )op.form.get( "name" ) ); 195 196 op.form.set( "value", p.getString( "value" ) ); 197 op.form.set( "description", p.getString( "description" ) ); 198 op.form.set( "system", p.getBoolean( "system_property" ) ? "on" : "" ); 199 200 return op.mapping.findForward( "saved" ); 201 } 202 203 public ActionForward doExecute( 204 ActionMapping mapping, 205 ActionForm form, 206 HttpServletRequest request, 207 HttpServletResponse response ) 208 throws 209 Exception { 210 211 DynaActionForm dynaForm = ( DynaActionForm )form; 215 PropertyPolicy policy = ( PropertyPolicy )StrutsUtil.getPolicy( mapping ); 216 AuthUser user = AuthUtil.getUser( request ); 217 218 OperationContext op = new OperationContext( mapping, dynaForm, request, response, user ); 219 220 if ( mapping.getPath().equals( "/listProperties" ) ) { 221 return doListProperties( op, policy ); 222 } 223 224 if ( mapping.getPath().equals( "/setPropertyForm" ) ) { 225 return doSetPropertyForm( op, policy ); 226 } 227 228 if ( mapping.getPath().equals( "/setProperty" ) ) { 229 return doSetProperty( op, policy ); 230 } 231 232 throw 233 new Exception ( "Unexpected mapping path \"" + mapping.getPath() + "\"" ); 234 } 235 236 238 } 240 | Popular Tags |