1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.workflow;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Properties;
22
23 import javax.xml.xpath.XPath;
24 import javax.xml.xpath.XPathExpressionException;
25 import javax.xml.xpath.XPathFactory;
26
27 import org.apache.commons.lang.StringUtils;
28 import org.kuali.rice.kew.engine.RouteContext;
29 import org.kuali.rice.kew.rule.xmlrouting.WorkflowFunctionResolver;
30 import org.kuali.rice.kew.rule.xmlrouting.WorkflowNamespaceContext;
31 import org.kuali.rice.kns.util.FieldUtils;
32 import org.kuali.rice.kns.web.ui.Field;
33 import org.kuali.rice.kns.web.ui.Row;
34 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
35 import org.kuali.rice.krad.util.KRADConstants;
36 import org.kuali.rice.krad.util.KRADPropertyConstants;
37 import org.kuali.rice.krad.util.UrlFactory;
38 import org.w3c.dom.Document;
39
40
41
42
43
44
45 @Deprecated
46 public final class WorkflowUtils {
47 private static final String XPATH_ROUTE_CONTEXT_KEY = "_xpathKey";
48 public static final String XSTREAM_SAFE_PREFIX = "wf:xstreamsafe('";
49 public static final String XSTREAM_SAFE_SUFFIX = "')";
50 public static final String XSTREAM_MATCH_ANYWHERE_PREFIX = "//";
51 public static final String XSTREAM_MATCH_RELATIVE_PREFIX = "./";
52
53 private WorkflowUtils() {
54 throw new UnsupportedOperationException("do not call");
55 }
56
57
58
59
60
61
62
63
64
65
66 public final static XPath getXPath(Document document) {
67 XPath xpath = getXPath(RouteContext.getCurrentRouteContext());
68 xpath.setNamespaceContext(new WorkflowNamespaceContext());
69 WorkflowFunctionResolver resolver = new WorkflowFunctionResolver();
70 resolver.setXpath(xpath);
71 resolver.setRootNode(document);
72 xpath.setXPathFunctionResolver(resolver);
73 return xpath;
74 }
75
76 public final static XPath getXPath(RouteContext routeContext) {
77 if (routeContext == null) {
78 return XPathFactory.newInstance().newXPath();
79 }
80 if (!routeContext.getParameters().containsKey(XPATH_ROUTE_CONTEXT_KEY)) {
81 routeContext.getParameters().put(XPATH_ROUTE_CONTEXT_KEY, XPathFactory.newInstance().newXPath());
82 }
83 return (XPath) routeContext.getParameters().get(XPATH_ROUTE_CONTEXT_KEY);
84 }
85
86
87
88
89
90
91
92
93
94
95
96 public static final String xstreamSafeEval(XPath xpath, String xpathExpression, Object item) {
97 String xstreamSafeXPath = xstreamSafeXPath(xpathExpression);
98 String evalResult = "";
99 try {
100 evalResult = xpath.evaluate(xstreamSafeXPath, item);
101 }
102 catch (XPathExpressionException e) {
103 throw new RuntimeException("XPathExpressionException occurred on xpath: " + xstreamSafeXPath, e);
104 }
105 return evalResult;
106 }
107
108
109
110
111
112
113
114
115 public static final String xstreamSafeXPath(String xpathExpression) {
116 return new StringBuilder(XSTREAM_SAFE_PREFIX).append(xpathExpression).append(XSTREAM_SAFE_SUFFIX).toString();
117 }
118
119
120
121
122
123
124
125
126 public static final String getBusinessObjectAttributeLabel(Class businessObjectClass, String attributeName) {
127 return KRADServiceLocatorWeb.getDataDictionaryService().getAttributeLabel(businessObjectClass, attributeName);
128 }
129
130
131
132
133
134
135
136
137
138
139
140
141
142 public static Row buildTextRow(Class propertyClass, String boPropertyName, String workflowPropertyKey) {
143 if (propertyClass == null) {
144 throw new IllegalArgumentException("Method parameter 'propertyClass' was passed a NULL value.");
145 }
146 if (StringUtils.isBlank(boPropertyName)) {
147 throw new IllegalArgumentException("Method parameter 'boPropertyName' was passed a NULL or blank value.");
148 }
149 if (StringUtils.isBlank(workflowPropertyKey)) {
150 throw new IllegalArgumentException("Method parameter 'workflowPropertyKey' was passed a NULL or blank value.");
151 }
152 List<Field> fields = new ArrayList<Field>();
153 Field field;
154 field = FieldUtils.getPropertyField(propertyClass, boPropertyName, false);
155 fields.add(field);
156 return new Row(fields);
157 }
158
159
160
161
162
163
164
165
166
167
168
169
170 public static Row buildTextRowWithLookup(Class propertyClass, String boPropertyName, String workflowPropertyKey) {
171 return buildTextRowWithLookup(propertyClass, boPropertyName, workflowPropertyKey, null);
172 }
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187 public static Row buildTextRowWithLookup(Class propertyClass, String boPropertyName, String workflowPropertyKey, Map fieldConversionsByBoPropertyName) {
188 if (propertyClass == null) {
189 throw new IllegalArgumentException("Method parameter 'propertyClass' was passed a NULL value.");
190 }
191 if (StringUtils.isBlank(boPropertyName)) {
192 throw new IllegalArgumentException("Method parameter 'boPropertyName' was passed a NULL or blank value.");
193 }
194 if (StringUtils.isBlank(workflowPropertyKey)) {
195 throw new IllegalArgumentException("Method parameter 'workflowPropertyKey' was passed a NULL or blank value.");
196 }
197 Field field;
198 field = FieldUtils.getPropertyField(propertyClass, boPropertyName, false);
199
200 List<Field> fields = new ArrayList<Field>();
201 fields.add(field);
202 return new Row(fields);
203 }
204
205
206
207
208
209
210
211
212
213
214
215
216
217 public static Row buildDropdownRow(Class propertyClass, String boPropertyName, String workflowPropertyKey, Map<String, String> optionMap, boolean addBlankRow) {
218 if (propertyClass == null) {
219 throw new IllegalArgumentException("Method parameter 'propertyClass' was passed a NULL value.");
220 }
221 if (StringUtils.isBlank(boPropertyName)) {
222 throw new IllegalArgumentException("Method parameter 'boPropertyName' was passed a NULL or blank value.");
223 }
224 if (StringUtils.isBlank(workflowPropertyKey)) {
225 throw new IllegalArgumentException("Method parameter 'workflowPropertyKey' was passed a NULL or blank value.");
226 }
227 if (optionMap == null) {
228 throw new IllegalArgumentException("Method parameter 'optionMap' was passed a NULL value.");
229 }
230 List<Field> fields = new ArrayList<Field>();
231 Field field;
232 field = FieldUtils.getPropertyField(propertyClass, boPropertyName, false);
233 fields.add(field);
234 return new Row(fields);
235 }
236 }