View Javadoc

1   /**
2    * Logback: the reliable, fast and flexible logging library for Java.
3    * 
4    * Copyright (C) 1999-2006, QOS.ch
5    * 
6    * This library is free software, you can redistribute it and/or modify it under
7    * the terms of the GNU Lesser General Public License as published by the Free
8    * Software Foundation.
9    */
10  
11  package chapter3.implicit;
12  
13  import org.xml.sax.Attributes;
14  
15  import ch.qos.logback.core.joran.action.ImplicitAction;
16  import ch.qos.logback.core.joran.spi.InterpretationContext;
17  import ch.qos.logback.core.joran.spi.Pattern;
18  
19  
20  
21  /**
22   *
23   * A rather trivial implicit action which is applicable as soon as an
24   * element has a printme attribute set to true. 
25   *
26   * @author Ceki Gülcü
27   */
28  public class PrintMeImplicitAction extends ImplicitAction {
29    
30    public boolean isApplicable(
31      Pattern pattern, Attributes attributes, InterpretationContext ec) {
32      String printmeStr = attributes.getValue("printme");
33  
34      return Boolean.valueOf(printmeStr).booleanValue();
35    }
36  
37    public void begin(InterpretationContext ec, String name, Attributes attributes) {
38      System.out.println("Element ["+name+"] asked to be printed.");
39     }
40  
41   
42    public void end(InterpretationContext ec, String name) {
43    }
44  }