1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.engine.node;
17
18 import java.io.StringReader;
19
20 import javax.xml.parsers.DocumentBuilder;
21 import javax.xml.parsers.DocumentBuilderFactory;
22
23 import org.apache.log4j.Level;
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.var.PropertyScheme;
28 import org.w3c.dom.Document;
29 import org.w3c.dom.Element;
30 import org.w3c.dom.NodeList;
31 import org.xml.sax.InputSource;
32
33
34
35
36
37
38
39 public class LogNode implements SimpleNode {
40 private static final Logger LOG = Logger.getLogger(LogNode.class);
41
42 public SimpleResult process(RouteContext context, RouteHelper helper) throws Exception {
43 LOG.error("processing");
44 DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
45 String contentFragment = context.getNodeInstance().getRouteNode().getContentFragment();
46 LOG.error("contentFragment=" + contentFragment);
47 Document d = db.parse(new InputSource(new StringReader(contentFragment)));
48 Element e = d.getDocumentElement();
49 String name = null;
50 NodeList list = e.getElementsByTagName("log");
51 if (list != null && list.getLength() > 0) {
52 name = list.item(0).getTextContent();
53 }
54 list = e.getElementsByTagName("level");
55 String level = "info";
56 if (list != null && list.getLength() > 0) {
57 level = list.item(0).getTextContent().toLowerCase();
58 }
59 LOG.error("doc content: "+ context.getDocument().getDocContent());
60 String valueRef = e.getElementsByTagName("message").item(0).getTextContent();
61 Object retrievedVal = PropertiesUtil.retrieveProperty(valueRef, PropertyScheme.LITERAL_SCHEME, context);
62 LOG.error("retrieved value '" + retrievedVal + " for message '" + valueRef);
63 Logger l;
64 if (name == null) {
65 l = LOG;
66 } else {
67 l = Logger.getLogger(name);
68 }
69 l.log(Level.toLevel(level), retrievedVal);
70 return new SimpleResult(true);
71 }
72
73 }