Java 类ch.qos.logback.core.util.OptionHelper 实例源码
项目:spring-boot-concourse
文件:DefaultLogbackConfiguration.java
private Appender<ILoggingEvent> fileAppender(LogbackConfigurator config,
String logFile) {
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<ILoggingEvent>();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
String logPattern = this.patterns.getProperty("file", FILE_LOG_PATTERN);
encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext()));
appender.setEncoder(encoder);
config.start(encoder);
appender.setFile(logFile);
FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setFileNamePattern(logFile + ".%i");
appender.setRollingPolicy(rollingPolicy);
rollingPolicy.setParent(appender);
config.start(rollingPolicy);
SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
triggeringPolicy.setMaxFileSize("10MB");
appender.setTriggeringPolicy(triggeringPolicy);
config.start(triggeringPolicy);
config.appender("FILE", appender);
return appender;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:DefaultLogbackConfiguration.java
private Appender<ILoggingEvent> fileAppender(LogbackConfigurator config,
String logFile) {
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<ILoggingEvent>();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
String logPattern = this.patterns.getProperty("file", FILE_LOG_PATTERN);
encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext()));
appender.setEncoder(encoder);
config.start(encoder);
appender.setFile(logFile);
FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setFileNamePattern(logFile + ".%i");
appender.setRollingPolicy(rollingPolicy);
rollingPolicy.setParent(appender);
config.start(rollingPolicy);
SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
triggeringPolicy.setMaxFileSize("10MB");
appender.setTriggeringPolicy(triggeringPolicy);
config.start(triggeringPolicy);
config.appender("FILE", appender);
return appender;
}
项目:bartleby
文件:Compiler.java
/**
* Attempt to create a converter using the information found in
* 'converterMap'.
*
* @param kn
* @return
*/
@SuppressWarnings("unchecked")
DynamicConverter<E> createConverter(SimpleKeywordNode kn) {
String keyword = (String) kn.getValue();
String converterClassStr = (String) converterMap.get(keyword);
if (converterClassStr != null) {
try {
return (DynamicConverter) OptionHelper.instantiateByClassName(
converterClassStr, DynamicConverter.class, context);
} catch (Exception e) {
addError("Failed to instantiate converter class [" + converterClassStr
+ "] for keyword ["+keyword+"]", e);
return null;
}
} else {
addError("There is no conversion class registered for conversion word ["
+ keyword + "]");
return null;
}
}
项目:bartleby
文件:Compiler.java
/**
* Attempt to create a converter using the information found in
* 'compositeConverterMap'.
*
* @param cn
* @return
*/
@SuppressWarnings("unchecked")
CompositeConverter<E> createCompositeConverter(CompositeNode cn) {
String keyword = (String) cn.getValue();
String converterClassStr = (String) converterMap.get(keyword);
if (converterClassStr != null) {
try {
return (CompositeConverter) OptionHelper.instantiateByClassName(
converterClassStr, CompositeConverter.class, context);
} catch (Exception e) {
addError("Failed to instantiate converter class [" + converterClassStr
+ "] as a composite converter for keyword ["+keyword+"]", e);
return null;
}
} else {
addError("There is no conversion class registered for composite conversion word ["
+ keyword + "]");
return null;
}
}
项目:bartleby
文件:NodeToStringTransformer.java
private String lookupKey(String key) {
String value = propertyContainer0.getProperty(key);
if (value != null)
return value;
if (propertyContainer1 != null) {
value = propertyContainer1.getProperty(key);
if (value != null)
return value;
}
value = OptionHelper.getSystemProperty(key, null);
if (value != null)
return value;
value = OptionHelper.getEnv(key);
if (value != null) {
return value;
}
return null;
}
项目:bartleby
文件:IncludeAction.java
URL getInputURL(InterpretationContext ec, Attributes attributes) {
String fileAttribute = attributes.getValue(FILE_ATTR);
String urlAttribute = attributes.getValue(URL_ATTR);
String resourceAttribute = attributes.getValue(RESOURCE_ATTR);
if (!OptionHelper.isEmpty(fileAttribute)) {
this.attributeInUse = ec.subst(fileAttribute);
return filePathAsURL(attributeInUse);
}
if (!OptionHelper.isEmpty(urlAttribute)) {
this.attributeInUse = ec.subst(urlAttribute);
return attributeToURL(attributeInUse);
}
if (!OptionHelper.isEmpty(resourceAttribute)) {
this.attributeInUse = ec.subst(resourceAttribute);
return resourceAsURL(attributeInUse);
}
// given previous checkAttributes() check we cannot reach this line
throw new IllegalStateException("A URL stream should have been returned");
}
项目:bartleby
文件:SSLParametersConfiguration.java
/**
* Gets the set of enabled protocols based on the configuration.
* @param supportedProtocols protocols supported by the SSL engine
* @param defaultProtocols default protocols enabled by the SSL engine
* @return enabled protocols
*/
private String[] enabledProtocols(String[] supportedProtocols,
String[] defaultProtocols) {
if (enabledProtocols == null) {
// we're assuming that the same engine is used for all configurables
// so once we determine the enabled set, we won't do it again
if (OptionHelper.isEmpty(getIncludedProtocols())
&& OptionHelper.isEmpty(getExcludedProtocols())) {
enabledProtocols = Arrays.copyOf(defaultProtocols,
defaultProtocols.length);
}
else {
enabledProtocols = includedStrings(supportedProtocols,
getIncludedProtocols(), getExcludedProtocols());
}
for (String protocol : enabledProtocols) {
addInfo("enabled protocol: " + protocol);
}
}
return enabledProtocols;
}
项目:bartleby
文件:SSLParametersConfiguration.java
/**
* Gets the set of enabled cipher suites based on the configuration.
* @param supportedCipherSuites cipher suites supported by the SSL engine
* @param defaultCipherSuites default cipher suites enabled by the SSL engine
* @return enabled cipher suites
*/
private String[] enabledCipherSuites(String[] supportedCipherSuites,
String[] defaultCipherSuites) {
if (enabledCipherSuites == null) {
// we're assuming that the same engine is used for all configurables
// so once we determine the enabled set, we won't do it again
if (OptionHelper.isEmpty(getIncludedCipherSuites())
&& OptionHelper.isEmpty(getExcludedCipherSuites())) {
enabledCipherSuites = Arrays.copyOf(defaultCipherSuites,
defaultCipherSuites.length);
}
else {
enabledCipherSuites = includedStrings(supportedCipherSuites,
getIncludedCipherSuites(), getExcludedCipherSuites());
}
for (String cipherSuite : enabledCipherSuites) {
addInfo("enabled cipher suite: " + cipherSuite);
}
}
return enabledCipherSuites;
}
项目:bartleby
文件:ConfigurationAction.java
void processScanAttrib(InterpretationContext ic, Attributes attributes) {
String scanAttrib = ic.subst(attributes.getValue(SCAN_ATTR));
if (!OptionHelper.isEmpty(scanAttrib)
&& !"false".equalsIgnoreCase(scanAttrib)) {
ReconfigureOnChangeFilter rocf = new ReconfigureOnChangeFilter();
rocf.setContext(context);
String scanPeriodAttrib = ic.subst(attributes.getValue(SCAN_PERIOD_ATTR));
if (!OptionHelper.isEmpty(scanPeriodAttrib)) {
try {
Duration duration = Duration.valueOf(scanPeriodAttrib);
rocf.setRefreshPeriod(duration.getMilliseconds());
addInfo("Setting ReconfigureOnChangeFilter scanning period to "
+ duration);
} catch (NumberFormatException nfe) {
addError("Error while converting [" + scanAttrib + "] to long", nfe);
}
}
rocf.start();
LoggerContext lc = (LoggerContext) context;
addInfo("Adding ReconfigureOnChangeFilter as a turbo filter");
lc.addTurboFilter(rocf);
}
}
项目:bartleby
文件:ContextSelectorStaticBinder.java
/**
* FOR INTERNAL USE. This method is intended for use by StaticLoggerBinder.
*
* @param defaultLoggerContext
* @throws ClassNotFoundException
* @throws NoSuchMethodException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
public void init(LoggerContext defaultLoggerContext, Object key) throws ClassNotFoundException,
NoSuchMethodException, InstantiationException, IllegalAccessException,
InvocationTargetException {
if(this.key == null) {
this.key = key;
} else if (this.key != key) {
throw new IllegalAccessException("Only certain classes can access this method.");
}
String contextSelectorStr = OptionHelper
.getSystemProperty(ClassicConstants.LOGBACK_CONTEXT_SELECTOR);
if (contextSelectorStr == null) {
contextSelector = new DefaultContextSelector(defaultLoggerContext);
} else if (contextSelectorStr.equals("JNDI")) {
// if jndi is specified, let's use the appropriate class
contextSelector = new ContextJNDISelector(defaultLoggerContext);
} else {
contextSelector = dynamicalContextSelector(defaultLoggerContext,
contextSelectorStr);
}
}
项目:bartleby
文件:LiteralAction.java
public void begin(InterpretationContext ic, String name, Attributes attributes) {
String valueStr = attributes.getValue(VALUE_ATR);
if (OptionHelper.isEmpty(valueStr)) {
ic.addError("The literal action requires a value attribute");
return;
}
try {
Integer i = Integer.valueOf(valueStr);
ic.pushObject(i);
} catch (NumberFormatException nfe) {
ic.addError("The value [" + valueStr
+ "] could not be converted to an Integer", nfe);
throw nfe;
}
}
项目:bartleby
文件:ConfigurationAction.java
@Override
public void begin(InterpretationContext ec, String name, Attributes attributes) {
// See LBCLASSIC-225 (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 = System.getProperty(DEBUG_SYSTEM_PROPERTY_KEY);
if (debugAttrib == null) {
debugAttrib = attributes.getValue(INTERNAL_DEBUG_ATTR);
}
if (OptionHelper.isEmpty(debugAttrib) || debugAttrib.equals("false") || debugAttrib.equals("null")) {
addInfo(INTERNAL_DEBUG_ATTR + " attribute not set");
} else {
OnConsoleStatusListener.addNewInstanceToContext(context);
}
new ContextUtil(context).addHostNameAsProperty();
// the context is appender attachable, so it is pushed on top of the stack
ec.pushObject(getContext());
}
项目:contestparser
文件:DefaultLogbackConfiguration.java
private Appender<ILoggingEvent> fileAppender(LogbackConfigurator config,
String logFile) {
RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<ILoggingEvent>();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
String logPattern = this.patterns.getProperty("file", FILE_LOG_PATTERN);
encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext()));
appender.setEncoder(encoder);
config.start(encoder);
appender.setFile(logFile);
FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setFileNamePattern(logFile + ".%i");
appender.setRollingPolicy(rollingPolicy);
rollingPolicy.setParent(appender);
config.start(rollingPolicy);
SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>();
triggeringPolicy.setMaxFileSize("10MB");
appender.setTriggeringPolicy(triggeringPolicy);
config.start(triggeringPolicy);
config.appender("FILE", appender);
return appender;
}
项目:goodees
文件:CatalinaValve.java
@Override
public void start() throws LifecycleException {
super.start();
ctx.start();
if (filename == null) {
filename = OptionHelper.getSystemProperty("logbackAccess.configurationFile");
if (filename == null) {
filename = DEFAULT_CONFIG_FILE;
}
ctx.getStatusManager().add(new InfoStatus("filename property not set. Assuming [" + filename + "]", this));
}
// TODO: Support classpath config
File configFile = new File(filename);
if (configFile.exists()) {
try {
JoranConfigurator jc = new JoranConfigurator();
jc.setContext(ctx);
jc.doConfigure(filename);
} catch (JoranException e) {
// TODO can we do better than printing a stack trace on syserr?
e.printStackTrace();
}
} else {
ctx.getStatusManager().add(new WarnStatus("[" + filename + "] does not exist", this));
}
if (!quiet) {
StatusPrinter.print(ctx.getStatusManager());
}
}
项目:konker-platform
文件:KonkerSelectorStaticBinder.java
public void init(KonkerLoggerContext defaultLoggerContext, Object key) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
if(this.key == null) {
this.key = key;
} else if(this.key != key) {
throw new IllegalAccessException("Only certain classes can access this method.");
}
String contextSelectorStr = OptionHelper.getSystemProperty("logback.ContextSelector");
if(contextSelectorStr == null) {
this.contextSelector = new KonkerDefaultContextSelector(defaultLoggerContext);
} else {
this.contextSelector = dynamicalContextSelector(defaultLoggerContext, contextSelectorStr);
}
}
项目:konker-platform
文件:KonkerStatusListenerConfigHelper.java
static void installIfAsked(KonkerLoggerContext loggerContext) {
String slClass = OptionHelper.getSystemProperty("logback.statusListenerClass");
if(!OptionHelper.isEmpty(slClass)) {
addStatusListener(loggerContext, slClass);
}
}
项目:konker-platform
文件:KonkerStatusListenerConfigHelper.java
private static StatusListener createListenerPerClassName(KonkerLoggerContext loggerContext,
String listenerClass) {
try {
return (StatusListener)OptionHelper.instantiateByClassName(listenerClass, StatusListener.class, loggerContext);
} catch (Exception var3) {
var3.printStackTrace();
return null;
}
}
项目:konker-platform
文件:KonkerContextInitializer.java
private URL findConfigFileURLFromSystemProperties(ClassLoader classLoader, boolean updateStatus) {
String logbackConfigFile = OptionHelper.getSystemProperty("logback.configurationFile");
if (logbackConfigFile != null) {
URL result = null;
URL f;
try {
result = new URL(logbackConfigFile);
URL e = result;
return e;
} catch (MalformedURLException var13) {
result = Loader.getResource(logbackConfigFile, classLoader);
if (result == null) {
File f1 = new File(logbackConfigFile);
if (!f1.exists() || !f1.isFile()) {
return null;
}
try {
result = f1.toURI().toURL();
URL e1 = result;
return e1;
} catch (MalformedURLException var12) {
return null;
}
}
f = result;
} finally {
if (updateStatus) {
this.statusOnResourceSearch(logbackConfigFile, classLoader, result);
}
}
return f;
} else {
return null;
}
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:SpringPropertyAction.java
@Override
public void begin(InterpretationContext ic, 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(ic, name, getValue(source, defaultValue), scope);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:DefaultLogbackConfiguration.java
private Appender<ILoggingEvent> consoleAppender(LogbackConfigurator config) {
ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
String logPattern = this.patterns.getProperty("console", CONSOLE_LOG_PATTERN);
encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext()));
encoder.setCharset(UTF8);
config.start(encoder);
appender.setEncoder(encoder);
config.appender("CONSOLE", appender);
return appender;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot
文件:SpringProfileAction.java
private boolean acceptsProfiles(InterpretationContext ic, Attributes attributes) {
String[] profileNames = StringUtils.trimArrayElements(StringUtils
.commaDelimitedListToStringArray(attributes.getValue(NAME_ATTRIBUTE)));
if (profileNames.length != 0) {
for (String profileName : profileNames) {
OptionHelper.substVars(profileName, ic, this.context);
}
return this.environment != null
&& this.environment.acceptsProfiles(profileNames);
}
return false;
}
项目:common-libraries
文件:ImprovedAuditorFactory.java
public static void setApplicationName(String name) throws AuditException {
if (clientApplication != null && clientApplication.getName().equals(name)) {
// don't configure again
return;
}
if (clientApplication != null && !clientApplication.getName().equals(name)) {
throw new IllegalStateException("Application name "
+ clientApplication.getName() + " once set cannot be renamed.");
}
if (OptionHelper.isEmpty(name)) {
throw new IllegalArgumentException(
"Application name cannot be null or empty");
} else {
// logger.info("Naming client application as [" + name + "]");
}
try {
InetAddress address = InetAddress.getLocalHost();
String fqdn = address.getCanonicalHostName();
// logger("Client application host is ["+fqdn+"].");
Application aplication = new Application(name, fqdn);
// all is nice and dandy
clientApplication = aplication;
} catch (UnknownHostException e) {
throw new IllegalStateException(
"Failed to determine the hostname for this host", e);
}
// defaultAuditor.close();
defaultAuditor = new Auditor();
defaultAuditor.setClientApplication(clientApplication);
defaultAuditor.setName(DEFAULT_AUDITOR_NAME);
autoConfig(defaultAuditor);
checkSanity(defaultAuditor);
AuditorFactory.defaultAuditor = defaultAuditor;
}
项目:spring-boot-concourse
文件:SpringPropertyAction.java
@Override
public void begin(InterpretationContext ic, 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(ic, name, getValue(source, defaultValue), scope);
}
项目:spring-boot-concourse
文件:DefaultLogbackConfiguration.java
private Appender<ILoggingEvent> consoleAppender(LogbackConfigurator config) {
ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
String logPattern = this.patterns.getProperty("console", CONSOLE_LOG_PATTERN);
encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext()));
encoder.setCharset(UTF8);
config.start(encoder);
appender.setEncoder(encoder);
config.appender("CONSOLE", appender);
return appender;
}
项目:spring-boot-concourse
文件:SpringProfileAction.java
private boolean acceptsProfiles(InterpretationContext ic, Attributes attributes) {
String[] profileNames = StringUtils.trimArrayElements(StringUtils
.commaDelimitedListToStringArray(attributes.getValue(NAME_ATTRIBUTE)));
if (profileNames.length != 0) {
for (String profileName : profileNames) {
OptionHelper.substVars(profileName, ic, this.context);
}
return this.environment != null
&& this.environment.acceptsProfiles(profileNames);
}
return false;
}
项目:bartleby
文件:ResourceExistsPropertyDefiner.java
/**
* 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);
}
项目:bartleby
文件:FileExistsPropertyDefiner.java
/**
* 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());
}
项目:bartleby
文件:ConsoleAppender.java
private OutputStream getTargetStreamForWindows(OutputStream targetStream) {
try {
addInfo("Enabling JANSI WindowsAnsiOutputStream for the console.");
Object windowsAnsiOutputStream = OptionHelper.instantiateByClassNameAndParameter(WindowsAnsiOutputStream_CLASS_NAME, Object.class, context,
OutputStream.class, targetStream);
return (OutputStream) windowsAnsiOutputStream;
} catch (Exception e) {
addWarn("Failed to create WindowsAnsiOutputStream. Falling back on the default stream.", e);
}
return targetStream;
}
项目:bartleby
文件:PropertyWrapperForScripts.java
public String property(String k) {
String val = OptionHelper.propertyLookup(k, local, context);
if(val != null)
return val;
else
return "";
}
项目:bartleby
文件:IfAction.java
@Override
public void begin(InterpretationContext ic, String name, Attributes attributes)
throws ActionException {
IfState state = new IfState();
boolean emptyStack = stack.isEmpty();
stack.push(state);
if(!emptyStack) {
return;
}
ic.pushObject(this);
if(!EnvUtil.isJaninoAvailable()) {
addError(MISSING_JANINO_MSG);
addError(MISSING_JANINO_SEE);
return;
}
state.active = true;
Condition condition = null;
String conditionAttribute = attributes.getValue(CONDITION_ATTR);
if (!OptionHelper.isEmpty(conditionAttribute)) {
conditionAttribute = OptionHelper.substVars(conditionAttribute, ic, context);
PropertyEvalScriptBuilder pesb = new PropertyEvalScriptBuilder(ic);
pesb.setContext(context);
try {
condition = pesb.build(conditionAttribute);
} catch (Exception e) {
addError("Failed to parse condition ["+conditionAttribute+"]", e);
}
if(condition!=null) {
state.boolResult = condition.evaluate();
}
}
}
项目:bartleby
文件:IncludeAction.java
@Override
public void begin(InterpretationContext ec, String name, Attributes attributes)
throws ActionException {
SaxEventRecorder recorder = new SaxEventRecorder(context);
this.attributeInUse = null;
this.optional = OptionHelper.toBoolean(attributes.getValue(OPTIONAL_ATTR), false);
if (!checkAttributes(attributes)) {
return;
}
InputStream in = getInputStream(ec, attributes);
try {
if (in != null) {
parseAndRecord(in, recorder);
// remove the <included> tag from the beginning and </included> from the end
trimHeadAndTail(recorder);
// offset = 2, because we need to get past this element as well as the end element
ec.getJoranInterpreter().getEventPlayer().addEventsDynamically(recorder.saxEventList, 2);
}
} catch (JoranException e) {
addError("Error while parsing " + attributeInUse, e);
} finally {
close(in);
}
}
项目:bartleby
文件:IncludeAction.java
private boolean checkAttributes(Attributes attributes) {
String fileAttribute = attributes.getValue(FILE_ATTR);
String urlAttribute = attributes.getValue(URL_ATTR);
String resourceAttribute = attributes.getValue(RESOURCE_ATTR);
int count = 0;
if (!OptionHelper.isEmpty(fileAttribute)) {
count++;
}
if (!OptionHelper.isEmpty(urlAttribute)) {
count++;
}
if (!OptionHelper.isEmpty(resourceAttribute)) {
count++;
}
if (count == 0) {
addError("One of \"path\", \"resource\" or \"url\" attributes must be set.");
return false;
} else if (count > 1) {
addError("Only one of \"file\", \"url\" or \"resource\" attributes should be set.");
return false;
} else if (count == 1) {
return true;
}
throw new IllegalStateException("Count value [" + count
+ "] is not expected");
}
项目:bartleby
文件:StatusListenerAction.java
public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException {
inError = false;
String className = attributes.getValue(CLASS_ATTRIBUTE);
if (OptionHelper.isEmpty(className)) {
addError("Missing class name for statusListener. Near ["
+ name + "] line " + getLineNumber(ec));
inError = true;
return;
}
try {
statusListener = (StatusListener) OptionHelper.instantiateByClassName(
className, StatusListener.class, context);
ec.getContext().getStatusManager().add(statusListener);
if (statusListener instanceof ContextAware) {
((ContextAware) statusListener).setContext(context);
}
addInfo("Added status listener of type [" + className + "]");
ec.pushObject(statusListener);
} catch (Exception e) {
inError = true;
addError(
"Could not create an StatusListener of type [" + className + "].", e);
throw new ActionException(e);
}
}
项目:bartleby
文件:ShutdownHookAction.java
/**
* Instantiates a shutdown hook of the given class and sets its name.
*
* The hook thus generated is placed in the {@link InterpretationContext}'s
* shutdown hook bag.
*/
@Override
public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException {
hook = null;
inError = false;
String className = attributes.getValue(CLASS_ATTRIBUTE);
if (OptionHelper.isEmpty(className)) {
addError("Missing class name for shutdown hook. Near [" + name
+ "] line " + getLineNumber(ic));
inError = true;
return;
}
try {
addInfo("About to instantiate shutdown hook of type [" + className + "]");
hook = (ShutdownHookBase) OptionHelper.instantiateByClassName(className,
ShutdownHookBase.class, context);
hook.setContext(context);
ic.pushObject(hook);
}catch (Exception e) {
inError = true;
addError("Could not create a shutdown hook of type [" + className + "].", e);
throw new ActionException(e);
}
}
项目:bartleby
文件:PropertyAction.java
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));
}
项目:bartleby
文件:PropertyAction.java
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));
}
项目:bartleby
文件:PropertyAction.java
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)));
}
项目:bartleby
文件:TimestampAction.java
@Override
public void begin(InterpretationContext ec, String name, Attributes attributes)
throws ActionException {
String keyStr = attributes.getValue(KEY_ATTRIBUTE);
if (OptionHelper.isEmpty(keyStr)) {
addError("Attribute named [" + KEY_ATTRIBUTE + "] cannot be empty");
inError = true;
}
String datePatternStr = attributes.getValue(DATE_PATTERN_ATTRIBUTE);
if (OptionHelper.isEmpty(datePatternStr)) {
addError("Attribute named [" + DATE_PATTERN_ATTRIBUTE
+ "] cannot be empty");
inError = true;
}
String timeReferenceStr = attributes.getValue(TIME_REFERENCE_ATTRIBUTE);
long timeReference;
if (CONTEXT_BIRTH.equalsIgnoreCase(timeReferenceStr)) {
addInfo("Using context birth as time reference.");
timeReference = context.getBirthTime();
} else {
timeReference = System.currentTimeMillis();
addInfo("Using current interpretation time, i.e. now, as time reference.");
}
if (inError)
return;
String scopeStr = attributes.getValue(SCOPE_ATTRIBUTE);
Scope scope = ActionUtil.stringToScope(scopeStr);
CachingDateFormatter sdf = new CachingDateFormatter(datePatternStr);
String val = sdf.format(timeReference);
addInfo("Adding property to the context with key=\"" + keyStr
+ "\" and value=\"" + val + "\" to the " + scope + " scope");
ActionUtil.setProperty(ec, keyStr, val, scope);
}
项目:bartleby
文件:ActionUtil.java
static public void setProperty(InterpretationContext ic, String key, String value, Scope scope) {
switch (scope) {
case LOCAL:
ic.addSubstitutionProperty(key, value);
break;
case CONTEXT:
ic.getContext().putProperty(key, value);
break;
case SYSTEM:
OptionHelper.setSystemProperty(ic, key, value);
}
}
项目:bartleby
文件:ActionUtil.java
/**
* Add all the properties found in the argument named 'props' to an
* InterpretationContext.
*/
static public void setProperties(InterpretationContext ic, Properties props,
Scope scope) {
switch (scope) {
case LOCAL:
ic.addSubstitutionProperties(props);
break;
case CONTEXT:
ContextUtil cu = new ContextUtil(ic.getContext());
cu.addProperties(props);
break;
case SYSTEM:
OptionHelper.setSystemProperties(ic, props);
}
}