View Javadoc

1   /**
2    * LOGBack: the generic, reliable, fast and flexible logging framework.
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 ch.qos.logback.core.joran.action;
12  
13  
14  import org.xml.sax.Attributes;
15  
16  import ch.qos.logback.core.joran.spi.InterpretationContext;
17  import ch.qos.logback.core.joran.spi.PropertySetter;
18  
19  
20  
21  public class ParamAction extends Action {
22    static String NO_NAME = "No name attribute in <param> element";
23    static String NO_VALUE = "No name attribute in <param> element";
24    boolean inError = false;
25  
26    public void begin(
27      InterpretationContext ec, String localName, Attributes attributes) {
28      String name = attributes.getValue(NAME_ATTRIBUTE);
29      String value = attributes.getValue(VALUE_ATTRIBUTE);
30  
31      if (name == null) {
32        inError = true;
33        addError(NO_NAME);
34        return;
35      }
36  
37      if (value == null) {
38        inError = true;
39        addError(NO_VALUE);
40        return;
41      }
42  
43      // remove both leading and trailing spaces
44      value = value.trim();
45  
46      Object o = ec.peekObject();
47      PropertySetter propSetter = new PropertySetter(o);
48      propSetter.setContext(context);
49      value = ec.subst(value);
50  
51      // allow for variable substitution for name as well
52      name = ec.subst(name);
53  
54      //getLogger().debug(
55      //  "In ParamAction setting parameter [{}] to value [{}].", name, value);
56      propSetter.setProperty(name, value);
57    }
58  
59    public void end(InterpretationContext ec, String localName) {
60    }
61  
62    public void finish(InterpretationContext ec) {
63    }
64  }