You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by cz...@apache.org on 2001/11/13 12:03:58 UTC

cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml AbstractXMLConsumer.java ContentHandlerWrapper.java JaxpParser.java Parser.java XMLConsumer.java XMLFragment.java XMLizable.java XercesParser.java

cziegeler    01/11/13 03:03:58

  Added:       src/scratchpad/org/apache/avalon/excalibur/source
                        ModifiableSource.java Source.java
               src/scratchpad/org/apache/avalon/excalibur/xml
                        AbstractXMLConsumer.java ContentHandlerWrapper.java
                        JaxpParser.java Parser.java XMLConsumer.java
                        XMLFragment.java XMLizable.java XercesParser.java
  Log:
  Start moving components from Cocoon to Avalon. First set includes Parser, XMLConsumer and the basic Source interfaces
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/ModifiableSource.java
  
  Index: ModifiableSource.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 file.                                                         *
   *****************************************************************************/
  package org.apache.avalon.excalibur.source;
  
  /**
   * Describes a {@link Source} object whose data content can change.
   *
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   */
  public interface ModifiableSource extends Source
  {
    /**
     * Refresh the content of this object after the underlying data
     * content has changed.
     */
    void refresh();
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/Source.java
  
  Index: Source.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 file.                                                         *
   *****************************************************************************/
  
  package org.apache.avalon.excalibur.source;
  
  import org.apache.avalon.excalibur.pool.Recyclable;
  import org.xml.sax.InputSource;
  import java.io.IOException;
  import java.io.InputStream;
  
  /**
   * Description of a source. This interface provides a simple interface
   * for accessing a source of data. The source of data is assumed to
   * <b>not change</b> during the lifetime of the Source object. If you
   * have a data source that can change its content and you want it to
   * reflect, use a {@link ModifiableSource} object instead.
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/13 11:03:58 $
   */
  
  public interface Source extends Recyclable {
    /**
     * Get the last modification date of the source or 0 if it
     * is not possible to determine the date.
     */
    long getLastModified();
  
    /**
     * Get the content length of the source or -1 if it
     * is not possible to determine the length.
     */
    long getContentLength();
  
    /**
     * Return an <code>InputStream</code> object to read from the source.
     */
    InputStream getInputStream()
    throws IOException;
  
    /**
     * Return an <code>InputSource</code> object to read the XML
     * content.
     *
     * @return an <code>InputSource</code> value
     * @exception ProcessingException if an error occurs
     * @exception IOException if an error occurs
     */
    InputSource getInputSource()
    throws IOException;
  
    /**
     * Return the unique identifer for this source
     */
    String getSystemId();
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/AbstractXMLConsumer.java
  
  Index: AbstractXMLConsumer.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 file.                                                         *
   *****************************************************************************/
  package org.apache.avalon.excalibur.xml;
  
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.xml.sax.Attributes;
  import org.xml.sax.Locator;
  import org.xml.sax.SAXException;
  
  /**
   * This abstract class provides default implementation of the methods specified
   * by the <code>XMLConsumer</code> interface.
   *
   * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
   *         (Apache Software Foundation, Exoffice Technologies)
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/13 11:03:58 $
   */
  public abstract class AbstractXMLConsumer extends AbstractLoggable implements XMLConsumer {
  
      /**
       * Receive an object for locating the origin of SAX document events.
       *
       * @param locator An object that can return the location of any SAX
       *                document event.
       */
      public void setDocumentLocator(Locator locator) {
      }
  
      /**
       * Receive notification of the beginning of a document.
       */
      public void startDocument()
      throws SAXException {
      }
  
      /**
       * Receive notification of the end of a document.
       */
      public void endDocument()
      throws SAXException {
      }
  
      /**
       * Begin the scope of a prefix-URI Namespace mapping.
       *
       * @param prefix The Namespace prefix being declared.
       * @param uri The Namespace URI the prefix is mapped to.
       */
      public void startPrefixMapping(String prefix, String uri)
      throws SAXException {
      }
  
      /**
       * End the scope of a prefix-URI mapping.
       *
       * @param prefix The prefix that was being mapping.
       */
      public void endPrefixMapping(String prefix)
      throws SAXException {
      }
  
      /**
       * Receive notification of the beginning of an element.
       *
       * @param uri The Namespace URI, or the empty string if the element has no
       *            Namespace URI or if Namespace
       *            processing is not being performed.
       * @param loc The local name (without prefix), or the empty string if
       *            Namespace processing is not being performed.
       * @param raw The raw XML 1.0 name (with prefix), or the empty string if
       *            raw names are not available.
       * @param a The attributes attached to the element. If there are no
       *          attributes, it shall be an empty Attributes object.
       */
      public void startElement(String uri, String loc, String raw, Attributes a)
      throws SAXException {
      }
  
  
      /**
       * Receive notification of the end of an element.
       *
       * @param uri The Namespace URI, or the empty string if the element has no
       *            Namespace URI or if Namespace
       *            processing is not being performed.
       * @param loc The local name (without prefix), or the empty string if
       *            Namespace processing is not being performed.
       * @param raw The raw XML 1.0 name (with prefix), or the empty string if
       *            raw names are not available.
       */
      public void endElement(String uri, String loc, String raw)
      throws SAXException {
      }
  
      /**
       * Receive notification of character data.
       *
       * @param ch The characters from the XML document.
       * @param start The start position in the array.
       * @param len The number of characters to read from the array.
       */
      public void characters(char ch[], int start, int len)
      throws SAXException {
      }
  
      /**
       * Receive notification of ignorable whitespace in element content.
       *
       * @param ch The characters from the XML document.
       * @param start The start position in the array.
       * @param len The number of characters to read from the array.
       */
      public void ignorableWhitespace(char ch[], int start, int len)
      throws SAXException {
      }
  
      /**
       * Receive notification of a processing instruction.
       *
       * @param target The processing instruction target.
       * @param data The processing instruction data, or null if none was
       *             supplied.
       */
      public void processingInstruction(String target, String data)
      throws SAXException {
      }
  
      /**
       * Receive notification of a skipped entity.
       *
       * @param name The name of the skipped entity.  If it is a  parameter
       *             entity, the name will begin with '%'.
       */
      public void skippedEntity(String name)
      throws SAXException {
      }
  
      /**
       * Report the start of DTD declarations, if any.
       *
       * @param name The document type name.
       * @param publicId The declared public identifier for the external DTD
       *                 subset, or null if none was declared.
       * @param systemId The declared system identifier for the external DTD
       *                 subset, or null if none was declared.
       */
      public void startDTD(String name, String publicId, String systemId)
      throws SAXException {
      }
  
      /**
       * Report the end of DTD declarations.
       */
      public void endDTD()
      throws SAXException {
      }
  
      /**
       * Report the beginning of an entity.
       *
       * @param name The name of the entity. If it is a parameter entity, the
       *             name will begin with '%'.
       */
      public void startEntity(String name)
      throws SAXException {
      }
  
      /**
       * Report the end of an entity.
       *
       * @param name The name of the entity that is ending.
       */
      public void endEntity(String name)
      throws SAXException {
      }
  
      /**
       * Report the start of a CDATA section.
       */
      public void startCDATA()
      throws SAXException {
      }
  
      /**
       * Report the end of a CDATA section.
       */
      public void endCDATA()
      throws SAXException {
      }
  
  
      /**
       * Report an XML comment anywhere in the document.
       *
       * @param ch An array holding the characters in the comment.
       * @param start The starting position in the array.
       * @param len The number of characters to use from the array.
       */
      public void comment(char ch[], int start, int len)
      throws SAXException {
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/ContentHandlerWrapper.java
  
  Index: ContentHandlerWrapper.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 file.                                                         *
   *****************************************************************************/
  
  package org.apache.avalon.excalibur.xml;
  
  import org.apache.avalon.excalibur.pool.Recyclable;
  import org.xml.sax.Attributes;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.Locator;
  import org.xml.sax.SAXException;
  import org.xml.sax.ext.LexicalHandler;
  
  /**
   * This class is an utility class &quot;wrapping&quot; around a SAX version 2.0
   * <code>ContentHandler</code> and forwarding it those events received throug
   * its <code>XMLConsumers</code> interface.
   * <br>
   *
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   *         (Apache Software Foundation, Computer Associates)
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/13 11:03:58 $
   */
  public class ContentHandlerWrapper extends AbstractXMLConsumer implements Recyclable {
  
      /** The current <code>ContentHandler</code>. */
      protected ContentHandler contentHandler;
  
      /** The optional <code>LexicalHandler</code> */
      protected LexicalHandler lexicalHandler;
  
      /**
       * Create a new <code>ContentHandlerWrapper</code> instance.
       */
      public ContentHandlerWrapper() {
          super();
       }
  
      /**
       * Create a new <code>ContentHandlerWrapper</code> instance.
       */
      public ContentHandlerWrapper(ContentHandler contentHandler) {
          this();
          this.setContentHandler(contentHandler);
      }
  
      /**
       * Create a new <code>ContentHandlerWrapper</code> instance.
       */
      public ContentHandlerWrapper(ContentHandler contentHandler,
                                   LexicalHandler lexicalHandler) {
          this();
          this.setContentHandler(contentHandler);
          this.setLexicalHandler(lexicalHandler);
      }
  
      /**
       * Set the <code>ContentHandler</code> that will receive XML data.
       *
       * @exception IllegalStateException If the <code>ContentHandler</code>
       *                                  was already set.
       */
      public void setContentHandler(ContentHandler contentHandler)
      throws IllegalStateException {
          if (this.contentHandler!=null) throw new IllegalStateException();
          this.contentHandler=contentHandler;
      }
  
      /**
       * Set the <code>LexicalHandler</code> that will receive XML data.
       *
       * @exception IllegalStateException If the <code>LexicalHandler</code>
       *                                  was already set.
       */
      public void setLexicalHandler(LexicalHandler lexicalHandler)
      throws IllegalStateException {
          if (this.lexicalHandler!=null) throw new IllegalStateException();
          this.lexicalHandler=lexicalHandler;
      }
  
      public void recycle () {
          this.contentHandler = null;
          this.lexicalHandler = null;
      }
  
      /**
       * Receive an object for locating the origin of SAX document events.
       */
      public void setDocumentLocator (Locator locator) {
          if (this.contentHandler==null) return;
          else this.contentHandler.setDocumentLocator(locator);
      }
  
      /**
       * Receive notification of the beginning of a document.
       */
      public void startDocument ()
      throws SAXException {
          if (this.contentHandler==null)
              throw new SAXException("ContentHandler not set");
          this.contentHandler.startDocument();
      }
  
      /**
       * Receive notification of the end of a document.
       */
      public void endDocument ()
      throws SAXException {
          this.contentHandler.endDocument();
      }
  
      /**
       * Begin the scope of a prefix-URI Namespace mapping.
       */
      public void startPrefixMapping(String prefix, String uri)
      throws SAXException {
          if (this.contentHandler==null)
              throw new SAXException("ContentHandler not set");
          this.contentHandler.startPrefixMapping(prefix, uri);
      }
  
      /**
       * End the scope of a prefix-URI mapping.
       */
      public void endPrefixMapping(String prefix)
      throws SAXException {
          this.contentHandler.endPrefixMapping(prefix);
      }
  
      /**
       * Receive notification of the beginning of an element.
       */
      public void startElement(String uri, String loc, String raw, Attributes a)
      throws SAXException {
          this.contentHandler.startElement(uri, loc, raw, a);
      }
  
  
      /**
       * Receive notification of the end of an element.
       */
      public void endElement(String uri, String loc, String raw)
      throws SAXException {
          this.contentHandler.endElement(uri, loc, raw);
      }
  
      /**
       * Receive notification of character data.
       */
      public void characters(char ch[], int start, int len)
      throws SAXException {
          this.contentHandler.characters(ch,start,len);
      }
  
      /**
       * Receive notification of ignorable whitespace in element content.
       */
      public void ignorableWhitespace(char ch[], int start, int len)
      throws SAXException {
          this.contentHandler.ignorableWhitespace(ch,start,len);
      }
  
      /**
       * Receive notification of a processing instruction.
       */
      public void processingInstruction(String target, String data)
      throws SAXException {
          this.contentHandler.processingInstruction(target,data);
      }
  
      /**
       * Receive notification of a skipped entity.
       *
       * @param name The name of the skipped entity.  If it is a  parameter
       *             entity, the name will begin with '%'.
       */
      public void skippedEntity(String name)
      throws SAXException {
          this.contentHandler.skippedEntity(name);
      }
  
          /**
       * Report the start of DTD declarations, if any.
       *
       * @param name The document type name.
       * @param publicId The declared public identifier for the external DTD
       *                 subset, or null if none was declared.
       * @param systemId The declared system identifier for the external DTD
       *                 subset, or null if none was declared.
       */
      public void startDTD(String name, String publicId, String systemId)
      throws SAXException {
          if (this.lexicalHandler != null)
              this.lexicalHandler.startDTD(name, publicId, systemId);
      }
  
      /**
       * Report the end of DTD declarations.
       */
      public void endDTD()
      throws SAXException {
          if (this.lexicalHandler != null)
              this.lexicalHandler.endDTD();
      }
  
      /**
       * Report the beginning of an entity.
       *
       * @param name The name of the entity. If it is a parameter entity, the
       *             name will begin with '%'.
       */
      public void startEntity(String name)
      throws SAXException {
          if (this.lexicalHandler != null)
              this.lexicalHandler.startEntity(name);
      }
  
      /**
       * Report the end of an entity.
       *
       * @param name The name of the entity that is ending.
       */
      public void endEntity(String name)
      throws SAXException {
          if (this.lexicalHandler != null)
              this.lexicalHandler.endEntity(name);
      }
  
      /**
       * Report the start of a CDATA section.
       */
      public void startCDATA()
      throws SAXException {
          if (this.lexicalHandler != null)
              this.lexicalHandler.startCDATA();
      }
  
      /**
       * Report the end of a CDATA section.
       */
      public void endCDATA()
      throws SAXException {
          if (this.lexicalHandler != null)
              this.lexicalHandler.endCDATA();
      }
  
  
      /**
       * Report an XML comment anywhere in the document.
       *
       * @param ch An array holding the characters in the comment.
       * @param start The starting position in the array.
       * @param len The number of characters to use from the array.
       */
      public void comment(char ch[], int start, int len)
      throws SAXException {
          if (this.lexicalHandler != null)
              this.lexicalHandler.comment(ch, start, len);
      }
  
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/JaxpParser.java
  
  Index: JaxpParser.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 file.                                                         *
   *****************************************************************************/
  package org.apache.avalon.excalibur.xml;
  
  import org.apache.avalon.excalibur.pool.Recyclable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.w3c.dom.Document;
  import org.xml.sax.*;
  
  import javax.xml.parsers.*;
  import java.io.IOException;
  
  /**
   * An XMLParser that is only dependant on JAXP 1.1 compliant parsers.
   * If only we can get rid of the need for the Document...
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/13 11:03:58 $
   */
  public class JaxpParser
  extends AbstractLoggable
  implements Parser, ErrorHandler, Configurable, Recyclable {
  
      /** the SAX Parser factory */
      protected SAXParserFactory factory;
  
      /** the Document Builder factory */
      protected DocumentBuilderFactory docfactory;
  
      /**
       * Configure
       */
      public void configure(Configuration config)
      throws ConfigurationException {
          Parameters params = Parameters.fromConfiguration(config);
          boolean validate = params.getParameterAsBoolean("validate", false);
          this.factory = SAXParserFactory.newInstance();
          this.docfactory = DocumentBuilderFactory.newInstance();
          this.factory.setNamespaceAware(true);
          this.factory.setValidating(validate);
          this.docfactory.setNamespaceAware(true);
          this.docfactory.setValidating(validate);
      }
  
      public void parse(InputSource in, XMLConsumer consumer)
      throws SAXException, IOException {
          SAXParser parser = null;
  
          try {
              parser = this.factory.newSAXParser();
          } catch (ParserConfigurationException e) {
              getLogger().error("Cannot produce a valid parser", e);
              throw new SAXException("Could not get valid parser" + e.getMessage(), e);
          }
  
          XMLReader reader = parser.getXMLReader();
  
          reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
          try {
              reader.setProperty("http://xml.org/sax/properties/lexical-handler",
                          consumer);
          } catch (SAXException e) {
              getLogger().warn("SAX2 driver does not support property: "+
                               "'http://xml.org/sax/properties/lexical-handler'");
          }
  
          reader.setErrorHandler(this);
          reader.setContentHandler(consumer);
          reader.parse(in);
      }
  
      /**
       * Parses a new Document object from the given InputSource.
       */
      public Document parseDocument(InputSource input) throws SAXException, IOException {
        DocumentBuilder builder = null;
        try {
          builder = this.docfactory.newDocumentBuilder();
        } catch (ParserConfigurationException pce) {
          getLogger().error("Could not build DocumentBuilder", pce);
          return null;
        }
        return builder.parse(input);
      }
  
      /**
       * Receive notification of a recoverable error.
       */
      public void error(SAXParseException e)
      throws SAXException {
          throw new SAXException("Error parsing "+e.getSystemId()+" (line "+
                                 e.getLineNumber()+" col. "+e.getColumnNumber()+
                                 "): "+e.getMessage(),e);
      }
  
      /**
       * Receive notification of a fatal error.
       */
      public void fatalError(SAXParseException e)
      throws SAXException {
          throw new SAXException("Fatal error parsing "+e.getSystemId()+" (line "+
                                 e.getLineNumber()+" col. "+e.getColumnNumber()+
                                 "): "+e.getMessage(),e);
      }
  
      /**
       * Receive notification of a warning.
       */
      public void warning(SAXParseException e)
      throws SAXException {
          throw new SAXException("Warning parsing "+e.getSystemId()+" (line "+
                                 e.getLineNumber()+" col. "+e.getColumnNumber()+
                                 "): "+e.getMessage(),e);
      }
  
      /**
       * Recycle
       */
      public void recycle() {
      }
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/Parser.java
  
  Index: Parser.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 file.                                                         *
   *****************************************************************************/
  package org.apache.avalon.excalibur.xml;
  
  import org.apache.avalon.framework.component.Component;
  import org.w3c.dom.Document;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  import org.xml.sax.ext.LexicalHandler;
  
  import java.io.IOException;
  
  /**
   *
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/13 11:03:58 $
   */
  public interface Parser extends Component {
  
      String ROLE = "org.apache.avalon.excalibur.xml.Parser";
  
      void parse(InputSource in, XMLConsumer consumer)
      throws SAXException, IOException;
  
      Document parseDocument(InputSource in)
      throws SAXException, IOException;
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/XMLConsumer.java
  
  Index: XMLConsumer.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 file.                                                         *
   *****************************************************************************/
  package org.apache.avalon.excalibur.xml;
  
  import org.xml.sax.ContentHandler;
  import org.xml.sax.ext.LexicalHandler;
  
  /**
   * This interfaces identifies classes that consume XML data, receiving
   * notification of SAX events.
   * <br>
   * This interface unites the idea of SAX <code>ContentHandler</code> and
   * <code>LexicalHandler</code>.
   *
   * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
   *         (Apache Software Foundation, Exoffice Technologies)
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/13 11:03:58 $
   */
  public interface XMLConsumer extends ContentHandler, LexicalHandler {
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/XMLFragment.java
  
  Index: XMLFragment.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 file.                                                         *
   *****************************************************************************/
  package org.apache.avalon.excalibur.xml;
  
  import org.w3c.dom.DOMException;
  import org.w3c.dom.Node;
  
  /**
   * This interface must be implemented by classes willing
   * to provide an XML representation of their current state.
   * <br/>
   *
   * @author <a href="mailto:sylvain.wallez@anyware-tech.com">Sylvain Wallez</a>
   * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a> for the original XObject class
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/13 11:03:58 $
   */
  
  public interface XMLFragment {
  
      /**
       * Appends children representing the object's state to the given node.
       */
      void toDOM(Node node) throws DOMException;
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/XMLizable.java
  
  Index: XMLizable.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 file.                                                         *
   *****************************************************************************/
  package org.apache.avalon.excalibur.xml;
  
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  
  /**
   * This interface can be implemented by classes willing to provide an XML representation
   * of their current state as SAX events.
   *
   * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/13 11:03:58 $
   */
  
  public interface XMLizable {
      /**
       * Generates SAX events representing the object's state.<br/>
       * <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!
       */
      void toSAX(ContentHandler handler) throws SAXException;
  
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/XercesParser.java
  
  Index: XercesParser.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 file.                                                         *
   *****************************************************************************/
  package org.apache.avalon.excalibur.xml;
  
  import org.apache.avalon.framework.logger.AbstractLoggable;
  import org.apache.avalon.framework.thread.SingleThreaded;
  import org.apache.xerces.parsers.DOMParser;
  import org.apache.xerces.parsers.SAXParser;
  import org.w3c.dom.Document;
  import org.xml.sax.ErrorHandler;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  import org.xml.sax.SAXParseException;
  
  import java.io.IOException;
  
  /**
   *
   * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
   *         (Apache Software Foundation, Exoffice Technologies)
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/13 11:03:58 $
   */
  public class XercesParser
  extends AbstractLoggable
  implements Parser, ErrorHandler, SingleThreaded {
  
      /** the SAX Parser */
      final SAXParser parser;
  
      public XercesParser ()
      throws SAXException {
          this.parser = new SAXParser();
  
          this.parser.setFeature("http://xml.org/sax/features/validation",false);
          this.parser.setFeature("http://xml.org/sax/features/namespaces",true);
          this.parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
                            true);
      }
  
      public void parse(InputSource in, XMLConsumer consumer)
      throws SAXException, IOException {
        this.parser.setProperty("http://xml.org/sax/properties/lexical-handler",
                                consumer);
          this.parser.setErrorHandler(this);
          this.parser.setContentHandler(consumer);
          this.parser.parse(in);
      }
  
      /**
       * Parses a new Document object from the given InputSource.
       */
      public Document parseDocument(InputSource input) throws SAXException, IOException {
          DOMParser parser = null;
  
          try {
              parser = new DOMParser();
  
              parser.setFeature("http://xml.org/sax/features/validation",false);
              parser.setFeature("http://xml.org/sax/features/namespaces",true);
              parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
                                true);
  
              parser.parse(input);
          } catch (Exception pce) {
              getLogger().error("Could not build DocumentBuilder", pce);
              return null;
          }
  
          return parser.getDocument();
      }
  
      /**
       * Receive notification of a recoverable error.
       */
      public void error(SAXParseException e)
      throws SAXException {
          throw new SAXException("Error parsing "+e.getSystemId()+" (line "+
                                 e.getLineNumber()+" col. "+e.getColumnNumber()+
                                 "): "+e.getMessage(),e);
      }
  
      /**
       * Receive notification of a fatal error.
       */
      public void fatalError(SAXParseException e)
      throws SAXException {
          throw new SAXException("Fatal error parsing "+e.getSystemId()+" (line "+
                                 e.getLineNumber()+" col. "+e.getColumnNumber()+
                                 "): "+e.getMessage(),e);
      }
  
      /**
       * Receive notification of a warning.
       */
      public void warning(SAXParseException e)
      throws SAXException {
          throw new SAXException("Warning parsing "+e.getSystemId()+" (line "+
                                 e.getLineNumber()+" col. "+e.getColumnNumber()+
                                 "): "+e.getMessage(),e);
      }
  }
  
  
  

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