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.edl;
018:
019: import java.io.IOException;
020:
021: import javax.servlet.RequestDispatcher;
022: import javax.servlet.ServletException;
023: import javax.servlet.http.HttpServlet;
024: import javax.servlet.http.HttpServletRequest;
025: import javax.servlet.http.HttpServletResponse;
026:
027: import org.apache.log4j.Logger;
028:
029: import edu.iu.uis.eden.KEWServiceLocator;
030: import edu.iu.uis.eden.exception.WorkflowRuntimeException;
031:
032: /**
033: * Takes edl web requests.
034: *
035: * @author rkirkend
036: *
037: */
038: public class EDLServlet extends HttpServlet {
039:
040: private static final long serialVersionUID = -6344765194278430690L;
041:
042: private static final Logger LOG = Logger
043: .getLogger(EDLServlet.class);
044:
045: public void init() throws ServletException {
046: try {
047: KEWServiceLocator.getEDocLiteService()
048: .initEDLGlobalConfig();
049: } catch (Exception e) {
050: LOG.error("Error initializing EDL", e);
051: }
052:
053: }
054:
055: protected void service(HttpServletRequest request,
056: HttpServletResponse response) throws ServletException,
057: IOException {
058:
059: try {
060: RequestParser requestParser = new RequestParser(request);
061: String edlName = requestParser.getParameterValue("edlName");
062: if (edlName == null) {
063: edlName = requestParser
064: .getParameterValue("docTypeName");//this is for 'WorkflowQuicklinks'
065: }
066: EDLController edlController = null;
067: if (edlName == null) {
068: String documentId = requestParser
069: .getParameterValue("docId");
070: if (documentId == null) {
071: throw new WorkflowRuntimeException(
072: "No edl name or document id detected");
073: }
074: edlController = KEWServiceLocator.getEDocLiteService()
075: .getEDLController(new Long(documentId));
076: } else {
077: edlController = KEWServiceLocator.getEDocLiteService()
078: .getEDLController(edlName);
079: }
080:
081: EDLControllerChain controllerChain = new EDLControllerChain();
082: controllerChain.addEdlController(edlController);
083: response.setContentType("text/html; charset=UTF-8");
084: controllerChain.renderEDL(requestParser, response);
085: } catch (Exception e) {
086: LOG.error("Error processing EDL", e);
087: outputError(request, response, e);
088: }
089: }
090:
091: private void outputError(HttpServletRequest request,
092: HttpServletResponse response, Exception e)
093: throws ServletException, IOException {
094: request.setAttribute("WORKFLOW_ERROR", e);
095: RequestDispatcher rd = getServletContext()
096: .getRequestDispatcher("/Error.do");
097: rd.forward(request, response);
098: }
099:
100: }
|