01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.core.workflow;
17:
18: import java.util.Properties;
19:
20: import javax.xml.xpath.XPath;
21: import javax.xml.xpath.XPathFactory;
22:
23: import org.kuali.RiceConstants;
24: import org.kuali.RicePropertyConstants;
25: import org.kuali.core.util.UrlFactory;
26: import org.kuali.rice.KNSServiceLocator;
27: import org.w3c.dom.Document;
28:
29: import edu.iu.uis.eden.engine.RouteContext;
30: import edu.iu.uis.eden.routetemplate.xmlrouting.WorkflowFunctionResolver;
31: import edu.iu.uis.eden.routetemplate.xmlrouting.WorkflowNamespaceContext;
32:
33: public class WorkflowUtils {
34: private static final String XPATH_ROUTE_CONTEXT_KEY = "_xpathKey";
35: public static final String XSTREAM_SAFE_PREFIX = "wf:xstreamsafe('";
36: public static final String XSTREAM_SAFE_SUFFIX = "')";
37: public static final String XSTREAM_MATCH_ANYWHERE_PREFIX = "//";
38: public static final String XSTREAM_MATCH_RELATIVE_PREFIX = "./";
39:
40: /**
41: *
42: * This method sets up the XPath with the correct workflow namespace and resolver initialized. This ensures that the XPath
43: * statements can use required workflow functions as part of the XPath statements.
44: *
45: * @param document - document
46: * @return a fully initialized XPath instance that has access to the workflow resolver and namespace.
47: *
48: */
49: public final static XPath getXPath(Document document) {
50: XPath xpath = getXPath(RouteContext.getCurrentRouteContext());
51: xpath.setNamespaceContext(new WorkflowNamespaceContext());
52: WorkflowFunctionResolver resolver = new WorkflowFunctionResolver();
53: resolver.setXpath(xpath);
54: resolver.setRootNode(document);
55: xpath.setXPathFunctionResolver(resolver);
56: return xpath;
57: }
58:
59: public final static XPath getXPath(RouteContext routeContext) {
60: if (routeContext == null) {
61: return XPathFactory.newInstance().newXPath();
62: }
63: if (!routeContext.getParameters().containsKey(
64: XPATH_ROUTE_CONTEXT_KEY)) {
65: routeContext.getParameters().put(XPATH_ROUTE_CONTEXT_KEY,
66: XPathFactory.newInstance().newXPath());
67: }
68: return (XPath) routeContext.getParameters().get(
69: XPATH_ROUTE_CONTEXT_KEY);
70: }
71:
72: /**
73: * This method is for use by WorkflowLookupableImpl and WorkflowAttribute implementations to derive the fieldHelpUrl for use on
74: * edu.iu.uis.eden.lookupable.Fields.
75: *
76: * @param field The kuali field that we need to derive a help url for. @ return Returns the help url for the field.
77: */
78: public static String getHelpUrl(org.kuali.core.web.ui.Field field) {
79: Properties params = new Properties();
80: params.put(RiceConstants.DISPATCH_REQUEST_PARAMETER,
81: "getAttributeHelpText");
82: params.put(RiceConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, field
83: .getBusinessObjectClassName());
84: params.put(RicePropertyConstants.ATTRIBUTE_NAME, field
85: .getPropertyName());
86: return UrlFactory.parameterizeUrl(KNSServiceLocator
87: .getKualiConfigurationService().getPropertyString(
88: RiceConstants.APPLICATION_URL_KEY)
89: + "/kr/help.do", params);
90: }
91: }
|