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