dims        01/07/13 07:16:27

  Modified:    src/org/apache/cocoon/components/source URLSource.java
  Log:
  Use Reflection to call getUserInfo - still keep compatability with JDK1.2.2
  
  Carsten,
  Can you check if this works for you.
  
  Thanks,
  dims
  
  Revision  Changes    Path
  1.6       +21 -7     
xml-cocoon2/src/org/apache/cocoon/components/source/URLSource.java
  
  Index: URLSource.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/source/URLSource.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- URLSource.java    2001/07/13 11:24:48     1.5
  +++ URLSource.java    2001/07/13 14:16:21     1.6
  @@ -15,6 +15,7 @@
   import java.io.InputStreamReader;
   import java.io.IOException;
   import java.io.Reader;
  +import java.lang.reflect.Method;
   import java.net.URL;
   import java.net.URLConnection;
   import org.apache.avalon.framework.component.ComponentException;
  @@ -31,7 +32,7 @@
    * Description of a source which is described by an URL.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.5 $ $Date: 2001/07/13 11:24:48 $
  + * @version CVS $Revision: 1.6 $ $Date: 2001/07/13 14:16:21 $
    */
   
   public final class URLSource
  @@ -90,12 +91,11 @@
                   try {
                       if (this.connection == null) {
                           this.connection = this.url.openConnection();
  -                             /* The following requires a jdk 1.3
  -                       String userInfo = this.url.getUserInfo();
  +                                     /* The following requires a jdk 1.3 */
  +                         String userInfo = this.url.getUserInfo();
                           if (this.url.getProtocol().startsWith("http") == true && 
userInfo != null) {
                               
this.connection.setRequestProperty("Authorization","Basic 
"+this.encodeBASE64(userInfo));
                           }
  -                        */
                       }
                       this.lastModificationDate = this.connection.getLastModified();
                       this.contentLength = this.connection.getContentLength();
  @@ -136,15 +136,29 @@
           } else {
               if (this.connection == null) {
                   this.connection = this.url.openConnection();
  -                /* The following requires a jdk 1.3
  -                String userInfo = this.url.getUserInfo();
  +                /* The following requires a jdk 1.3 */
  +                String userInfo = getUserInfo(url);
                   if (this.url.getProtocol().startsWith("http") == true && userInfo 
!= null) {
                       this.connection.setRequestProperty("Authorization","Basic 
"+encodeBASE64(userInfo));
                   }
  -                */
               }
               return this.connection.getInputStream();
           }
  +    }
  +
  +    private String getUserInfo(URL url)
  +    {
  +        try {
  +            //System.out.println(">>>> getUserInfo: " + url);
  +            Class  paramTypes[] = new Class[0];
  +            Object params[] = new Object[0];
  +            Method method = URL.class.getMethod("getUserInfo",paramTypes);
  +            return (String) method.invoke(url,params);
  +        } catch (Exception e){
  +            //System.out.println("Exception in getUserInfo (likely to happen on 
JDK-1.2.2 and below):" + e);
  +            //e.printStackTrace();
  +        }
  +        return null;
       }
   
       /**
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to