View Javadoc

1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2011, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.joran.action;
15  
16  
17  import org.xml.sax.Attributes;
18  
19  import ch.qos.logback.core.joran.spi.InterpretationContext;
20  import ch.qos.logback.core.joran.util.PropertySetter;
21  
22  
23  
24  public class ParamAction extends Action {
25    static String NO_NAME = "No name attribute in <param> element";
26    static String NO_VALUE = "No name attribute in <param> element";
27    boolean inError = false;
28  
29    public void begin(
30      InterpretationContext ec, String localName, Attributes attributes) {
31      String name = attributes.getValue(NAME_ATTRIBUTE);
32      String value = attributes.getValue(VALUE_ATTRIBUTE);
33  
34      if (name == null) {
35        inError = true;
36        addError(NO_NAME);
37        return;
38      }
39  
40      if (value == null) {
41        inError = true;
42        addError(NO_VALUE);
43        return;
44      }
45  
46      // remove both leading and trailing spaces
47      value = value.trim();
48  
49      Object o = ec.peekObject();
50      PropertySetter propSetter = new PropertySetter(o);
51      propSetter.setContext(context);
52      value = ec.subst(value);
53  
54      // allow for variable substitution for name as well
55      name = ec.subst(name);
56  
57      //getLogger().debug(
58      //  "In ParamAction setting parameter [{}] to value [{}].", name, value);
59      propSetter.setProperty(name, value);
60    }
61  
62    public void end(InterpretationContext ec, String localName) {
63    }
64  
65    public void finish(InterpretationContext ec) {
66    }
67  }