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.spi.ContextAwarePropertyContainer;
18  import ch.qos.logback.core.util.OptionHelper;
19  
20  public class ActionUtil {
21  
22      public enum Scope {
23          LOCAL, CONTEXT, SYSTEM
24      };
25  
26      /**
27       * Convert a string into a scope. Scope.LOCAL is returned by default.
28       * 
29       * @param scopeStr
30       * @return a scope corresponding to the input string; Scope.LOCAL by default.
31       */
32      static public Scope stringToScope(String scopeStr) {
33          if (Scope.SYSTEM.toString().equalsIgnoreCase(scopeStr))
34              return Scope.SYSTEM;
35          if (Scope.CONTEXT.toString().equalsIgnoreCase(scopeStr))
36              return Scope.CONTEXT;
37  
38          return Scope.LOCAL;
39      }
40  
41  
42      static public void setProperty(ContextAwarePropertyContainer ic, String key, String value, Scope scope) {
43          switch (scope) {
44          case LOCAL:
45              ic.addSubstitutionProperty(key, value);
46              break;
47          case CONTEXT:
48              ic.getContext().putProperty(key, value);
49              break;
50          case SYSTEM:
51              OptionHelper.setSystemProperty(ic, key, value);
52          }
53      }
54  }