/** * Search for value of DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY in the web-app first, then as a system property and * as an environment variable last. * * @param ctx * @return True if value of DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY is available and set to "true", false otherwise. */ boolean isDisabledByConfiguration(ServletContext ctx) { String disableAttributeStr = null; Object disableAttribute = ctx.getInitParameter(DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY); if (disableAttribute instanceof String) { disableAttributeStr = (String) disableAttribute; } if (OptionHelper.isEmpty(disableAttributeStr)) { disableAttributeStr = OptionHelper.getSystemProperty(DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY); } if (OptionHelper.isEmpty(disableAttributeStr)) { disableAttributeStr = OptionHelper.getEnv(DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY); } if (OptionHelper.isEmpty(disableAttributeStr)) return false; return disableAttributeStr.equalsIgnoreCase("true"); }
private Duration getDuration(String scanAttrib, String scanPeriodAttrib) { Duration duration = null; if (!OptionHelper.isEmpty(scanPeriodAttrib)) { try { duration = Duration.valueOf(scanPeriodAttrib); } catch (NumberFormatException nfe) { addError("Error while converting [" + scanAttrib + "] to long", nfe); } } return duration; }
public void begin(InterpretationContext ec, String name, Attributes attributes) { inError = false; LoggerContext loggerContext = (LoggerContext) this.context; root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); String levelStr = ec.subst(attributes.getValue(ActionConst.LEVEL_ATTRIBUTE)); if (!OptionHelper.isEmpty(levelStr)) { Level level = Level.toLevel(levelStr); addInfo("Setting level of ROOT logger to " + level); root.setLevel(level); } ec.pushObject(root); }
@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 public void start() { key = getFirstOption(); if (OptionHelper.isEmpty(key)) { addWarn("Missing key for the request parameter"); } else { super.start(); } }
if (OptionHelper.isEmpty(loggerName)) { inError = true; String aroundLine = getLineColStr(ec); if (!OptionHelper.isEmpty(levelStr)) { if (ActionConst.INHERITED.equalsIgnoreCase(levelStr) || ActionConst.NULL.equalsIgnoreCase(levelStr)) { addInfo("Setting level of logger [" + loggerName + "] to null, i.e. INHERITED"); if (!OptionHelper.isEmpty(additivityStr)) { boolean additive = OptionHelper.toBoolean(additivityStr, true); addInfo("Setting additivity of logger [" + loggerName + "] to " + additive);
if (OptionHelper.isEmpty(envEntryName)) { String lineColStr = getLineColStr(ec); addError("[" + ENV_ENTRY_NAME_ATTR + "] missing, around " + lineColStr); if (OptionHelper.isEmpty(asKey)) { String lineColStr = getLineColStr(ec); addError("[" + AS_ATTR + "] missing, around " + lineColStr); Context ctx = JNDIUtil.getInitialContext(); envEntryValue = JNDIUtil.lookup(ctx, envEntryName); if (OptionHelper.isEmpty(envEntryValue)) { addError("[" + envEntryName + "] has null or empty value"); } else {
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { inError = false; String className = attributes.getValue(CLASS_ATTRIBUTE); if (OptionHelper.isEmpty(className)) { addError("Mandatory \"" + CLASS_ATTRIBUTE + "\" attribute not set for <loggerContextListener> element"); inError = true; return; } try { lcl = (LoggerContextListener) OptionHelper.instantiateByClassName(className, LoggerContextListener.class, context); if (lcl instanceof ContextAware) { ((ContextAware) lcl).setContext(context); } ec.pushObject(lcl); addInfo("Adding LoggerContextListener of type [" + className + "] to the object stack"); } catch (Exception oops) { inError = true; addError("Could not create LoggerContextListener of type " + className + "].", oops); } }
public void begin(InterpretationContext ic, String name, Attributes attributes) { threshold = System.currentTimeMillis(); // See LOGBACK-527 (the system property is looked up first. Thus, it overrides // the equivalent property in the config file. This reversal of scope priority is justified // by the use case: the admin trying to chase rogue config file String debugAttrib = getSystemProperty(DEBUG_SYSTEM_PROPERTY_KEY); if (debugAttrib == null) { debugAttrib = ic.subst(attributes.getValue(INTERNAL_DEBUG_ATTR)); } if (OptionHelper.isEmpty(debugAttrib) || debugAttrib.equalsIgnoreCase("false") || debugAttrib.equalsIgnoreCase("null")) { addInfo(INTERNAL_DEBUG_ATTR + " attribute not set"); } else { StatusListenerConfigHelper.addOnConsoleListenerInstance(context, new OnConsoleStatusListener()); } processScanAttrib(ic, attributes); LoggerContext lc = (LoggerContext) context; boolean packagingData = OptionHelper.toBoolean(ic.subst(attributes.getValue(PACKAGING_DATA_ATTR)), LoggerContext.DEFAULT_PACKAGING_DATA); lc.setPackagingDataEnabled(packagingData); if (EnvUtil.isGroovyAvailable()) { ContextUtil contextUtil = new ContextUtil(context); contextUtil.addGroovyPackages(lc.getFrameworkPackages()); } // the context is turbo filter attachable, so it is pushed on top of the // stack ic.pushObject(getContext()); }
@Override public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException { String className = attributes.getValue(CLASS_ATTRIBUTE); if (OptionHelper.isEmpty(className)) { addError("Missing class name for receiver. Near [" + name + "] line " + getLineNumber(ic)); inError = true; return; } try { addInfo("About to instantiate receiver of type [" + className + "]"); receiver = (ReceiverBase) OptionHelper.instantiateByClassName(className, ReceiverBase.class, context); receiver.setContext(context); ic.pushObject(receiver); } catch (Exception ex) { inError = true; addError("Could not create a receiver of type [" + className + "].", ex); throw new ActionException(ex); } }
void processScanAttrib(InterpretationContext ic, Attributes attributes) { String scanAttrib = ic.subst(attributes.getValue(SCAN_ATTR)); if (!OptionHelper.isEmpty(scanAttrib) && !"false".equalsIgnoreCase(scanAttrib)) { ScheduledExecutorService scheduledExecutorService = context.getScheduledExecutorService(); URL mainURL = ConfigurationWatchListUtil.getMainWatchURL(context); if (mainURL == null) { addWarn("Due to missing top level configuration file, reconfiguration on change (configuration file scanning) cannot be done."); return; } ReconfigureOnChangeTask rocTask = new ReconfigureOnChangeTask(); rocTask.setContext(context); context.putObject(CoreConstants.RECONFIGURE_ON_CHANGE_TASK, rocTask); String scanPeriodAttrib = ic.subst(attributes.getValue(SCAN_PERIOD_ATTR)); Duration duration = getDuration(scanAttrib, scanPeriodAttrib); if (duration == null) { return; } addInfo("Will scan for changes in [" + mainURL + "] "); // Given that included files are encountered at a later phase, the complete list of files // to scan can only be determined when the configuration is loaded in full. // However, scan can be active if mainURL is set. Otherwise, when changes are detected // the top level config file cannot be accessed. addInfo("Setting ReconfigureOnChangeTask scanning period to " + duration); ScheduledFuture<?> scheduledFuture = scheduledExecutorService.scheduleAtFixedRate(rocTask, duration.getMilliseconds(), duration.getMilliseconds(), TimeUnit.MILLISECONDS); context.addScheduledFuture(scheduledFuture); } }
boolean checkFileAttributeSanity(Attributes attributes) { String file = attributes.getValue(FILE_ATTRIBUTE); String name = attributes.getValue(NAME_ATTRIBUTE); String value = attributes.getValue(VALUE_ATTRIBUTE); String resource = attributes.getValue(RESOURCE_ATTRIBUTE); return !(OptionHelper.isEmpty(file)) && (OptionHelper.isEmpty(name) && OptionHelper.isEmpty(value) && OptionHelper .isEmpty(resource)); }
boolean checkValueNameAttributesSanity(Attributes attributes) { String file = attributes.getValue(FILE_ATTRIBUTE); String name = attributes.getValue(NAME_ATTRIBUTE); String value = attributes.getValue(VALUE_ATTRIBUTE); String resource = attributes.getValue(RESOURCE_ATTRIBUTE); return (!(OptionHelper.isEmpty(name) || OptionHelper.isEmpty(value)) && (OptionHelper .isEmpty(file) && OptionHelper.isEmpty(resource))); }
boolean checkResourceAttributeSanity(Attributes attributes) { String file = attributes.getValue(FILE_ATTRIBUTE); String name = attributes.getValue(NAME_ATTRIBUTE); String value = attributes.getValue(VALUE_ATTRIBUTE); String resource = attributes.getValue(RESOURCE_ATTRIBUTE); return !(OptionHelper.isEmpty(resource)) && (OptionHelper.isEmpty(name) && OptionHelper.isEmpty(value) && OptionHelper .isEmpty(file)); }
/** * Returns "true" if the file specified by {@link #setPath(String) path} property exists. * Returns "false" otherwise. * * @return "true"|"false" depending on the existence of file */ public String getPropertyValue() { if (OptionHelper.isEmpty(path)) { addError("The \"path\" property must be set."); return null; } File file = new File(path); return booleanAsStr(file.exists()); } }
static void installIfAsked(LoggerContext loggerContext) { String slClass = OptionHelper.getSystemProperty( ContextInitializer.STATUS_LISTENER_CLASS); if (!OptionHelper.isEmpty(slClass)) { addStatusListener(loggerContext, slClass); } }
public void begin(InterpretationContext ec, String name, Attributes attributes) { inError = false; LoggerContext loggerContext = (LoggerContext) this.context; root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME); String levelStr = ec.subst(attributes.getValue(ActionConst.LEVEL_ATTRIBUTE)); if (!OptionHelper.isEmpty(levelStr)) { Level level = Level.toLevel(levelStr); addInfo("Setting level of ROOT logger to " + level); root.setLevel(level); } ec.pushObject(root); }
/** * Returns the string "true" if the {@link #setResource(String) resource} specified by the * user is available on the class path, "false" otherwise. * * @return "true"|"false" depending on the availability of resource on the classpath */ public String getPropertyValue() { if (OptionHelper.isEmpty(resourceStr)) { addError("The \"resource\" property must be set."); return null; } URL resourceURL = Loader.getResourceBySelfClassLoader(resourceStr); return booleanAsStr(resourceURL != null); }