avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl URLSource.java
Date Fri, 24 May 2002 09:09:29 GMT
cziegeler    02/05/24 02:09:29

  Modified:    sourceresolve/src/java/org/apache/excalibur/source/impl
                        URLSource.java
  Log:
  Throwing SourceNotFoundException when the file is not found.
  
  Revision  Changes    Path
  1.10      +65 -56    jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/URLSource.java
  
  Index: URLSource.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/sourceresolve/src/java/org/apache/excalibur/source/impl/URLSource.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- URLSource.java	13 May 2002 12:17:40 -0000	1.9
  +++ URLSource.java	24 May 2002 09:09:29 -0000	1.10
  @@ -9,6 +9,7 @@
   
   import java.io.File;
   import java.io.FileInputStream;
  +import java.io.FileNotFoundException;
   import java.io.IOException;
   import java.io.InputStream;
   import java.lang.reflect.Method;
  @@ -19,6 +20,7 @@
   import java.util.Map;
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceException;
  +import org.apache.excalibur.source.SourceNotFoundException;
   import org.apache.excalibur.source.SourceParameters;
   import org.apache.excalibur.source.SourceUtil;
   import org.apache.excalibur.source.SourceValidity;
  @@ -28,7 +30,7 @@
    * Description of a source which is described by an URL.
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.9 $ $Date: 2002/05/13 12:17:40 $
  + * @version CVS $Revision: 1.10 $ $Date: 2002/05/24 09:09:29 $
    */
   
   public class URLSource
  @@ -195,73 +197,80 @@
       public InputStream getInputStream()
           throws IOException, SourceException
       {
  -        getInfos();
  -        InputStream input = null;
  -        if( this.isFile == true )
  -        {
  -            input = new FileInputStream( this.systemId.substring( FILE.length() ) );
  -        }
  -        else
  +        try
           {
  -            if( this.connection == null )
  +            getInfos();
  +            InputStream input = null;
  +            if( this.isFile == true )
  +            {
  +                input = new FileInputStream( this.systemId.substring( FILE.length() ) );
  +            }
  +            else
               {
  -                this.connection = this.url.openConnection();
  -                /* The following requires a jdk 1.3 */
  -                String userInfo = this.getUserInfo();
  -                if( this.url.getProtocol().startsWith( "http" ) && userInfo !=
null )
  +                if( this.connection == null )
                   {
  -                    this.connection.setRequestProperty( "Authorization", "Basic " + SourceUtil.encodeBASE64(
userInfo ) );
  -                }
  +                    this.connection = this.url.openConnection();
  +                    /* The following requires a jdk 1.3 */
  +                    String userInfo = this.getUserInfo();
  +                    if( this.url.getProtocol().startsWith( "http" ) && userInfo
!= null )
  +                    {
  +                        this.connection.setRequestProperty( "Authorization", "Basic " +
SourceUtil.encodeBASE64( userInfo ) );
  +                    }
   
  -                // do a post operation
  -                if( this.connection instanceof HttpURLConnection
  -                    && this.isPost )
  -                {
  -                    StringBuffer buffer = new StringBuffer( 2000 );
  -                    String key;
  -                    Iterator i = this.parameters.getParameterNames();
  -                    Iterator values;
  -                    String value;
  -                    boolean first = true;
  -                    while( i.hasNext() )
  +                    // do a post operation
  +                    if( this.connection instanceof HttpURLConnection
  +                        && this.isPost )
                       {
  -                        key = (String)i.next();
  -                        values = this.parameters.getParameterValues( key );
  -                        while( values.hasNext() == true )
  +                        StringBuffer buffer = new StringBuffer( 2000 );
  +                        String key;
  +                        Iterator i = this.parameters.getParameterNames();
  +                        Iterator values;
  +                        String value;
  +                        boolean first = true;
  +                        while( i.hasNext() )
                           {
  -                            value = SourceUtil.encode( (String)values.next() );
  -                            if( first == false ) buffer.append( '&' );
  -                            first = false;
  -                            buffer.append( key.toString() );
  -                            buffer.append( '=' );
  -                            buffer.append( value );
  +                            key = (String)i.next();
  +                            values = this.parameters.getParameterValues( key );
  +                            while( values.hasNext() == true )
  +                            {
  +                                value = SourceUtil.encode( (String)values.next() );
  +                                if( first == false ) buffer.append( '&' );
  +                                first = false;
  +                                buffer.append( key.toString() );
  +                                buffer.append( '=' );
  +                                buffer.append( value );
  +                            }
                           }
  -                    }
  -                    HttpURLConnection httpCon = (HttpURLConnection)connection;
  -                    httpCon.setDoInput( true );
  +                        HttpURLConnection httpCon = (HttpURLConnection)connection;
  +                        httpCon.setDoInput( true );
   
  -                    if( buffer.length() > 1 )
  -                    { // only post if we have parameters
  -                        String postString = buffer.toString();
  -                        httpCon.setRequestMethod( "POST" ); // this is POST
  -                        httpCon.setDoOutput( true );
  -                        httpCon.setRequestProperty( "Content-type", "application/x-www-form-urlencoded"
);
  -
  -                        // A content-length header must be contained in a POST request
  -                        httpCon.setRequestProperty( "Content-length", Integer.toString(
postString.length() ) );
  -                        java.io.OutputStream out = new java.io.BufferedOutputStream( httpCon.getOutputStream()
);
  -                        out.write( postString.getBytes() );
  -                        out.close();
  +                        if( buffer.length() > 1 )
  +                        { // only post if we have parameters
  +                            String postString = buffer.toString();
  +                            httpCon.setRequestMethod( "POST" ); // this is POST
  +                            httpCon.setDoOutput( true );
  +                            httpCon.setRequestProperty( "Content-type", "application/x-www-form-urlencoded"
);
  +
  +                            // A content-length header must be contained in a POST request
  +                            httpCon.setRequestProperty( "Content-length", Integer.toString(
postString.length() ) );
  +                            java.io.OutputStream out = new java.io.BufferedOutputStream(
httpCon.getOutputStream() );
  +                            out.write( postString.getBytes() );
  +                            out.close();
  +                        }
  +                        input = httpCon.getInputStream();
  +                        this.connection = null; // make sure a new connection is created
next time
  +                        return input;
                       }
  -                    input = httpCon.getInputStream();
  -                    this.connection = null; // make sure a new connection is created next
time
  -                    return input;
                   }
  +                input = this.connection.getInputStream();
  +                this.connection = null; // make sure a new connection is created next time
               }
  -            input = this.connection.getInputStream();
  -            this.connection = null; // make sure a new connection is created next time
  +            return input;
  +        }
  +        catch (FileNotFoundException fnfe)
  +        {
  +            throw new SourceNotFoundException("Resource not found " + this.systemId);
           }
  -        return input;
       }
   
       private static boolean checkedURLClass = false;
  
  
  

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