001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.core.joran.action; 015 016import ch.qos.logback.core.model.processor.ModelInterpretationContext; 017import ch.qos.logback.core.spi.ContextAwarePropertyContainer; 018import ch.qos.logback.core.util.OptionHelper; 019 020public class ActionUtil { 021 022 public enum Scope { 023 LOCAL, CONTEXT, SYSTEM 024 }; 025 026 /** 027 * Convert a string into a scope. Scope.LOCAL is returned by default. 028 * 029 * @param scopeStr 030 * @return a scope corresponding to the input string; Scope.LOCAL by default. 031 */ 032 static public Scope stringToScope(String scopeStr) { 033 if (Scope.SYSTEM.toString().equalsIgnoreCase(scopeStr)) 034 return Scope.SYSTEM; 035 if (Scope.CONTEXT.toString().equalsIgnoreCase(scopeStr)) 036 return Scope.CONTEXT; 037 038 return Scope.LOCAL; 039 } 040 041 042 static public void setProperty(ContextAwarePropertyContainer ic, String key, String value, Scope scope) { 043 switch (scope) { 044 case LOCAL: 045 ic.addSubstitutionProperty(key, value); 046 break; 047 case CONTEXT: 048 ic.getContext().putProperty(key, value); 049 break; 050 case SYSTEM: 051 OptionHelper.setSystemProperty(ic, key, value); 052 } 053 } 054}