commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nicola...@apache.org
Subject cvs commit: jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/pipelines SAXMorpherPipeline.java
Date Mon, 05 Aug 2002 13:35:14 GMT
nicolaken    2002/08/05 06:35:14

  Modified:    morphos  status.xml
               morphos/src/java/org/apache/commons/morphos
                        MorphException.java Morpher.java
                        MorpherPipeline.java Morphos.java
                        ObjectFlavorException.java package.html
               morphos/src/java/org/apache/commons/morphos/morphers/dataform
                        InputSource2SAXMorpher.java
               morphos/src/java/org/apache/commons/morphos/morphers/poi
                        ElementProcessorMorpher.java HSSFMorpher.java
                        POIFSMorpher.java
  Added:       morphos/lib dependencies.txt
               morphos/src/examples/stylesheets test2.xsl
               morphos/src/java/org/apache/commons/morphos/factories
                        BasicMorpherFactory.java
               morphos/src/java/org/apache/commons/morphos/helpers
                        Abstract2OutputStreamMorpher.java
                        AbstractMorpher.java
               morphos/src/java/org/apache/commons/morphos/morphers/poi
                        POIFS2OutputStreamMorpher.java
               morphos/src/java/org/apache/commons/morphos/morphers/xml
                        StylesheetAware.java XSLTMorpher.java
               morphos/src/java/org/apache/commons/morphos/pipelines
                        SAXMorpherPipeline.java
  Removed:     morphos/src/java/org/apache/commons/morphos
                        AbstractMorpher.java BasicMorpherFactory.java
  Log:
      <action dev="nicolaken" type="update" context="code">
       Refactored by adding a "factories" and a "pipelines" packages under morphos, and moved
       relevant files there; moved abstract helper classes under "helpers".
      </action>
      <action dev="nicolaken" type="update" due-to="Sven Kuenzler" due-to-email="svenk@imost.de" context="code">
       Made exceptions Nestable, updated the poi Morpher adding a POIFS2OutputStreamMorpher
       and fixed erroneous javadocs.
      </action>
      <action dev="nicolaken" type="add" due-to="Sven Kuenzler" due-to-email="svenk@imost.de" context="code">
       Added XSLTMorpher, first SAX pipeline implementation and first BasicMorpherFactory implementation.
      </action>
  
  Revision  Changes    Path
  1.2       +12 -1     jakarta-commons-sandbox/morphos/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/morphos/status.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- status.xml	26 Jul 2002 07:58:26 -0000	1.1
  +++ status.xml	5 Aug 2002 13:35:13 -0000	1.2
  @@ -16,7 +16,18 @@
    </todo>
   
     <changes>
  -   <release version="0.1-dev" date="2002">
  +   <release version="1.0-dev" date="2002">
  +    <action dev="nicolaken" type="update" context="code">
  +     Refactored by adding a "factories" and a "pipelines" packages under morphos, and moved
  +     relevant files there; moved abstract helper classes under "helpers".
  +    </action>
  +    <action dev="nicolaken" type="update" due-to="Sven Kuenzler" due-to-email="svenk@imost.de" context="code">
  +     Made exceptions Nestable, updated the poi Morpher adding a POIFS2OutputStreamMorpher
  +     and fixed erroneous javadocs.
  +    </action>
  +    <action dev="nicolaken" type="add" due-to="Sven Kuenzler" due-to-email="svenk@imost.de" context="code">
  +     Added XSLTMorpher, first SAX pipeline implementation and first BasicMorpherFactory implementation.
  +    </action>
       <action dev="nicolaken" type="fix" due-to="Sven Kuenzler" due-to-email="svenk@imost.de" context="code">
        Fixed poi and dataform Morphers that weren't using the Morpher interface.
       </action>
  
  
  
  1.1                  jakarta-commons-sandbox/morphos/lib/dependencies.txt
  
  Index: dependencies.txt
  ===================================================================
  commons-lang.jar
  xerces.jar
  jakarta-poi-1.7.0-dev-20020624.jar
  
  
  
  1.1                  jakarta-commons-sandbox/morphos/src/examples/stylesheets/test2.xsl
  
  Index: test2.xsl
  ===================================================================
  <?xml version="1.0" encoding="utf-8"?>
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  xmlns:gmr="http://www.gnome.org/gnumeric/v7" version="1.0">
  
    <xsl:output method="xml"/>
  
  
    <xsl:template match="gmr:Cells">
      <gmr:Cells>
          <gmr:Cell Col="0" Row="0" ValueType="60">
            <gmr:Content>This spreadsheet has been pestered by the all new XSLTMorpher</gmr:Content>
          </gmr:Cell>
          <xsl:apply-templates/>
        </gmr:Cells>
    </xsl:template>
  
    <xsl:template match="gmr:Cell[@Col='0' and @Row='0']"/>
  
    <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
  
  
  </xsl:stylesheet>
  
  
  
  1.2       +7 -6      jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/MorphException.java
  
  Index: MorphException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/MorphException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MorphException.java	25 Jul 2002 13:18:10 -0000	1.1
  +++ MorphException.java	5 Aug 2002 13:35:13 -0000	1.2
  @@ -61,12 +61,14 @@
   
   package org.apache.commons.morphos;
   
  - public class MorphException extends Exception {
  +import org.apache.commons.lang.exception.NestableException;
  +
  + public class MorphException extends NestableException {
    
      public MorphException(String message){
        super(message);
      }
  -   
  +
      public MorphException(String message, Throwable cause){
        super(message, cause);
      }
  @@ -74,7 +76,6 @@
      public MorphException(Throwable cause){
        super(cause);
      }
  -   
   }
   
   
  
  
  
  1.2       +4 -4      jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/Morpher.java
  
  Index: Morpher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/Morpher.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  
  
  
  1.2       +5 -14     jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/MorpherPipeline.java
  
  Index: MorpherPipeline.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/MorpherPipeline.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MorpherPipeline.java	25 Jul 2002 13:18:10 -0000	1.1
  +++ MorpherPipeline.java	5 Aug 2002 13:35:13 -0000	1.2
  @@ -80,17 +80,8 @@
       /**
        * Construct a "call method" rule with the specified method name.
        *
  -     * @param digester The associated Digester
  -     * @param methodName Method name of the parent method to call
  -     * @param paramCount The number of parameters to collect, or
  -     *  zero for a single argument from the body of ths element
  -     * @param paramTypes The Java class names of the arguments
  -     *  (if you wish to use a primitive type, specify the corresonding
  -     *  Java wrapper class instead, such as <code>java.lang.Boolean</code>
  -     *  for a <code>boolean</code> parameter)
  +     * @exception MorphException? FIXME if the nextMorpher cannot be added
        *
  -     * @deprecated The digester instance is now set in the {@link Digester#addRule} method. 
  -     * Use {@link #CallMethodRule(String methodName,int paramCount, String [] paramTypes)} instead.
        */
        void addStage(Morpher nextMorpher); 
   }
  
  
  
  1.3       +25 -17    jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/Morphos.java
  
  Index: Morphos.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/Morphos.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Morphos.java	26 Jul 2002 07:58:35 -0000	1.2
  +++ Morphos.java	5 Aug 2002 13:35:13 -0000	1.3
  @@ -61,7 +61,8 @@
   
   package org.apache.commons.morphos;
   
  -
  +import org.apache.commons.morphos.factories.BasicMorpherFactory;
  +import org.apache.commons.morphos.pipelines.SAXMorpherPipeline;
   import java.io.*;
   
   import javax.xml.parsers.SAXParserFactory;
  @@ -73,6 +74,8 @@
   import org.xml.sax.InputSource;
   import org.xml.sax.XMLReader;
   
  +import org.apache.commons.morphos.morphers.xml.*;
  +
   /**
    * @author Nicola Ken Barozzi
    * @author svenk@imost.de
  @@ -82,8 +85,8 @@
    public class Morphos {
    
   	public static void main(String args[]) throws Exception{
  -		if(args.length!=2){
  -			System.err.println("Usage: org.apache.commons.morphos.morphers.poi.test.HSSF infile outfile");
  +		if(args.length<2){
  +			System.err.println("Usage: org.apache.commons.morphos.Morphos infile outfile [xsl-transform]");
   			System.exit(2);
   		}
                   
  @@ -100,16 +103,21 @@
                   InputSource input = new InputSource(new FileInputStream(args[0]));	
   		OutputStream output = new FileOutputStream(args[1]);
                   
  -                
  -		Morpher morpher1 = new InputSource2SAXMorpher();
  -		morpher1.setInput(input);
  -                
  -                  Morpher morpher2 = new HSSFMorpher();
  -		  morpher2.setOutput(output);
  -                  
  -                morpher1.setOutput(morpher2);
  -                
  -                morpher1.morph();
  +                MorpherFactory mf = new BasicMorpherFactory();
  +		MorpherPipeline mp = new SAXMorpherPipeline();
  +
  +		mp.addStage(mf.getMorpher("is2sax"));
  +		Morpher xslt = mf.getMorpher("xslt");
  +		if(args.length==3){
  +		    ((StylesheetAware)xslt).setStylesheet(new javax.xml.transform.sax.SAXSource(new InputSource(new FileInputStream(args[2]))));
  +		}
  +		mp.addStage(xslt);
  +		mp.addStage(mf.getMorpher("gnumeric2xls"));
  +
  +		mp.setInput(input);                
  +		mp.setOutput(output);
  +		
  +                mp.morph();
                   
                   output.flush();
                   output.close();
  
  
  
  1.2       +5 -5      jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/ObjectFlavorException.java
  
  Index: ObjectFlavorException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/ObjectFlavorException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ObjectFlavorException.java	25 Jul 2002 13:18:10 -0000	1.1
  +++ ObjectFlavorException.java	5 Aug 2002 13:35:13 -0000	1.2
  @@ -60,8 +60,9 @@
    */
   
   package org.apache.commons.morphos;
  +import org.apache.commons.lang.exception.NestableException;
   
  - public class ObjectFlavorException extends Exception {
  + public class ObjectFlavorException extends NestableException {
    
      public ObjectFlavorException(String message){
        super(message);
  @@ -74,7 +75,6 @@
      public ObjectFlavorException(Throwable cause){
        super(cause);
      }
  -   
   }
   
   
  
  
  
  1.2       +31 -28    jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/package.html
  
  Index: package.html
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/package.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- package.html	25 Jul 2002 13:18:10 -0000	1.1
  +++ package.html	5 Aug 2002 13:35:13 -0000	1.2
  @@ -4,44 +4,47 @@
     <title>Package Documentation for org.apache.commons.digester Package</title>
   </head>
     <body style="background-color: white;">
  - The Morphos package transforms "file formats" in a pluggable and extensible 
  -manner.<br>
  -  <br>
  -      <a name="doc.Depend"></a>   
  +  The Morphos package transforms "file formats" in a pluggable and extensible
  + manner.<br>
  +   <br>
  +       <a name="doc.Depend"></a>    
   <h3>External Dependencies</h3>
  -      
  +        
   <ul>
  -     <li>Xerces</li>
  -  <li>POI 1.7-dev<br>
  +      <li>Xerces</li>
  +  <li>Commons lang<br>
     </li>
  -     
  +   <li>POI 1.7-dev<br>
  +   </li>
  +       
   </ul>
  -    <a name="doc.Intro"></a>   
  +     <a name="doc.Intro"></a>    
   <h3>Introduction</h3>
  -      
  -<p>Morphos is a package with the aim of transforming "file formats" in a pluggable
  -and extensible manner.<br>
  - The code units to transform from-to different formats are called Morphers.</p>
  - These morphers transform between different ObjectFlavors, that specify both 
  -the datatype and the dataform.<br>
  - For example a gif image file and a jped image file have a different dataType 
  -but same dataForm (file).<br>
  - An SVG file and an SVG DOM in memory have same dataType but different dataForm<br>
  - <br>
  - Morphos is the commandline version.<br>
  - MorpherFactory make it possible to specify clever ways of autoresolving
  -morphers given the ObjectFlavors. 
  +        
  +<p>Morphos is a package with the aim of transforming "file formats" in a
  +pluggable and extensible manner.<br>
  +  The code units to transform from-to different formats are called Morphers.</p>
  +  These morphers transform between different ObjectFlavors, that specify
  +both  the datatype and the dataform.<br>
  +  For example a gif image file and a jped image file have a different dataType
  + but same dataForm (file).<br>
  +  An SVG file and an SVG DOM in memory have same dataType but different dataForm<br>
  +  <br>
  +  Morphos is the commandline version.<br>
  +  MorpherFactory make it possible to specify clever ways of autoresolving 
  +morphers given the ObjectFlavors.  
   <p></p>
  - <br>
  -    <a name="doc.Properties"></a>   
  +  <br>
  +     <a name="doc.Properties"></a>    
   <h3>Example of full-feature use</h3>
  -      
  +        
   <p>/** </p>
  - 
  +   
   <pre>//<span style="font-weight: bold;"> NOTE</span> Currently Factories are not yet implemented, you must<br>//      create Morphers with <span
    style="font-weight: bold;">new</span><br><br>//<span
    style="font-weight: bold;"> NOTE </span>Currently pipelining is not yet done, it has to be<br>//      done by hand<br><br>// Create the Manager that gives me the morphers <br>Morpherfactory  mfactory = new SimpleMorpherFactory("mmanager-conf.xml");<br><br>// Get a jaxp Morpher by name<br>Morpher jaxpmorpher =  mfactory.getMorpher("jaxp");<br><br>jaxpmorpher.setStylesheet("transform.xml");<br><br>// Get a Morpher that serializes an XML dom to a stream<br>Morpher streammorpher =<br>  mfactory.getMorpher(<br>     new ObjectFlavor("text/xml", "object/dom"),<br>     new ObjectFlavor("text/xml", "stream/unix")<br>   );<br><br>//Chain the two:<br><br>MorpherPipeline mpipeline =  new SimpleMorpherPipeline();<br>mpipeline.addStage(jaxpmorpher );<br>mpipeline.addStage(streammorpher );<br><br>try{<br>  mpipeline.setInput(myDomObject);<br>  mpipeline.setOutput(outputstream);<br>  mpipeline.morph();<br>}<br>catch(MorphException ioe){<br> .....}<br>catch(OblectFlavorException ofe){<br>.....}<br></pre>
  -     <br>
  -   <br>
  +      <br>
  +    <br>
  + <br>
   </body>
   </html>
  
  
  
  1.1                  jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/factories/BasicMorpherFactory.java
  
  Index: BasicMorpherFactory.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/factories/BasicMorpherFactory.java,v 1.1 2002/08/05 13:35:13 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/05 13:35:13 $
   *
   * ====================================================================
   *
   * 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 apache@apache.org.
   *
   * 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/>.
   *
   */
  
  package org.apache.commons.morphos.factories;
  
  import org.apache.commons.morphos.Morpher;
  import org.apache.commons.morphos.MorpherFactory;
  import org.apache.commons.morphos.ObjectFlavor;
  import java.util.HashMap;
  
  /**
   *
   * @author Nicola Ken Barozzi
   * @author Sven Künzler
   * @version $Revision: 1.1 $ $Date: 2002/08/05 13:35:13 $
   */
  public class BasicMorpherFactory implements MorpherFactory {
       private HashMap knownMorphers;
  
       public BasicMorpherFactory(){
  	 super();
  	 knownMorphers=new HashMap();
  	 // FIXME Make configurable
  	 knownMorphers.put("gnumeric2xls","org.apache.commons.morphos.morphers.poi.HSSFMorpher");
  	 knownMorphers.put("gnumeric2poi","org.apache.commons.morphos.morphers.poi.HSSFMorpher");
  	 knownMorphers.put("xslt","org.apache.commons.morphos.morphers.xml.XSLTMorpher");
  	 knownMorphers.put("poi2xls","org.apache.commons.morphos.morphers.poi.POIFSMorpher");
  	 knownMorphers.put("is2sax","org.apache.commons.morphos.morphers.dataform.InputSource2SAXMorpher");
       }
  		   
      public Morpher getMorpher(ObjectFlavor inputFlavor, ObjectFlavor outputFlavor){
  	throw new UnsupportedOperationException("implement me :-)");
      }
  
      public Morpher getMorpher(String name){
  	Morpher morpher=null;
  	String clazzName = (String)knownMorphers.get(name);
  
  	if(clazzName!=null){
  	     try{
  		 morpher = (Morpher)Class.forName(clazzName).newInstance();
  	     } catch(Exception e){
  		 e.printStackTrace();
  	     }
  	}
  	return morpher;
      }    
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  1.1                  jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/helpers/Abstract2OutputStreamMorpher.java
  
  Index: Abstract2OutputStreamMorpher.java
  ===================================================================
  /*
  
   ============================================================================
                     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 modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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/>.
  
  */
  package org.apache.commons.morphos.helpers;
  
  import org.apache.commons.morphos.helpers.AbstractMorpher;
  import java.io.OutputStream;
  
  import org.apache.commons.morphos.*;
  
  /**
   *  Base class for Morphers producing an OutputStream.
   *
   *@author   Sven Künzler (svenk@imost.de)
   *@version $Revision: 1.1 $ $Date: 2002/08/05 13:35:13 $
   */
  public abstract class Abstract2OutputStreamMorpher  extends AbstractMorpher
  {
    protected OutputStream output;
      
    public Abstract2OutputStreamMorpher() {
      super();
      output=null;
    }
        
    public void setOutput(Object output) throws ObjectFlavorException
    {
       if(output instanceof OutputStream){
         this.output = (OutputStream)output;
       } else {
         throw new ObjectFlavorException("Cannot handle output object of class "+
                             output.getClass().getName()+", expected OutputStream");
       }
    }
        
    public abstract void morph() throws MorphException;
  }
  
  
  
  1.1                  jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/helpers/AbstractMorpher.java
  
  Index: AbstractMorpher.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/helpers/AbstractMorpher.java,v 1.1 2002/08/05 13:35:13 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/05 13:35:13 $
   *
   * ====================================================================
   *
   * 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 apache@apache.org.
   *
   * 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/>.
   *
   */
  
  package org.apache.commons.morphos.helpers;
  
  import org.apache.commons.morphos.MorphException;
  import org.apache.commons.morphos.Morpher;
  import org.apache.commons.morphos.ObjectFlavorException;
  
  
  /**
   * @author Nicola Ken Barozzi
   * @version $Revision: 1.1 $ $Date: 2002/08/05 13:35:13 $
   */
   public class AbstractMorpher implements Morpher {
  
       public void setInput(Object input) throws ObjectFlavorException{
         throw new ObjectFlavorException("The ObjectFlavor used is not supported by this morpher.");
       }
       
       public void setOutput(Object output) throws ObjectFlavorException{
         throw new ObjectFlavorException("The ObjectFlavor used is not supported by this morpher.");     
       }
  
       public void morph() throws MorphException{
         throw new MorphException("This is a passive Morpher, the morphing process must be done in a pipeline.");     
       }
       
       /*
       void addNotificationListener(NotificationListener nl);
       void removeNotificationListener(NotificationListener nl);
       void clearNotificationListeners();
  */
          
  }
  
  
  
  
  
  
  
  
  
  
  
  
  1.3       +2 -1      jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/morphers/dataform/InputSource2SAXMorpher.java
  
  Index: InputSource2SAXMorpher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/morphers/dataform/InputSource2SAXMorpher.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InputSource2SAXMorpher.java	26 Jul 2002 07:58:35 -0000	1.2
  +++ InputSource2SAXMorpher.java	5 Aug 2002 13:35:14 -0000	1.3
  @@ -50,6 +50,7 @@
   */
   package org.apache.commons.morphos.morphers.dataform;
   
  +import org.apache.commons.morphos.helpers.AbstractMorpher;
   import java.io.*;
   
   import javax.xml.parsers.*;
  
  
  
  1.3       +1 -31     jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/morphers/poi/ElementProcessorMorpher.java
  
  Index: ElementProcessorMorpher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/morphers/poi/ElementProcessorMorpher.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ElementProcessorMorpher.java	26 Jul 2002 07:58:35 -0000	1.2
  +++ ElementProcessorMorpher.java	5 Aug 2002 13:35:14 -0000	1.3
  @@ -50,6 +50,7 @@
   */
   package org.apache.commons.morphos.morphers.poi;
   
  +import org.apache.commons.morphos.helpers.AbstractMorpher;
   import org.apache.commons.morphos.helpers.elementprocessor.types.Attribute;
   import org.apache.commons.morphos.helpers.elementprocessor.ElementProcessorFactory;
   import org.apache.commons.morphos.helpers.elementprocessor.ElementProcessor;
  @@ -62,8 +63,6 @@
   import org.xml.sax.ContentHandler;
   
   import java.io.IOException;
  -import java.io.OutputStream;
  -
   import java.util.Stack;
   
   /**
  @@ -84,8 +83,6 @@
   public abstract class ElementProcessorMorpher 
           extends AbstractMorpher implements ContentHandler 
   {
  -    private static final boolean _should_set_content_length = false;
  -    private OutputStream         _output_stream;    
       private Stack                _open_elements;
       private Locator              _locator;
   
  @@ -96,7 +93,6 @@
   
       public ElementProcessorMorpher()
       {
  -        _output_stream = null;    
           _open_elements = new Stack();
           _locator       = null;
       }
  @@ -121,32 +117,6 @@
   
       protected abstract void doPreInitialization(ElementProcessor processor)
   	throws SAXException;
  -
  -    /**
  -     * @return the output stream
  -     */
  -
  -    protected OutputStream getOutputStream()
  -    {
  -	return _output_stream;
  -    }
  -    
  -    /**
  -     * Set the OutputStream where the requested resource should be
  -     * serialized.
  -     *
  -     * @param output the OutputStream to which the serialized data will
  -     *            be written
  -     */
  -     public void setOutput(Object output) throws ObjectFlavorException
  -      {
  -        if(output instanceof OutputStream){
  -          _output_stream = (OutputStream)output;
  -        } else {
  -          throw new ObjectFlavorException("Cannot handle output object of class "
  -                             +output.getClass().getName()+", expected OutputStream.");
  -        }
  -      } 
        
       /**
        * Create a new SAXException
  
  
  
  1.2       +2 -22     jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/morphers/poi/HSSFMorpher.java
  
  Index: HSSFMorpher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/morphers/poi/HSSFMorpher.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HSSFMorpher.java	25 Jul 2002 13:19:50 -0000	1.1
  +++ HSSFMorpher.java	5 Aug 2002 13:35:14 -0000	1.2
  @@ -52,22 +52,13 @@
   
   import org.apache.commons.morphos.morphers.poi.elementprocessor.hssf.HSSFElementProcessorFactory;
   import org.apache.commons.morphos.helpers.elementprocessor.ElementProcessorFactory;
  -import java.io.FileOutputStream;
  -import java.io.OutputStream;
  -import java.io.InputStream;
  -
  -import javax.xml.parsers.SAXParserFactory;
  -
  -import org.xml.sax.InputSource;
  -import org.xml.sax.XMLReader;
  -
   
   /**
    *  Morpher to produce an HSSF stream.
    *
    *@author   Marc Johnson (marc_johnson27591@hotmail.com)
    *@author   Nicola Ken Barozzi (nicolaken@apache.org) 
  - *@author svenk@imost.de
  + *@author   Sven Künzler svenk@imost.de
    *@created  26 febbraio 2002
    *@version $Revision$ $Date$
    */
  @@ -76,7 +67,6 @@
         extends POIFSMorpher
   {
     private ElementProcessorFactory _element_processor_factory;
  -  private final static String _mime_type = "vnd.ms-excel";
       
     /**
      *  Constructor
  @@ -87,16 +77,6 @@
       _element_processor_factory  = new HSSFElementProcessorFactory();
     }
           
  -  /**
  -   *  get the mime type
  -   *
  -   *@return    vnd.ms-excel
  -   */
  -
  -  public String getMimeType() {
  -    return _mime_type;
  -  }
  -
     /**
      *  get the ElementProcessorFactory
      *
  
  
  
  1.2       +29 -7     jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/morphers/poi/POIFSMorpher.java
  
  Index: POIFSMorpher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/morphers/poi/POIFSMorpher.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- POIFSMorpher.java	25 Jul 2002 13:19:50 -0000	1.1
  +++ POIFSMorpher.java	5 Aug 2002 13:35:14 -0000	1.2
  @@ -54,11 +54,12 @@
   import java.io.OutputStream;
   
   import org.apache.commons.morphos.helpers.elementprocessor.ElementProcessor;
  -
   import org.apache.commons.morphos.helpers.elementprocessor.CannotCreateElementProcessorException;
  +
   import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  -import org.apache.commons.morphos.morphers.poi.elementprocessor.POIFSElementProcessor;
   
  +import org.apache.commons.morphos.ObjectFlavorException;
  +import org.apache.commons.morphos.morphers.poi.elementprocessor.POIFSElementProcessor;
   
   import org.xml.sax.SAXException;
   
  @@ -84,6 +85,7 @@
         extends ElementProcessorMorpher
   {
     private POIFSFileSystem _filesystem;
  +  private OutputStream _outputStream;
   
     /**
      *  Constructor
  @@ -91,8 +93,30 @@
   
     public POIFSMorpher() {
       super();
  -    _filesystem = new POIFSFileSystem();
     }
  +  
  +    /**
  +     * Set the OutputStream or FileSystem where the requested resource should be
  +     * serialized.
  +     *
  +     * @param output the OutputStream or POIFSFileSystem  to which the data will
  +     *            be written
  +     */
  +     public void setOutput(Object output) throws ObjectFlavorException
  +      {
  +	if(output instanceof POIFSFileSystem){
  +	  _outputStream=null;
  +          _filesystem=(POIFSFileSystem)output;
  +        } else if(output instanceof OutputStream){
  +          // FIXME: Factor this out to a POIFS2OutputStreamMorpher?
  +          _outputStream=(OutputStream)output;
  +          _filesystem=new POIFSFileSystem();
  +        } else {
  +          throw new ObjectFlavorException("Output of class "
  +                             +output.getClass().getName()+", expected one of: OutputStream, POIFSFileSystem.");
  +        }
  +      } 
  +  
   
     /*
      *  ********** START implementation of ContentHandler **********
  @@ -108,11 +132,9 @@
       throws SAXException {
       doLocalPreEndDocument();
   
  -    OutputStream stream = getOutputStream();
  -
  -    if ( stream != null ) {
  +    if ( _outputStream != null ) {
         try {
  -        _filesystem.writeFilesystem( stream );
  +        _filesystem.writeFilesystem( _outputStream );
         }
         catch ( IOException e ) {
           throw SAXExceptionFactory(
  
  
  
  1.1                  jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/morphers/poi/POIFS2OutputStreamMorpher.java
  
  Index: POIFS2OutputStreamMorpher.java
  ===================================================================
  /*
  
   ============================================================================
                     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 modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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/>.
  
  */
  package org.apache.commons.morphos.morphers.poi;
  
  import java.io.OutputStream;
  
  import org.apache.commons.morphos.*;
  import org.apache.commons.morphos.helpers.Abstract2OutputStreamMorpher;
  
  import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  
  
  /**
   *  Base class for Morphers producing an OutputStream.
   *
   *@author   Sven Künzler (svenk@imost.de)
   *@version $Revision: 1.1 $ $Date: 2002/08/05 13:35:14 $
   */
  public class POIFS2OutputStreamMorpher extends Abstract2OutputStreamMorpher
  {
    protected POIFSFileSystem input;
      
    public POIFS2OutputStreamMorpher() {
      super();
      input=null;
    }
        
    public void setInput(Object input) throws ObjectFlavorException
    {
       if(input instanceof POIFSFileSystem){
         this.input = (POIFSFileSystem)input;
       } else {
         throw new ObjectFlavorException("Cannot handle input object of class "+
                             input.getClass().getName()+", expected POIFSFileSystem");
       }
    }
        
    public void morph() throws MorphException{
      try{
      	input.writeFilesystem(output);
      } catch(Exception e){
      	throw new MorphException(e);
      }
    }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/morphers/xml/StylesheetAware.java
  
  Index: StylesheetAware.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/morphers/xml/StylesheetAware.java,v 1.1 2002/08/05 13:35:14 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/05 13:35:14 $
   *
   * ====================================================================
   *
   * 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 apache@apache.org.
   *
   * 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/>.
   *
   */
  
  package org.apache.commons.morphos.morphers.xml;
  
  
  /**
   * @author Sven Künzler
   * @version $Revision: 1.1 $ $Date: 2002/08/05 13:35:14 $
   */
   
   public interface StylesheetAware {
       /** Accept a JAXP Source for use as Template/Stylesheet. Beware that implementations may 
        *  not support all incarnations (e.g. SAXSource only).
        */
       void setStylesheet(javax.xml.transform.Source s);
   }
  
  
  
  
  
  
  
  
  
  
  
  1.1                  jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/morphers/xml/XSLTMorpher.java
  
  Index: XSLTMorpher.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/morphers/xml/XSLTMorpher.java,v 1.1 2002/08/05 13:35:14 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/05 13:35:14 $
   *
   * ====================================================================
   *
   * 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 apache@apache.org.
   *
   * 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/>.
   *
   */
  
  package org.apache.commons.morphos.morphers.xml;
  
  import org.apache.commons.morphos.helpers.AbstractMorpher;
  import org.apache.commons.morphos.*;
  
  import javax.xml.transform.*;
  import javax.xml.transform.sax.*;
  import org.xml.sax.*;
  
  /**
   *  
   *
   * @author Sven Künzler
   * @version $Revision: 1.1 $ $Date: 2002/08/05 13:35:14 $
   */
   
  public class XSLTMorpher extends AbstractMorpher implements ContentHandler, StylesheetAware{
      private TransformerHandler tHandler;
  
      private ContentHandler output;
      private Source stylesheetSource;
  
       public XSLTMorpher(){
  	 super();
  	 output=null;
  	 stylesheetSource=null;
       }
  
      public void setStylesheet(Source s){
  	stylesheetSource=s;
      }
  
      public void setOutput(Object output) throws ObjectFlavorException{
  	if(output instanceof ContentHandler){
  	    this.output=(ContentHandler)output;
  	} else throw new ObjectFlavorException("Output class "+output.getClass().getName()+" not instance of ContentHandler.");
      }
  
      /* ********** START implementation of ContentHandler ********** */
  
      /**
       * Receive notification of character data.
       *
       * @param ch the character array
       * @param start the start index in ch
       * @param length the length of the valid part of ch
       *
       * @exception SAXException if anything goes wrong in processing
       *            the character data
       */
  
      public void characters(final char [] ch, final int start,
                             final int length)
          throws SAXException
      
      {
  	tHandler.characters(ch,start,length);
      }
  
      /**
       * Receive notification of the end of an element.
       *
       * @param ignored_namespaceURI
       * @param ignored_localName
       * @param ignored_qName
       *
       * @exception SAXException on any errors processing the event.
       */
  
      public void endElement(final String ignored_namespaceURI,
                             final String ignored_localName,
                             final String ignored_qName)
          throws SAXException
      {
  	tHandler.endElement(ignored_namespaceURI,ignored_localName, ignored_qName);
      }
  
      /**
       * End the scope of a prefix-URI mapping. We don't really care.
       *
       * @param ignored_prefix
       */
  
      public void endPrefixMapping(final String ignored_prefix)throws SAXException
      {
  	tHandler.endPrefixMapping(ignored_prefix);
      }
  
      /**
       * Receive notification of ignorable whitespace in element
       * content.
       *
       * @param ch the character array
       * @param start the start index in ch
       * @param length the length of the valid part of ch
       *
       * @exception SAXException if anything goes wrong in processing
       *            the character data
       */
  
      public void ignorableWhitespace(final char [] ch, final int start,
                                      final int length)
          throws SAXException
      {
  	tHandler.ignorableWhitespace(ch,start,length);
      }
  
      /**
       * Receive notification of a processing instruction. We don't
       * really care.
       *
       * @param ignored_target
       * @param ignored_data
       */
  
      public void processingInstruction(final String ignored_target,
                                        final String ignored_data)        throws SAXException
  
      {
  	tHandler.processingInstruction(ignored_target,ignored_data);
      }
  
      private Locator documentLocator;
      /**
       * Receive an object for locating the origin of SAX document
       * events.
       *
       * @param locator the Locator object
       */
      public void setDocumentLocator(final Locator locator)       
  
      {
  	documentLocator=locator;
  	if(tHandler!=null) tHandler.setDocumentLocator(locator);
      }
  
      /**
       * Receive notification of a skipped entity. We don't really care.
       *
       * @param ignored_name
       */
  
      public void skippedEntity(final String ignored_name) throws SAXException
  
      {
  	tHandler.skippedEntity(ignored_name);
      }
  
      /**
       * Receive notification of the beginning of a document.
       */
      public void startDocument() throws SAXException
  
      {
  	try{
  	    SAXTransformerFactory factory=(SAXTransformerFactory)TransformerFactory.newInstance();
  	    if(stylesheetSource==null){
  		tHandler=factory.newTransformerHandler();
  	    } else {
  		tHandler=factory.newTransformerHandler(stylesheetSource);
  		tHandler.setDocumentLocator(documentLocator);
  
  	    }
  	    if(output!=null) tHandler.setResult(new SAXResult(output));
  	} catch(TransformerConfigurationException tce){
  	    throw new SAXException(tce);
  	} catch(ClassCastException cce){
  	    throw new SAXException("Installed JAXP implementation does not support SAXTransformerFactory");
  	}
  	tHandler.startDocument();
      }
      
      /**
       * Receive notification of the beginning of a document.
       */
      public void endDocument()        throws SAXException
  
      {
  	tHandler.endDocument();
      }
  
      /**
       * Receive notification of the beginning of an element.
       *
       * @param namespaceURI the namespace this element is in
       * @param localName the local name of the element
       * @param qName the qualified name of the element
       * @param atts the Attributes, if any, of the element
       *
       * @exception SAXException if we cannot  handle the element
       */
  
      public void startElement(final String namespaceURI,
                               final String localName, final String qName,
                               final Attributes atts)
          throws SAXException
      {
  	tHandler.startElement(namespaceURI,localName,qName,atts);
      }
  
      /**
       * Begin the scope of a prefix-URI Namespace mapping. We don't
       * really care.
       *
       * @param ignored_prefix
       * @param ignored_uri
       */
  
      public void startPrefixMapping(final String ignored_prefix,
                                     final String ignored_uri) throws SAXException
      {
  	tHandler.startPrefixMapping(ignored_prefix,ignored_uri);
      }
  
      /* **********  END  implementation of ContentHandler ********** */
  
  		   
  }
  
  
  
  
  
  
  
  
  
  
  
  
  1.1                  jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/pipelines/SAXMorpherPipeline.java
  
  Index: SAXMorpherPipeline.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/morphos/src/java/org/apache/commons/morphos/pipelines/SAXMorpherPipeline.java,v 1.1 2002/08/05 13:35:14 nicolaken Exp $
   * $Revision: 1.1 $
   * $Date: 2002/08/05 13:35:14 $
   *
   * ====================================================================
   *
   * 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 apache@apache.org.
   *
   * 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/>.
   *
   */
  
  package org.apache.commons.morphos.pipelines;
  
  import org.apache.commons.morphos.*;
  
  /** A simple SAX-only xml processing pipeline. This pipeline has the following constraints:
   * <ul>
   *  <li>The first morpher added may be any morpher</li>
   *  <li>Morphers added subsequently must implement org.xml.sax.ContentHandler (or a SAXMorpher TBD). </li>
   *  <li>You may add morphers as long as all previously added Morphers
   *      support org.xml.sax.ContentHandler as output ObjectFlavor.</li>
   * </ul>
   */
  public class SAXMorpherPipeline implements MorpherPipeline{
      private Morpher firstMorpher, lastMorpher;
  
      private boolean addStageAllowed;
  
  
      Object input,output;
  
      public SAXMorpherPipeline(){
  	super();
  	firstMorpher=null;
  	lastMorpher=null;
  	addStageAllowed=true;
  	input=null;
  	output=null;
      }
      
      public void setInput(Object input) throws ObjectFlavorException {
  	/* addStageAllowed=false; //? see morph()
  	if(firstMorpher==null) throw new IllegalStateException("Pipeline uninitialized");
  	firstMorpher.setInput(input);
  	*/
  	this.input=input;
      }
  
      public void setOutput(Object output) throws ObjectFlavorException {
  	// likewise, see setInput()
  	this.output=output;
      }
      
      public void addStage(Morpher nextMorpher) /* FIXME  throws MorphException? */ {
  	if(!addStageAllowed) throw new UnsupportedOperationException("Cannot add further stages to this pipeline");
  	if(firstMorpher==null){
  	    firstMorpher=nextMorpher;
  	    lastMorpher=nextMorpher;
  	} else if(!(nextMorpher instanceof org.xml.sax.ContentHandler)) {
  	    throw new IllegalArgumentException("Morpher must implement ContentHandler for second and subsequent stages");
  	} else {
  	    try{
  		//System.out.println(lastMorpher+"->"+nextMorpher);
  		lastMorpher.setOutput(nextMorpher);
  		lastMorpher=nextMorpher;
  	    } catch (ObjectFlavorException ofe){
  		addStageAllowed=false;
  		throw new UnsupportedOperationException("Previous Morpher marks end of pipeline");
  	    }
  	}
      }
  
      public void morph() throws MorphException{
  	if(firstMorpher==null || lastMorpher==null) throw new MorphException("Pipeline uninitialized.");
  	addStageAllowed=false;
  
  	try{
  	    firstMorpher.setInput(input);
  	    lastMorpher.setOutput(output);
  	} catch(ObjectFlavorException ofe){
  	    // FIXME: ugly. Maybe OFE should extend MorphException?
  	    // Alternative: setInput/setOutput may be called 
  	    //              after the final addStage only?
  	    //              That way, the objects can be passed to
  	    //              the responsible morphers directly
  	    //              But then, setInput/setOutput must throw 
  	    //              MorphException anyway.
  	    throw new MorphException(ofe);
  	}
  
  	firstMorpher.morph();
      }
  }
  
  
  
  
  
  

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


Mime
View raw message