001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.shim;
022:
023: import org.apache.struts.action.Action;
024: import org.apache.struts.action.ActionMapping;
025: import org.apache.struts.action.ActionForm;
026: import org.apache.struts.action.DynaActionForm;
027: import org.apache.struts.action.ActionForward;
028:
029: import com.methodhead.auth.AuthAction;
030:
031: import javax.servlet.RequestDispatcher;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034: import com.methodhead.auth.AuthUser;
035: import com.methodhead.auth.AuthUtil;
036: import com.methodhead.sitecontext.SiteContext;
037: import com.methodhead.util.OperationContext;
038: import com.methodhead.util.StrutsUtil;
039: import com.methodhead.persistable.PersistableException;
040: import java.util.Iterator;
041: import com.methodhead.aikp.IntKey;
042:
043: public class ViewPageAction extends Action {
044:
045: // constructors /////////////////////////////////////////////////////////////
046:
047: // constants ////////////////////////////////////////////////////////////////
048:
049: // classes //////////////////////////////////////////////////////////////////
050:
051: // methods //////////////////////////////////////////////////////////////////
052:
053: /**
054: * Forwards to <code>form</code>.
055: */
056: protected ActionForward doEmptySite(OperationContext op,
057: ShimPolicy policy) throws Exception {
058:
059: return op.mapping.findForward("form");
060: }
061:
062: /**
063: * Forwards to <code>form</code>.
064: */
065: protected ActionForward doPageNotFound(OperationContext op,
066: ShimPolicy policy) throws Exception {
067:
068: return op.mapping.findForward("form");
069: }
070:
071: public ActionForward execute(ActionMapping mapping,
072: ActionForm form, HttpServletRequest request,
073: HttpServletResponse response) throws Exception {
074:
075: //
076: // get some things we'll need
077: //
078: DynaActionForm dynaForm = (DynaActionForm) form;
079: ShimPolicy policy = (ShimPolicy) StrutsUtil.getPolicy(mapping);
080: AuthUser user = AuthUtil.getUser(request);
081:
082: //
083: // mapping authorized?
084: //
085: if (!policy.isMappingAuthorized(user, mapping.getPath()))
086: return mapping.findForward("accessDenied");
087:
088: OperationContext op = new OperationContext(mapping, dynaForm,
089: request, response, user);
090:
091: //
092: // execute the appopriate method
093: //
094: if (mapping.getPath().equals("/emptySite")) {
095: return doEmptySite(op, policy);
096: }
097: if (mapping.getPath().equals("/pageNotFound")) {
098: return doPageNotFound(op, policy);
099: }
100:
101: throw new Exception("Unexpected mapping path \""
102: + mapping.getPath() + "\"");
103: }
104:
105: // properties ///////////////////////////////////////////////////////////////
106:
107: // attributes ///////////////////////////////////////////////////////////////
108: }
|