You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ha...@apache.org on 2004/02/15 21:48:53 UTC

cvs commit: cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/source/impl AsyncCachingSource.java CachingSource.java

haul        2004/02/15 12:48:53

  Modified:    src/blocks/scratchpad/java/org/apache/cocoon/components/source/impl
                        AsyncCachingSource.java CachingSource.java
  Log:
  change visibility of extrcted methods to protected
  remove duplicate code
  
  Revision  Changes    Path
  1.3       +4 -40     cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/source/impl/AsyncCachingSource.java
  
  Index: AsyncCachingSource.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/source/impl/AsyncCachingSource.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AsyncCachingSource.java	25 Oct 2003 18:06:19 -0000	1.2
  +++ AsyncCachingSource.java	15 Feb 2004 20:48:53 -0000	1.3
  @@ -51,7 +51,6 @@
   package org.apache.cocoon.components.source.impl;
   
   import java.io.ByteArrayInputStream;
  -import java.io.ByteArrayOutputStream;
   import java.io.IOException;
   import java.io.InputStream;
   import java.net.MalformedURLException;
  @@ -59,20 +58,16 @@
   
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.Serviceable;
  +
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.caching.CachedResponse;
   import org.apache.cocoon.caching.ExtendedCachedResponse;
  -import org.apache.cocoon.components.sax.XMLDeserializer;
  -import org.apache.cocoon.xml.ContentHandlerWrapper;
  -import org.apache.cocoon.xml.XMLConsumer;
  +
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceException;
   import org.apache.excalibur.source.SourceValidity;
   import org.apache.excalibur.xml.sax.XMLizable;
  -import org.xml.sax.ContentHandler;
  -import org.xml.sax.SAXException;
   
   /**
    * This class implements a proxy like source that uses another source
  @@ -123,21 +118,10 @@
               
               this.initSource();
               
  -            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -            final byte[] buffer = new byte[2048];
  -            final InputStream inputStream = this.source.getInputStream();
  -            int length;
  -        
  -            while ((length = inputStream.read(buffer)) > -1) {
  -                baos.write(buffer, 0, length);
  -            }
  -            baos.flush();
  -            inputStream.close();
  -            
               // update cache
               final byte[] xmlResponse = this.cachedResponse.getAlternativeResponse();
               this.cachedResponse = new ExtendedCachedResponse(this.cachedResponse.getValidityObjects(),
  -                                                             baos.toByteArray());
  +                                                             this.readBinaryResponse());
               this.cachedResponse.setAlternativeResponse(xmlResponse);
               try {
                   this.cache.store(this.streamKey, this.cachedResponse);
  @@ -164,26 +148,6 @@
        */
       public void initialize() throws Exception {
           this.validity = this.cachedResponse.getValidityObjects()[0];
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.excalibur.xml.sax.XMLizable#toSAX(org.xml.sax.ContentHandler)
  -     */
  -    public void toSAX(ContentHandler contentHandler) throws SAXException {
  -       XMLDeserializer deserializer = null;
  -       try {
  -           deserializer = (XMLDeserializer) this.manager.lookup(XMLDeserializer.ROLE);
  -           if ( contentHandler instanceof XMLConsumer) {
  -               deserializer.setConsumer((XMLConsumer)contentHandler);
  -           } else {
  -               deserializer.setConsumer(new ContentHandlerWrapper(contentHandler));
  -           }
  -           deserializer.deserialize( this.cachedResponse.getAlternativeResponse() );
  -       } catch (ServiceException se ) {
  -           throw new SAXException("Unable to lookup xml deserializer.", se);
  -       } finally {
  -           this.manager.release(deserializer);
  -       }
       }
   
   }
  
  
  
  1.4       +3 -3      cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/source/impl/CachingSource.java
  
  Index: CachingSource.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/scratchpad/java/org/apache/cocoon/components/source/impl/CachingSource.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- CachingSource.java	15 Feb 2004 20:33:19 -0000	1.3
  +++ CachingSource.java	15 Feb 2004 20:48:53 -0000	1.4
  @@ -405,7 +405,7 @@
   	 * @throws IOException
   	 * @throws CascadingIOException
   	 */
  -	private byte[] readXMLResponse() throws SAXException, IOException, CascadingIOException {
  +	protected byte[] readXMLResponse() throws SAXException, IOException, CascadingIOException {
   		XMLSerializer serializer = null;
   		SAXParser parser = null;
           byte[] result = null;
  @@ -439,7 +439,7 @@
   	 * @throws IOException
   	 * @throws SourceNotFoundException
   	 */
  -	private byte[] readBinaryResponse() throws IOException, SourceNotFoundException {
  +	protected byte[] readBinaryResponse() throws IOException, SourceNotFoundException {
   		final ByteArrayOutputStream baos = new ByteArrayOutputStream();
   		final byte[] buffer = new byte[2048];
   		final InputStream inputStream = this.source.getInputStream();