View Javadoc

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.ArrayList;
20  import java.util.Iterator;
21  import java.util.List;
22  
23  import org.kuali.rice.kew.edl.EDLContext;
24  import org.kuali.rice.kew.edl.EDLModelComponent;
25  import org.kuali.rice.kew.edl.EDLXmlUtils;
26  import org.kuali.rice.kew.edl.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  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  		RequestParser requestParser = edlContext.getRequestParser();
51  		this.edlContext = edlContext;
52  		
53  		
54  		this.definitionElement = currentDefinitionElement;
55  		Element configElementForDOM = getReplacementConfigElement(currentDefinitionElement);
56  		if (configElementForDOM == null) {
57  			configElementForDOM = currentDefinitionElement;
58  		}
59  
60  		Element edlContentElement = EDLXmlUtils.getEDLContent(dom, false);
61  		edlContentElement.appendChild(configElementForDOM);
62  		
63  		Element currentVersion = VersioningPreprocessor.findCurrentVersion(dom);
64  		
65  		List matchingParams = getMatchingParams(configElementForDOM, requestParser, edlContext);
66  		for (Iterator iter = matchingParams.iterator(); iter.hasNext();) {
67  			MatchingParam matchingParam = (MatchingParam) iter.next();
68  			EDLXmlUtils.createFieldDataElement(currentVersion, matchingParam);
69  		}
70  	}
71  	
72  	public Element getReplacementConfigElement(Element element) {
73  		return null;
74  	}
75  
76  	public List getMatchingParams(Element originalConfigElement, RequestParser requestParser, EDLContext edlContext) {
77  		List params = new ArrayList();
78  		String paramName = originalConfigElement.getAttribute("name");
79  		String[] paramValues = requestParser.getParameterValues(paramName);
80  		if (paramValues == null) {
81  			return params;
82  		}
83  		for (int i = 0; i < paramValues.length; i++) {
84  			String value = paramValues[i];
85  			MatchingParam matchingParam = new MatchingParam();
86  			matchingParam.setParamName(paramName);
87  			matchingParam.setParamValue(value);
88  			String errorMessage = getErrorMessage(originalConfigElement, requestParser, matchingParam);
89  			if (errorMessage != null) {
90  				matchingParam.setError(Boolean.TRUE);
91  				matchingParam.setErrorMessage(errorMessage);
92  				edlContext.setInError(true);
93  			}
94  			params.add(matchingParam);
95  		}
96  		return params;
97  	}
98  
99  	public String getErrorMessage(Element originalConfigElement, RequestParser requestParser, MatchingParam matchingParam) {
100 		return null;
101 	}
102 
103 	public Element getDefinitionElement() {
104 		return definitionElement;
105 	}
106 
107 	public void setDefinitionElement(Element definitionElement) {
108 		this.definitionElement = definitionElement;
109 	}
110 
111 	public EDLContext getEdlContext() {
112 		return edlContext;
113 	}
114 
115 	public void setEdlContext(EDLContext edlContext) {
116 		this.edlContext = edlContext;
117 	}
118 }