1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.engine.node.var; |
18 | |
|
19 | |
import java.io.StringReader; |
20 | |
|
21 | |
import javax.xml.parsers.DocumentBuilder; |
22 | |
import javax.xml.parsers.DocumentBuilderFactory; |
23 | |
|
24 | |
import org.apache.log4j.Logger; |
25 | |
import org.kuali.rice.kew.engine.RouteContext; |
26 | |
import org.kuali.rice.kew.engine.RouteHelper; |
27 | |
import org.kuali.rice.kew.engine.node.BranchState; |
28 | |
import org.kuali.rice.kew.engine.node.PropertiesUtil; |
29 | |
import org.kuali.rice.kew.engine.node.SimpleNode; |
30 | |
import org.kuali.rice.kew.engine.node.SimpleResult; |
31 | |
import org.kuali.rice.kew.exception.InvalidXmlException; |
32 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
33 | |
import org.w3c.dom.Document; |
34 | |
import org.w3c.dom.Element; |
35 | |
import org.xml.sax.InputSource; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 0 | public class SetVarNode implements SimpleNode { |
56 | 0 | private static final Logger LOG = Logger.getLogger(SetVarNode.class); |
57 | |
|
58 | |
public SimpleResult process(RouteContext context, RouteHelper helper) throws Exception { |
59 | 0 | LOG.debug("processing"); |
60 | 0 | DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
61 | 0 | String contentFragment = context.getNodeInstance().getRouteNode().getContentFragment(); |
62 | 0 | LOG.debug("contentFragment=" + contentFragment); |
63 | 0 | Document d = db.parse(new InputSource(new StringReader(contentFragment))); |
64 | 0 | Element e = d.getDocumentElement(); |
65 | 0 | String name = e.getElementsByTagName("name").item(0).getTextContent(); |
66 | |
|
67 | 0 | if (name == null) { |
68 | 0 | throw new InvalidXmlException("SetVar node required 'name' attribute to be specified"); |
69 | |
} |
70 | 0 | String valueRef = e.getElementsByTagName("value").item(0).getTextContent(); |
71 | 0 | Object retrievedVal = PropertiesUtil.retrieveProperty(valueRef, PropertyScheme.LITERAL_SCHEME, context); |
72 | 0 | LOG.debug("retrieved value '" + retrievedVal + " for value '" + valueRef); |
73 | |
|
74 | |
|
75 | 0 | String stringVal = null; |
76 | 0 | if (retrievedVal != null) { |
77 | 0 | stringVal = retrievedVal.toString(); |
78 | 0 | if (stringVal.length() > 255) { |
79 | 0 | stringVal = stringVal.substring(0, 255); |
80 | |
} |
81 | |
} |
82 | 0 | LOG.debug("setting value '" + stringVal + "' for variable " + name); |
83 | 0 | KEWServiceLocator.getBranchService().setScopedVariableValue(context.getNodeInstance().getBranch(), BranchState.VARIABLE_PREFIX + name, stringVal); |
84 | |
|
85 | 0 | return new SimpleResult(true); |
86 | |
} |
87 | |
|
88 | |
} |