You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by cz...@apache.org on 2002/04/24 09:46:31 UTC

cvs commit: jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlizer/impl HTMLXMLizer.java TextXMLizer.java XMLizerImpl.java

cziegeler    02/04/24 00:46:31

  Modified:    .        build.xml
               xmlbundle build.xml default.properties
  Added:       xmlbundle/lib README.txt jaxen-full.jar jdom.jar
                        jtidy-04aug2000r7-dev.jar saxpath.jar
               xmlbundle/src/java/org/apache/excalibur/xmlizer XMLizer.java
               xmlbundle/src/java/org/apache/excalibur/xmlizer/impl
                        HTMLXMLizer.java TextXMLizer.java XMLizerImpl.java
  Removed:     all/lib  README.txt jaxen-full.jar jdom.jar saxpath.jar
               all/src/scratchpad/org/apache/excalibur/xmlizer XMLizer.java
               all/src/scratchpad/org/apache/excalibur/xmlizer/impl
                        HTMLXMLizer.java TextXMLizer.java XMLizerImpl.java
  Log:
  Removing XMLizer
  
  Revision  Changes    Path
  1.160     +3 -3      jakarta-avalon-excalibur/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/build.xml,v
  retrieving revision 1.159
  retrieving revision 1.160
  diff -u -r1.159 -r1.160
  --- build.xml	24 Apr 2002 01:19:11 -0000	1.159
  +++ build.xml	24 Apr 2002 07:46:29 -0000	1.160
  @@ -25,12 +25,12 @@
           <ant dir="threadcontext" target="dist"/>
           <ant dir="sourceresolve" target="dist"/>
           <ant dir="monitor" target="dist"/>
  -        <ant dir="xmlbundle" target="dist"/>
           
           <!-- Sub projects with dependencies. -->
           <ant dir="pool" target="dist"/>               <!-- collections, concurrent, instrument -->
           <ant dir="thread" target="dist"/>             <!-- lang, instrument, threadcontext, pool -->
           <ant dir="component" target="dist"/>          <!-- collections, logger, instrument, pool -->
  +        <ant dir="xmlbundle" target="dist"/>          <!-- component -->
           <ant dir="util" target="dist"/>               <!-- component -->
           <ant dir="testcase" target="dist"/>           <!-- logger, component -->
           <ant dir="event" target="dist"/>              <!-- collections, concurrent, lang, pool, thread, util, event -->
  @@ -145,10 +145,10 @@
           <ant dir="datasource" target="jar"/>
           <ant dir="sourceresolve" target="jar"/>
           <ant dir="monitor" target="jar"/>
  -        <ant dir="xmlbundle" target="jar"/>
           <ant dir="all" target="all"/>
           <ant dir="cli" target="jar"/>
           <ant dir="component" target="jar"/>
  +        <ant dir="xmlbundle" target="jar"/>
           <ant dir="collections" target="jar"/>
           <ant dir="concurrent" target="jar"/>
           <ant dir="i18n" target="jar"/>
  @@ -204,13 +204,13 @@
           <ant dir="threadcontext" target="jar"/>
           <ant dir="sourceresolve" target="jar"/>
           <ant dir="monitor" target="jar"/>
  -        <ant dir="xmlbundle" target="jar"/>
           
           <!-- Sub projects with dependencies. -->
           <ant dir="pool" target="jar"/>               <!-- collections, concurrent, instrument, sourceresolve -->
           <ant dir="datasource" target="jar"/>         <!-- pool -->
           <ant dir="thread" target="jar"/>             <!-- lang, instrument, threadcontext, pool -->
           <ant dir="component" target="jar"/>          <!-- collections, logger, instrument, pool -->
  +        <ant dir="xmlbundle" target="jar"/>          <!-- component -->
           <ant dir="util" target="jar"/>               <!-- component -->
           <ant dir="testcase" target="jar"/>           <!-- logger, component -->
           <ant dir="event" target="jar"/>              <!-- collections, concurrent, lang, pool, thread, util, event -->
  
  
  
  1.14      +14 -0     jakarta-avalon-excalibur/xmlbundle/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/xmlbundle/build.xml,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- build.xml	22 Apr 2002 10:06:04 -0000	1.13
  +++ build.xml	24 Apr 2002 07:46:29 -0000	1.14
  @@ -14,11 +14,17 @@
           <pathelement path="${java.class.path}"/>
           <pathelement location="${build.classes}"/>
           <pathelement location="${avalon-framework.jar}"/>
  +        <pathelement location="${excalibur-logger.jar}"/>
  +        <pathelement location="${avalon-logkit.jar}"/>
  +        <pathelement location="${excalibur-component.jar}"/>
           <pathelement location="${excalibur-pool.jar}"/>
           <pathelement location="${checkstyle.jar}"/>
           <pathelement location="${xalan.jar}"/>
           <pathelement location="${xerces.jar}"/>
           <pathelement location="${xml-apis.jar}"/>
  +        <fileset dir="${lib.dir}">
  +            <include name="*.jar" />
  +        </fileset>
       </path>
   
       <path id="tools.class.path">
  @@ -46,11 +52,17 @@
           <available property="jaxen.present" classname="org.jaxen.dom.XPath">
               <classpath refid="project.class.path"/>
           </available>
  +        <available property="jtidy.present" classname="org.w3c.tidy.Tidy">
  +            <classpath refid="project.class.path"/>
  +        </available>
       </target>
   
       <target name="dependencies" description="Check dependencies" unless="skip.dependencies">
           <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkCommon"/>
           <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkFramework"/>
  +        <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkLogkit"/>
  +        <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkLogger"/>
  +        <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkComponent"/>
           <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkPool"/>
           <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkRequiredFile">
               <property name="name" value="xerces.jar"/>
  @@ -93,6 +105,8 @@
                   unless="xpath.present"/> 
               <exclude name="org/apache/avalon/excalibur/xml/xpath/JaxenProcessorImpl.java"
                   unless="jaxen.present"/>
  +            <exclude name="org/apache/excalibur/xmlizer/impl/HTMLXMLizer.java"
  +                unless="jtidy.present"/>
           </javac>
   
           <!-- copy resources to same location as .class files -->
  
  
  
  1.7       +16 -0     jakarta-avalon-excalibur/xmlbundle/default.properties
  
  Index: default.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/xmlbundle/default.properties,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- default.properties	22 Apr 2002 10:06:04 -0000	1.6
  +++ default.properties	24 Apr 2002 07:46:29 -0000	1.7
  @@ -20,6 +20,21 @@
   avalon-framework.lib=${avalon-framework.home}/build/lib
   avalon-framework.jar=${avalon-framework.lib}/avalon-framework.jar
   
  +# ----- Logkit -----
  +avalon-logkit.home=${basedir}/../../jakarta-avalon-logkit
  +avalon-logkit.lib=${avalon-logkit.home}/build/lib
  +avalon-logkit.jar=${avalon-logkit.lib}/logkit.jar
  +
  +# ----- Excalibur logger, version 1.0 or later -----
  +excalibur-logger.home=${basedir}/../logger/dist
  +excalibur-logger.lib=${excalibur-logger.home}
  +excalibur-logger.jar=${excalibur-logger.lib}/excalibur-logger-1.0.jar
  +
  +# ----- Excalibur component, version 1.0 or later -----
  +excalibur-component.home=${basedir}/../component/dist
  +excalibur-component.lib=${excalibur-component.home}
  +excalibur-component.jar=${excalibur-component.lib}/excalibur-component-1.0.jar
  +
   # ----- Excalibur Pool, version 1.0 or later -----
   excalibur-pool.home=${basedir}/../pool/dist
   excalibur-pool.lib=${excalibur-pool.home}
  @@ -51,6 +66,7 @@
   
   #  Set the properties for source directories
   src.dir = src
  +lib.dir = lib
   java.dir = ${src.dir}/java
   conf.dir = ${src.dir}/conf
   test.dir = ${src.dir}/test
  
  
  
  1.1                  jakarta-avalon-excalibur/xmlbundle/lib/README.txt
  
  Index: README.txt
  ===================================================================
  Place any third party jars here.
  
  You can find the latest Jaxen at:
  http://sourceforge.net/project/showfiles.php?group_id=31447
  
  
  
  1.1                  jakarta-avalon-excalibur/xmlbundle/lib/jaxen-full.jar
  
  	<<Binary file>>
  
  
  1.1                  jakarta-avalon-excalibur/xmlbundle/lib/jdom.jar
  
  	<<Binary file>>
  
  
  1.1                  jakarta-avalon-excalibur/xmlbundle/lib/jtidy-04aug2000r7-dev.jar
  
  	<<Binary file>>
  
  
  1.1                  jakarta-avalon-excalibur/xmlbundle/lib/saxpath.jar
  
  	<<Binary file>>
  
  
  1.1                  jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlizer/XMLizer.java
  
  Index: XMLizer.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.xmlizer;
  
  import java.io.InputStream;
  import java.io.IOException;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  
  /**
   * Converter for transforming any input stream with a given mime-type
   * into SAX events.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/04/24 07:46:30 $
   */
  
  public interface XMLizer
      extends Component
  {
      String ROLE = XMLizer.class.getName();
  
      /**
       * Generates SAX events from the given input stream
       * <b>NOTE</b> : if the implementation can produce lexical events, care should be taken
       * that <code>handler</code> can actually be a
       * {@link org.apache.avalon.excalibur.xml.XMLConsumer} that accepts such
       * events or directly implements the LexicalHandler interface!
       * @param stream    the data
       * @param mimeType  the mime-type for the data
       * @param systemID  the URI defining the data (this is optional and can be null)
       * @throws ComponentException if no suitable converter is found
       */
      void toSAX( InputStream    stream,
                  String         mimeType,
                  String         systemID,
                  ContentHandler handler )
      throws SAXException, IOException, ComponentException;
  
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlizer/impl/HTMLXMLizer.java
  
  Index: HTMLXMLizer.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.xmlizer.impl;
  
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.StringReader;
  import java.io.StringWriter;
  import java.util.Properties;
  import javax.xml.transform.OutputKeys;
  import javax.xml.transform.Transformer;
  import javax.xml.transform.TransformerException;
  import javax.xml.transform.TransformerFactory;
  import javax.xml.transform.dom.DOMSource;
  import javax.xml.transform.stream.StreamResult;
  import org.apache.avalon.excalibur.xml.Parser;
  import org.apache.excalibur.xmlizer.XMLizer;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.w3c.tidy.Tidy;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  
  /**
   * Converter for transforming an input stream contain text/html data
   * to SAX events.
   * This class uses jtidy.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/04/24 07:46:30 $
   */
  
  public class HTMLXMLizer
      extends AbstractLogEnabled
      implements XMLizer, ThreadSafe, Composable
  {
  
      /** The component manager */
      protected ComponentManager manager;
  
      /** Used for converting DOM -> SAX */
      protected static Properties format;
  
      static {
          Properties format = new Properties();
          format.put(OutputKeys.METHOD, "xml");
          format.put(OutputKeys.OMIT_XML_DECLARATION, "no");
          format.put(OutputKeys.INDENT, "yes");
      }
  
      /**
       * Composable interface
       */
      public void compose(ComponentManager manager)
      {
          this.manager = manager;
      }
  
      /**
       * Generates SAX events from the given input stream
       * <b>NOTE</b> : if the implementation can produce lexical events, care should be taken
       * that <code>handler</code> can actually be a {@link XMLConsumer} that accepts such
       * events or directly implements the LexicalHandler interface!
       * @param stream    the data
       * @param mimeType  the mime-type for the data
       * @param systemID  the URI defining the data (this is optional and can be null)
       * @throws ComponentException if no suitable converter is found
       */
      public void toSAX( InputStream    stream,
                         String         mimeType,
                         String         systemID,
                         ContentHandler handler )
          throws SAXException, IOException, ComponentException
      {
          if ( null == stream ) {
              throw new ComponentException("Stream must not be null.");
          }
          if ( null == handler ) {
              throw new ComponentException("Handler must not be null.");
          }
          if ( null == mimeType ) {
              if ( this.getLogger().isDebugEnabled() ) {
                  this.getLogger().debug("No mime-type for xmlizing " + systemID +
                                         ", guessing text/html");
              }
          } else if ( !mimeType.equalsIgnoreCase("text/html") ) {
              if ( this.getLogger().isDebugEnabled() ) {
                  this.getLogger().debug("Mime-type " + mimeType +
                                         "not supported for xmlizing " + systemID +
                                         ", guessing text/html");
              }
          }
  
          final Tidy xhtmlconvert = new Tidy();
          xhtmlconvert.setXmlOut(true);
          xhtmlconvert.setXHTML(true);
          xhtmlconvert.setShowWarnings(false);
          final StringWriter writer = new StringWriter();
          try {
              final Transformer transformer = TransformerFactory.newInstance().newTransformer();
              transformer.setOutputProperties(format);
              transformer.transform(new DOMSource(xhtmlconvert.parseDOM(stream, null)),
                                new StreamResult(writer));
          } catch (TransformerException te) {
              throw new SAXException("Exception during transformation.", te);
          }
          final InputSource inputSource =
                new InputSource( new java.io.StringReader(writer.toString()) );
          if ( null != systemID) inputSource.setSystemId( systemID );
  
          Parser parser = null;
          try
          {
              parser = (Parser)this.manager.lookup( Parser.ROLE );
  
              parser.parse( inputSource, handler );
          }
          finally
          {
              if( parser != null ) this.manager.release( parser );
          }
      }
  
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlizer/impl/TextXMLizer.java
  
  Index: TextXMLizer.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.xmlizer.impl;
  
  import java.io.InputStream;
  import java.io.IOException;
  import org.apache.avalon.excalibur.xml.Parser;
  import org.apache.excalibur.xmlizer.XMLizer;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  
  /**
   * Converter for transforming an input stream contain text/xml data
   * to SAX events.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/04/24 07:46:30 $
   */
  
  public class TextXMLizer
      extends AbstractLogEnabled
      implements XMLizer, ThreadSafe, Composable
  {
  
      /** The component manager */
      protected ComponentManager manager;
  
      /**
       * Composable interface
       */
      public void compose(ComponentManager manager)
      {
          this.manager = manager;
      }
  
      /**
       * Generates SAX events from the given input stream
       * <b>NOTE</b> : if the implementation can produce lexical events, care should be taken
       * that <code>handler</code> can actually be a {@link XMLConsumer} that accepts such
       * events or directly implements the LexicalHandler interface!
       * @param stream    the data
       * @param mimeType  the mime-type for the data
       * @param systemID  the URI defining the data (this is optional and can be null)
       * @throws ComponentException if no suitable converter is found
       */
      public void toSAX( InputStream    stream,
                         String         mimeType,
                         String         systemID,
                         ContentHandler handler )
          throws SAXException, IOException, ComponentException
      {
          if ( null == stream ) {
              throw new ComponentException("Stream must not be null.");
          }
          if ( null == handler ) {
              throw new ComponentException("Handler must not be null.");
          }
          if ( null == mimeType ) {
              if ( this.getLogger().isDebugEnabled() ) {
                  this.getLogger().debug("No mime-type for xmlizing " + systemID +
                                         ", guessing text/xml");
              }
          } else if ( !mimeType.equalsIgnoreCase("text/xml") ) {
              if ( this.getLogger().isDebugEnabled() ) {
                  this.getLogger().debug("Mime-type " + mimeType +
                                         "not supported for xmlizing " + systemID +
                                         ", guessing text/xml");
              }
          }
  
  
          final InputSource inputSource = new InputSource( stream );
          if ( null != systemID ) inputSource.setSystemId( systemID );
  
          Parser parser = null;
          try
          {
              parser = (Parser)this.manager.lookup( Parser.ROLE );
  
              parser.parse( inputSource, handler );
          }
          finally
          {
              if( parser != null ) this.manager.release( parser );
          }
      }
  
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/xmlbundle/src/java/org/apache/excalibur/xmlizer/impl/XMLizerImpl.java
  
  Index: XMLizerImpl.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.xmlizer.impl;
  
  import java.io.InputStream;
  import java.io.IOException;
  import org.apache.excalibur.xmlizer.XMLizer;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.excalibur.component.DefaultComponentSelector;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  
  /**
   * Converter for transforming any input stream with a given mime-type
   * into SAX events.
   * This component acts like a selector. All XMLizer can "register"
   * themselfes for a given mime-type and this component forwards
   * the transformation to the registered on.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/04/24 07:46:30 $
   */
  
  public class XMLizerImpl
      extends DefaultComponentSelector
      implements XMLizer, ThreadSafe
  {
  
      /** The default mimeType used when no mimeType is given */
      protected String defaultMimeType = "text/xml";
  
      /**
       * Generates SAX events from the given input stream
       * <b>NOTE</b> : if the implementation can produce lexical events, care should be taken
       * that <code>handler</code> can actually be a {@link XMLConsumer} that accepts such
       * events or directly implements the LexicalHandler interface!
       * @param stream    the data
       * @param mimeType  the mime-type for the data
       * @param systemID  the URI defining the data (this is optional and can be null)
       * @throws ComponentException if no suitable converter is found
       */
      public void toSAX( InputStream    stream,
                         String         mimeType,
                         String         systemID,
                         ContentHandler handler )
          throws SAXException, IOException, ComponentException
      {
          if ( null == stream ) {
              throw new ComponentException("Stream must not be null.");
          }
          if ( null == handler ) {
              throw new ComponentException("Handler must not be null.");
          }
          if ( null == mimeType ) {
              if ( this.getLogger().isDebugEnabled() ) {
                  this.getLogger().debug("No mime-type for xmlizing " + systemID + ", guessing " + this.defaultMimeType);
              }
              mimeType = this.defaultMimeType;
          }
  
          if ( !this.hasComponent ( mimeType ) ) {
              throw new ComponentException("No XMLizer registered for mimeType " + mimeType);
          }
  
          XMLizer realXMLizer = null;
          try
          {
              realXMLizer = (XMLizer) this.select( mimeType );
              realXMLizer.toSAX( stream, mimeType, systemID, handler );
          } finally {
              this.release( realXMLizer );
          }
  
      }
  
  }
  
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>