cziegeler 01/07/16 00:43:06
Modified: src/org/apache/cocoon/components/source Tag:
cocoon_20_branch URLSource.java
Log:
Check for getUserInfo is cached
Revision Changes Path
No revision
No revision
1.1.2.6 +36 -16
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.1.2.5
retrieving revision 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- URLSource.java 2001/07/13 14:15:44 1.1.2.5
+++ URLSource.java 2001/07/16 07:43:05 1.1.2.6
@@ -32,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.1.2.5 $ $Date: 2001/07/13 14:15:44 $
+ * @version CVS $Revision: 1.1.2.6 $ $Date: 2001/07/16 07:43:05 $
*/
public final class URLSource
@@ -91,8 +91,7 @@
try {
if (this.connection == null) {
this.connection = this.url.openConnection();
- /* The following requires a jdk 1.3 */
- String userInfo = this.url.getUserInfo();
+ String userInfo = this.getUserInfo();
if (this.url.getProtocol().startsWith("http") == true &&
userInfo != null) {
this.connection.setRequestProperty("Authorization","Basic
"+this.encodeBASE64(userInfo));
}
@@ -137,7 +136,7 @@
if (this.connection == null) {
this.connection = this.url.openConnection();
/* The following requires a jdk 1.3 */
- String userInfo = getUserInfo(url);
+ String userInfo = this.getUserInfo();
if (this.url.getProtocol().startsWith("http") == true && userInfo
!= null) {
this.connection.setRequestProperty("Authorization","Basic
"+encodeBASE64(userInfo));
}
@@ -146,19 +145,40 @@
}
}
- 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();
+ private static boolean checkedURLClass = false;
+ private static boolean urlSupportsGetUserInfo = false;
+ private static Method urlGetUserInfo = null;
+ private static Object[] emptyParams = new Object[0];
+
+ /**
+ * Check if the <code>URL</code> class supports the getUserInfo()
+ * method which is introduced in jdk 1.3
+ */
+ private String getUserInfo() {
+ if (URLSource.checkedURLClass == true) {
+ if (URLSource.urlSupportsGetUserInfo == true) {
+ try {
+ return (String) URLSource.urlGetUserInfo.invoke(this.url,
URLSource.emptyParams);
+ } catch (Exception e){
+ // ignore this anyway
+ }
+ }
+ return null;
+ } else {
+ // test if the url class supports the getUserInfo method
+ try {
+ URLSource.urlGetUserInfo = URL.class.getMethod("getUserInfo", null);
+ String ui = (String)URLSource.urlGetUserInfo.invoke(this.url,
URLSource.emptyParams);
+ URLSource.checkedURLClass = true;
+ URLSource.urlSupportsGetUserInfo = true;
+ return ui;
+ } catch (Exception e){
+ }
+ URLSource.checkedURLClass = true;
+ URLSource.urlSupportsGetUserInfo = false;
+ URLSource.urlGetUserInfo = null;
+ return null;
}
- return null;
}
/**
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]