Coverage Report - org.kuali.rice.edl.impl.EDLControllerChain
 
Classes in this File Line Coverage Branch Coverage Complexity
EDLControllerChain
0%
0/39
0%
0/12
2.75
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.kuali.rice.edl.impl;
 18  
 
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.apache.log4j.Logger;
 21  
 import org.kuali.rice.core.util.xml.XmlJotter;
 22  
 import org.kuali.rice.kim.bo.Person;
 23  
 import org.kuali.rice.krad.util.GlobalVariables;
 24  
 import org.w3c.dom.Document;
 25  
 
 26  
 import javax.servlet.http.HttpServletResponse;
 27  
 import javax.xml.transform.OutputKeys;
 28  
 import javax.xml.transform.Transformer;
 29  
 import javax.xml.transform.dom.DOMSource;
 30  
 import javax.xml.transform.stream.StreamResult;
 31  
 import java.util.Stack;
 32  
 
 33  
 
 34  
 /**
 35  
  * Contains a stack of EDLControllers.  Allows EDL components to add new controllers to the chain runtime.  The idea
 36  
  * being that this is how you would page between edls.  Uses the template associated with the last edl controller
 37  
  * to render the dom of the last edl controller.
 38  
  *
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  *
 41  
  */
 42  0
 public class EDLControllerChain {
 43  
 
 44  0
         private static final Logger LOG = Logger.getLogger(EDLControllerChain.class);
 45  
 
 46  0
         private Stack<EDLController> edlControllers = new Stack<EDLController>();
 47  
 
 48  
         public void renderEDL(RequestParser requestParser, HttpServletResponse response) throws Exception {
 49  0
                 EDLController edlController = edlControllers.pop();
 50  0
                 edlController.setEdlContext(getInitialEDLContext(edlController, requestParser, edlController.getStyle().newTransformer()));
 51  
 
 52  0
                 Document dom = edlController.notifyComponents();
 53  0
                 if (edlControllers.isEmpty()) {
 54  0
                         transform(edlController.getEdlContext(), dom, response);
 55  
                 } else {
 56  0
                         renderEDL(requestParser, response);
 57  
                 }
 58  0
         }
 59  
 
 60  
         public void addEdlController(EDLController edlController) {
 61  0
                 edlControllers.add(edlController);
 62  0
         }
 63  
 
 64  
         private void transform(EDLContext edlContext, Document dom, HttpServletResponse response) throws Exception {
 65  0
                 if (StringUtils.isNotBlank(edlContext.getRedirectUrl())) {
 66  0
                         response.sendRedirect(edlContext.getRedirectUrl());
 67  0
                         return;
 68  
                 }
 69  0
             response.setContentType("text/html; charset=UTF-8");
 70  0
                 Transformer transformer = edlContext.getTransformer();
 71  
 
 72  0
         transformer.setOutputProperty("indent", "yes");
 73  0
         transformer.setOutputProperty(OutputKeys.INDENT, "yes");
 74  0
         String user = null;
 75  0
         String loggedInUser = null;
 76  0
         if (edlContext.getUserSession() != null) {
 77  0
             Person wu = edlContext.getUserSession().getPerson();
 78  0
             if (wu != null) user = wu.getPrincipalId();
 79  0
             wu = edlContext.getUserSession().getPerson();
 80  0
             if (wu != null) loggedInUser = wu.getPrincipalId();
 81  
         }
 82  0
         transformer.setParameter("user", user);
 83  0
         transformer.setParameter("loggedInUser", loggedInUser);
 84  0
         if (LOG.isDebugEnabled()) {
 85  0
                 LOG.debug("Transforming dom " + XmlJotter.jotNode(dom, true));
 86  
         }
 87  0
         transformer.transform(new DOMSource(dom), new StreamResult(response.getOutputStream()));
 88  0
         }
 89  
 
 90  
         private EDLContext getInitialEDLContext(EDLController edlController, RequestParser requestParser, Transformer transformer) {
 91  0
                 EDLContext edlContext = new EDLContext();
 92  0
                 edlContext.setEdlControllerChain(this);
 93  0
                 edlContext.setEdocLiteAssociation(edlController.getEdocLiteAssociation());
 94  0
                 edlContext.setUserSession(GlobalVariables.getUserSession());
 95  0
                 edlContext.setTransformer(transformer);
 96  0
                 edlContext.setRequestParser(requestParser);
 97  0
                 return edlContext;
 98  
         }
 99  
 
 100  
 }