You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2003/02/13 20:24:21 UTC

cvs commit: jakarta-commons/betwixt/xdocs index.xml

rdonkin     2003/02/13 11:24:21

  Modified:    betwixt/src/java/org/apache/commons/betwixt/io
                        SAXBeanWriter.java
               betwixt/src/test/org/apache/commons/betwixt/io
                        TestSAXBeanWriter.java
               betwixt/xdocs index.xml
  Log:
  Added property to control whether start and end documents events should be generated. Submitted by Jakob Praher.
  
  Revision  Changes    Path
  1.7       +31 -7     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/SAXBeanWriter.java
  
  Index: SAXBeanWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/SAXBeanWriter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SAXBeanWriter.java	8 Jan 2003 22:07:21 -0000	1.6
  +++ SAXBeanWriter.java	13 Feb 2003 19:24:21 -0000	1.7
  @@ -94,6 +94,8 @@
       private AttributesImpl attributes;
       /** Is there a element currently waiting to be written out? */
       private boolean elementWaiting = false;
  +    /** Should document events (ie. start and end) be called? */
  +    private boolean callDocumentEvents = true;
       
       /**
        * <p> Constructor sets writer used for output.</p>
  @@ -104,6 +106,24 @@
           this.contentHandler = contentHandler;
       }
   
  +    /** 
  +     * Should document events (ie start and end) be called?
  +     *
  +     * @return true if this SAXWriter should call start and end of the content handler
  +     */
  +    public boolean getCallDocumentEvents() {
  +        return callDocumentEvents;
  +    }
  +    
  +    /**
  +     * Sets whether the document events (ie start and end) should be called.
  +     *
  +     * @param callDocumentEvents should document events be called
  +     */
  +    public void setCallDocumentEvents(boolean callDocumentEvents) {
  +        this.callDocumentEvents = callDocumentEvents;
  +    }
  +
       /**
        * <p> Set the log implementation used. </p>
        *
  @@ -227,7 +247,9 @@
        * @see org.apache.commons.betwixt.io.AbstractBeanWriter#end()
        */
       public void start() throws SAXException {
  -        contentHandler.startDocument();
  +        if ( callDocumentEvents ) {
  +            contentHandler.startDocument();
  +        }
       }
   
       /**
  @@ -237,7 +259,9 @@
        * @see org.apache.commons.betwixt.io.AbstractBeanWriter#start()
        */
       public void end() throws SAXException {
  -        contentHandler.endDocument();
  +        if ( callDocumentEvents ) {
  +            contentHandler.endDocument();
  +        }
       }
   
   }
  
  
  
  1.3       +42 -5     jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/io/TestSAXBeanWriter.java
  
  Index: TestSAXBeanWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/io/TestSAXBeanWriter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestSAXBeanWriter.java	16 Jan 2003 00:54:50 -0000	1.2
  +++ TestSAXBeanWriter.java	13 Feb 2003 19:24:21 -0000	1.3
  @@ -77,6 +77,7 @@
   import org.w3c.dom.Node;
   import org.w3c.dom.NodeList;
   import org.xml.sax.InputSource;
  +import org.xml.sax.helpers.DefaultHandler;
   
   /** 
    * Test harness for SAXBeanWriter.
  @@ -140,6 +141,42 @@
               }
           }
       }       
  +        
  +    public void testDocumentElements() throws Exception {
  +        
  +        class TestDocHandler extends DefaultHandler {
  +            
  +            boolean startCalled = false;
  +            boolean endCalled = false;
  +            
  +            public void startDocument() {
  +                startCalled = true;
  +            }	
  +            
  +            public void endDocument() {
  +                endCalled = true;
  +            }
  +            
  +        }
  +        
  +        PersonBean bean = new PersonBean(35, "John Smith");
  +        
  +        TestDocHandler handler = new TestDocHandler();
  +        SAXBeanWriter writer = new SAXBeanWriter(handler);
  +        writer.setCallDocumentEvents(true);
  +        writer.write(bean);
  +        
  +        assertEquals("Start not called", handler.startCalled , true); 
  +        assertEquals("End not called", handler.endCalled , true); 
  +        
  +        handler = new TestDocHandler();
  +        writer = new SAXBeanWriter(handler);
  +        writer.setCallDocumentEvents(false);
  +        writer.write(bean);
  +        
  +        assertEquals("Start called", handler.startCalled , false); 
  +        assertEquals("End called", handler.endCalled , false);     
  +    }
           
       public static Test suite() {
           return new TestSuite(TestSAXBeanWriter.class);
  
  
  
  1.5       +1 -1      jakarta-commons/betwixt/xdocs/index.xml
  
  Index: index.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/xdocs/index.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- index.xml	28 Jan 2003 22:49:18 -0000	1.4
  +++ index.xml	13 Feb 2003 19:24:21 -0000	1.5
  @@ -30,7 +30,7 @@
       <p>
       <strong>Betwixt 1.0 Alpha 1</strong> - 28 Jan 2003
       <ul>
  -      <li>Download the binary disribution from 
  +      <li>Download the binary distribution from 
         <a href='http://jakarta.apache.org/site/sourceindex.cgi'>a mirror here</a></li>
         <li>Download the source distribution from 
         <a href='http://jakarta.apache.org/site/sourceindex.cgi'>a mirror here</a></li>
  
  
  

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