harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r559907 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/text/html/ test/api/java.injected/javax/swing/ test/api/java.injected/javax/swing/text/html/ test/resources/javax/swing/
Date Thu, 26 Jul 2007 17:55:26 GMT
Author: ayza
Date: Thu Jul 26 10:55:24 2007
New Revision: 559907

URL: http://svn.apache.org/viewvc?view=rev&rev=559907
Log:
Applying patch from HARMONY-4529 ([classlib][swing][html] Relative links in HTML are resolved
incorrectly)

Added:
    harmony/enhanced/classlib/trunk/modules/swing/src/test/resources/javax/swing/testhtml.jar
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTML.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/JEditorPaneTest.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLTest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTML.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTML.java?view=diff&rev=559907&r1=559906&r2=559907
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTML.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/HTML.java
Thu Jul 26 10:55:24 2007
@@ -25,8 +25,6 @@
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
@@ -554,38 +552,47 @@
         if (url == null) {
             return null;
         }
-        return resolveURL(url.toString(), base != null ? base.toString() : null);
+
+        try {
+            return ((base != null) ? new URL(base, url.toString()) : url);
+        } catch (MalformedURLException e) {
+            return null;
+        }
     }
 
     static URL resolveURL(final String url, final URL base) {
         if (Utilities.isEmptyString(url)) {
             return null;
         }
-        return resolveURL(url, base != null ? base.toString() : null);
-    }
 
-    static URL resolveURL(final String url, final String base) {
-        if (Utilities.isEmptyString(url)) {
+        try {
+            return ((base != null) ? new URL(base, url) : new URL(url));
+        } catch (MalformedURLException e) {
             return null;
         }
+    }
 
-        URI uri = null;
-        if (base != null) {
-            try {
-                uri = new URI(base).resolve(url);
-            } catch (URISyntaxException e) { }
+    static URL resolveURL(final URL url, final String base) {
+        if (url == null) {
+            return null;
         }
 
-        URL result = null;
         try {
-            if (uri != null) {
-                result = uri.toURL();
-            } else {
-                result = new URL(url);
-            }
-        } catch (final MalformedURLException e) { }
+            return ((base != null) ? new URL(new URL(base), url.toString()) : url);
+        } catch (MalformedURLException e) {
+            return null;
+        }
+    }
+
+    static URL resolveURL(final String url, final String base) {
+        if (Utilities.isEmptyString(url)) {
+            return null;
+        }
 
-        return result;
+        try {
+            return ((base != null) ? new URL(new URL(base), url) : new URL(url));
+        } catch (MalformedURLException e) {
+            return null;
+        }
     }
 }
-

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/JEditorPaneTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/JEditorPaneTest.java?view=diff&rev=559907&r1=559906&r2=559907
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/JEditorPaneTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/JEditorPaneTest.java
Thu Jul 26 10:55:24 2007
@@ -460,6 +460,17 @@
                 "javax.swing.text.html.HTMLEditorKit", "text/html", TEST_URL, jep);
     }
 
+    public void testJEditorPaneJarHTML() {
+        try {
+            // Regression for HARMONY-4529
+            URL jar = getClass().getResource("testhtml.jar");
+            URL url = new URL("jar:" + jar + "!/index.html");
+            new JEditorPane(url);
+        } catch (Exception e) {
+            fail("Unexpected exception: " + e);
+        }
+    }
+
     private void assertEquals(final ArrayList<HyperlinkListener> a, final Object objects[])
{
         int size = a.size();
         assertEquals(size, objects.length);

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLTest.java?view=diff&rev=559907&r1=559906&r2=559907
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLTest.java
Thu Jul 26 10:55:24 2007
@@ -20,6 +20,8 @@
  */
 package javax.swing.text.html;
 
+import java.net.URL;
+
 import javax.swing.BasicSwingTestCase;
 import javax.swing.text.MutableAttributeSet;
 import javax.swing.text.SimpleAttributeSet;
@@ -681,6 +683,47 @@
             assertSame("Static attribute for Tag " + tags[i] + ", index " + i,
                        tags[i],
                        StyleContext.getStaticAttribute(staticKey));
+        }
+    }
+
+    public void testResolveURL() {
+        try {
+            // Regression for HARMONY-4529
+            String base = "jar:file:test.jar!/root/current";
+            String relative = "dir/file";
+            String absolute = "http://host/file";
+            URL baseURL = new URL(base);
+            URL absoluteURL = new URL(absolute);
+            URL resolvedURL = new URL("jar:file:test.jar!/root/dir/file");
+
+            assertEquals(resolvedURL, HTML.resolveURL(relative, base));
+            assertEquals(resolvedURL, HTML.resolveURL(relative, baseURL));
+
+            assertEquals(absoluteURL, HTML.resolveURL(absolute, base));
+            assertEquals(absoluteURL, HTML.resolveURL(absolute, baseURL));
+            assertEquals(absoluteURL, HTML.resolveURL(absoluteURL, base));
+            assertEquals(absoluteURL, HTML.resolveURL(absoluteURL, baseURL));
+
+            assertEquals(absoluteURL, HTML.resolveURL(absolute, (URL) null));
+            assertEquals(absoluteURL, HTML.resolveURL(absolute, (String) null));
+            assertEquals(absoluteURL, HTML.resolveURL(absoluteURL, (URL) null));
+            assertEquals(absoluteURL, HTML.resolveURL(absoluteURL, (String) null));
+
+            assertNull(HTML.resolveURL("", base));
+            assertNull(HTML.resolveURL("", baseURL));
+            assertNull(HTML.resolveURL((URL) null, base));
+            assertNull(HTML.resolveURL((URL) null, baseURL));
+            assertNull(HTML.resolveURL((String) null, base));
+            assertNull(HTML.resolveURL((String) null, baseURL));
+
+            assertNull(HTML.resolveURL("", (URL) null));
+            assertNull(HTML.resolveURL("", (String) null));
+            assertNull(HTML.resolveURL((URL) null, (URL) null));
+            assertNull(HTML.resolveURL((URL) null, (String) null));
+            assertNull(HTML.resolveURL((String) null, (URL) null));
+            assertNull(HTML.resolveURL((String) null, (String) null));
+        } catch (Exception e) {
+            fail("Unexpected exception: " + e);
         }
     }
 }

Added: harmony/enhanced/classlib/trunk/modules/swing/src/test/resources/javax/swing/testhtml.jar
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/resources/javax/swing/testhtml.jar?view=auto&rev=559907
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/classlib/trunk/modules/swing/src/test/resources/javax/swing/testhtml.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message