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