You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsrp4j-dev@portals.apache.org by cz...@apache.org on 2006/02/03 10:53:31 UTC

svn commit: r374626 - in /portals/wsrp4j/trunk/src/org/apache/wsrp4j: consumer/app/driver/URLGeneratorImpl.java exception/WSRPException.java producer/provider/driver/URLComposerImpl.java util/Utility.java

Author: cziegeler
Date: Fri Feb  3 01:53:16 2006
New Revision: 374626

URL: http://svn.apache.org/viewcvs?rev=374626&view=rev
Log:
Make us compilable with JDK 1.3

Modified:
    portals/wsrp4j/trunk/src/org/apache/wsrp4j/consumer/app/driver/URLGeneratorImpl.java
    portals/wsrp4j/trunk/src/org/apache/wsrp4j/exception/WSRPException.java
    portals/wsrp4j/trunk/src/org/apache/wsrp4j/producer/provider/driver/URLComposerImpl.java
    portals/wsrp4j/trunk/src/org/apache/wsrp4j/util/Utility.java

Modified: portals/wsrp4j/trunk/src/org/apache/wsrp4j/consumer/app/driver/URLGeneratorImpl.java
URL: http://svn.apache.org/viewcvs/portals/wsrp4j/trunk/src/org/apache/wsrp4j/consumer/app/driver/URLGeneratorImpl.java?rev=374626&r1=374625&r2=374626&view=diff
==============================================================================
--- portals/wsrp4j/trunk/src/org/apache/wsrp4j/consumer/app/driver/URLGeneratorImpl.java (original)
+++ portals/wsrp4j/trunk/src/org/apache/wsrp4j/consumer/app/driver/URLGeneratorImpl.java Fri Feb  3 01:53:16 2006
@@ -16,7 +16,6 @@
 package org.apache.wsrp4j.consumer.app.driver;
 
 import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -24,6 +23,7 @@
 import org.apache.wsrp4j.log.LogManager;
 import org.apache.wsrp4j.log.Logger;
 import org.apache.wsrp4j.util.Constants;
+import org.apache.wsrp4j.util.Utility;
 
 /**
  * This class implements the URLGenerator-interface providing methods
@@ -117,7 +117,7 @@
             {
                 try
                 {
-                    return URLDecoder.decode(resourceURL, "utf-8");
+                    return Utility.decode(resourceURL, "utf-8");
                 } catch (UnsupportedEncodingException uee) {
                     // ignore
                 }

Modified: portals/wsrp4j/trunk/src/org/apache/wsrp4j/exception/WSRPException.java
URL: http://svn.apache.org/viewcvs/portals/wsrp4j/trunk/src/org/apache/wsrp4j/exception/WSRPException.java?rev=374626&r1=374625&r2=374626&view=diff
==============================================================================
--- portals/wsrp4j/trunk/src/org/apache/wsrp4j/exception/WSRPException.java (original)
+++ portals/wsrp4j/trunk/src/org/apache/wsrp4j/exception/WSRPException.java Fri Feb  3 01:53:16 2006
@@ -15,6 +15,8 @@
  */
 package org.apache.wsrp4j.exception;
 
+import java.lang.reflect.Method;
+
 /**
  * Common Exception class within the WSRP environment 
  * @version $Id$
@@ -44,10 +46,21 @@
     // type (range) of the exception
     private int exceptionRange = 0;
 
-    /*
-      Creates a new common exception
-      @deprecated
-    */
+    // FIXME Remove when JDK1.3 support is removed.
+    private static Method initCause = null;
+
+    static {
+        try {
+            initCause = Exception.class.getMethod("initCause", new Class[]{Throwable.class});
+        } catch (NoSuchMethodException e) {
+            // EMPTY
+        }
+    } 
+
+    /**
+     * Creates a new common exception
+     * @deprecated
+     */
     public WSRPException()
     {
         this(0, null);
@@ -63,16 +76,22 @@
     }
 
     /**
-      Creates a new common excpetion. The message to be passed will be ignored
-      @param errorCode integer representing an error code
-      @param t Throwable to be wrapped
-    */
+     * Creates a new common excpetion. The message to be passed will be ignored
+     * @param errorCode integer representing an error code
+     * @param t Throwable to be wrapped
+     */
     public WSRPException(int errorCode, Throwable t)
     {
-        //String message = Messages.get(errorCode);
-        super(Messages.get(errorCode),t);
+        super(Messages.get(errorCode));
         errCode = errorCode;
         nestedThrowable = t;
+        if ( initCause != null ) {
+            try {
+                initCause.invoke(this, new Object[] {t});
+            } catch (Exception ignore) {
+                // we ignore this
+            }
+        }
     }
 
     /**

Modified: portals/wsrp4j/trunk/src/org/apache/wsrp4j/producer/provider/driver/URLComposerImpl.java
URL: http://svn.apache.org/viewcvs/portals/wsrp4j/trunk/src/org/apache/wsrp4j/producer/provider/driver/URLComposerImpl.java?rev=374626&r1=374625&r2=374626&view=diff
==============================================================================
--- portals/wsrp4j/trunk/src/org/apache/wsrp4j/producer/provider/driver/URLComposerImpl.java (original)
+++ portals/wsrp4j/trunk/src/org/apache/wsrp4j/producer/provider/driver/URLComposerImpl.java Fri Feb  3 01:53:16 2006
@@ -16,7 +16,6 @@
 package org.apache.wsrp4j.producer.provider.driver;
 
 import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
 
 import oasis.names.tc.wsrp.v1.types.PortletContext;
 import oasis.names.tc.wsrp.v1.types.RuntimeContext;
@@ -31,6 +30,7 @@
 import org.apache.wsrp4j.producer.provider.Provider;
 import org.apache.wsrp4j.producer.provider.URLComposer;
 import org.apache.wsrp4j.util.Constants;
+import org.apache.wsrp4j.util.Utility;
 
 /**
  * <p>This class implements the URLComposer interface providing methods to generate
@@ -454,7 +454,7 @@
         {
             resultURL.append(Constants.NEXT_PARAM_AMP);
             try {
-                resultURL.append(appendNameValuePair(Constants.URL, URLEncoder.encode(url, "utf-8")));
+                resultURL.append(appendNameValuePair(Constants.URL, Utility.encode(url, "utf-8")));
             } catch (UnsupportedEncodingException uee) {
                 // this should never happen
                 resultURL.append(appendNameValuePair(Constants.URL, url));

Modified: portals/wsrp4j/trunk/src/org/apache/wsrp4j/util/Utility.java
URL: http://svn.apache.org/viewcvs/portals/wsrp4j/trunk/src/org/apache/wsrp4j/util/Utility.java?rev=374626&r1=374625&r2=374626&view=diff
==============================================================================
--- portals/wsrp4j/trunk/src/org/apache/wsrp4j/util/Utility.java (original)
+++ portals/wsrp4j/trunk/src/org/apache/wsrp4j/util/Utility.java Fri Feb  3 01:53:16 2006
@@ -16,6 +16,11 @@
 package org.apache.wsrp4j.util;
 
 import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
 import java.util.Properties;
 
 import org.apache.wsrp4j.exception.ErrorCodes;
@@ -57,4 +62,58 @@
 
     }
 
+    // FIXME Remove when JDK1.3 support is removed.
+    private static Method urlEncode = null;
+    private static Method urlDecode = null;
+
+    static {
+        try {
+            urlEncode = URLEncoder.class.getMethod("encode", new Class[]{String.class, String.class});
+            urlDecode = URLDecoder.class.getMethod("decode", new Class[]{String.class, String.class});
+        } catch (NoSuchMethodException e) {
+            // EMPTY
+        }
+    } 
+
+    /**
+     * Pass through to the {@link java.net.URLEncoder}. If running under JDK &lt; 1.4,
+     * default encoding will always be used.
+     */
+    public static String encode(String s, String enc) throws UnsupportedEncodingException {
+        if (urlEncode != null) {
+            try {
+                return (String)urlEncode.invoke(s, new Object[]{ s, enc } );
+            } catch (IllegalAccessException e) {
+                // EMPTY
+            } catch (InvocationTargetException e) {
+                if (e.getTargetException() instanceof UnsupportedEncodingException) {
+                    throw (UnsupportedEncodingException)e.getTargetException();
+                } else if (e.getTargetException() instanceof RuntimeException) {
+                    throw (RuntimeException)e.getTargetException();
+                }
+            }
+        }
+        return URLEncoder.encode(s);
+    }
+
+    /**
+     * Pass through to the {@link java.net.URLDecoder}. If running under JDK &lt; 1.4,
+     * default encoding will always be used.
+     */
+    public static String decode(String s, String enc) throws UnsupportedEncodingException {
+        if (urlDecode != null) {
+            try {
+                return (String)urlDecode.invoke(s, new Object[]{ s, enc } );
+            } catch (IllegalAccessException e) {
+                // EMPTY
+            } catch (InvocationTargetException e) {
+                if (e.getTargetException() instanceof UnsupportedEncodingException) {
+                    throw (UnsupportedEncodingException)e.getTargetException();
+                } else if (e.getTargetException() instanceof RuntimeException) {
+                    throw (RuntimeException)e.getTargetException();
+                }
+            }
+        }
+        return URLDecoder.decode(s);
+    }
 }