@Override public void begin(InterpretationContext context, String elementName, Attributes attributes) throws ActionException { String name = attributes.getValue(NAME_ATTRIBUTE); String source = attributes.getValue(SOURCE_ATTRIBUTE); Scope scope = ActionUtil.stringToScope(attributes.getValue(SCOPE_ATTRIBUTE)); String defaultValue = attributes.getValue(DEFAULT_VALUE_ATTRIBUTE); if (OptionHelper.isEmpty(name) || OptionHelper.isEmpty(source)) { addError( "The \"name\" and \"source\" attributes of <springProperty> must be set"); } ActionUtil.setProperty(context, name, getValue(source, defaultValue), scope); }
@Override protected void addInstanceRules(RuleStore rs) { super.addInstanceRules(rs); rs.addRule(new ElementSelector("configuration/appender"), new AppenderAction<ILoggingEvent>()); }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { addError("The [contextProperty] element has been removed. Please use [substitutionProperty] element instead"); }
@Override protected void addInstanceRules(RuleStore rs) { // is "configuration/variable" referenced in the docs? rs.addRule(new ElementSelector("configuration/variable"), new PropertyAction()); rs.addRule(new ElementSelector("configuration/property"), new PropertyAction()); rs.addRule(new ElementSelector("configuration/substitutionProperty"), new PropertyAction()); rs.addRule(new ElementSelector("configuration/timestamp"), new TimestampAction()); rs.addRule(new ElementSelector("configuration/define"), new DefinePropertyAction()); // the contextProperty pattern is deprecated. It is undocumented // and will be dropped in future versions of logback rs.addRule(new ElementSelector("configuration/contextProperty"), new ContextPropertyAction()); rs.addRule(new ElementSelector("configuration/conversionRule"), new ConversionRuleAction()); rs.addRule(new ElementSelector("configuration/statusListener"), new StatusListenerAction()); rs.addRule(new ElementSelector("configuration/appender"), new AppenderAction()); rs.addRule(new ElementSelector("configuration/appender/appender-ref"), new AppenderRefAction()); rs.addRule(new ElementSelector("configuration/newRule"), new NewRuleAction()); rs.addRule(new ElementSelector("*/param"), new ParamAction()); }
@Override protected void addImplicitRules(Interpreter interpreter) { // The following line adds the capability to parse nested components NestedComplexPropertyIA nestedComplexPropertyIA = new NestedComplexPropertyIA(); nestedComplexPropertyIA.setContext(context); interpreter.addImplicitAction(nestedComplexPropertyIA); NestedBasicPropertyIA nestedBasicIA = new NestedBasicPropertyIA(); nestedBasicIA.setContext(context); interpreter.addImplicitAction(nestedBasicIA); }
rs.addRule(new ElementSelector("configuration/appender/sift/*"), new NOPAction()); rs.addRule(new ElementSelector("configuration/logger/appender-ref"), new AppenderRefAction<ILoggingEvent>()); rs.addRule(new ElementSelector("configuration/root/appender-ref"), new AppenderRefAction<ILoggingEvent>()); rs.addRule(new ElementSelector("*/if/then/*"), new NOPAction()); rs.addRule(new ElementSelector("*/if/else"), new ElseAction()); rs.addRule(new ElementSelector("*/if/else/*"), new NOPAction()); rs.addRule(new ElementSelector("configuration/jmxConfigurator"), new JMXConfiguratorAction()); rs.addRule(new ElementSelector("configuration/include"), new IncludeAction());
@Override protected void addInstanceRules(RuleStore rs) { rs.addRule(new ElementSelector("configuration/property"), new PropertyAction()); rs.addRule(new ElementSelector("configuration/timestamp"), new TimestampAction()); rs.addRule(new ElementSelector("configuration/define"), new DefinePropertyAction()); }
protected String getLineColStr(InterpretationContext ic) { return "line: " + getLineNumber(ic) + ", column: " + getColumnNumber(ic); } }
InputStream getInputStream(InterpretationContext ec, Attributes attributes) { URL inputURL = getInputURL(ec, attributes); if (inputURL == null) return null; ConfigurationWatchListUtil.addToWatchList(context, inputURL); return openURL(inputURL); }
URL attributeToURL(String urlAttribute) { try { return new URL(urlAttribute); } catch (MalformedURLException mue) { String errMsg = "URL [" + urlAttribute + "] is not well formed."; addError(errMsg, mue); return null; } }
private InputStream getInputStreamByUrl(URL url) { return openURL(url); }
@Override public void addInstanceRules(RuleStore rs) { super.addInstanceRules(rs); Environment environment = this.initializationContext.getEnvironment(); rs.addRule(new ElementSelector("configuration/springProperty"), new SpringPropertyAction(environment)); rs.addRule(new ElementSelector("*/springProfile"), new SpringProfileAction(environment)); rs.addRule(new ElementSelector("*/springProfile/*"), new NOPAction()); }
/** * Convert a string into a scope. Scole.LOCAL is returned by default. * @param scopeStr * @return a scope corresponding to the input string; Scope.LOCAL by default. */ static public Scope stringToScope(String scopeStr) { if(Scope.SYSTEM.toString().equalsIgnoreCase(scopeStr)) return Scope.SYSTEM; if(Scope.CONTEXT.toString().equalsIgnoreCase(scopeStr)) return Scope.CONTEXT; return Scope.LOCAL; }
void loadAndSetProperties(InterpretationContext ec, InputStream istream, Scope scope) throws IOException { Properties props = new Properties(); props.load(istream); istream.close(); ActionUtil.setProperties(ec, props, scope); }
private InputStream getInputStreamByFilePath(String pathToFile) { try { return new FileInputStream(pathToFile); } catch (IOException ioe) { String warningMsg = "File [" + pathToFile + "] does not exist."; addWarn(warningMsg); return null; } }
@Override protected void addImplicitRules(Interpreter interpreter) { NestedComplexPropertyIA nestedComplexIA = new NestedComplexPropertyIA(); nestedComplexIA.setContext(context); interpreter.addImplicitAction(nestedComplexIA); NestedBasicPropertyIA nestedSimpleIA = new NestedBasicPropertyIA(); nestedSimpleIA.setContext(context); interpreter.addImplicitAction(nestedSimpleIA); }
Scope scope = ActionUtil.stringToScope(scopeStr); } else { addInfo("Setting variable [" + asKey + "] to [" + envEntryValue + "] in [" + scope + "] scope"); ActionUtil.setProperty(ec, asKey, envEntryValue, scope);
InputStream openURL(URL url) { try { return url.openStream(); } catch (IOException e) { if (!optional) { String errMsg = "Failed to open [" + url.toString() + "]"; addError(errMsg, e); } return null; } }
private InputStream getInputStreamByResource(URL url) { return openURL(url); }
URL resourceAsURL(String resourceAttribute) { URL url = Loader.getResourceBySelfClassLoader(resourceAttribute); if (url == null) { if (!optional) { String errMsg = "Could not find resource corresponding to [" + resourceAttribute + "]"; addError(errMsg); } return null; } else return url; }