[logback-dev] svn commit: r672 - logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi

noreply.ceki at qos.ch noreply.ceki at qos.ch
Fri Oct 13 17:17:37 CEST 2006


Author: ceki
Date: Fri Oct 13 17:17:37 2006
New Revision: 672

Added:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/BodyEvent.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/EndEvent.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/JoranException.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SaxEvent.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SaxEventRecorder.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/StartEvent.java
Modified:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Pattern.java

Log:
ongoing work on replaying Joran

Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/BodyEvent.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/BodyEvent.java	Fri Oct 13 17:17:37 2006
@@ -0,0 +1,23 @@
+package ch.qos.logback.core.joran.spi;
+
+import org.xml.sax.Locator;
+
+public class BodyEvent extends SaxEvent {
+  
+  final String text;
+  
+  BodyEvent(String text, Locator locator) {
+    super(null, null, null, locator);
+    this.text = text;
+  }
+
+  public String getText() {
+    return text;
+  }
+  
+  @Override
+  public String toString() {
+    return "BodyEvent("+getText()+")"+locator.getLineNumber()+","+locator.getColumnNumber();
+  }
+
+}

Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/EndEvent.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/EndEvent.java	Fri Oct 13 17:17:37 2006
@@ -0,0 +1,17 @@
+package ch.qos.logback.core.joran.spi;
+
+import org.xml.sax.Locator;
+
+public class EndEvent extends SaxEvent {
+
+  EndEvent(String namespaceURI, String localName, String qName, Locator locator) {
+    super(namespaceURI, localName, qName, locator);
+  }
+
+  @Override
+  public String toString() {
+    return "  EndEvent("+getQName()+")  ["+locator.getLineNumber()+","+locator.getColumnNumber()+"]";
+  }
+
+
+}

Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/JoranException.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/JoranException.java	Fri Oct 13 17:17:37 2006
@@ -0,0 +1,14 @@
+package ch.qos.logback.core.joran.spi;
+
+public class JoranException extends Exception {
+
+  private static final long serialVersionUID = 1112493363728774021L;
+
+  public JoranException(String msg) {
+    super(msg);
+  }
+  
+  public JoranException(String msg, Throwable cause) {
+    super(msg, cause);
+  }
+}

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Pattern.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Pattern.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Pattern.java	Fri Oct 13 17:17:37 2006
@@ -129,6 +129,7 @@
     return match;
   }
 
+  @Override
   public boolean equals(Object o) {
     //System.out.println("in equals:" +this+ " vs. " + o);
     if ((o == null) || !(o instanceof Pattern)) {
@@ -155,6 +156,7 @@
     return true;
   }
 
+  @Override
   public int hashCode() {
     int hc = 0;
     int len = size();
@@ -168,6 +170,7 @@
     return hc;
   }
 
+  @Override
   public String toString() {
     int size = components.size();
     String result = "";

Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SaxEvent.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SaxEvent.java	Fri Oct 13 17:17:37 2006
@@ -0,0 +1,41 @@
+package ch.qos.logback.core.joran.spi;
+
+import org.xml.sax.Locator;
+import org.xml.sax.helpers.LocatorImpl;
+
+public class SaxEvent {
+
+  final String namespaceURI;
+  final String localName;
+  final String qName;
+  final Locator locator;
+
+  SaxEvent(String namespaceURI, String localName, String qName, Locator locator) {
+    this.namespaceURI = namespaceURI;
+    this.localName = localName;
+    this.qName = qName;
+    // locator impl is used to take a snapshot!
+    this.locator = new LocatorImpl(locator);
+  }
+
+  public String getLocalName() {
+    return localName;
+  }
+
+  public Locator getLocator() {
+    return locator;
+  }
+
+  public String getNamespaceURI() {
+    return namespaceURI;
+  }
+
+  public String getQName() {
+    return qName;
+  }
+
+  @Override
+  public String toString() {
+    return this.getClass().getName()+", "+locator.getLineNumber()+","+locator.getColumnNumber();
+  }
+}

Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SaxEventRecorder.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SaxEventRecorder.java	Fri Oct 13 17:17:37 2006
@@ -0,0 +1,83 @@
+package ch.qos.logback.core.joran.spi;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class SaxEventRecorder extends DefaultHandler {
+  
+  private ExecutionContext ec;
+  
+  public List<SaxEvent> saxEventList = new ArrayList<SaxEvent>();
+  Locator locator;
+  Pattern globalPattern;
+  
+  public void startDocument() {
+  }
+
+  public Locator getLocator() {
+    return locator;
+  }
+
+  public void setDocumentLocator(Locator l) {
+    locator = l;
+  }
+
+  
+  public void startElement(String namespaceURI, String localName, String qName,
+      Attributes atts) {
+
+    String tagName = getTagName(localName, qName);
+    globalPattern.push(tagName);
+    Pattern current = (Pattern) globalPattern.clone();
+    saxEventList.add(new StartEvent(current, namespaceURI, localName, qName, atts, getLocator()));
+   }
+
+  public void characters(char[] ch, int start, int length) {
+    String body = new String(ch, start, length);    
+
+    if(body != null) {
+      body = body.trim();
+    }
+    if(body.length() > 0) {
+      saxEventList.add(new BodyEvent(body, getLocator()));
+    }
+  }
+  
+  public void endElement(String namespaceURI, String localName, String qName) {
+    saxEventList.add(new EndEvent(namespaceURI, localName, qName, getLocator()));
+    globalPattern.pop();
+  }
+
+  
+  String getTagName(String localName, String qName) {
+    String tagName = localName;
+    if ((tagName == null) || (tagName.length() < 1)) {
+      tagName = qName;
+    }
+    return tagName;
+  }
+  
+  public void error(SAXParseException spe) throws SAXException {
+    ec.addError("Parsing error", this, spe);
+    ec.addError("Parsing problem on line " + spe.getLineNumber()
+        + " and column " + spe.getColumnNumber(), this, spe);
+  }
+
+  public void fatalError(SAXParseException spe) throws SAXException {
+    ec.addError("Parsing fatal error", this, spe);
+    ec.addError("Parsing problem on line " + spe.getLineNumber()
+        + " and column " + spe.getColumnNumber(), this, spe);
+  }
+
+  public void warning(SAXParseException spe) throws SAXException {
+    ec.addWarn("Parsing warning", this, spe);
+    ec.addWarn("Parsing problem on line " + spe.getLineNumber()
+        + " and column " + spe.getColumnNumber(), this, spe);
+  }
+}

Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/StartEvent.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/StartEvent.java	Fri Oct 13 17:17:37 2006
@@ -0,0 +1,29 @@
+package ch.qos.logback.core.joran.spi;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+
+public class StartEvent extends SaxEvent {
+
+  final Attributes attributes;
+  final Pattern pattern;
+  
+  StartEvent(Pattern pattern, String namespaceURI, String localName, String qName,
+      Attributes attributes, Locator locator) {
+    super(namespaceURI, localName, qName, locator);
+    // locator impl is used to take a snapshot!
+    this.attributes = attributes;
+    this.pattern = pattern;
+  }
+
+  public Attributes getAttributes() {
+    return attributes;
+  }
+
+  
+  @Override
+  public String toString() {
+    return "StartEvent("+getQName()+")  ["+locator.getLineNumber()+","+locator.getColumnNumber()+"]";
+  }
+
+}



More information about the logback-dev mailing list