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