001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.routing.web;
018:
019: import javax.servlet.http.HttpServletRequest;
020: import javax.servlet.http.HttpServletResponse;
021:
022: import org.apache.struts.action.ActionForm;
023: import org.apache.struts.action.ActionForward;
024: import org.apache.struts.action.ActionMapping;
025: import org.apache.struts.action.ActionMessages;
026:
027: import edu.iu.uis.eden.KEWServiceLocator;
028: import edu.iu.uis.eden.clientapp.IDocHandler;
029: import edu.iu.uis.eden.doctype.DocumentType;
030: import edu.iu.uis.eden.doctype.DocumentTypeService;
031: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
032: import edu.iu.uis.eden.routeheader.RouteHeaderService;
033: import edu.iu.uis.eden.web.WorkflowAction;
034:
035: /**
036: * A Struts Action for redirecting from the KEW web application to the appropriate
037: * Doc Handler for a document.
038: *
039: * @author rkirkend
040: */
041: public class ClientAppDocHandlerRedirectAction extends WorkflowAction {
042:
043: public ActionForward start(ActionMapping mapping, ActionForm form,
044: HttpServletRequest request, HttpServletResponse response)
045: throws Exception {
046: DocHandlerForm docHandlerForm = (DocHandlerForm) form;
047:
048: String docHandler = null;
049:
050: if (request.getParameter(IDocHandler.ROUTEHEADER_ID_PARAMETER) != null) {
051: RouteHeaderService rhSrv = (RouteHeaderService) KEWServiceLocator
052: .getService(KEWServiceLocator.DOC_ROUTE_HEADER_SRV);
053: DocumentRouteHeaderValue routeHeader = rhSrv
054: .getRouteHeader(docHandlerForm.getDocId());
055:
056: if (routeHeader.isLocked()) {
057: return mapping.findForward("documentLocked");
058: }
059:
060: docHandler = routeHeader.getDocumentType()
061: .getDocHandlerUrl();
062: if (docHandler.indexOf("?") == -1) {
063: docHandler += "?";
064: } else {
065: docHandler += "&";
066: }
067: docHandler += IDocHandler.ROUTEHEADER_ID_PARAMETER + "="
068: + docHandlerForm.getDocId();
069: } else if (request.getParameter(IDocHandler.DOCTYPE_PARAMETER) != null) {
070: DocumentTypeService documentTypeService = (DocumentTypeService) KEWServiceLocator
071: .getService(KEWServiceLocator.DOCUMENT_TYPE_SERVICE);
072: DocumentType documentType = documentTypeService
073: .findByName(docHandlerForm.getDocTypeName());
074: docHandler = documentType.getDocHandlerUrl();
075: if (docHandler.indexOf("?") == -1) {
076: docHandler += "?";
077: } else {
078: docHandler += "&";
079: }
080: docHandler += IDocHandler.DOCTYPE_PARAMETER + "="
081: + docHandlerForm.getDocTypeName();
082: } else {
083: //TODO what should happen here if parms are missing; no proper ActionForward from here
084: throw new RuntimeException(
085: "Cannot determine document handler");
086: }
087:
088: docHandler += "&" + IDocHandler.COMMAND_PARAMETER + "="
089: + docHandlerForm.getCommand();
090: if (getUserSession(request).isBackdoorInUse()) {
091: docHandler += "&" + IDocHandler.BACKDOOR_ID_PARAMETER + "="
092: + getUserSession(request).getNetworkId();
093: }
094: return new ActionForward(docHandler, true);
095: }
096:
097: public ActionMessages establishRequiredState(
098: HttpServletRequest request, ActionForm form)
099: throws Exception {
100: return null;
101: }
102: }
|