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