ceki 2003/08/25 09:17:59
Modified: src/java/org/apache/joran JoranParser.java RuleStore.java
Context.java SimpleRuleStore.java Rule.java
Action.java Pattern.java
tests/src/java/org/apache/joran SimpleStoreTestCase.java
Log:
Jalopy formatting
Revision Changes Path
1.2 +121 -75 jakarta-log4j/src/java/org/apache/joran/JoranParser.java
Index: JoranParser.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/joran/JoranParser.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JoranParser.java 25 Aug 2003 15:37:18 -0000 1.1
+++ JoranParser.java 25 Aug 2003 16:17:59 -0000 1.2
@@ -1,86 +1,132 @@
-package org.apache.joran;
+/*
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "log4j" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation. For more information on the
+ * Apache Software Foundation, please see <http://www.apache.org/>.
+ *
+ */
-import java.util.Iterator;
-import java.util.List;
+package org.apache.joran;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-public class JoranParser {
+import java.util.Iterator;
+import java.util.List;
- private RuleStore ruleStore;
- JoranParser(RuleStore rs) {
- ruleStore = rs;
- }
-
- public void parse(Document document) {
-
- Pattern pattern = new Pattern();
- Element e = document.getDocumentElement();
- loop(e, pattern);
- }
-
- void loop(Node n, Pattern pattern) {
- if (n == null) {
- return;
- }
-
- try {
- pattern.push(n.getNodeName());
- if (n instanceof Element) {
- System.out.println("pattern is " + pattern);
- }
-
- List applicableActionList = ruleStore.matchActions(pattern);
-
- if(applicableActionList != null) {
- callBeginAction(applicableActionList, n);
- }
-
- if (n.hasChildNodes()) {
- for (Node c = n.getFirstChild();
- c != null;
- c = c.getNextSibling()) {
- loop(c, pattern);
- }
- }
- if(applicableActionList != null) {
- callEndAction(n);
- }
- } finally {
- pattern.pop();
- }
- }
-
- void callBeginAction(List applicableActionList, Node n) {
- if(applicableActionList == null) {
- return;
- }
-
- short type = n.getNodeType();
-
- if(type != Node.ELEMENT_NODE) {
- return;
- }
-
- Element e = (Element) n;
- String localName = n.getNodeName();
- System.out.println("New node: <" + localName + ">");
- System.out.println(" node is an element");
- System.out.println(
- " element attribs: " + e.getAttributes());
-
- Iterator i = applicableActionList.iterator();
-
- while (i.hasNext()) {
- Action action = (Action) i.next();
- action.begin(e);
- }
- }
+public class JoranParser {
+ private RuleStore ruleStore;
- void callEndAction(Node n) {
- }
+ JoranParser(RuleStore rs) {
+ ruleStore = rs;
+ }
+
+ public void parse(Document document) {
+ Pattern pattern = new Pattern();
+ Element e = document.getDocumentElement();
+ loop(e, pattern);
+ }
+
+ void loop(Node n, Pattern pattern) {
+ if (n == null) {
+ return;
+ }
+
+ try {
+ pattern.push(n.getNodeName());
+
+ if (n instanceof Element) {
+ System.out.println("pattern is " + pattern);
+ }
+
+ List applicableActionList = ruleStore.matchActions(pattern);
+
+ if (applicableActionList != null) {
+ callBeginAction(applicableActionList, n);
+ }
+
+ if (n.hasChildNodes()) {
+ for (Node c = n.getFirstChild(); c != null; c = c.getNextSibling()) {
+ loop(c, pattern);
+ }
+ }
+
+ if (applicableActionList != null) {
+ callEndAction(n);
+ }
+ } finally {
+ pattern.pop();
+ }
+ }
+
+ void callBeginAction(List applicableActionList, Node n) {
+ if (applicableActionList == null) {
+ return;
+ }
+
+ short type = n.getNodeType();
+
+ if (type != Node.ELEMENT_NODE) {
+ return;
+ }
+
+ Element e = (Element) n;
+ String localName = n.getNodeName();
+ System.out.println("New node: <" + localName + ">");
+ System.out.println(" node is an element");
+ System.out.println(" element attribs: " + e.getAttributes());
+
+ Iterator i = applicableActionList.iterator();
+
+ while (i.hasNext()) {
+ Action action = (Action) i.next();
+ action.begin(e);
+ }
+ }
+ void callEndAction(Node n) {
+ }
}
1.2 +51 -2 jakarta-log4j/src/java/org/apache/joran/RuleStore.java
Index: RuleStore.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/joran/RuleStore.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RuleStore.java 25 Aug 2003 15:37:18 -0000 1.1
+++ RuleStore.java 25 Aug 2003 16:17:59 -0000 1.2
@@ -1,10 +1,59 @@
+/*
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "log4j" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation. For more information on the
+ * Apache Software Foundation, please see <http://www.apache.org/>.
+ *
+ */
+
package org.apache.joran;
import java.util.List;
-public interface RuleStore {
+public interface RuleStore {
public void addRule(Pattern pattern, Action action);
-
+
public List matchActions(Pattern pattern);
}
1.2 +52 -5 jakarta-log4j/src/java/org/apache/joran/Context.java
Index: Context.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/joran/Context.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Context.java 25 Aug 2003 15:37:18 -0000 1.1
+++ Context.java 25 Aug 2003 16:17:59 -0000 1.2
@@ -1,4 +1,53 @@
/*
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "log4j" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation. For more information on the
+ * Apache Software Foundation, please see <http://www.apache.org/>.
+ *
+ */
+
+/*
* Created on Aug 23, 2003
*
* To change the template for this generated file go to
@@ -10,13 +59,11 @@
/**
- *
+ *
* Joran is designed to parse DOM trees
- *
+ *
*/
public class Context {
-
- Stack objectStack;
+ Stack objectStack;
Stack ipStack;
-
}
1.2 +96 -48 jakarta-log4j/src/java/org/apache/joran/SimpleRuleStore.java
Index: SimpleRuleStore.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/joran/SimpleRuleStore.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SimpleRuleStore.java 25 Aug 2003 15:37:18 -0000 1.1
+++ SimpleRuleStore.java 25 Aug 2003 16:17:59 -0000 1.2
@@ -1,59 +1,107 @@
+/*
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "log4j" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation. For more information on the
+ * Apache Software Foundation, please see <http://www.apache.org/>.
+ *
+ */
+
package org.apache.joran;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-public class SimpleRuleStore implements RuleStore {
+public class SimpleRuleStore implements RuleStore {
HashMap rules = new HashMap();
-
- public void addRule(Pattern pattern, Action action) {
- //System.out.println("pattern to add is:" + pattern + "hashcode:" +
pattern.hashCode());
- List a4p = (List) rules.get(pattern);
-
- if(a4p == null) {
- a4p = new ArrayList();
- rules.put(pattern, a4p);
- }
- a4p.add(action);
- }
-
- public List matchActions(Pattern pattern) {
-
- //System.out.println("pattern to search for:" + pattern + ", hashcode:
" + pattern.hashCode());
- //System.out.println("rules:" + rules);
-
- ArrayList a4p = (ArrayList) rules.get(pattern);
-
- if(a4p != null) {
- return a4p;
- } else {
-
- Iterator patternsIterator = rules.keySet().iterator();
- int max = 0;
- Pattern longestMatch = null;
- while(patternsIterator.hasNext()) {
- Pattern p = (Pattern) patternsIterator.next();
- if((p.size() > 1) && p.get(0).equals("*")) {
- int r = pattern.tailMatch(p);
- //System.out.println("tailMatch " +r);
- if(r > max) {
- //System.out.println("New longest match "+p);
- max = r;
- longestMatch = p;
- }
- }
- }
-
- if(longestMatch != null) {
- return (ArrayList) rules.get(longestMatch);
- } else {
- return null;
- }
- }
-
- }
+ public void addRule(Pattern pattern, Action action) {
+ //System.out.println("pattern to add is:" + pattern + "hashcode:" +
pattern.hashCode());
+ List a4p = (List) rules.get(pattern);
+
+ if (a4p == null) {
+ a4p = new ArrayList();
+ rules.put(pattern, a4p);
+ }
+
+ a4p.add(action);
+ }
+
+ public List matchActions(Pattern pattern) {
+ //System.out.println("pattern to search for:" + pattern + ", hashcode: " +
pattern.hashCode());
+ //System.out.println("rules:" + rules);
+ ArrayList a4p = (ArrayList) rules.get(pattern);
+
+ if (a4p != null) {
+ return a4p;
+ } else {
+ Iterator patternsIterator = rules.keySet().iterator();
+ int max = 0;
+ Pattern longestMatch = null;
+
+ while (patternsIterator.hasNext()) {
+ Pattern p = (Pattern) patternsIterator.next();
+
+ if ((p.size() > 1) && p.get(0).equals("*")) {
+ int r = pattern.tailMatch(p);
+
+ //System.out.println("tailMatch " +r);
+ if (r > max) {
+ //System.out.println("New longest match "+p);
+ max = r;
+ longestMatch = p;
+ }
+ }
+ }
+ if (longestMatch != null) {
+ return (ArrayList) rules.get(longestMatch);
+ } else {
+ return null;
+ }
+ }
+ }
}
1.2 +49 -13 jakarta-log4j/src/java/org/apache/joran/Rule.java
Index: Rule.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/joran/Rule.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Rule.java 25 Aug 2003 15:37:18 -0000 1.1
+++ Rule.java 25 Aug 2003 16:17:59 -0000 1.2
@@ -1,24 +1,60 @@
/*
- * Created on Aug 23, 2003
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "log4j" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation. For more information on the
+ * Apache Software Foundation, please see <http://www.apache.org/>.
*
- * To change the template for this generated file go to
- * Window>Preferences>Java>Code Generation>Code and Comments
*/
+
package org.apache.joran;
-/**
- * @author ceki
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
public class Rule {
-
Pattern pattern;
Action action;
-
+
Rule(Pattern p, Action a) {
- pattern = p;
- action = a;
+ pattern = p;
+ action = a;
}
}
1.2 +3 -3 jakarta-log4j/src/java/org/apache/joran/Action.java
Index: Action.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/joran/Action.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Action.java 25 Aug 2003 15:37:18 -0000 1.1
+++ Action.java 25 Aug 2003 16:17:59 -0000 1.2
@@ -62,14 +62,14 @@
* project of the Apache Software Foundation.
*
* @author Craig McClanahan
- * @authro Christopher Lenz
+ * @authro Christopher Lenz
* @author Ceki Gülcü
*
*/
public abstract class Action {
-
-
public abstract void begin(Element e);
+
public abstract void end(Element e);
+
public abstract void finish();
}
1.2 +161 -102 jakarta-log4j/src/java/org/apache/joran/Pattern.java
Index: Pattern.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/joran/Pattern.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Pattern.java 25 Aug 2003 15:37:18 -0000 1.1
+++ Pattern.java 25 Aug 2003 16:17:59 -0000 1.2
@@ -1,132 +1,191 @@
+/*
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "log4j" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation. For more information on the
+ * Apache Software Foundation, please see <http://www.apache.org/>.
+ *
+ */
+
package org.apache.joran;
import java.util.ArrayList;
+
public class Pattern {
+ //String patternStr;
+ ArrayList components;
+
+ public Pattern() {
+ components = new ArrayList();
+ }
+
+ Pattern(String p) {
+ this();
- //String patternStr;
- ArrayList components;
-
- public Pattern() {
- components = new ArrayList();
- }
-
- Pattern(String p) {
- this();
-
- if(p == null) {
- return;
- }
-
- int lastIndex = 0;
- //System.out.println("p is "+ p);
- while(true) {
- int k = p.indexOf('/', lastIndex);
- //System.out.println("k is "+ k);
- if(k == -1) {
- components.add(p.substring(lastIndex));
- break;
- } else {
- String c = p.substring(lastIndex, k);
- if(c.length() > 0) {
- components.add(c);
- }
- lastIndex = k+1;
- }
- }
-
- //System.out.println(components);
- }
-
- void push(String s) {
- components.add(s);
- }
+ if (p == null) {
+ return;
+ }
+
+ int lastIndex = 0;
+
+ //System.out.println("p is "+ p);
+ while (true) {
+ int k = p.indexOf('/', lastIndex);
+
+ //System.out.println("k is "+ k);
+ if (k == -1) {
+ components.add(p.substring(lastIndex));
+
+ break;
+ } else {
+ String c = p.substring(lastIndex, k);
+
+ if (c.length() > 0) {
+ components.add(c);
+ }
+
+ lastIndex = k + 1;
+ }
+ }
+
+ //System.out.println(components);
+ }
+
+ void push(String s) {
+ components.add(s);
+ }
public int size() {
- return components.size();
+ return components.size();
}
public String get(int i) {
- return (String) components.get(i);
+ return (String) components.get(i);
}
- void pop() {
- if (!components.isEmpty()) {
- components.remove(components.size() - 1);
- }
- }
+ void pop() {
+ if (!components.isEmpty()) {
+ components.remove(components.size() - 1);
+ }
+ }
/**
- * Returns the number of "tail" components that this pattern has in common
+ * Returns the number of "tail" components that this pattern has in common
* with the pattern p passed as parameter. By "tail" components we mean the
* components at the end of the pattern.
*/
public int tailMatch(Pattern p) {
- if(p == null) {
- return 0;
+ if (p == null) {
+ return 0;
}
-
- int lSize = this.components.size();
- int rSize = p.components.size();
+
+ int lSize = this.components.size();
+ int rSize = p.components.size();
// no match possible for empty sets
- if(lSize == 0 || rSize == 0) {
- return 0;
- }
-
- int minLen = lSize <= rSize ? lSize : rSize;
- int match = 0;
- // loop from the end to the front
- for(int i = 1; i <= minLen; i++) {
- String l = (String) this.components.get(lSize-i);
- String r = (String) p.components.get(rSize-i);
- if(l.equals(r)) {
- match++;
- } else {
- break;
- }
- }
- return match;
+ if ((lSize == 0) || (rSize == 0)) {
+ return 0;
+ }
+
+ int minLen = (lSize <= rSize) ? lSize : rSize;
+ int match = 0;
+
+ // loop from the end to the front
+ for (int i = 1; i <= minLen; i++) {
+ String l = (String) this.components.get(lSize - i);
+ String r = (String) p.components.get(rSize - i);
+
+ if (l.equals(r)) {
+ match++;
+ } else {
+ break;
+ }
+ }
+
+ return match;
}
-
+
public boolean equals(Object o) {
- //System.out.println("in equals:" +this+ " vs. " + o);
- if((o == null) || !(o instanceof Pattern)) {
- return false;
- }
-
- //System.out.println("both are Patterns");
- Pattern r = (Pattern) o;
-
- if(r.size() != size()) {
- return false;
- }
-
- //System.out.println("both are size compatible");
- int len = size();
-
- for(int i = 0; i <len; i++) {
- if(!(get(i).equals(r.get(i)))) {
- return false;
- }
- }
-
- // if everything matches, then the twp patterns are equal
- return true;
+ //System.out.println("in equals:" +this+ " vs. " + o);
+ if ((o == null) || !(o instanceof Pattern)) {
+ return false;
+ }
+
+ //System.out.println("both are Patterns");
+ Pattern r = (Pattern) o;
+
+ if (r.size() != size()) {
+ return false;
+ }
+
+ //System.out.println("both are size compatible");
+ int len = size();
+
+ for (int i = 0; i < len; i++) {
+ if (!(get(i).equals(r.get(i)))) {
+ return false;
+ }
+ }
+
+ // if everything matches, then the twp patterns are equal
+ return true;
}
-
+
public int hashCode() {
- int hc = 0;
- int len = size();
- for(int i = 0; i < len; i++) {
- hc ^= get(i).hashCode();
- //System.out.println("i = "+i+", hc="+hc);
- }
- return hc;
+ int hc = 0;
+ int len = size();
+
+ for (int i = 0; i < len; i++) {
+ hc ^= get(i).hashCode();
+
+ //System.out.println("i = "+i+", hc="+hc);
+ }
+
+ return hc;
}
-
-
+
public String toString() {
- return components.toString();
+ return components.toString();
}
}
1.2 +199 -134
jakarta-log4j/tests/src/java/org/apache/joran/SimpleStoreTestCase.java
Index: SimpleStoreTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/tests/src/java/org/apache/joran/SimpleStoreTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SimpleStoreTestCase.java 25 Aug 2003 16:14:32 -0000 1.1
+++ SimpleStoreTestCase.java 25 Aug 2003 16:17:59 -0000 1.2
@@ -1,4 +1,53 @@
/*
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "log4j" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation. For more information on the
+ * Apache Software Foundation, please see <http://www.apache.org/>.
+ *
+ */
+
+/*
* Created on Aug 25, 2003
*
* To change the template for this generated file go to
@@ -6,15 +55,16 @@
*/
package org.apache.joran;
+import junit.framework.TestCase;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import junit.framework.TestCase;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
/**
* @author ceki
@@ -23,133 +73,148 @@
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class SimpleStoreTestCase extends TestCase {
-
- /**
- * Constructor for SimpleStoreTestCase.
- * @param name
- */
- public SimpleStoreTestCase(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() throws Exception {
-
- //Document doc = getW3Document("file:input/joran/parser1.xml");
-
- SimpleRuleStore srs = new SimpleRuleStore();
- srs.addRule(new Pattern("a/b"), new XAction());
-
- List r = srs.matchActions(new Pattern("a/b"));
- assertNotNull(r);
- assertEquals(1, r.size());
- if (!(r.get(0) instanceof XAction)) {
- fail("Wring type");
- }
-
- srs = new SimpleRuleStore();
- srs.addRule(new Pattern("a/b"), new XAction());
- srs.addRule(new Pattern("a/b"), new YAction());
-
- r = srs.matchActions(new Pattern("a/b"));
- assertNotNull(r);
- assertEquals(2, r.size());
- if (!(r.get(0) instanceof XAction)) {
- fail("Wrong type");
- }
- if (!(r.get(1) instanceof YAction)) {
- fail("Wrong type");
- }
-
- //jp.parse(doc);
- }
-
- public void test2() throws Exception {
- SimpleRuleStore srs = new SimpleRuleStore();
- srs.addRule(new Pattern("*/b"), new XAction());
- List r = srs.matchActions(new Pattern("a/b"));
- assertNotNull(r);
- //System.out.println(r);
- assertEquals(1, r.size());
- if (!(r.get(0) instanceof XAction)) {
- fail("Wring type");
- }
- }
-
- public void test3() throws Exception {
- SimpleRuleStore srs = new SimpleRuleStore();
- srs.addRule(new Pattern("*/b"), new XAction());
- srs.addRule(new Pattern("*/a/b"), new YAction());
-
- List r = srs.matchActions(new Pattern("a/b"));
- assertNotNull(r);
- //System.out.println("restulg list is: "+r);
- assertEquals(1, r.size());
- if (!(r.get(0) instanceof YAction)) {
- fail("Wring type");
- }
- }
-
- public void test4() throws Exception {
- SimpleRuleStore srs = new SimpleRuleStore();
- srs.addRule(new Pattern("*/b"), new XAction());
- srs.addRule(new Pattern("*/a/b"), new YAction());
- srs.addRule(new Pattern("a/b"), new ZAction());
-
- List r = srs.matchActions(new Pattern("a/b"));
- assertNotNull(r);
- //System.out.println("restulg list is: "+r);
- assertEquals(1, r.size());
- if (!(r.get(0) instanceof ZAction)) {
- fail("Wring type");
- }
- }
-
- Document getW3Document(String file) throws Exception {
- DocumentBuilderFactory dbf = null;
- dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder docBuilder = dbf.newDocumentBuilder();
- //inputSource.setSystemId("dummy://log4j.dtd");
- return docBuilder.parse(file);
- }
-
- class XAction extends Action {
- public void begin(Element e) {
- }
- public void end(Element e) {
- }
- public void finish() {
- }
- }
-
- class YAction extends Action {
- public void begin(Element e) {
- }
- public void end(Element e) {
- }
- public void finish() {
- }
- }
- class ZAction extends Action {
- public void begin(Element e) {
- }
- public void end(Element e) {
- }
- public void finish() {
- }
- }
-
-}
\ No newline at end of file
+ /**
+ * Constructor for SimpleStoreTestCase.
+ * @param name
+ */
+ public SimpleStoreTestCase(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() throws Exception {
+ //Document doc = getW3Document("file:input/joran/parser1.xml");
+ SimpleRuleStore srs = new SimpleRuleStore();
+ srs.addRule(new Pattern("a/b"), new XAction());
+
+ List r = srs.matchActions(new Pattern("a/b"));
+ assertNotNull(r);
+ assertEquals(1, r.size());
+
+ if (!(r.get(0) instanceof XAction)) {
+ fail("Wring type");
+ }
+
+ srs = new SimpleRuleStore();
+ srs.addRule(new Pattern("a/b"), new XAction());
+ srs.addRule(new Pattern("a/b"), new YAction());
+
+ r = srs.matchActions(new Pattern("a/b"));
+ assertNotNull(r);
+ assertEquals(2, r.size());
+
+ if (!(r.get(0) instanceof XAction)) {
+ fail("Wrong type");
+ }
+
+ if (!(r.get(1) instanceof YAction)) {
+ fail("Wrong type");
+ }
+
+ //jp.parse(doc);
+ }
+
+ public void test2() throws Exception {
+ SimpleRuleStore srs = new SimpleRuleStore();
+ srs.addRule(new Pattern("*/b"), new XAction());
+
+ List r = srs.matchActions(new Pattern("a/b"));
+ assertNotNull(r);
+
+ //System.out.println(r);
+ assertEquals(1, r.size());
+
+ if (!(r.get(0) instanceof XAction)) {
+ fail("Wring type");
+ }
+ }
+
+ public void test3() throws Exception {
+ SimpleRuleStore srs = new SimpleRuleStore();
+ srs.addRule(new Pattern("*/b"), new XAction());
+ srs.addRule(new Pattern("*/a/b"), new YAction());
+
+ List r = srs.matchActions(new Pattern("a/b"));
+ assertNotNull(r);
+
+ //System.out.println("restulg list is: "+r);
+ assertEquals(1, r.size());
+
+ if (!(r.get(0) instanceof YAction)) {
+ fail("Wring type");
+ }
+ }
+
+ public void test4() throws Exception {
+ SimpleRuleStore srs = new SimpleRuleStore();
+ srs.addRule(new Pattern("*/b"), new XAction());
+ srs.addRule(new Pattern("*/a/b"), new YAction());
+ srs.addRule(new Pattern("a/b"), new ZAction());
+
+ List r = srs.matchActions(new Pattern("a/b"));
+ assertNotNull(r);
+
+ //System.out.println("restulg list is: "+r);
+ assertEquals(1, r.size());
+
+ if (!(r.get(0) instanceof ZAction)) {
+ fail("Wring type");
+ }
+ }
+
+ Document getW3Document(String file) throws Exception {
+ DocumentBuilderFactory dbf = null;
+ dbf = DocumentBuilderFactory.newInstance();
+
+ DocumentBuilder docBuilder = dbf.newDocumentBuilder();
+
+ //inputSource.setSystemId("dummy://log4j.dtd");
+ return docBuilder.parse(file);
+ }
+
+ class XAction extends Action {
+ public void begin(Element e) {
+ }
+
+ public void end(Element e) {
+ }
+
+ public void finish() {
+ }
+ }
+
+ class YAction extends Action {
+ public void begin(Element e) {
+ }
+
+ public void end(Element e) {
+ }
+
+ public void finish() {
+ }
+ }
+
+ class ZAction extends Action {
+ public void begin(Element e) {
+ }
+
+ public void end(Element e) {
+ }
+
+ public void finish() {
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]