KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > shim > ViewPageAction


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.shim;
22
23 import org.apache.struts.action.Action;
24 import org.apache.struts.action.ActionMapping;
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.DynaActionForm;
27 import org.apache.struts.action.ActionForward;
28
29 import com.methodhead.auth.AuthAction;
30
31 import javax.servlet.RequestDispatcher JavaDoc;
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34 import com.methodhead.auth.AuthUser;
35 import com.methodhead.auth.AuthUtil;
36 import com.methodhead.sitecontext.SiteContext;
37 import com.methodhead.util.OperationContext;
38 import com.methodhead.util.StrutsUtil;
39 import com.methodhead.persistable.PersistableException;
40 import java.util.Iterator JavaDoc;
41 import com.methodhead.aikp.IntKey;
42
43 public class ViewPageAction
44 extends
45   Action {
46
47   // constructors /////////////////////////////////////////////////////////////
48

49   // constants ////////////////////////////////////////////////////////////////
50

51   // classes //////////////////////////////////////////////////////////////////
52

53   // methods //////////////////////////////////////////////////////////////////
54

55   /**
56    * Forwards to <code>form</code>.
57    */

58   protected ActionForward doEmptySite(
59     OperationContext op,
60     ShimPolicy policy )
61   throws
62     Exception JavaDoc {
63
64     return op.mapping.findForward( "form" );
65   }
66
67   /**
68    * Forwards to <code>form</code>.
69    */

70   protected ActionForward doPageNotFound(
71     OperationContext op,
72     ShimPolicy policy )
73   throws
74     Exception JavaDoc {
75
76     return op.mapping.findForward( "form" );
77   }
78
79   public ActionForward execute(
80     ActionMapping mapping,
81     ActionForm form,
82     HttpServletRequest JavaDoc request,
83     HttpServletResponse JavaDoc response )
84   throws
85     Exception JavaDoc {
86
87     //
88
// get some things we'll need
89
//
90
DynaActionForm dynaForm = ( DynaActionForm )form;
91     ShimPolicy policy = ( ShimPolicy )StrutsUtil.getPolicy( mapping );
92     AuthUser user = AuthUtil.getUser( request );
93
94     //
95
// mapping authorized?
96
//
97
if ( !policy.isMappingAuthorized( user, mapping.getPath() ) )
98       return mapping.findForward( "accessDenied" );
99
100     OperationContext op =
101       new OperationContext( mapping, dynaForm, request, response, user );
102
103     //
104
// execute the appopriate method
105
//
106
if ( mapping.getPath().equals( "/emptySite" ) ) {
107       return doEmptySite( op, policy );
108     }
109     if ( mapping.getPath().equals( "/pageNotFound" ) ) {
110       return doPageNotFound( op, policy );
111     }
112
113     throw
114       new Exception JavaDoc( "Unexpected mapping path \"" + mapping.getPath() + "\"" );
115   }
116
117   // properties ///////////////////////////////////////////////////////////////
118

119   // attributes ///////////////////////////////////////////////////////////////
120
}
121
Popular Tags