Coverage Report - org.kuali.rice.kew.engine.node.LogNode
 
Classes in this File Line Coverage Branch Coverage Complexity
LogNode
0%
0/25
0%
0/10
6
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  * 
 4  
  * 
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 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  
  * A node which Logs messages to Log4j.
 37  
  *
 38  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
 }