View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, 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  import org.xml.sax.Attributes;
17  
18  import ch.qos.logback.core.joran.spi.SaxEventInterpretationContext;
19  import ch.qos.logback.core.model.Model;
20  import ch.qos.logback.core.model.PropertyModel;
21  
22  /**
23   * This class serves to build a model for properties which are to the ANT
24   * <property> task which add/set properties of a given object.
25   * 
26   * @author Ceki Gülcü
27   */
28  public class PropertyAction extends BaseModelAction {
29  
30      static final String RESOURCE_ATTRIBUTE = "resource";
31  
32      @Override
33      protected boolean validPreconditions(SaxEventInterpretationContext interpretationContext, String localName,
34              Attributes attributes) {
35          if ("substitutionProperty".equals(localName)) {
36              addWarn("[substitutionProperty] element has been deprecated. Please use the [variable] element instead.");
37          }
38          return true;
39      }
40  
41      @Override
42      protected Model buildCurrentModel(SaxEventInterpretationContext interpretationContext, String name,
43              Attributes attributes) {
44          PropertyModel propertyModel = new PropertyModel();
45          propertyModel.setName(attributes.getValue(NAME_ATTRIBUTE));
46          propertyModel.setValue(attributes.getValue(VALUE_ATTRIBUTE));
47          propertyModel.setScopeStr(attributes.getValue(SCOPE_ATTRIBUTE));
48          propertyModel.setFile(attributes.getValue(FILE_ATTRIBUTE));
49          propertyModel.setResource(attributes.getValue(RESOURCE_ATTRIBUTE));
50          return propertyModel;
51      }
52  
53  }