logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject cvs commit: logging-log4j/src/java/org/apache/joran Interpreter.java
Date Sat, 03 Apr 2004 15:16:10 GMT
ceki        2004/04/03 07:16:10

  Modified:    tests/input/joran newRule1.xml
               tests/src/java/org/apache/joran InterpreterTest.java
               src/java/org/apache/joran Interpreter.java
  Added:       tests/input/joran illFormed.xml
  Removed:     src/java/org/apache/joran/helper SAXErrorHandler.java
  Log:
  
  Slightly better treatment of SAX parsing errors.
  
  In accordance with the YAGNI principle, removed support for custom
  SAXErrorHandlers from Intertreter.
  
  Revision  Changes    Path
  1.3       +1 -1      logging-log4j/tests/input/joran/newRule1.xml
  
  Index: newRule1.xml
  ===================================================================
  RCS file: /home/cvs/logging-log4j/tests/input/joran/newRule1.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- newRule1.xml	3 Apr 2004 14:11:46 -0000	1.2
  +++ newRule1.xml	3 Apr 2004 15:16:10 -0000	1.3
  @@ -1,7 +1,7 @@
   <?xml version="1.0" encoding="UTF-8" ?>
   <!DOCTYPE log4j:configuration>
   
  -<log4j:configuration "xmlns:log4j="http://jakarta.apache.org/log4j/">
  +<log4j:configuration>
   
     <newRule pattern="log4j:configuration/hello" actionClass="org.apache.joran.action.HelloAction"></newRule>
   
  
  
  
  1.1                  logging-log4j/tests/input/joran/illFormed.xml
  
  Index: illFormed.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?>
  <!DOCTYPE log4j:configuration>
  
  <log4j:configuration ">
    <root
      <level value ="debug" />
    </root>  
  </log4j:configuration>
  
  
  
  1.5       +34 -12    logging-log4j/tests/src/java/org/apache/joran/InterpreterTest.java
  
  Index: InterpreterTest.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/joran/InterpreterTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- InterpreterTest.java	3 Apr 2004 14:11:11 -0000	1.4
  +++ InterpreterTest.java	3 Apr 2004 15:16:10 -0000	1.5
  @@ -50,6 +50,7 @@
   import org.apache.log4j.rolling.RollingFileAppender;
   import org.apache.log4j.rolling.SizeBasedTriggeringPolicy;
   import org.apache.log4j.rolling.SlidingWindowRollingPolicy;
  +import org.xml.sax.SAXParseException;
   
   import java.util.HashMap;
   import java.util.Stack;
  @@ -100,6 +101,26 @@
       return spf.newSAXParser();
     }
     
  +  public void testIllFormedXML() throws Exception {
  +    RuleStore rs = new SimpleRuleStore();
  +   
  +    Interpreter jp = new Interpreter(rs);
  +    ExecutionContext ec = jp.getExecutionContext();
  +    SAXParser saxParser = createParser();
  +    try {
  +     saxParser.parse("file:input/joran/illFormed.xml", jp);
  +     fail("A parser exception should have occured");
  +    } catch(SAXParseException e) {
  +      assertEquals(1, ec.getErrorList().size());
  +      ErrorItem e0 = (ErrorItem) ec.getErrorList().get(0);
  +      String e0msg = e0.getMessage();
  +      if(!e0msg.startsWith("Parsing fatal error")) {
  +        fail("Expected error string [Parsing fatal error] but got ["+e0msg+"]");
  +      }
  +      
  +    }
  +  }
  +  
     /** 
      * Tests the basic looping contruct in Interpreter.
      * 
  @@ -163,12 +184,12 @@
       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")) {
  +    ErrorItem e0 = (ErrorItem) ec.getErrorList().get(0);
  +    if(!e0.getMessage().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>")) {
  +    ErrorItem e1 = (ErrorItem) ec.getErrorList().get(1);
  +    if(!e1.getMessage().startsWith("For element <level>")) {
         fail("Expected error string [For element <level>]");
       }
     }
  @@ -227,16 +248,16 @@
       a1Back = (FileAppender) rootLogger.getAppender("A1");  
       
       assertEquals(3, ec.getErrorList().size());
  -    String e0 = (String) ec.getErrorList().get(0);
  -    if(!e0.startsWith("No 'name' attribute in element")) {
  +    ErrorItem e0 = (ErrorItem) ec.getErrorList().get(0);
  +    if(!e0.getMessage().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>")) {
  +    ErrorItem e1 = (ErrorItem) ec.getErrorList().get(1);
  +    if(!e1.getMessage().startsWith("For element <level>")) {
         fail("Expected error string [For element <level>]");
       }
  -    String e2 = (String) ec.getErrorList().get(2);
  -    if(!e2.startsWith("Could not find an AppenderAttachable at the top of execution stack.
Near")) {
  +    ErrorItem e2 = (ErrorItem) ec.getErrorList().get(2);
  +    if(!e2.getMessage().startsWith("Could not find an AppenderAttachable at the top of
execution stack. Near")) {
         fail("Expected error string [Could not find an AppenderAttachable at the top of execution
stack. Near]");
       }
       
  @@ -350,12 +371,13 @@
       assertEquals("Hello John Doe.", str);
     }
     
  -  public static Test xsuite() {
  +  public static Test Xsuite() {
       TestSuite suite = new TestSuite();
  +     suite.addTest(new InterpreterTest("testIllFormedXML"));
       //suite.addTest(new InterpreterTest("testBasicLoop"));
       //suite.addTest(new InterpreterTest("testParsing1"));
       //suite.addTest(new InterpreterTest("testParsing2"));
  -    suite.addTest(new InterpreterTest("testParsing3"));
  +    //suite.addTest(new InterpreterTest("testParsing3"));
       return suite;
     }
   
  
  
  
  1.4       +13 -14    logging-log4j/src/java/org/apache/joran/Interpreter.java
  
  Index: Interpreter.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/joran/Interpreter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Interpreter.java	3 Apr 2004 14:05:15 -0000	1.3
  +++ Interpreter.java	3 Apr 2004 15:16:10 -0000	1.4
  @@ -18,11 +18,10 @@
   
   import org.apache.joran.action.*;
   
  -
   import org.apache.log4j.Logger;
  +import org.apache.log4j.helpers.LogLog;
   
   import org.xml.sax.Attributes;
  -import org.xml.sax.ErrorHandler;
   import org.xml.sax.Locator;
   import org.xml.sax.SAXException;
   import org.xml.sax.SAXParseException;
  @@ -74,7 +73,6 @@
     private ArrayList implicitActions;
     Pattern pattern;
     Locator locator;
  -  ErrorHandler saxExceptionHandler;
     
     /**
      * The <id>actionListStack</id> contains a list of actions that are
  @@ -232,24 +230,25 @@
     }
   
     public void error(SAXParseException spe) throws SAXException {
  -    if(saxExceptionHandler != null) {
  -      saxExceptionHandler.error(spe);  
  -    }
  +    ec.addError(new ErrorItem("Parsing error", getLocator(), spe));
  +    LogLog.error(
  +        "Parsing problem on line " + spe.getLineNumber() + " and column "
  +        + spe.getColumnNumber());
     }
     
     public void fatalError(SAXParseException spe)  throws SAXException {
  -    if(saxExceptionHandler != null) {
  -      saxExceptionHandler.fatalError(spe);  
  -    }
  +    ec.addError(new ErrorItem("Parsing fatal error", getLocator(), spe));
  +    LogLog.error(
  +        "Parsing problem on line " + spe.getLineNumber() + " and column "
  +        + spe.getColumnNumber());
     }
     
     public void warning(SAXParseException spe) throws SAXException {
  -    if(saxExceptionHandler != null) {
  -      saxExceptionHandler.warning(spe);  
  -    }
  +    ec.addError(new ErrorItem("Parsing warning", getLocator(), spe));
  +    LogLog.warn(
  +        "Parsing problem on line " + spe.getLineNumber() + " and column "
  +        + spe.getColumnNumber());
     } 
  -
  -
   
     public void endPrefixMapping(java.lang.String prefix) {
     }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message