1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
33
34
35
36
37
38
39
40
41
42 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 RequestParser requestParser = edlContext.getRequestParser();
50 this.edlContext = edlContext;
51
52
53 this.definitionElement = currentDefinitionElement;
54 Element configElementForDOM = getReplacementConfigElement(currentDefinitionElement);
55 if (configElementForDOM == null) {
56 configElementForDOM = currentDefinitionElement;
57 }
58
59 Element edlContentElement = EDLXmlUtils.getEDLContent(dom, false);
60 edlContentElement.appendChild(configElementForDOM);
61
62 Element currentVersion = VersioningPreprocessor.findCurrentVersion(dom);
63
64 List matchingParams = getMatchingParams(configElementForDOM, requestParser, edlContext);
65 for (Iterator iter = matchingParams.iterator(); iter.hasNext();) {
66 MatchingParam matchingParam = (MatchingParam) iter.next();
67 EDLXmlUtils.createFieldDataElement(currentVersion, matchingParam);
68 }
69 }
70
71 public Element getReplacementConfigElement(Element element) {
72 return null;
73 }
74
75 public List getMatchingParams(Element originalConfigElement, RequestParser requestParser, EDLContext edlContext) {
76 List params = new ArrayList();
77 String paramName = originalConfigElement.getAttribute("name");
78 String[] paramValues = requestParser.getParameterValues(paramName);
79 if (paramValues == null) {
80 return params;
81 }
82 for (int i = 0; i < paramValues.length; i++) {
83 String value = paramValues[i];
84 MatchingParam matchingParam = new MatchingParam();
85 matchingParam.setParamName(paramName);
86 matchingParam.setParamValue(value);
87 String errorMessage = getErrorMessage(originalConfigElement, requestParser, matchingParam);
88 if (errorMessage != null) {
89 matchingParam.setError(Boolean.TRUE);
90 matchingParam.setErrorMessage(errorMessage);
91 edlContext.setInError(true);
92 }
93 params.add(matchingParam);
94 }
95 return params;
96 }
97
98 public String getErrorMessage(Element originalConfigElement, RequestParser requestParser, MatchingParam matchingParam) {
99 return null;
100 }
101
102 public Element getDefinitionElement() {
103 return definitionElement;
104 }
105
106 public void setDefinitionElement(Element definitionElement) {
107 this.definitionElement = definitionElement;
108 }
109
110 public EDLContext getEdlContext() {
111 return edlContext;
112 }
113
114 public void setEdlContext(EDLContext edlContext) {
115 this.edlContext = edlContext;
116 }
117 }