avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mirceat...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/xmlutil/src/java/org/apache/excalibur/xml/dom DOMHandlerFactory.java DOMHandler.java DefaultDOMHandlerFactory.java DefaultDOMHandler.java
Date Tue, 06 Aug 2002 19:58:18 GMT
mirceatoma    2002/08/06 12:58:18

  Added:       xmlutil/src/java/org/apache/excalibur/xml/dom
                        DOMHandlerFactory.java DOMHandler.java
                        DefaultDOMHandlerFactory.java
                        DefaultDOMHandler.java
  Log:
  Moved to new location in org.apache.excalibur package.
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/xmlutil/src/java/org/apache/excalibur/xml/dom/DOMHandlerFactory.java
  
  Index: DOMHandlerFactory.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.xml.dom;
  
  /**
   * The factory creates a DOMHandler encapsulating a DOM document. The document 
   * behaviour is setup by the factory.
   *
   * @author <a href="mailto:mirceatoma@apache.org">Mircea Toma</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/08/06 19:58:18 $
   */
  public interface DOMHandlerFactory {
      
      String ROLE = DOMHandlerFactory.class.getName();
      
      DOMHandler createDOMHandler() throws Exception;    
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/xmlutil/src/java/org/apache/excalibur/xml/dom/DOMHandler.java
  
  Index: DOMHandler.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.xml.dom;
  
  import org.w3c.dom.Document;
  import org.xml.sax.ContentHandler;
  
  /**
   * ContentHandler encapsulating a DOM document. The document tree is built
   * from SAX events sent to the handler.
   *
   * @author <a href="mailto:mirceatoma@apache.org">Mircea Toma</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/08/06 19:58:18 $
   */
  public interface DOMHandler extends ContentHandler {
      
      Document getDocument();
      
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/xmlutil/src/java/org/apache/excalibur/xml/dom/DefaultDOMHandlerFactory.java
  
  Index: DefaultDOMHandlerFactory.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.xml.dom;
  
  import org.w3c.dom.Document;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.transform.sax.SAXTransformerFactory;
  import javax.xml.transform.sax.TransformerHandler;
  import javax.xml.transform.dom.DOMResult;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  /**
   * @author <a href="mailto:mirceatoma@apache.org">Mircea Toma</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/08/06 19:58:18 $
   */
  public class DefaultDOMHandlerFactory extends AbstractLogEnabled implements DOMHandlerFactory,
Configurable, Initializable, Component, ThreadSafe
  {   
      private final SAXTransformerFactory m_transformerFactory = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
      private final DocumentBuilderFactory m_documentBuilderFactory = DocumentBuilderFactory.newInstance();
      private DocumentBuilder m_documentBuilder;
      private boolean m_ignoreWhitespaces;
      private boolean m_ignoreComments;
  
      public void configure( Configuration configuration ) throws ConfigurationException
      {
          m_ignoreWhitespaces = configuration.getChild( "ignore-whitespaces", true ).getValueAsBoolean(
false );
          m_ignoreComments = configuration.getChild( "ignore-comments", true ).getValueAsBoolean(
false );
      }
  
      public void initialize() throws Exception    
      {
          m_documentBuilder = m_documentBuilderFactory.newDocumentBuilder();
      }
      
      public DOMHandler createDOMHandler() throws Exception
      {
          final Document document = m_documentBuilder.newDocument();
          final DOMResult result = new DOMResult( document );
          final TransformerHandler transformerHandler = m_transformerFactory.newTransformerHandler();
          transformerHandler.setResult( result );
          
          return new DefaultDOMHandler( transformerHandler, result, m_ignoreComments, m_ignoreWhitespaces
);
      }        
          
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/xmlutil/src/java/org/apache/excalibur/xml/dom/DefaultDOMHandler.java
  
  Index: DefaultDOMHandler.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.xml.dom;
  
  import org.xml.sax.SAXException;
  import org.w3c.dom.Document;
  import javax.xml.transform.dom.DOMResult;
  import javax.xml.transform.sax.TransformerHandler;
  import org.apache.avalon.excalibur.xml.ContentHandlerWrapper;
  
  /**
   * @author <a href="mailto:mirceatoma@apache.org">Mircea Toma</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/08/06 19:58:18 $
   */
  public class DefaultDOMHandler 
      extends ContentHandlerWrapper
      implements DOMHandler
  {    
      private final DOMResult m_result;
      private final boolean m_ignoreWhitespaces;
      private final boolean m_ignoreComments;
      
      public DefaultDOMHandler( TransformerHandler handler, DOMResult result , boolean ignoreComments,
boolean ignoreWhitespaces )
      {
          super( handler, handler );
          m_result = result;
          m_ignoreComments = ignoreComments;
          m_ignoreWhitespaces = ignoreWhitespaces;
      }
      
      public Document getDocument()
      {
          return (Document)m_result.getNode();
      }
      
      public void ignorableWhitespace( final char[] ch, final int start, final int len )
      throws SAXException
      {
          if ( !m_ignoreWhitespaces ) super.ignorableWhitespace( ch, start, len );       

      }
      
      public void comment( final char[] ch, final int start, final int len )
      throws SAXException
      {
          if ( !m_ignoreComments ) super.comment( ch, start, len );
      }
      
  }
  
  
  

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


Mime
View raw message