Coverage Report - org.kuali.rice.edl.impl.components.PageHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
PageHandler
0%
0/23
0%
0/10
2.5
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.edl.impl.components;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.apache.commons.lang.StringUtils;
 21  
 import org.kuali.rice.edl.impl.EDLContext;
 22  
 import org.kuali.rice.edl.impl.EDLModelComponent;
 23  
 import org.kuali.rice.edl.impl.EDLXmlUtils;
 24  
 import org.kuali.rice.edl.impl.RequestParser;
 25  
 import org.w3c.dom.Document;
 26  
 import org.w3c.dom.Element;
 27  
 
 28  
 
 29  
 /**
 30  
  * Handles setting the current page in the EDL XML.
 31  
  *
 32  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 33  
  *
 34  
  */
 35  0
 public class PageHandler implements EDLModelComponent {
 36  
 
 37  
         public static final String CURRENT_PAGE = "currentPage";
 38  
         public static final String PREVIOUS_PAGE = "previousPage";
 39  
         public static final String GOTO_PAGE = "edl.gotoPage";
 40  
         
 41  
         public void updateDOM(Document dom, Element configElement, EDLContext edlContext) {
 42  0
             String currentPage = edlContext.getRequestParser().getParameterValue("edl." + CURRENT_PAGE);
 43  0
             String previousPage = edlContext.getRequestParser().getParameterValue("edl." + PREVIOUS_PAGE);
 44  0
             String gotoPage = findGotoPage(edlContext.getRequestParser(), currentPage);
 45  0
             if (!StringUtils.isBlank(gotoPage)) {
 46  0
                 previousPage = currentPage;
 47  0
                 currentPage = gotoPage;
 48  
             }
 49  0
             establishCurrentPage(dom, currentPage);
 50  0
             establishPreviousPage(dom, previousPage);
 51  0
         }
 52  
         
 53  
         /**
 54  
          * Find parameter that looks like gotoPage:<pageName>
 55  
          */
 56  
         private String findGotoPage(RequestParser requestParser, String currentPage) {
 57  0
             List<String> parameterNames = requestParser.getParameterNames();
 58  0
             for (String parameterName : parameterNames) {
 59  0
                 if (parameterName.startsWith(GOTO_PAGE + ":")) {
 60  0
                     return parameterName.split(":")[1];
 61  
                 }
 62  
             }
 63  0
             return null;
 64  
         }
 65  
 
 66  
         private void establishCurrentPage(Document dom, String currentPage) {
 67  0
             if (!StringUtils.isBlank(currentPage)) {
 68  0
                 Element currentPageElement = EDLXmlUtils.getOrCreateChildElement(dom.getDocumentElement(), CURRENT_PAGE, true);
 69  0
                 currentPageElement.appendChild(dom.createTextNode(currentPage));
 70  
             }
 71  0
         }
 72  
         
 73  
 
 74  
         private void establishPreviousPage(Document dom, String previousPage) {
 75  0
             if (!StringUtils.isBlank(previousPage)) {
 76  0
                 Element previousPageElement = EDLXmlUtils.getOrCreateChildElement(dom.getDocumentElement(), PREVIOUS_PAGE, true);
 77  0
                 previousPageElement.appendChild(dom.createTextNode(previousPage));
 78  
             }
 79  0
         }
 80  
             
 81  
 
 82  
 }