1 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 import com.methodhead.util.StrutsUtil; 29 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 33 import com.methodhead.auth.AuthUtil; 34 import com.methodhead.auth.AuthUser; 35 import com.methodhead.auth.AuthAction; 36 import com.methodhead.util.OperationContext; 37 import com.methodhead.tree.FoldingTreeNode; 38 import com.methodhead.sitecontext.SiteContext; 39 import com.methodhead.aikp.IntKey; 40 import com.methodhead.event.Event; 41 import org.apache.commons.lang.StringUtils; 42 43 public class HomeAction 44 extends 45 AuthAction { 46 47 49 51 53 55 58 protected ActionForward doHome( 59 OperationContext op, 60 Object policy ) 61 throws 62 Exception { 63 64 String msg = ( ( ShimPolicy )policy ).isHomeAuthorized( op ); 65 if ( msg != null ) { 66 StrutsUtil.addMessage( op.request, msg, null, null, null ); 67 return op.mapping.findForward( "accessDenied" ); 68 } 69 70 if ( SiteContext.getContext( op.request ) != null ) { 74 SiteMap siteMap = ShimUtils.getSiteMap( op.request ); 75 Link root = ( Link )siteMap.getRoot(); 76 if ( root != null ) { 77 return new ActionForward( "/editPage.do?id=" + root.getPageId() ); 78 } 79 } 80 81 return op.mapping.findForward( "form" ); 82 } 83 84 87 protected ActionForward doSiteMap( 88 OperationContext op, 89 Object policy ) 90 throws 91 Exception { 92 93 String msg = ( ( ShimPolicy )policy ).isSiteMapAuthorized( op ); 94 if ( msg != null ) { 95 StrutsUtil.addMessage( op.request, msg, null, null, null ); 96 return op.mapping.findForward( "accessDenied" ); 97 } 98 99 return op.mapping.findForward( "form" ); 100 } 101 102 protected ActionForward doLink( 103 OperationContext op, 104 Object policy ) 105 throws 106 Exception { 107 108 String msg = ( ( ShimPolicy )policy ).isLinkAuthorized( op ); 109 if ( msg != null ) { 110 StrutsUtil.addMessage( op.request, msg, null, null, null ); 111 return op.mapping.findForward( "accessDenied" ); 112 } 113 114 FoldingTreeNode root = 115 ( FoldingTreeNode )ShimUtils.getSiteMapTree( op.request ).getRoot(); 116 117 if ( !StringUtils.isBlank( ( String )op.form.get( "open" ) ) ) 118 root.openNode( Integer.parseInt( ( String )op.form.get( "open" ) ) ); 119 if ( !StringUtils.isBlank( ( String )op.form.get( "close" ) ) ) 120 root.closeNode( Integer.parseInt( ( String )op.form.get( "close" ) ) ); 121 122 return new ActionForward( "/siteMap.do" ); 123 } 124 125 protected ActionForward doSwitch( 126 OperationContext op, 127 Object policy ) 128 throws 129 Exception { 130 131 String msg = ( ( ShimPolicy )policy ).isSwitchAuthorized( op ); 132 if ( msg != null ) { 133 StrutsUtil.addMessage( op.request, msg, null, null, null ); 134 return op.mapping.findForward( "accessDenied" ); 135 } 136 137 ShimUtils.tearDownShimSession( op.request ); 138 139 SiteContext siteContext = new SiteContext(); 140 siteContext.load( new IntKey( op.form.get( "id" ) ) ); 141 142 ShimUtils.setUpShimSession( op.request, siteContext ); 143 144 Event.log( 145 null, 146 op.user.getLogin(), 147 "shim", 148 "Switched to site \"" + siteContext.getDomains().get( 0 ) + "\"" ); 149 150 return new ActionForward( "/home.do" ); 151 } 152 153 public ActionForward doExecute( 154 ActionMapping mapping, 155 ActionForm form, 156 HttpServletRequest request, 157 HttpServletResponse response ) 158 throws 159 Exception { 160 161 Object policy = StrutsUtil.getPolicy( mapping ); 165 166 DynaActionForm dynaForm = ( DynaActionForm )form; 167 AuthUser user = AuthUtil.getUser( request ); 168 169 OperationContext op = 170 new OperationContext( mapping, dynaForm, request, response, user ); 171 172 if ( mapping.getPath().equals( "/home" ) ) { 176 return doHome( op, policy ); 177 } 178 if ( mapping.getPath().equals( "/link" ) ) { 179 return doLink( op, policy ); 180 } 181 if ( mapping.getPath().equals( "/switch" ) ) { 182 return doSwitch( op, policy ); 183 } 184 if ( mapping.getPath().equals( "/siteMap" ) ) { 185 return doSiteMap( op, policy ); 186 } 187 188 throw 189 new Exception ( "Unexpected mapping path \"" + mapping.getPath() + "\"" ); 190 } 191 192 194 } 196 | Popular Tags |