1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
34
35
36
37
38
39
40
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 }