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