Coverage Report - org.kuali.rice.kew.edl.components.PageHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
PageHandler
0%
0/23
0%
0/10
2.5
 
 1  
 /*
 2  
  * Copyright 2005-2008 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.kew.edl.components;
 18  
 
 19  
 import java.util.List;
 20  
 
 21  
 import org.apache.commons.lang.StringUtils;
 22  
 import org.kuali.rice.kew.edl.EDLContext;
 23  
 import org.kuali.rice.kew.edl.EDLModelComponent;
 24  
 import org.kuali.rice.kew.edl.EDLXmlUtils;
 25  
 import org.kuali.rice.kew.edl.RequestParser;
 26  
 import org.w3c.dom.Document;
 27  
 import org.w3c.dom.Element;
 28  
 
 29  
 
 30  
 /**
 31  
  * Handles setting the current page in the EDL XML.
 32  
  *
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  *
 35  
  */
 36  0
 public class PageHandler implements EDLModelComponent {
 37  
 
 38  
         public static final String CURRENT_PAGE = "currentPage";
 39  
         public static final String PREVIOUS_PAGE = "previousPage";
 40  
         public static final String GOTO_PAGE = "edl.gotoPage";
 41  
         
 42  
         public void updateDOM(Document dom, Element configElement, EDLContext edlContext) {
 43  0
             String currentPage = edlContext.getRequestParser().getParameterValue("edl." + CURRENT_PAGE);
 44  0
             String previousPage = edlContext.getRequestParser().getParameterValue("edl." + PREVIOUS_PAGE);
 45  0
             String gotoPage = findGotoPage(edlContext.getRequestParser(), currentPage);
 46  0
             if (!StringUtils.isBlank(gotoPage)) {
 47  0
                 previousPage = currentPage;
 48  0
                 currentPage = gotoPage;
 49  
             }
 50  0
             establishCurrentPage(dom, currentPage);
 51  0
             establishPreviousPage(dom, previousPage);
 52  0
         }
 53  
         
 54  
         /**
 55  
          * Find parameter that looks like gotoPage:<pageName>
 56  
          */
 57  
         private String findGotoPage(RequestParser requestParser, String currentPage) {
 58  0
             List<String> parameterNames = requestParser.getParameterNames();
 59  0
             for (String parameterName : parameterNames) {
 60  0
                 if (parameterName.startsWith(GOTO_PAGE + ":")) {
 61  0
                     return parameterName.split(":")[1];
 62  
                 }
 63  
             }
 64  0
             return null;
 65  
         }
 66  
 
 67  
         private void establishCurrentPage(Document dom, String currentPage) {
 68  0
             if (!StringUtils.isBlank(currentPage)) {
 69  0
                 Element currentPageElement = EDLXmlUtils.getOrCreateChildElement(dom.getDocumentElement(), CURRENT_PAGE, true);
 70  0
                 currentPageElement.appendChild(dom.createTextNode(currentPage));
 71  
             }
 72  0
         }
 73  
         
 74  
 
 75  
         private void establishPreviousPage(Document dom, String previousPage) {
 76  0
             if (!StringUtils.isBlank(previousPage)) {
 77  0
                 Element previousPageElement = EDLXmlUtils.getOrCreateChildElement(dom.getDocumentElement(), PREVIOUS_PAGE, true);
 78  0
                 previousPageElement.appendChild(dom.createTextNode(previousPage));
 79  
             }
 80  0
         }
 81  
             
 82  
 
 83  
 }