[jboss-svn-commits] JBoss Common SVN: r3818 - in jboss-logmanager/trunk: src/main/java/org/jboss/logmanager and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Dec 2 22:01:41 EST 2009
Author: david.lloyd at jboss.com
Date: 2009-12-02 22:01:40 -0500 (Wed, 02 Dec 2009)
New Revision: 3818
Modified:
jboss-logmanager/trunk/pom.xml
jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/PropertyConfigurator.java
Log:
JBAS-7427 - Remove dependency on common-core to allow logmanager to exist on boot classpath
Modified: jboss-logmanager/trunk/pom.xml
===================================================================
--- jboss-logmanager/trunk/pom.xml 2009-12-02 19:56:15 UTC (rev 3817)
+++ jboss-logmanager/trunk/pom.xml 2009-12-03 03:01:40 UTC (rev 3818)
@@ -38,12 +38,6 @@
<classifier>jdk15</classifier>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-common-core</artifactId>
- <version>2.2.14.GA</version>
- <scope>provided</scope>
- </dependency>
</dependencies>
<build>
<plugins>
Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/PropertyConfigurator.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/PropertyConfigurator.java 2009-12-02 19:56:15 UTC (rev 3817)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/PropertyConfigurator.java 2009-12-03 03:01:40 UTC (rev 3818)
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Closeable;
+import java.io.File;
import java.util.Properties;
import java.util.List;
import java.util.ArrayList;
@@ -38,7 +39,6 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.charset.Charset;
-import org.jboss.util.StringPropertyReplacer;
import java.util.logging.Filter;
import java.util.logging.Handler;
@@ -347,7 +347,7 @@
private static String getStringProperty(final Properties properties, final String key) {
final String val = properties.getProperty(key);
- return val == null ? null : StringPropertyReplacer.replaceProperties(val);
+ return val == null ? null : replaceProperties(val);
}
private static String[] getStringCsvArray(final Properties properties, final String key) {
@@ -355,7 +355,7 @@
if (value.length() == 0) {
return EMPTY_STRINGS;
}
- final String realValue = StringPropertyReplacer.replaceProperties(value);
+ final String realValue = replaceProperties(value);
return realValue.split("\\s*,\\s*");
}
@@ -378,4 +378,130 @@
// can't do anything about it
}
}
+
+ private static final int INITIAL = 0;
+ private static final int GOT_DOLLAR = 1;
+ private static final int GOT_OPEN_BRACE = 2;
+ private static final int RESOLVED = 3;
+ private static final int DEFAULT = 4;
+
+ /**
+ * Replace properties of the form:
+ * <code>${<i><name>[</i>,<i><name2>[</i>,<i><name3>...]][</i>:<i><default>]</i>}</code>
+ * @param value
+ * @return
+ */
+ private static String replaceProperties(String value) {
+ final StringBuilder builder = new StringBuilder();
+ final char[] chars = value.toCharArray();
+ final int len = chars.length;
+ int state = 0;
+ int start = -1;
+ int nameStart = -1;
+ for (int i = 0; i < len; i ++) {
+ char ch = chars[i];
+ switch (state) {
+ case INITIAL: {
+ switch (ch) {
+ case '$': {
+ state = GOT_DOLLAR;
+ continue;
+ }
+ default: {
+ builder.append(ch);
+ continue;
+ }
+ }
+ // not reachable
+ }
+ case GOT_DOLLAR: {
+ switch (ch) {
+ case '$': {
+ builder.append(ch);
+ state = INITIAL;
+ continue;
+ }
+ case '{': {
+ start = i + 1;
+ nameStart = start;
+ state = GOT_OPEN_BRACE;
+ continue;
+ }
+ default: {
+ // invalid; emit and resume
+ builder.append('$').append(ch);
+ state = INITIAL;
+ continue;
+ }
+ }
+ // not reachable
+ }
+ case GOT_OPEN_BRACE: {
+ switch (ch) {
+ case ':':
+ case '}':
+ case ',': {
+ final String name = value.substring(nameStart, i).trim();
+ if ("/".equals(name)) {
+ builder.append(File.separator);
+ state = ch == '}' ? INITIAL : RESOLVED;
+ continue;
+ } else if (":".equals(name)) {
+ builder.append(File.pathSeparator);
+ state = ch == '}' ? INITIAL : RESOLVED;
+ continue;
+ }
+ final String val = System.getProperty(name);
+ if (val != null) {
+ builder.append(val);
+ state = ch == '}' ? INITIAL : RESOLVED;
+ continue;
+ } else if (ch == ',') {
+ nameStart = i + 1;
+ continue;
+ } else if (ch == ':') {
+ start = i + 1;
+ state = DEFAULT;
+ continue;
+ } else {
+ builder.append(value.substring(start - 2, i + 1));
+ state = INITIAL;
+ continue;
+ }
+ }
+ default: {
+ continue;
+ }
+ }
+ // not reachable
+ }
+ case RESOLVED: {
+ if (ch == '}') {
+ state = INITIAL;
+ }
+ continue;
+ }
+ case DEFAULT: {
+ if (ch == '}') {
+ state = INITIAL;
+ builder.append(value.substring(start, i));
+ }
+ continue;
+ }
+ default: throw new IllegalStateException();
+ }
+ }
+ switch (state) {
+ case GOT_DOLLAR: {
+ builder.append('$');
+ break;
+ }
+ case DEFAULT:
+ case GOT_OPEN_BRACE: {
+ builder.append(value.substring(start - 2));
+ break;
+ }
+ }
+ return builder.toString();
+ }
}
More information about the jboss-svn-commits
mailing list