cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ard Schrijvers" <a.schrijv...@hippo.nl>
Subject RE: SAX parser problem
Date Thu, 01 Dec 2005 21:19:30 GMT
Replace stuff below 

>  		WfsXMLPipe n = new WfsXMLPipe(contentHandler);
> 			   // this is where I catch the inputstream..
> WfsResponse is 
> 			   // the InputStream : 
> 			   // WfsResponse = connection.getInputStream();
> 			   InputSource i = new InputSource(new
> InputStreamReader(WfsResponse));
> 			   getLogger().debug("got the input source");
> 			   SAXParser respParser =
> (SAXParser)manager.lookup(SAXParser.ROLE);
> 			   try
> 			   {
> 				   respParser.parse(i,n);
> 			   }
> 			   finally
> 			   {
> 	
> 				   
> manager.release((Component)respParser);
> 				   WfsResponse.close();
> 			   }
> 			   
>>

with:

			  InputStream sourceStream = inputSource.getInputStream();
                    try
                    {
                        m_contentHandler.startElement(null, "damenContent", "damenContent",
attr);
                        DelegatingContentHandler dcHandler = new DelegatingContentHandler
								(m_contentHandler,m_resolver ,true);
                        try
                        {
                            SourceUtil.toSAX(inputSource, dcHandler);
                        }
                        catch (ProcessingException e)
                        {
                            e.printStackTrace();
                        }
                      
                         
                        m_contentHandler.endElement(null, "damenContent", "damenContent");
                    }
                    finally
                    {
                        sourceStream.close();
                    } 

and the DelegatingContentHandler.java looks like:

package nl.hippo.generation.handbook;


import org.apache.cocoon.environment.SourceResolver;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class DelegatingContentHandler extends DefaultHandler
{
    private ContentHandler m_contentHandler;
    private SourceResolver m_resolver;
    private boolean m_skipDocumentEvents;

    public DelegatingContentHandler(ContentHandler contentHandler)
    {
        super();
        
        m_contentHandler = contentHandler;
    }

    public DelegatingContentHandler(ContentHandler contentHandler,SourceResolver resolver,
boolean skipDocumentEvents)
    {
        super();
        
        m_contentHandler = contentHandler;
        m_resolver = resolver;
        m_skipDocumentEvents = skipDocumentEvents;
    }

    public void endDocument() throws SAXException
    {
        if (!m_skipDocumentEvents)
        {
            m_contentHandler.endDocument();
        }
    }

    public void startDocument() throws SAXException
    {
        if (!m_skipDocumentEvents)
        {
            m_contentHandler.startDocument();
        }
    }

    public void characters(char[] ch, int start, int length) throws SAXException
    {
        m_contentHandler.characters(ch, start, length);
    }

    public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
    {
        m_contentHandler.ignorableWhitespace(ch, start, length);
    }

    public void endPrefixMapping(String prefix) throws SAXException
    {
        m_contentHandler.endPrefixMapping(prefix);
    }

    public void skippedEntity(String name) throws SAXException
    {
        m_contentHandler.skippedEntity(name);
    }

    public void setDocumentLocator(Locator locator)
    {
        m_contentHandler.setDocumentLocator(locator);
    }

    public void processingInstruction(String target, String data) throws SAXException
    {
        m_contentHandler.processingInstruction(target, data);
    }

    public void startPrefixMapping(String prefix, String uri) throws SAXException
    {
        m_contentHandler.startPrefixMapping(prefix, uri);
    }

    public void endElement(String namespaceURI, String localName, String qName) throws SAXException
    {
           m_contentHandler.endElement(namespaceURI, qName, qName);
       
    }

    public void startElement(String namespaceURI, String localName, String qName, Attributes
atts) throws SAXException
    {
           m_contentHandler.startElement(namespaceURI, qName, qName, atts);

    }
    
  
}


Good luck!

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message