Coverage Report - org.kuali.rice.edl.impl.components.SimpleWorkflowEDLConfigComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleWorkflowEDLConfigComponent
0%
0/41
0%
0/10
1.75
 
 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.ArrayList;
 19  
 import java.util.Iterator;
 20  
 import java.util.List;
 21  
 
 22  
 import org.kuali.rice.edl.impl.EDLContext;
 23  
 import org.kuali.rice.edl.impl.EDLModelComponent;
 24  
 import org.kuali.rice.edl.impl.EDLXmlUtils;
 25  
 import org.kuali.rice.edl.impl.RequestParser;
 26  
 import org.w3c.dom.Document;
 27  
 import org.w3c.dom.Element;
 28  
 
 29  
 
 30  
 
 31  
 /**
 32  
  * Matches request params to fields defined in edl configs.  Places matched value on the dom for rendering.  Places 
 33  
  * currentDefinitionElement definition ( the element used to get the param from the request) element on the
 34  
  * dom for rendering.
 35  
  * 
 36  
  * This is the base EDL Config Component for dealing with defined elements in an edl definition.  Most 
 37  
  * custom edl element behavior can be achieved by subclassing this.
 38  
  * 
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 40  
  *
 41  
  */
 42  0
 public class SimpleWorkflowEDLConfigComponent implements EDLModelComponent {
 43  
 
 44  
         protected Element definitionElement;
 45  
         private EDLContext edlContext;
 46  
 
 47  
         public void updateDOM(Document dom, Element currentDefinitionElement, EDLContext edlContext) {
 48  
 
 49  0
                 RequestParser requestParser = edlContext.getRequestParser();
 50  0
                 this.edlContext = edlContext;
 51  
                 
 52  
                 
 53  0
                 this.definitionElement = currentDefinitionElement;
 54  0
                 Element configElementForDOM = getReplacementConfigElement(currentDefinitionElement);
 55  0
                 if (configElementForDOM == null) {
 56  0
                         configElementForDOM = currentDefinitionElement;
 57  
                 }
 58  
 
 59  0
                 Element edlContentElement = EDLXmlUtils.getEDLContent(dom, false);
 60  0
                 edlContentElement.appendChild(configElementForDOM);
 61  
                 
 62  0
                 Element currentVersion = VersioningPreprocessor.findCurrentVersion(dom);
 63  
                 
 64  0
                 List matchingParams = getMatchingParams(configElementForDOM, requestParser, edlContext);
 65  0
                 for (Iterator iter = matchingParams.iterator(); iter.hasNext();) {
 66  0
                         MatchingParam matchingParam = (MatchingParam) iter.next();
 67  0
                         EDLXmlUtils.createFieldDataElement(currentVersion, matchingParam);
 68  0
                 }
 69  0
         }
 70  
         
 71  
         public Element getReplacementConfigElement(Element element) {
 72  0
                 return null;
 73  
         }
 74  
 
 75  
         public List getMatchingParams(Element originalConfigElement, RequestParser requestParser, EDLContext edlContext) {
 76  0
                 List params = new ArrayList();
 77  0
                 String paramName = originalConfigElement.getAttribute("name");
 78  0
                 String[] paramValues = requestParser.getParameterValues(paramName);
 79  0
                 if (paramValues == null) {
 80  0
                         return params;
 81  
                 }
 82  0
                 for (int i = 0; i < paramValues.length; i++) {
 83  0
                         String value = paramValues[i];
 84  0
                         MatchingParam matchingParam = new MatchingParam();
 85  0
                         matchingParam.setParamName(paramName);
 86  0
                         matchingParam.setParamValue(value);
 87  0
                         String errorMessage = getErrorMessage(originalConfigElement, requestParser, matchingParam);
 88  0
                         if (errorMessage != null) {
 89  0
                                 matchingParam.setError(Boolean.TRUE);
 90  0
                                 matchingParam.setErrorMessage(errorMessage);
 91  0
                                 edlContext.setInError(true);
 92  
                         }
 93  0
                         params.add(matchingParam);
 94  
                 }
 95  0
                 return params;
 96  
         }
 97  
 
 98  
         public String getErrorMessage(Element originalConfigElement, RequestParser requestParser, MatchingParam matchingParam) {
 99  0
                 return null;
 100  
         }
 101  
 
 102  
         public Element getDefinitionElement() {
 103  0
                 return definitionElement;
 104  
         }
 105  
 
 106  
         public void setDefinitionElement(Element definitionElement) {
 107  0
                 this.definitionElement = definitionElement;
 108  0
         }
 109  
 
 110  
         public EDLContext getEdlContext() {
 111  0
                 return edlContext;
 112  
         }
 113  
 
 114  
         public void setEdlContext(EDLContext edlContext) {
 115  0
                 this.edlContext = edlContext;
 116  0
         }
 117  
 }