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