1 20 21 package com.methodhead.event; 22 23 import java.util.List ; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpServletResponse ; 27 28 import org.apache.log4j.Logger; 29 30 import org.apache.struts.action.Action; 31 import org.apache.struts.action.ActionForm; 32 import org.apache.struts.action.ActionForward; 33 import org.apache.struts.action.ActionMapping; 34 import org.apache.struts.action.DynaActionForm; 35 import com.methodhead.sitecontext.SiteContext; 36 import com.methodhead.property.Property; 37 import com.methodhead.util.OperationContext; 38 import com.methodhead.util.StrutsUtil; 39 import com.methodhead.auth.AuthUser; 40 import com.methodhead.auth.AuthAction; 41 import com.methodhead.auth.AuthUtil; 42 import com.methodhead.test.TestUtils; 43 import java.util.Date ; 44 import java.text.DateFormat ; 45 import java.text.ParseException ; 46 import java.util.Calendar ; 47 import java.util.GregorianCalendar ; 48 import org.apache.commons.lang.StringUtils; 49 50 51 95 public class EventAction 96 extends 97 AuthAction { 98 99 101 103 105 107 public ActionForward doListEvents( 108 OperationContext op, 109 EventPolicy policy ) 110 throws 111 Exception { 112 113 String msg = policy.isListEventsAuthorized( op ); 117 if ( msg != null ) { 118 StrutsUtil.addMessage( op.request, msg, null, null, null ); 119 return op.mapping.findForward( "accessDenied" ); 120 } 121 122 Date start = TestUtils.getCurrentDate(); 123 Date end = null; 124 DateFormat format = DateFormat.getDateInstance( DateFormat.SHORT ); 125 126 if ( !StringUtils.isBlank( ( String )op.form.get( "date" ) ) ) { 130 try { 131 start = format.parse( ( String )op.form.get( "date" ) ); 132 } 133 catch ( ParseException e ) { 134 Logger.getLogger( "EventAction" ).error( 135 "Couldn't parse page from \"" + op.form.get( "page" ) + "\"" ); 136 } 137 } 138 139 Calendar cal = new GregorianCalendar (); 143 cal.setTime( start ); 144 145 cal.set( Calendar.HOUR_OF_DAY, 0 ); 146 cal.set( Calendar.MINUTE, 0 ); 147 cal.set( Calendar.SECOND, 0 ); 148 cal.set( Calendar.MILLISECOND, 0 ); 149 start = cal.getTime(); 150 151 cal.add( Calendar.DAY_OF_MONTH, 1 ); 152 end = cal.getTime(); 153 154 Event event = new Event(); 158 event.setSiteContext( SiteContext.getContext( op.request ) ); 159 op.form.set( "events", event.getEvents( start, end ) ); 160 161 op.form.set( "date", format.format( start ) ); 165 op.form.set( "next", format.format( end ) ); 166 167 cal.add( Calendar.DAY_OF_MONTH, -2 ); 168 op.form.set( "prev", format.format( cal.getTime() ) ); 169 170 return op.mapping.findForward( "list" ); 174 } 175 176 public ActionForward doExecute( 177 ActionMapping mapping, 178 ActionForm form, 179 HttpServletRequest request, 180 HttpServletResponse response ) 181 throws 182 Exception { 183 184 DynaActionForm dynaForm = ( DynaActionForm )form; 188 EventPolicy policy = ( EventPolicy )StrutsUtil.getPolicy( mapping ); 189 AuthUser user = AuthUtil.getUser( request ); 190 OperationContext op = new OperationContext( mapping, dynaForm, request, response, user ); 191 192 if ( mapping.getPath().equals( "/listEvents" ) ) 193 return doListEvents( op, policy ); 194 195 throw 196 new Exception ( "Unexpected mapping path \"" + mapping.getPath() + "\"" ); 197 } 198 199 201 } 203 | Popular Tags |