morgand     2002/10/14 14:31:16

  Modified:    jelly/src/java/org/apache/commons/jelly XMLOutput.java
  Added:       jelly/src/test/org/apache/commons/jelly/test/xml
                        TestDummyXMLOutput.java producesOutput.jelly
  Log:
  added no-op XML output for efficiency
  
  Revision  Changes    Path
  1.8       +17 -5     
jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/XMLOutput.java
  
  Index: XMLOutput.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/XMLOutput.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XMLOutput.java    17 Sep 2002 15:27:04 -0000      1.7
  +++ XMLOutput.java    14 Oct 2002 21:31:15 -0000      1.8
  @@ -79,6 +79,7 @@
   import org.xml.sax.XMLReader;
   import org.xml.sax.ext.LexicalHandler;
   import org.xml.sax.helpers.AttributesImpl;
  +import org.xml.sax.helpers.DefaultHandler;
   
   /** <p><code>XMLOutput</code> is used to output XML events 
     * in a SAX-like manner. This also allows pipelining to be done
  @@ -214,6 +215,17 @@
           XMLWriter xmlWriter = new XMLWriter(out);
           xmlWriter.setEscapeText(escapeText);
           return createXMLOutput(xmlWriter);
  +    }
  +
  +    /**
  +     * returns an XMLOutput object that will discard all
  +     * tag-generated XML events.  Useful when tag output is not expected
  +     * or not significant. 
  +     * 
  +     * @return a no-op XMLOutput
  +     */
  +    public static XMLOutput createDummyXMLOutput() {
  +        return new XMLOutput(new DefaultHandler());
       }
       
       // Extra helper methods provided for tag authors
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/test/xml/TestDummyXMLOutput.java
  
  Index: TestDummyXMLOutput.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/test/xml/TestDummyXMLOutput.java,v
 1.1 2002/10/14 21:31:15 morgand Exp $
   * $Revision: 1.1 $
   * $Date: 2002/10/14 21:31:15 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", 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 names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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/>.
   * 
   * $Id: TestDummyXMLOutput.java,v 1.1 2002/10/14 21:31:15 morgand Exp $
   */
  package org.apache.commons.jelly.test.xml;
  
  import java.net.URL;
  
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.jelly.Jelly;
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.XMLOutput;
  
  /**
   * Confirm that <i>new XMLOutput()</i>
   * doesn't do anything funky when it's not
   * attached to any event handlers or
   * output streams.
   * 
   * @author Morgan Delagrange
   * @version $Revision: 1.1 $
   */
  public class TestDummyXMLOutput extends TestCase {
  
      Jelly jelly = null;
      JellyContext context = null;
      XMLOutput xmlOutput = null;
  
      public TestDummyXMLOutput(String name) {
          super(name);
      }
  
      public static TestSuite suite() throws Exception {
          return new TestSuite(TestDummyXMLOutput.class);        
      }
  
      public void setUp(String scriptName) throws Exception {
          this.context = new JellyContext();
          this.xmlOutput = XMLOutput.createDummyXMLOutput();
  
          this.jelly = new Jelly();
          
          String script = scriptName;
          URL url = this.getClass().getResource(script);
          if ( url == null ) {
              throw new Exception( 
                  "Could not find Jelly script: " + script 
                  + " in package of class: " + this.getClass().getName() 
              );
          }
          this.jelly.setUrl(url);
      }
  
      public void testDummyXMLOutput() throws Exception {
          // without validation
          setUp("producesOutput.jelly");
          Script script = this.jelly.compileScript();
          script.run(this.context,this.xmlOutput);
          assertTrue("should have set 'foo' variable to 'bar'",
                     this.context.getVariable("foo").equals("bar"));
  
      }
  
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/test/xml/producesOutput.jelly
  
  Index: producesOutput.jelly
  ===================================================================
  <?xml version="1.0"?>
  <!DOCTYPE j:jelly [
  
    <!-- document is valid -->
    <!ELEMENT j:jelly (j:set)>
    <!ATTLIST j:jelly xmlns:j CDATA 'jelly:core'>
    
    <!ELEMENT j:set EMPTY>
    <!ATTLIST j:set var   CDATA #REQUIRED
                    value CDATA #REQUIRED>
  
  ]>
  <j:jelly 
        xmlns:j="jelly:core">
          
    <ignoreThisOutput/>
    
    <j:set var="foo" value="bar"/>
    
  </j:jelly>
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to