avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon/src/test/org/apache/avalon/framework/configuration/test SAXConfigurationHandlerTestCase.java
Date Mon, 29 Oct 2001 16:16:28 GMT
bloritsch    01/10/29 08:16:28

  Modified:    src/java/org/apache/avalon/framework/configuration
                        DefaultConfigurationSerializer.java
                        SAXConfigurationHandler.java
               src/test/org/apache/avalon/framework/configuration/test
                        SAXConfigurationHandlerTestCase.java
  Log:
  Fix SAXConfigurationHandler to handle faulty SAX Readers that do not properly handle prefix
mapping.
  
  Revision  Changes    Path
  1.4       +1 -1      jakarta-avalon/src/java/org/apache/avalon/framework/configuration/DefaultConfigurationSerializer.java
  
  Index: DefaultConfigurationSerializer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon/src/java/org/apache/avalon/framework/configuration/DefaultConfigurationSerializer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultConfigurationSerializer.java	2001/10/29 14:58:48	1.3
  +++ DefaultConfigurationSerializer.java	2001/10/29 16:16:28	1.4
  @@ -132,7 +132,7 @@
           }
           else
           {
  -            qName = prefix + ":" + localName;
  +            qName = nsPrefix + ":" + localName;
           }
   
           this.m_handler.startElement(nsURI, localName, qName, attr);
  
  
  
  1.7       +39 -1     jakarta-avalon/src/java/org/apache/avalon/framework/configuration/SAXConfigurationHandler.java
  
  Index: SAXConfigurationHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon/src/java/org/apache/avalon/framework/configuration/SAXConfigurationHandler.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SAXConfigurationHandler.java	2001/10/29 14:58:48	1.6
  +++ SAXConfigurationHandler.java	2001/10/29 16:16:28	1.7
  @@ -8,6 +8,7 @@
   package org.apache.avalon.framework.configuration;
   
   import java.util.ArrayList;
  +import java.util.Iterator;
   import org.xml.sax.Attributes;
   import org.xml.sax.ErrorHandler;
   import org.xml.sax.Locator;
  @@ -15,6 +16,7 @@
   import org.xml.sax.SAXParseException;
   import org.xml.sax.helpers.DefaultHandler;
   import org.xml.sax.helpers.NamespaceSupport;
  +import org.xml.sax.helpers.AttributesImpl;
   
   /**
    * A SAXConfigurationHandler helps build Configurations out of sax events.
  @@ -27,6 +29,7 @@
       implements ErrorHandler
   {
       private final ArrayList              m_elements         = new ArrayList();
  +    private final ArrayList              m_prefixes         = new ArrayList();
       private Configuration                m_configuration;
       private Locator                      m_locator;
       private NamespaceSupport             m_namespaceSupport = new NamespaceSupport();
  @@ -39,6 +42,12 @@
       public void clear()
       {
           m_elements.clear();
  +        Iterator i = m_prefixes.iterator();
  +        while ( i.hasNext() )
  +        {
  +            ( (ArrayList) i.next() ).clear();
  +        }
  +        m_prefixes.clear();
           m_locator = null;
       }
   
  @@ -92,6 +101,14 @@
       {
           final int location = m_elements.size() - 1;
           final Object object = m_elements.remove( location );
  +        final ArrayList prefixes = (ArrayList) m_prefixes.remove( location );
  +
  +        final Iterator i = prefixes.iterator();
  +        while ( i.hasNext() )
  +        {
  +            endPrefixMapping( (String) i.next() );
  +        }
  +        prefixes.clear();
   
           if( 0 == location )
           {
  @@ -117,6 +134,26 @@
           throws SAXException
       {
           m_namespaceSupport.pushContext();
  +        final ArrayList prefixes = new ArrayList();
  +        AttributesImpl componentAttr = new AttributesImpl();
  +
  +        for (int i = 0; i < attributes.getLength(); i++)
  +        {
  +            if ( attributes.getQName(i).startsWith("xmlns") )
  +            {
  +                prefixes.add( attributes.getLocalName(i) );
  +                this.startPrefixMapping( attributes.getLocalName(i),
  +                                         attributes.getValue(i) );
  +            }
  +            else
  +            {
  +                componentAttr.addAttribute( attributes.getURI( i ),
  +                                            attributes.getLocalName( i ),
  +                                            attributes.getQName( i ),
  +                                            attributes.getType( i ),
  +                                            attributes.getValue( i ) );
  +            }
  +        }
   
           final DefaultConfiguration configuration =
               createConfiguration( localName, namespaceURI, getLocationString() );
  @@ -138,8 +175,9 @@
           }
   
           m_elements.add( configuration );
  +        m_prefixes.add( prefixes );
   
  -        final int attributesSize = attributes.getLength();
  +        final int attributesSize = componentAttr.getLength();
   
           for( int i = 0; i < attributesSize; i++ )
           {
  
  
  
  1.4       +1 -0      jakarta-avalon/src/test/org/apache/avalon/framework/configuration/test/SAXConfigurationHandlerTestCase.java
  
  Index: SAXConfigurationHandlerTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon/src/test/org/apache/avalon/framework/configuration/test/SAXConfigurationHandlerTestCase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SAXConfigurationHandlerTestCase.java	2001/10/29 15:49:25	1.3
  +++ SAXConfigurationHandlerTestCase.java	2001/10/29 16:16:28	1.4
  @@ -70,6 +70,7 @@
                                   "CDATA",attValue);
   
           final AttributesImpl childAttributes  = new AttributesImpl();
  +        childAttributes.addAttribute("", "child", "xmlns:child", "CDATA", childURI);
   
           m_handler.startDocument();
           m_handler.startElement( rootURI, rootlocal, rootraw, attributes );
  
  
  

--
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