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 | 0 | public class LogNode implements SimpleNode { |
41 | 0 | private static final Logger LOG = Logger.getLogger(LogNode.class); |
42 | |
|
43 | |
public SimpleResult process(RouteContext context, RouteHelper helper) throws Exception { |
44 | 0 | LOG.error("processing"); |
45 | 0 | DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); |
46 | 0 | String contentFragment = context.getNodeInstance().getRouteNode().getContentFragment(); |
47 | 0 | LOG.error("contentFragment=" + contentFragment); |
48 | 0 | Document d = db.parse(new InputSource(new StringReader(contentFragment))); |
49 | 0 | Element e = d.getDocumentElement(); |
50 | 0 | String name = null; |
51 | 0 | NodeList list = e.getElementsByTagName("log"); |
52 | 0 | if (list != null && list.getLength() > 0) { |
53 | 0 | name = list.item(0).getTextContent(); |
54 | |
} |
55 | 0 | list = e.getElementsByTagName("level"); |
56 | 0 | String level = "info"; |
57 | 0 | if (list != null && list.getLength() > 0) { |
58 | 0 | level = list.item(0).getTextContent().toLowerCase(); |
59 | |
} |
60 | 0 | LOG.error("doc content: "+ context.getDocument().getDocContent()); |
61 | 0 | String valueRef = e.getElementsByTagName("message").item(0).getTextContent(); |
62 | 0 | Object retrievedVal = PropertiesUtil.retrieveProperty(valueRef, PropertyScheme.LITERAL_SCHEME, context); |
63 | 0 | LOG.error("retrieved value '" + retrievedVal + " for message '" + valueRef); |
64 | |
Logger l; |
65 | 0 | if (name == null) { |
66 | 0 | l = LOG; |
67 | |
} else { |
68 | 0 | l = Logger.getLogger(name); |
69 | |
} |
70 | 0 | l.log(Level.toLevel(level), retrievedVal); |
71 | 0 | return new SimpleResult(true); |
72 | |
} |
73 | |
|
74 | |
} |