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