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 ch.qos.logback.core.model.processor.ModelInterpretationContext;
17  import ch.qos.logback.core.util.OptionHelper;
18  
19  public class ActionUtil {
20  
21      public enum Scope {
22          LOCAL, CONTEXT, SYSTEM
23      };
24  
25      /**
26       * Convert a string into a scope. Scope.LOCAL is returned by default.
27       * 
28       * @param scopeStr
29       * @return a scope corresponding to the input string; Scope.LOCAL by default.
30       */
31      static public Scope stringToScope(String scopeStr) {
32          if (Scope.SYSTEM.toString().equalsIgnoreCase(scopeStr))
33              return Scope.SYSTEM;
34          if (Scope.CONTEXT.toString().equalsIgnoreCase(scopeStr))
35              return Scope.CONTEXT;
36  
37          return Scope.LOCAL;
38      }
39  
40  //    static public void setProperty(SaxEventInterpretationContext ic, String key, String value, Scope scope) {
41  //        switch (scope) {
42  //        case LOCAL:
43  //            ic.addSubstitutionProperty(key, value);
44  //            break;
45  //        case CONTEXT:
46  //            ic.getContext().putProperty(key, value);
47  //            break;
48  //        case SYSTEM:
49  //            OptionHelper.setSystemProperty(ic, key, value);
50  //        }
51  //    }
52  
53      static public void setProperty(ModelInterpretationContext ic, String key, String value, Scope scope) {
54          switch (scope) {
55          case LOCAL:
56              ic.addSubstitutionProperty(key, value);
57              break;
58          case CONTEXT:
59              ic.getContext().putProperty(key, value);
60              break;
61          case SYSTEM:
62              OptionHelper.setSystemProperty(ic, key, value);
63          }
64      }
65  
66  //    /**
67  //     * Add all the properties found in the argument named 'props' to an
68  //     * InterpretationContext.
69  //     */
70  //    static public void setProperties(SaxEventInterpretationContext ic, Properties props, Scope scope) {
71  //        switch (scope) {
72  //        case LOCAL:
73  //            ic.addSubstitutionProperties(props);
74  //            break;
75  //        case CONTEXT:
76  //            ContextUtil cu = new ContextUtil(ic.getContext());
77  //            cu.addProperties(props);
78  //            break;
79  //        case SYSTEM:
80  //            OptionHelper.setSystemProperties(ic, props);
81  //        }
82  //    }
83  
84  }