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/avalon/excalibur/xml DefaultDOMHandlerFactory.java DefaultDOMHandler.java
Date Tue, 06 Aug 2002 18:14:29 GMT
mirceatoma    2002/08/06 11:14:29

  Added:       xmlutil/src/java/org/apache/avalon/excalibur/xml
                        DefaultDOMHandlerFactory.java
                        DefaultDOMHandler.java
  Log:
  Add default implementation for DOMHandler*.
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/xmlutil/src/java/org/apache/avalon/excalibur/xml/DefaultDOMHandlerFactory.java
  
  Index: DefaultDOMHandlerFactory.java
  ===================================================================
  /*
   * DefaultDOMHandlerFactory.java
   *
   * Created on August 2, 2002, 3:28 PM
   */
  
  package org.apache.avalon.excalibur.xml;
  
  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;
  
  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/avalon/excalibur/xml/DefaultDOMHandler.java
  
  Index: DefaultDOMHandler.java
  ===================================================================
  package org.apache.avalon.excalibur.xml;
  
  import org.xml.sax.SAXException;
  import org.w3c.dom.Document;
  import javax.xml.transform.dom.DOMResult;
  import javax.xml.transform.sax.TransformerHandler;
  
  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