ceki 2004/03/30 09:13:22
Modified: src/java/org/apache/joran/action ParamAction.java
NestComponentIA.java ImplicitAction.java
NewRuleAction.java Action.java
tests/src/java/org/apache/joran/action HelloAction.java
src/java/org/apache/log4j/joran/action LevelAction.java
ConversionRuleAction.java LoggerAction.java
AppenderRefAction.java AppenderAction.java
RootLoggerAction.java LayoutAction.java
src/java/org/apache/joran JoranParser.java Pattern.java
tests/src/java/org/apache/joran PatternTest.java
SimpleStoreTest.java JoranParserTest.java
Added: tests/src/java/org/apache/joran/action
StackCounterAction.java
Log:
Joran now uses SAX instead of DOM. SAX has the advantage of better
error reporting with no real disadvantages.
Revision Changes Path
1.4 +5 -5 logging-log4j/src/java/org/apache/joran/action/ParamAction.java
Index: ParamAction.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/joran/action/ParamAction.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ParamAction.java 25 Sep 2003 09:28:17 -0000 1.3
+++ ParamAction.java 30 Mar 2004 17:13:21 -0000 1.4
@@ -5,7 +5,7 @@
import org.apache.log4j.Logger;
import org.apache.log4j.config.PropertySetter;
import org.apache.log4j.helpers.OptionConverter;
-import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
public class ParamAction extends Action {
@@ -15,9 +15,9 @@
static String NO_NAME = "No name attribute in <param> element";
static String NO_VALUE = "No name attribute in <param> element";
- public void begin(ExecutionContext ec, Element element) {
- String name = element.getAttribute(NAME_ATTRIBUTE);
- String value = (element.getAttribute(VALUE_ATTRIBUTE));
+ public void begin(ExecutionContext ec, String localName, Attributes attributes) {
+ String name = attributes.getValue(NAME_ATTRIBUTE);
+ String value = attributes.getValue(VALUE_ATTRIBUTE);
if(name==null) {
inError = true;
@@ -40,7 +40,7 @@
propSetter.setProperty(name, value);
}
- public void end(ExecutionContext ec, Element e) {
+ public void end(ExecutionContext ec, String localName) {
}
public void finish(ExecutionContext ec) {
1.4 +12 -16
logging-log4j/src/java/org/apache/joran/action/NestComponentIA.java
Index: NestComponentIA.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/joran/action/NestComponentIA.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- NestComponentIA.java 27 Feb 2004 16:47:28 -0000 1.3
+++ NestComponentIA.java 30 Mar 2004 17:13:21 -0000 1.4
@@ -25,6 +25,7 @@
import org.apache.log4j.spi.OptionHandler;
import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
/**
@@ -38,13 +39,11 @@
int containmentType;
PropertySetter parentBean;
- public boolean isApplicable(Element nestedElement, ExecutionContext ec) {
+ public boolean isApplicable(ExecutionContext ec, String nestedElementTagName) {
inError = false;
Object o = ec.peekObject();
parentBean = new PropertySetter(o);
- String nestedElementTagName = nestedElement.getTagName();
-
containmentType = parentBean.canContainComponent(nestedElementTagName);
switch (containmentType) {
@@ -64,37 +63,37 @@
}
}
- public void begin(ExecutionContext ec, Element e) {
+ public void begin(ExecutionContext ec, String localName, Attributes attributes) {
// inError was reset in isApplicable. It should not be touched here
- String className = e.getAttribute(CLASS_ATTRIBUTE);
+ String className = attributes.getValue(CLASS_ATTRIBUTE);
- String tagName = e.getTagName();
+
if(Option.isEmpty(className)) {
inError = true;
- String errMsg = "No class name attribute in <"+tagName+">";
+ String errMsg = "No class name attribute in <"+localName+">";
logger.error(errMsg);
ec.addError(errMsg);
return;
}
try {
- logger.debug("About to instantiate component <"+tagName+ "> of type [" +
className + "]");
+ logger.debug("About to instantiate component <"+localName+ "> of type [" +
className + "]");
nestedComponent = Loader.loadClass(className).newInstance();
- logger.debug("Pushing component <"+tagName+"> on top of the object stack.");
+ logger.debug("Pushing component <"+localName+"> on top of the object
stack.");
ec.pushObject(nestedComponent);
} catch (Exception oops) {
inError = true;
- String msg = "Could not create component <"+tagName+">.";
+ String msg = "Could not create component <"+localName+">.";
logger.error(msg, oops);
ec.addError(msg);
}
}
- public void end(ExecutionContext ec, Element e) {
+ public void end(ExecutionContext ec, String tagName) {
if (inError) {
return;
}
@@ -111,9 +110,7 @@
} else {
logger.warn("Removing component from the object stack");
ec.popObject();
-
-
- String tagName = e.getTagName();
+
// Now let us attach the component
switch (containmentType) {
case PropertySetter.AS_PROPERTY:
@@ -123,8 +120,7 @@
case PropertySetter.AS_COLLECTION:
logger.debug("Adding ["+tagName+"] to parent.");
- parentBean.addComponent(e.getTagName(), nestedComponent);
-
+ parentBean.addComponent(tagName, nestedComponent);
break;
}
}
1.3 +1 -2
logging-log4j/src/java/org/apache/joran/action/ImplicitAction.java
Index: ImplicitAction.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/joran/action/ImplicitAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ImplicitAction.java 27 Feb 2004 16:47:28 -0000 1.2
+++ ImplicitAction.java 30 Mar 2004 17:13:21 -0000 1.3
@@ -17,7 +17,6 @@
package org.apache.joran.action;
import org.apache.joran.ExecutionContext;
-import org.w3c.dom.Element;
/**
* ImplcitActions are like normal (explicit) actions except that are applied
@@ -30,5 +29,5 @@
*/
public abstract class ImplicitAction extends Action {
- public abstract boolean isApplicable(Element e, ExecutionContext ec);
+ public abstract boolean isApplicable(ExecutionContext ec, String
nestedElementTagName);
}
1.4 +5 -6
logging-log4j/src/java/org/apache/joran/action/NewRuleAction.java
Index: NewRuleAction.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/joran/action/NewRuleAction.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- NewRuleAction.java 27 Feb 2004 16:47:28 -0000 1.3
+++ NewRuleAction.java 30 Mar 2004 17:13:21 -0000 1.4
@@ -22,8 +22,7 @@
import org.apache.log4j.Layout;
import org.apache.log4j.Logger;
-
-import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
public class NewRuleAction extends Action {
@@ -34,12 +33,12 @@
* Instantiates an layout of the given class and sets its name.
*
*/
- public void begin(ExecutionContext ec, Element element) {
+ public void begin(ExecutionContext ec, String localName, Attributes attributes) {
// Let us forget about previous errors (in this object)
inError = false;
String errorMsg;
- String pattern = element.getAttribute(PATTERN_ATTRIBUTE);
- String actionClass = element.getAttribute(ACTION_CLASS_ATTRIBUTE);
+ String pattern = attributes.getValue(PATTERN_ATTRIBUTE);
+ String actionClass = attributes.getValue(ACTION_CLASS_ATTRIBUTE);
if(Option.isEmpty(pattern)) {
inError = true;
@@ -72,7 +71,7 @@
* Once the children elements are also parsed, now is the time to activate
* the appender options.
*/
- public void end(ExecutionContext ec, Element e) {
+ public void end(ExecutionContext ec, String n) {
}
public void finish(ExecutionContext ec) {
1.6 +25 -26 logging-log4j/src/java/org/apache/joran/action/Action.java
Index: Action.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/joran/action/Action.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Action.java 27 Feb 2004 16:47:28 -0000 1.5
+++ Action.java 30 Mar 2004 17:13:21 -0000 1.6
@@ -1,12 +1,12 @@
/*
* Copyright 1999,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,7 @@
package org.apache.joran.action;
import org.apache.joran.ExecutionContext;
-import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
/**
@@ -30,37 +30,36 @@
* project of the Apache Software Foundation.
*
* @author Craig McClanahan
- * @authro Christopher Lenz
+ * @author Christopher Lenz
* @author Ceki Gülcü
*
*/
public abstract class Action {
-
public static final String NAME_ATTRIBUTE = "name";
public static final String VALUE_ATTRIBUTE = "value";
public static final String CLASS_ATTRIBUTE = "class";
public static final String PATTERN_ATTRIBUTE = "pattern";
public static final String ACTION_CLASS_ATTRIBUTE = "actionClass";
-
- /**
- * When actions encounter an error condition they set this variable to true.
- */
- protected boolean inError = false;
-
-
- /**
- * Called when the parser first encounters an element.
- *
- * The return value indicates whether child elements should be processed. If
- * the returned value is 'false', then child elements are ignored.
- */
- public abstract void begin(ExecutionContext ec, Element e);
- public abstract void end(ExecutionContext ec, Element e);
+ /**
+ * When actions encounter an error condition they set this variable to true.
+ */
+ protected boolean inError = false;
+
+ /**
+ * Called when the parser first encounters an element.
+ *
+ * The return value indicates whether child elements should be processed. If
+ * the returned value is 'false', then child elements are ignored.
+ */
+ public abstract void begin(
+ ExecutionContext ec, String name, Attributes attributes);
+
+ public abstract void end(ExecutionContext ec, String name);
+
public abstract void finish(ExecutionContext ec);
-
- public String toString() {
- return this.getClass().getName();
- }
-
+
+ public String toString() {
+ return this.getClass().getName();
+ }
}
1.3 +3 -5
logging-log4j/tests/src/java/org/apache/joran/action/HelloAction.java
Index: HelloAction.java
===================================================================
RCS file:
/home/cvs/logging-log4j/tests/src/java/org/apache/joran/action/HelloAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HelloAction.java 27 Feb 2004 16:47:36 -0000 1.2
+++ HelloAction.java 30 Mar 2004 17:13:22 -0000 1.3
@@ -20,7 +20,7 @@
import org.apache.log4j.Layout;
import org.apache.log4j.Logger;
-import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
public class HelloAction extends Action {
@@ -34,9 +34,7 @@
* Instantiates an layout of the given class and sets its name.
*
*/
- public void begin(ExecutionContext ec, Element element) {
-
- String name = element.getAttribute("name");
+ public void begin(ExecutionContext ec, String name, Attributes attributes) {
String str = "Hello "+name+".";
ec.getObjectMap().put("hello", str);
}
@@ -45,7 +43,7 @@
* Once the children elements are also parsed, now is the time to activate
* the appender options.
*/
- public void end(ExecutionContext ec, Element e) {
+ public void end(ExecutionContext ec, String name) {
}
public void finish(ExecutionContext ec) {
1.1
logging-log4j/tests/src/java/org/apache/joran/action/StackCounterAction.java
Index: StackCounterAction.java
===================================================================
/*
* Copyright 1999,2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.joran.action;
import org.apache.joran.ExecutionContext;
import org.apache.log4j.Layout;
import org.apache.log4j.Logger;
import org.xml.sax.Attributes;
public class StackCounterAction extends Action {
static final Logger logger = Logger.getLogger(HelloAction.class);
Layout layout;
public StackCounterAction() {
}
/**
* Instantiates an layout of the given class and sets its name.
*
*/
public void begin(ExecutionContext ec, String name, Attributes attributes) {
String str = "Pushing "+name+"-begin";
ec.pushObject(name+"-begin");
}
/**
* Once the children elements are also parsed, now is the time to activate
* the appender options.
*/
public void end(ExecutionContext ec, String name) {
String str = "Pushing "+name+"-end";
ec.pushObject(name+"-end");
}
public void finish(ExecutionContext ec) {
}
}
1.2 +8 -8
logging-log4j/src/java/org/apache/log4j/joran/action/LevelAction.java
Index: LevelAction.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/joran/action/LevelAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LevelAction.java 25 Sep 2003 09:28:17 -0000 1.1
+++ LevelAction.java 30 Mar 2004 17:13:22 -0000 1.2
@@ -7,7 +7,7 @@
import org.apache.log4j.Logger;
import org.apache.log4j.helpers.Loader;
import org.apache.log4j.helpers.OptionConverter;
-import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
import java.lang.reflect.Method;
@@ -23,7 +23,7 @@
static final Class[] ONE_STRING_PARAM = new Class[] { String.class };
- public void begin(ExecutionContext ec, Element element) {
+ public void begin(ExecutionContext ec, String name, Attributes attributes) {
Object o = ec.peekObject();
@@ -35,21 +35,21 @@
}
Logger l = (Logger) o;
-
String loggerName = l.getName();
- String levelStr = element.getAttribute(VALUE_ATTR);
+ String levelStr = attributes.getValue(VALUE_ATTR);
logger.debug(
- "Level value for logger [" + loggerName + "] is [" + levelStr + "].");
+ "Encapsulating logger name is [" + loggerName + "], levelvalue is ["
+ + levelStr + "].");
if (INHERITED.equalsIgnoreCase(levelStr)
|| NULL.equalsIgnoreCase(levelStr)) {
l.setLevel(null);
} else {
- String className = element.getAttribute(CLASS_ATTR);
+ String className = attributes.getValue(CLASS_ATTR);
- if (EMPTY_STR.equals(className)) {
+ if (className == null || EMPTY_STR.equals(className)) {
l.setLevel(OptionConverter.toLevel(levelStr, Level.DEBUG));
} else {
logger.debug("Desired Level sub-class: [" + className + ']');
@@ -73,7 +73,7 @@
}
- public void end(ExecutionContext ec, Element e) {
+ public void end(ExecutionContext ec, String e) {
}
public void finish(ExecutionContext ec) {
1.3 +6 -5
logging-log4j/src/java/org/apache/log4j/joran/action/ConversionRuleAction.java
Index: ConversionRuleAction.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/joran/action/ConversionRuleAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ConversionRuleAction.java 27 Feb 2004 16:47:32 -0000 1.2
+++ ConversionRuleAction.java 30 Mar 2004 17:13:22 -0000 1.3
@@ -24,7 +24,8 @@
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
-import org.w3c.dom.Element;
+
+import org.xml.sax.Attributes;
public class ConversionRuleAction extends Action {
@@ -35,15 +36,15 @@
* Instantiates an layout of the given class and sets its name.
*
*/
- public void begin(ExecutionContext ec, Element element) {
+ public void begin(ExecutionContext ec, String localName, Attributes attributes) {
// Let us forget about previous errors (in this object)
inError = false;
String errorMsg;
String conversionWord =
- element.getAttribute(ActionConst.CONVERSION_WORD_ATTRIBUTE);
+ attributes.getValue(ActionConst.CONVERSION_WORD_ATTRIBUTE);
String converterClass =
- element.getAttribute(ActionConst.CONVERTER_CLASS_ATTRIBUTE);
+ attributes.getValue(ActionConst.CONVERTER_CLASS_ATTRIBUTE);
if (Option.isEmpty(conversionWord)) {
inError = true;
@@ -86,7 +87,7 @@
* Once the children elements are also parsed, now is the time to activate
* the appender options.
*/
- public void end(ExecutionContext ec, Element e) {
+ public void end(ExecutionContext ec, String n) {
}
public void finish(ExecutionContext ec) {
1.2 +49 -32
logging-log4j/src/java/org/apache/log4j/joran/action/LoggerAction.java
Index: LoggerAction.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/joran/action/LoggerAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- LoggerAction.java 25 Sep 2003 09:28:17 -0000 1.1
+++ LoggerAction.java 30 Mar 2004 17:13:22 -0000 1.2
@@ -1,3 +1,19 @@
+/*
+ * Copyright 1999,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.apache.log4j.joran.action;
import org.apache.joran.ExecutionContext;
@@ -9,36 +25,38 @@
import org.apache.log4j.helpers.OptionConverter;
import org.apache.log4j.spi.LoggerRepository;
-import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
import java.lang.reflect.Method;
+
public class LoggerAction extends Action {
-
Logger logger = Logger.getLogger(LoggerAction.class);
- public void begin(ExecutionContext ec, Element loggerElement) {
- // Let us forget about previous errors (in this object)
- inError = false;
-
+ public void begin(ExecutionContext ec, String name, Attributes attributes) {
+ // Let us forget about previous errors (in this object)
+ inError = false;
+
LoggerRepository repository = (LoggerRepository) ec.getObject(0);
// Create a new org.apache.log4j.Category object from the <category> element.
- String loggerName = loggerElement.getAttribute(NAME_ATTRIBUTE);
- if(Option.isEmpty(loggerName)) {
+ String loggerName = attributes.getValue(NAME_ATTRIBUTE);
+
+ if (Option.isEmpty(loggerName)) {
inError = true;
- String errorMsg = "No 'name' attribute in element "
- +loggerElement.getTagName();
- logger.warn(errorMsg);
+
+ String errorMsg = "No 'name' attribute in element " + name;
+ logger.warn(errorMsg);
ec.addError(errorMsg);
+
return;
}
-
- logger.debug("Logger name is ["+loggerName+"].");
+
+ logger.debug("Logger name is [" + loggerName + "].");
Logger l;
- String className = loggerElement.getAttribute(CLASS_ATTRIBUTE);
+ String className = attributes.getValue(CLASS_ATTRIBUTE);
if (Option.isEmpty(className)) {
logger.debug("Retreiving an instance of org.apache.log4j.Logger.");
@@ -50,38 +68,37 @@
Class clazz = Loader.loadClass(className);
Method getInstanceMethod =
clazz.getMethod("getLogger", ActionConst.ONE_STRING_PARAM);
- l = (Logger) getInstanceMethod.invoke(null, new Object[] { loggerName });
+ l = (Logger) getInstanceMethod.invoke(
+ null, new Object[] { loggerName });
} catch (Exception oops) {
logger.error(
- "Could not retrieve category ["
- + loggerName
- + "]. Reported error follows.",
- oops);
+ "Could not retrieve category [" + loggerName
+ + "]. Reported error follows.", oops);
+
return;
- }
+ }
}
boolean additivity =
OptionConverter.toBoolean(
- loggerElement.getAttribute(ActionConst.ADDITIVITY_ATTRIBUTE),
- true);
+ attributes.getValue(ActionConst.ADDITIVITY_ATTRIBUTE), true);
logger.debug(
"Setting [" + l.getName() + "] additivity to [" + additivity + "].");
l.setAdditivity(additivity);
-
- logger.debug("Pushing logger named ["+loggerName+"].");
- ec.pushObject(l);
+
+ logger.debug("Pushing logger named [" + loggerName + "].");
+ ec.pushObject(l);
}
- public void end(ExecutionContext ec, Element e) {
- logger.debug("end() called.");
- if(!inError) {
- logger.debug("Removing logger from stack.");
- ec.popObject();
- }
+ public void end(ExecutionContext ec, String e) {
+ logger.debug("end() called.");
+
+ if (!inError) {
+ logger.debug("Removing logger from stack.");
+ ec.popObject();
+ }
}
public void finish(ExecutionContext ec) {
}
-
}
1.3 +21 -32
logging-log4j/src/java/org/apache/log4j/joran/action/AppenderRefAction.java
Index: AppenderRefAction.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/joran/action/AppenderRefAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AppenderRefAction.java 27 Feb 2004 16:47:32 -0000 1.2
+++ AppenderRefAction.java 30 Mar 2004 17:13:22 -0000 1.3
@@ -1,12 +1,12 @@
/*
* Copyright 1999,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -19,21 +19,26 @@
import org.apache.joran.ExecutionContext;
import org.apache.joran.action.Action;
import org.apache.joran.helper.Option;
+
import org.apache.log4j.Appender;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.AppenderAttachable;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+
+import org.xml.sax.Attributes;
+
import java.util.HashMap;
public class AppenderRefAction extends Action {
static final Logger logger = Logger.getLogger(AppenderRefAction.class);
- public void begin(ExecutionContext ec, Element appenderRef) {
- // Let us forget about previous errors (in this object)
- inError = false;
+ public void begin(
+ ExecutionContext ec, String localName, Attributes attributes) {
+ // Let us forget about previous errors (in this object)
+ inError = false;
logger.debug("begin called");
@@ -51,28 +56,12 @@
AppenderAttachable appenderAttachable = (AppenderAttachable) o;
- String appenderName = appenderRef.getAttribute(ActionConst.REF_ATTRIBUTE);
+ String appenderName = attributes.getValue(ActionConst.REF_ATTRIBUTE);
if (Option.isEmpty(appenderName)) {
// print a meaningful error message and return
- Node parentNode = appenderRef.getParentNode();
String errMsg = "Missing appender ref attribute in <appender-ref> tag.";
- if (parentNode instanceof Element) {
- Element parentElement = (Element) parentNode;
- String parentTag = parentElement.getTagName();
-
- if ("logger".equals(parentTag)) {
- String loggerName = parentElement.getAttribute("name");
- errMsg =
- errMsg + " Within <" + parentTag + ">" + " named [" + loggerName
- + "].";
- }
-
- errMsg = errMsg + " Within <" + parentTag + ">";
- }
-
- parentNode.getAttributes();
logger.warn(errMsg);
inError = true;
ec.addError(errMsg);
@@ -92,20 +81,20 @@
return;
}
-
- if(appenderAttachable instanceof Logger) {
- logger.debug(
- "Attaching appender named [" + appenderName + "] to logger named ["
- + ((Logger)appenderAttachable).getName() +"].");
+ if (appenderAttachable instanceof Logger) {
+ logger.debug(
+ "Attaching appender named [" + appenderName + "] to logger named ["
+ + ((Logger) appenderAttachable).getName() + "].");
} else {
- logger.debug(
- "Attaching appender named [" + appenderName +
"] to "
- + appenderAttachable);
+ logger.debug(
+ "Attaching appender named [" + appenderName + "] to "
+ + appenderAttachable);
}
+
appenderAttachable.addAppender(appender);
}
- public void end(ExecutionContext ec, Element e) {
+ public void end(ExecutionContext ec, String n) {
}
public void finish(ExecutionContext ec) {
1.3 +5 -6
logging-log4j/src/java/org/apache/log4j/joran/action/AppenderAction.java
Index: AppenderAction.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/joran/action/AppenderAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AppenderAction.java 27 Feb 2004 16:47:32 -0000 1.2
+++ AppenderAction.java 30 Mar 2004 17:13:22 -0000 1.3
@@ -25,7 +25,7 @@
import org.apache.log4j.helpers.OptionConverter;
import org.apache.log4j.spi.OptionHandler;
-import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
import java.util.HashMap;
@@ -39,9 +39,9 @@
*
* The appender thus generated is placed in the ExecutionContext appender bag.
*/
- public void begin(ExecutionContext ec, Element appenderElement) {
+ public void begin(ExecutionContext ec, String localName, Attributes attributes) {
String className =
- appenderElement.getAttribute(CLASS_ATTRIBUTE);
+ attributes.getValue(CLASS_ATTRIBUTE);
try {
logger.debug(
@@ -52,8 +52,7 @@
className, org.apache.log4j.Appender.class, null);
appender = (Appender) instance;
- String appenderName =
- appenderElement.getAttribute(NAME_ATTRIBUTE);
+ String appenderName = attributes.getValue(NAME_ATTRIBUTE);
if (Option.isEmpty(appenderName)) {
logger.warn(
@@ -81,7 +80,7 @@
* Once the children elements are also parsed, now is the time to activate
* the appender options.
*/
- public void end(ExecutionContext ec, Element e) {
+ public void end(ExecutionContext ec, String name) {
if (inError) {
return;
}
1.3 +3 -2
logging-log4j/src/java/org/apache/log4j/joran/action/RootLoggerAction.java
Index: RootLoggerAction.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/joran/action/RootLoggerAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RootLoggerAction.java 27 Feb 2004 16:47:32 -0000 1.2
+++ RootLoggerAction.java 30 Mar 2004 17:13:22 -0000 1.3
@@ -23,6 +23,7 @@
import org.apache.log4j.spi.LoggerRepository;
import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
public class RootLoggerAction extends Action {
@@ -34,7 +35,7 @@
Logger logger = Logger.getLogger(RootLoggerAction.class);
Logger root;
- public void begin(ExecutionContext ec, Element loggerElement) {
+ public void begin(ExecutionContext ec, String name, Attributes attributes) {
inError = false;
logger.debug("In begin method");
@@ -45,7 +46,7 @@
ec.pushObject(root);
}
- public void end(ExecutionContext ec, Element e) {
+ public void end(ExecutionContext ec, String name) {
logger.debug("end() called.");
if (inError) {
1.3 +4 -4
logging-log4j/src/java/org/apache/log4j/joran/action/LayoutAction.java
Index: LayoutAction.java
===================================================================
RCS file:
/home/cvs/logging-log4j/src/java/org/apache/log4j/joran/action/LayoutAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LayoutAction.java 27 Feb 2004 16:47:32 -0000 1.2
+++ LayoutAction.java 30 Mar 2004 17:13:22 -0000 1.3
@@ -25,7 +25,7 @@
import org.apache.log4j.helpers.OptionConverter;
import org.apache.log4j.spi.OptionHandler;
-import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
public class LayoutAction extends Action {
@@ -36,12 +36,12 @@
* Instantiates an layout of the given class and sets its name.
*
*/
- public void begin(ExecutionContext ec, Element appenderElement) {
+ public void begin(ExecutionContext ec, String name, Attributes attributes) {
// Let us forget about previous errors (in this object)
inError = false;
String className =
- appenderElement.getAttribute(CLASS_ATTRIBUTE);
+ attributes.getValue(CLASS_ATTRIBUTE);
try {
logger.debug("About to instantiate layout of type [" + className + "]");
@@ -64,7 +64,7 @@
* Once the children elements are also parsed, now is the time to activate
* the appender options.
*/
- public void end(ExecutionContext ec, Element e) {
+ public void end(ExecutionContext ec, String e) {
if (inError) {
return;
}
1.8 +67 -73 logging-log4j/src/java/org/apache/joran/JoranParser.java
Index: JoranParser.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/joran/JoranParser.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- JoranParser.java 27 Feb 2004 16:47:28 -0000 1.7
+++ JoranParser.java 30 Mar 2004 17:13:22 -0000 1.8
@@ -1,12 +1,12 @@
/*
* Copyright 1999,2004 The Apache Software Foundation.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,83 +20,78 @@
import org.apache.log4j.Logger;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
+import org.xml.sax.Attributes;
+import org.xml.sax.helpers.DefaultHandler;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-public class JoranParser {
+public class JoranParser extends DefaultHandler {
static final Logger logger = Logger.getLogger(JoranParser.class);
private RuleStore ruleStore;
private ExecutionContext ec;
private ArrayList implicitActions;
-
+ Pattern pattern;
+
JoranParser(RuleStore rs) {
ruleStore = rs;
ec = new ExecutionContext(this);
implicitActions = new ArrayList(3);
+ pattern = new Pattern();
}
public ExecutionContext getExecutionContext() {
return ec;
}
- public void addImplcitAction(ImplicitAction ia) {
- implicitActions.add(ia);
- }
-
- public void parse(Document document) {
- Pattern currentPattern = new Pattern();
- Element e = document.getDocumentElement();
- loop(e, currentPattern);
+ public void startDocument() {
+ System.out.println(" in JP startDocument");
}
- public void loop(Node n, Pattern currentPattern) {
- if (n == null) {
- return;
- }
+ public void startElement(
+ String namespaceURI, String localName, String qName, Attributes atts) {
+ String x = null;
+
+ String tagName = getTagName(localName, qName);
+ logger.debug("in startElement <" + tagName + ">");
+
+ pattern.push(tagName);
- //logger.debug("Node type is "+n.getNodeType()+", name is "+n.getNodeName()+",
value "+n.getNodeValue());
+ List applicableActionList = getapplicableActionList(pattern);
-
- try {
- // Element currentElement = (Element) n;
-
- currentPattern.push(n.getNodeName());
- // only print the pattern for ELEMENT NODES
- if(n.getNodeType() == Node.ELEMENT_NODE) {
- logger.debug("pattern is " + currentPattern);
- }
- List applicableActionList = ruleStore.matchActions(currentPattern);
+ if (applicableActionList != null) {
+ callBeginAction(applicableActionList, tagName, atts);
+ } else {
+ logger.debug("no applicable action for <"+tagName+">.");
+ }
+ }
- //logger.debug("set of applicable patterns: " + applicableActionList);
+ public void endElement(String namespaceURI, String localName, String qName) {
+ List applicableActionList = getapplicableActionList(pattern);
- if (applicableActionList == null) {
- if(n instanceof Element)
- applicableActionList = lookupImplicitAction((Element)n, ec);
- }
+ if (applicableActionList != null) {
+ callEndAction(applicableActionList, getTagName(localName, qName));
+ }
- if (applicableActionList != null) {
- callBeginAction(applicableActionList, n);
- }
+ // given that we always push, we must also pop the pattern
+ pattern.pop();
+ }
- if (n.hasChildNodes()) {
- for (Node c = n.getFirstChild(); c != null; c = c.getNextSibling()) {
- loop(c, currentPattern);
- }
- }
+ String getTagName(String localName, String qName) {
+ String tagName = localName;
- if (applicableActionList != null) {
- callEndAction(applicableActionList, n);
- }
- } finally {
- currentPattern.pop();
+ if ((tagName == null) || (tagName.length() < 1)) {
+ tagName = qName;
}
+
+ return tagName;
+ }
+
+ public void addImplcitAction(ImplicitAction ia) {
+ implicitActions.add(ia);
}
/**
@@ -104,62 +99,62 @@
* action is found, it is returned. Thus, the returned list will have at most
* one element.
*/
- List lookupImplicitAction(Element element, ExecutionContext ec) {
+ List lookupImplicitAction(ExecutionContext ec, Pattern pattern) {
int len = implicitActions.size();
- for(int i = 0; i < len; i++) {
+
+ for (int i = 0; i < len; i++) {
ImplicitAction ia = (ImplicitAction) implicitActions.get(i);
- if(ia.isApplicable(element, ec)) {
+
+ if (ia.isApplicable(ec, pattern.peekLast())) {
List actionList = new ArrayList(1);
actionList.add(ia);
+
return actionList;
}
-
}
+
return null;
}
- void callBeginAction(List applicableActionList, Node n) {
+ /**
+ * Return the list of applicable patterns for this
+ */
+ List getapplicableActionList(Pattern pattern) {
+ List applicableActionList = ruleStore.matchActions(pattern);
+
+ //logger.debug("set of applicable patterns: " + applicableActionList);
if (applicableActionList == null) {
- return;
+ applicableActionList = lookupImplicitAction(ec, pattern);
}
- short type = n.getNodeType();
+ return applicableActionList;
+ }
- if (type != Node.ELEMENT_NODE) {
+ void callBeginAction(
+ List applicableActionList, String tagName, Attributes atts) {
+ if (applicableActionList == null) {
return;
}
- Element e = (Element) n;
- String localName = n.getNodeName();
-
Iterator i = applicableActionList.iterator();
while (i.hasNext()) {
Action action = (Action) i.next();
- action.begin(ec, e);
+ action.begin(ec, tagName, atts);
}
}
- void callEndAction(List applicableActionList, Node n) {
+ void callEndAction(List applicableActionList, String tagName) {
if (applicableActionList == null) {
return;
}
- short type = n.getNodeType();
-
- if (type != Node.ELEMENT_NODE) {
- return;
- }
-
- Element e = (Element) n;
- String localName = n.getNodeName();
//logger.debug("About to call end actions on node: <" + localName + ">");
-
Iterator i = applicableActionList.iterator();
while (i.hasNext()) {
Action action = (Action) i.next();
- action.end(ec, e);
+ action.end(ec, tagName);
}
}
@@ -170,5 +165,4 @@
public void setRuleStore(RuleStore ruleStore) {
this.ruleStore = ruleStore;
}
-
}
1.5 +9 -0 logging-log4j/src/java/org/apache/joran/Pattern.java
Index: Pattern.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/joran/Pattern.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Pattern.java 27 Feb 2004 16:47:28 -0000 1.4
+++ Pattern.java 30 Mar 2004 17:13:22 -0000 1.5
@@ -76,6 +76,15 @@
components.remove(components.size() - 1);
}
}
+
+ String peekLast() {
+ if (!components.isEmpty()) {
+ int size = components.size();
+ return (String) components.get(size - 1);
+ } else {
+ return null;
+ }
+ }
/**
* Returns the number of "tail" components that this pattern has in common
1.2 +83 -68 logging-log4j/tests/src/java/org/apache/joran/PatternTest.java
Index: PatternTest.java
===================================================================
RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/joran/PatternTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PatternTest.java 11 Sep 2003 16:06:28 -0000 1.1
+++ PatternTest.java 30 Mar 2004 17:13:22 -0000 1.2
@@ -1,4 +1,20 @@
/*
+ * Copyright 1999,2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
* Created on Aug 25, 2003
*
* To change the template for this generated file go to
@@ -8,6 +24,7 @@
import junit.framework.TestCase;
+
/**
* @author ceki
*
@@ -15,73 +32,71 @@
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class PatternTest extends TestCase {
-
- /**
- * Constructor for PatternTestCase.
- * @param name
- */
- public PatternTest(String name) {
- super(name);
- }
-
- /*
- * @see TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- /*
- * @see TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- public void test1() {
- Pattern p = new Pattern("a");
- assertEquals(1, p.size());
- assertEquals("a", p.get(0));
- }
-
- public void test2() {
- Pattern p = new Pattern("a/b");
- assertEquals(2, p.size());
- assertEquals("a", p.get(0));
- assertEquals("b", p.get(1));
- }
-
- public void test3() {
- Pattern p = new Pattern("a123/b1234/cvvsdf");
- assertEquals(3, p.size());
- assertEquals("a123", p.get(0));
- assertEquals("b1234", p.get(1));
- assertEquals("cvvsdf", p.get(2));
- }
-
- public void test4() {
- Pattern p = new Pattern("/a123/b1234/cvvsdf");
- assertEquals(3, p.size());
- assertEquals("a123", p.get(0));
- assertEquals("b1234", p.get(1));
- assertEquals("cvvsdf", p.get(2));
- }
-
-
- public void test5() {
- Pattern p = new Pattern("//a");
- assertEquals(1, p.size());
- assertEquals("a", p.get(0));
- }
-
- public void test6() {
- Pattern p = new Pattern("//a//b");
- assertEquals(2, p.size());
- assertEquals("a", p.get(0));
- assertEquals("b", p.get(1));
- }
-
-
-
+ /**
+ * Constructor for PatternTestCase.
+ * @param name
+ */
+ public PatternTest(String name) {
+ super(name);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void test1() {
+ Pattern p = new Pattern("a");
+ assertEquals(1, p.size());
+ assertEquals("a", p.peekLast());
+ assertEquals("a", p.get(0));
+ }
+
+ public void test2() {
+ Pattern p = new Pattern("a/b");
+ assertEquals(2, p.size());
+ assertEquals("b", p.peekLast());
+ assertEquals("a", p.get(0));
+ assertEquals("b", p.get(1));
+ }
+
+ public void test3() {
+ Pattern p = new Pattern("a123/b1234/cvvsdf");
+ assertEquals(3, p.size());
+ assertEquals("a123", p.get(0));
+ assertEquals("b1234", p.get(1));
+ assertEquals("cvvsdf", p.get(2));
+ }
+
+ public void test4() {
+ Pattern p = new Pattern("/a123/b1234/cvvsdf");
+ assertEquals(3, p.size());
+ assertEquals("a123", p.get(0));
+ assertEquals("b1234", p.get(1));
+ assertEquals("cvvsdf", p.get(2));
+ }
+
+ public void test5() {
+ Pattern p = new Pattern("//a");
+ assertEquals(1, p.size());
+ assertEquals("a", p.get(0));
+ }
+
+ public void test6() {
+ Pattern p = new Pattern("//a//b");
+ assertEquals(2, p.size());
+ assertEquals("a", p.get(0));
+ assertEquals("b", p.get(1));
+ }
+
}
1.3 +7 -7
logging-log4j/tests/src/java/org/apache/joran/SimpleStoreTest.java
Index: SimpleStoreTest.java
===================================================================
RCS file:
/home/cvs/logging-log4j/tests/src/java/org/apache/joran/SimpleStoreTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SimpleStoreTest.java 27 Feb 2004 16:47:35 -0000 1.2
+++ SimpleStoreTest.java 30 Mar 2004 17:13:22 -0000 1.3
@@ -26,7 +26,7 @@
import junit.framework.TestCase;
import org.w3c.dom.Document;
-import org.w3c.dom.Element;
+import org.xml.sax.Attributes;
import java.util.List;
@@ -154,10 +154,10 @@
}
class XAction extends Action {
- public void begin(ExecutionContext ec, Element e) {
+ public void begin(ExecutionContext ec, String name, Attributes attributes) {
}
- public void end(ExecutionContext ec, Element e) {
+ public void end(ExecutionContext ec, String name) {
}
public void finish(ExecutionContext ec) {
@@ -165,20 +165,20 @@
}
class YAction extends Action {
- public void begin(ExecutionContext ec, Element e) {
+ public void begin(ExecutionContext ec, String name, Attributes
attributes) {
}
- public void end(ExecutionContext ec, Element e) {
+ public void end(ExecutionContext ec, String name) {
}
public void finish(ExecutionContext ec) {
} }
class ZAction extends Action {
- public void begin(ExecutionContext ec, Element e) {
+ public void begin(ExecutionContext ec, String name, Attributes
attributes) {
}
- public void end(ExecutionContext ec, Element e) {
+ public void end(ExecutionContext ec, String name) {
}
public void finish(ExecutionContext ec) {
1.9 +81 -53
logging-log4j/tests/src/java/org/apache/joran/JoranParserTest.java
Index: JoranParserTest.java
===================================================================
RCS file:
/home/cvs/logging-log4j/tests/src/java/org/apache/joran/JoranParserTest.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- JoranParserTest.java 27 Feb 2004 16:47:35 -0000 1.8
+++ JoranParserTest.java 30 Mar 2004 17:13:22 -0000 1.9
@@ -22,14 +22,18 @@
*/
package org.apache.joran;
+import junit.framework.Test;
import junit.framework.TestCase;
+import junit.framework.TestSuite;
import org.apache.joran.action.NestComponentIA;
import org.apache.joran.action.NewRuleAction;
import org.apache.joran.action.ParamAction;
+import org.apache.joran.action.StackCounterAction;
import org.apache.log4j.Appender;
import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
@@ -42,12 +46,11 @@
import org.apache.log4j.joran.action.LoggerAction;
import org.apache.log4j.joran.action.RootLoggerAction;
-import org.w3c.dom.Document;
-
import java.util.HashMap;
+import java.util.Stack;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
/**
@@ -86,17 +89,42 @@
LogManager.shutdown();
}
- public void xtestLoop() throws Exception {
- logger.debug("Starting testLoop");
-
- DocumentBuilderFactory dbf = null;
-
- dbf = DocumentBuilderFactory.newInstance();
+ SAXParser createParser() throws Exception {
+ SAXParserFactory spf = SAXParserFactory.newInstance();
+ return spf.newSAXParser();
+ }
+ public void testBasicLoop() throws Exception {
+
+ RuleStore rs = new SimpleRuleStore();
+ rs.addRule(
+ new Pattern("log4j:configuration"), new StackCounterAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/root"), new StackCounterAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/root/level"), new StackCounterAction());
- DocumentBuilder docBuilder = dbf.newDocumentBuilder();
+ JoranParser jp = new JoranParser(rs);
+ ExecutionContext ec = jp.getExecutionContext();
+ SAXParser saxParser = createParser();
+ saxParser.parse("file:input/joran/basicLoop.xml", jp);
+
+ Stack witness = new Stack();
+ witness.push("log4j:configuration-begin");
+ witness.push("root-begin");
+ witness.push("level-begin");
+ witness.push("level-end");
+ witness.push("root-end");
+ witness.push("log4j:configuration-end");
+ assertEquals(witness, ec.getObjectStack());
+ }
+
+ /**
+ * This test verifies that <logger>, <root> and embedded <level> elements
+ * are handled correctly.
+ */
+ public void testLoop() throws Exception {
+ logger.debug("Starting testLoop");
- //inputSource.setSystemId("dummy://log4j.dtd");
- Document doc = docBuilder.parse("file:input/joran/parser1.xml");
RuleStore rs = new SimpleRuleStore();
logger.debug("pattern: " + new Pattern("log4j:configuration/logger"));
rs.addRule(new Pattern("log4j:configuration/logger"), new LoggerAction());
@@ -105,27 +133,35 @@
rs.addRule(
new Pattern("log4j:configuration/root"), new RootLoggerAction());
rs.addRule(
- new Pattern("log4j:configuration/root"), new RootLoggerAction());
+ new Pattern("log4j:configuration/root/level"), new LevelAction());
JoranParser jp = new JoranParser(rs);
ExecutionContext ec = jp.getExecutionContext();
HashMap omap = ec.getObjectMap();
omap.put(ActionConst.APPENDER_BAG, new HashMap());
ec.pushObject(LogManager.getLoggerRepository());
- jp.parse(doc);
+ SAXParser saxParser = createParser();
+ saxParser.parse("file:input/joran/parser1.xml", jp);
+
+ Logger rootLogger = LogManager.getLoggerRepository().getRootLogger();
+ assertSame(Level.WARN, rootLogger.getLevel());
+
+ Logger asdLogger = LogManager.getLoggerRepository().getLogger("asd");
+ assertSame(Level.DEBUG, asdLogger.getLevel());
+
+ assertEquals(2, ec.getErrorList().size());
+ String e0 = (String) ec.getErrorList().get(0);
+ if(!e0.startsWith("No 'name' attribute in element")) {
+ fail("Expected error string [No 'name' attribute in element]");
+ }
+ String e1 = (String) ec.getErrorList().get(1);
+ if(!e1.startsWith("For element <level>")) {
+ fail("Expected error string [For element <level>]");
+ }
}
public void xtestLoop2() throws Exception {
logger.debug("Starting testLoop2");
-
- DocumentBuilderFactory dbf = null;
-
- dbf = DocumentBuilderFactory.newInstance();
-
- DocumentBuilder docBuilder = dbf.newDocumentBuilder();
-
- //inputSource.setSystemId("dummy://log4j.dtd");
- Document doc = docBuilder.parse("file:input/joran/parser2.xml");
RuleStore rs = new SimpleRuleStore();
rs.addRule(new Pattern("log4j:configuration/logger"), new LoggerAction());
rs.addRule(
@@ -151,20 +187,13 @@
HashMap omap = ec.getObjectMap();
omap.put(ActionConst.APPENDER_BAG, new HashMap());
ec.pushObject(LogManager.getLoggerRepository());
- jp.parse(doc);
+ SAXParser saxParser = createParser();
+ saxParser.parse("file:input/joran/parser2.xml", jp);
}
public void xtestLoop3() throws Exception {
logger.debug("Starting testLoop3");
- DocumentBuilderFactory dbf = null;
-
- dbf = DocumentBuilderFactory.newInstance();
-
- DocumentBuilder docBuilder = dbf.newDocumentBuilder();
-
- //inputSource.setSystemId("dummy://log4j.dtd");
- Document doc = docBuilder.parse("file:input/joran/parser3.xml");
RuleStore rs = new SimpleRuleStore();
rs.addRule(new Pattern("log4j:configuration/logger"), new LoggerAction());
rs.addRule(
@@ -194,20 +223,15 @@
omap.put(ActionConst.APPENDER_BAG, new HashMap());
ec.pushObject(LogManager.getLoggerRepository());
logger.debug("About to parse doc");
- jp.parse(doc);
+
+ SAXParser saxParser = createParser();
+ saxParser.parse("file:input/joran/parser3.xml", jp);
+
}
public void testNewConversionWord() throws Exception {
logger.debug("Starting testNewConversionWord");
- DocumentBuilderFactory dbf = null;
-
- dbf = DocumentBuilderFactory.newInstance();
-
- DocumentBuilder docBuilder = dbf.newDocumentBuilder();
-
- //inputSource.setSystemId("dummy://log4j.dtd");
- Document doc = docBuilder.parse("file:input/joran/conversionRule.xml");
RuleStore rs = new SimpleRuleStore();
rs.addRule(
new Pattern("log4j:configuration/appender"), new AppenderAction());
@@ -226,7 +250,9 @@
HashMap omap = ec.getObjectMap();
omap.put(ActionConst.APPENDER_BAG, new HashMap());
ec.pushObject(LogManager.getLoggerRepository());
- jp.parse(doc);
+
+ SAXParser saxParser = createParser();
+ saxParser.parse("file:input/joran/conversionRule.xml", jp);
HashMap appenderBag =
(HashMap) ec.getObjectMap().get(ActionConst.APPENDER_BAG);
@@ -237,15 +263,7 @@
public void testNewRule1() throws Exception {
logger.debug("Starting testNewConversionWord");
-
- DocumentBuilderFactory dbf = null;
-
- dbf = DocumentBuilderFactory.newInstance();
-
- DocumentBuilder docBuilder = dbf.newDocumentBuilder();
-
- //inputSource.setSystemId("dummy://log4j.dtd");
- Document doc = docBuilder.parse("file:input/joran/newRule1.xml");
+
RuleStore rs = new SimpleRuleStore();
rs.addRule(
new Pattern("log4j:configuration/newRule"),
@@ -256,9 +274,19 @@
HashMap omap = ec.getObjectMap();
omap.put(ActionConst.APPENDER_BAG, new HashMap());
ec.pushObject(LogManager.getLoggerRepository());
- jp.parse(doc);
+
+ SAXParser saxParser = createParser();
+ saxParser.parse("file:input/joran/newRule1.xml", jp);
String str = (String) ec.getObjectMap().get("hello");
assertEquals("Hello John Doe.", str);
}
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ //suite.addTest(new JoranParserTest("testBasicLoop"));
+ suite.addTest(new JoranParserTest("testLoop"));
+ return suite;
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]