[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-18-g4e5aba2

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Wed Feb 10 23:24:50 CET 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".

The branch, master has been updated
       via  4e5aba2f2489bd7d2a1f8284202a8cf7d3373a22 (commit)
      from  3884318ebb54e4020756c0ae289d12f02a2f7aec (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=4e5aba2f2489bd7d2a1f8284202a8cf7d3373a22
http://github.com/ceki/logback/commit/4e5aba2f2489bd7d2a1f8284202a8cf7d3373a22

commit 4e5aba2f2489bd7d2a1f8284202a8cf7d3373a22
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Wed Feb 10 23:22:27 2010 +0100

    Fixed LBCORE-134 reported by Michael Franz. While reading
    configuration files (in XML), the event handler will correctly process
    body text, in particular spaces, even when delivered in multiple
    chunks. The previous behavior of trimming leading and trailing white
    space has been preserved. Moreover, body text consisting of white
    space surrounding child elements is ignored.

diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/event/BodyEvent.java b/logback-core/src/main/java/ch/qos/logback/core/joran/event/BodyEvent.java
index 1ab4f17..5cf61e6 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/event/BodyEvent.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/event/BodyEvent.java
@@ -25,7 +25,15 @@ public class BodyEvent extends SaxEvent {
     this.text = text;
   }
 
+  /**
+   * Always trim trailing spaces from the body text.
+   * 
+   * @return
+   */
   public String getText() {
+    if(text != null) {
+      return text.trim();
+    } 
     return text;
   }
 
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/event/SaxEventRecorder.java b/logback-core/src/main/java/ch/qos/logback/core/joran/event/SaxEventRecorder.java
index 9afddd0..b8760c0 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/event/SaxEventRecorder.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/event/SaxEventRecorder.java
@@ -37,17 +37,16 @@ import ch.qos.logback.core.status.Status;
 
 public class SaxEventRecorder extends DefaultHandler implements ContextAware {
 
-  
   final ContextAwareImpl cai;
-  
+
   public SaxEventRecorder() {
-    cai =  new ContextAwareImpl(this);
+    cai = new ContextAwareImpl(this);
   }
+
   public List<SaxEvent> saxEventList = new ArrayList<SaxEvent>();
   Locator locator;
   Pattern globalPattern = new Pattern();
 
- 
   final public void recordEvents(InputStream inputStream) throws JoranException {
     recordEvents(new InputSource(inputStream));
   }
@@ -104,28 +103,22 @@ public class SaxEventRecorder extends DefaultHandler implements ContextAware {
   }
 
   public void characters(char[] ch, int start, int length) {
-
-    String body = new String(ch, start, length);
-    if (body == null) {
-      return;
-    }
-
-    // if the body string is null
-    if (body != null) {
-      String bodyTrimmed = body.trim();
-      if (bodyTrimmed.length() == 0) {
-        return;
-      }
-    }
-
+    String bodyStr = new String(ch, start, length);
     SaxEvent lastEvent = getLastEvent();
     if (lastEvent instanceof BodyEvent) {
       BodyEvent be = (BodyEvent) lastEvent;
-      be.append(body);
+      be.append(bodyStr);
     } else {
-      saxEventList.add(new BodyEvent(body, getLocator()));
+      // ignore space only text if the previous event is not a BodyEvent
+      if (!isSpaceOnly(bodyStr)) {
+        saxEventList.add(new BodyEvent(bodyStr, getLocator()));
+      }
     }
+  }
 
+  boolean isSpaceOnly(String bodyStr) {
+    String bodyTrimmed = bodyStr.trim();
+    return (bodyTrimmed.length() == 0);
   }
 
   SaxEvent getLastEvent() {
@@ -156,8 +149,8 @@ public class SaxEventRecorder extends DefaultHandler implements ContextAware {
   }
 
   public void fatalError(SAXParseException spe) throws SAXException {
-    addError("Parsing fatal error on line " + spe.getLineNumber() + " and column "
-        + spe.getColumnNumber(), spe);
+    addError("Parsing fatal error on line " + spe.getLineNumber()
+        + " and column " + spe.getColumnNumber(), spe);
   }
 
   public void warning(SAXParseException spe) throws SAXException {
diff --git a/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java b/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
index 757a43b..5f47444 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/rolling/RollingPolicyBase.java
@@ -55,7 +55,6 @@ public abstract class RollingPolicyBase extends ContextAwareBase implements
     }
   }
 
-  
   public void setFileNamePattern(String fnp) {
     fileNamePatternStr = fnp;
   }
diff --git a/logback-core/src/test/input/joran/spacesAndQuotes.xml b/logback-core/src/test/input/joran/spacesAndQuotes.xml
new file mode 100644
index 0000000..771a9a9
--- /dev/null
+++ b/logback-core/src/test/input/joran/spacesAndQuotes.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!-- the following text should not be modidied in any way.
+     it summarizes the issue outlined in http://jira.qos.ch/browse/LBCORE-134
+-->
+<x>[x][x] &quot;xyz&quot;%n</x>
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/event/EventRecorderTest.java b/logback-core/src/test/java/ch/qos/logback/core/joran/event/EventRecorderTest.java
deleted file mode 100644
index a45d2f2..0000000
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/event/EventRecorderTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2009, QOS.ch. All rights reserved.
- *
- * This program and the accompanying materials are dual-licensed under
- * either the terms of the Eclipse Public License v1.0 as published by
- * the Eclipse Foundation
- *
- *   or (per the licensee's choosing)
- *
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
- */
-package ch.qos.logback.core.joran.event;
-
-import static org.junit.Assert.*;
-
-import java.io.FileInputStream;
-import java.util.List;
-
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.junit.Test;
-import org.xml.sax.Attributes;
-
-import ch.qos.logback.core.Context;
-import ch.qos.logback.core.ContextBase;
-import ch.qos.logback.core.status.Status;
-import ch.qos.logback.core.status.StatusManager;
-import ch.qos.logback.core.util.CoreTestConstants;
-
-/**
- * Test whether SaxEventRecorder does a good job.
- * 
- * @author Ceki Gulcu
- */
-public class EventRecorderTest {
-
-  Context context =  new ContextBase();
-
-
-  SAXParser createParser() throws Exception {
-    SAXParserFactory spf = SAXParserFactory.newInstance();
-    return spf.newSAXParser();
-  }
-
-  public List<SaxEvent> doTest(String filename) throws Exception {
-    SaxEventRecorder recorder = new SaxEventRecorder();
-    recorder.setContext(context);
-    FileInputStream fis = new FileInputStream(CoreTestConstants.TEST_DIR_PREFIX
-        + "input/joran/"+ filename);
-    recorder.recordEvents(fis);
-    return  recorder.getSaxEventList();
-    
- 
-  }
- 
-  public void dump(List<SaxEvent> seList) {
-    for (SaxEvent se : seList) {
-      System.out.println(se);
-    }
-  }
-  /**
-   * Tests that whenever an action throws an exception, processing of child
-   * elements is skipped.
-   * 
-   * @throws Exception
-   */
-  @Test
-  public void test1() throws Exception {
-    List<SaxEvent> seList = doTest("event1.xml");
-    StatusManager sm = context.getStatusManager();
-    assertTrue(sm.getLevel() == Status.INFO);
-    //dump(seList);  
-    assertEquals(11, seList.size());
-    
-  }
-
-  @Test
-  public void test2() throws Exception {
-    List<SaxEvent> seList = doTest("ampEvent.xml");
-    StatusManager sm = context.getStatusManager();
-    assertTrue(sm.getLevel() == Status.INFO);
-    //dump(seList);  
-    assertEquals(3, seList.size());
-    
-    BodyEvent be = (BodyEvent) seList.get(1);
-    assertEquals("xxx & yyy", be.getText());
-  }
-
-  @Test
-  public void test3() throws Exception {
-    List<SaxEvent> seList = doTest("inc.xml");
-    StatusManager sm = context.getStatusManager();
-    assertTrue(sm.getLevel() == Status.INFO);
-    //dump(seList);  
-    assertEquals(4, seList.size());
-    
-    StartEvent se = (StartEvent) seList.get(1);
-    Attributes attr = se.getAttributes();
-    assertNotNull(attr);
-    assertEquals("1", attr.getValue("increment"));
-  }
-
-}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/event/PackageTest.java b/logback-core/src/test/java/ch/qos/logback/core/joran/event/PackageTest.java
index 260c5c4..0771ded 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/event/PackageTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/joran/event/PackageTest.java
@@ -18,6 +18,6 @@ import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
 
 @RunWith(Suite.class)
- at SuiteClasses({EventRecorderTest.class, InPlayFireTest.class})
+ at SuiteClasses({SaxEventRecorderTest.class, InPlayFireTest.class})
 public class PackageTest {
 }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/SamplePatternLayoutTest.java b/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/SamplePatternLayoutTest.java
index befeef3..8bed2f4 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/SamplePatternLayoutTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/pattern/parser/SamplePatternLayoutTest.java
@@ -49,8 +49,6 @@ public class SamplePatternLayoutTest extends AbstractPatternLayoutBaseTest {
     assertEquals("x123", s);
   }
 
-
-  
   @Test
   public void testEscapeClosingParentheses() {
     PatternLayoutBase<Object> plb = getPatternLayoutBase();
diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html
index 4e27d5b..ef6b2c2 100644
--- a/logback-site/src/site/pages/news.html
+++ b/logback-site/src/site/pages/news.html
@@ -42,6 +42,18 @@
     prevents compatibility issues, in particular with recent versions
     of Tomcat whcih store request header names in lower-case.</p>
 
+
+    <p>Fixed <a
+    href="http://jira.qos.ch/browse/LBCORE-134">LBCORE-134</a>
+    reported by Michael Franz. While reading configuration files (in
+    XML), the event handler will correctly process body text, in
+    particular spaces, even when delivered in multiple chunks. The
+    previous behavior of trimming leading and trailing white space has
+    been preserved. Moreover, body text consisting of white space
+    surrounding child elements is ignored.
+    </p>
+    
+
     <p>Fixed <a
     href="http://jira.qos.ch/browse/LBCORE-130">LBCORE-130</a>. <code>FileNamePattern</code>
     no longer treats parenthesis as special.

-----------------------------------------------------------------------

Summary of changes:
 .../ch/qos/logback/core/joran/event/BodyEvent.java |    8 ++
 .../logback/core/joran/event/SaxEventRecorder.java |   37 +++----
 .../logback/core/rolling/RollingPolicyBase.java    |    1 -
 .../src/test/input/joran/spacesAndQuotes.xml       |    6 +
 .../core/joran/event/EventRecorderTest.java        |  106 --------------------
 .../qos/logback/core/joran/event/PackageTest.java  |    2 +-
 .../pattern/parser/SamplePatternLayoutTest.java    |    2 -
 logback-site/src/site/pages/news.html              |   12 ++
 8 files changed, 42 insertions(+), 132 deletions(-)
 create mode 100644 logback-core/src/test/input/joran/spacesAndQuotes.xml
 delete mode 100644 logback-core/src/test/java/ch/qos/logback/core/joran/event/EventRecorderTest.java


hooks/post-receive
-- 
Logback: the generic, reliable, fast and flexible logging framework.


More information about the logback-dev mailing list