You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by de...@apache.org on 2003/04/23 02:46:11 UTC
cvs commit: xml-batik/test-resources/org/apache/batik/util unitTesting.xml
deweese 2003/04/22 17:46:11
Modified: sources/org/apache/batik/bridge BridgeContext.java
URIResolver.java
sources/org/apache/batik/util ParsedURL.java
ParsedURLData.java
ParsedURLDefaultProtocolHandler.java
test-resources/org/apache/batik/util unitTesting.xml
Log:
Fixed a bug in handling Fragment URL's with colon's in them.
Revision Changes Path
1.59 +2 -1 xml-batik/sources/org/apache/batik/bridge/BridgeContext.java
Index: BridgeContext.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeContext.java,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- BridgeContext.java 11 Apr 2003 13:54:41 -0000 1.58
+++ BridgeContext.java 23 Apr 2003 00:46:11 -0000 1.59
@@ -453,6 +453,7 @@
} catch (InterruptedIOException ex) {
throw new InterruptedBridgeException();
} catch (IOException ex) {
+ ex.printStackTrace();
throw new BridgeException(e, ERR_URI_IO,
new Object[] {uri});
} catch (IllegalArgumentException ex) {
1.21 +4 -1 xml-batik/sources/org/apache/batik/bridge/URIResolver.java
Index: URIResolver.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/URIResolver.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- URIResolver.java 11 Apr 2003 13:54:57 -0000 1.20
+++ URIResolver.java 23 Apr 2003 00:46:11 -0000 1.21
@@ -84,11 +84,14 @@
throws MalformedURLException, IOException, SecurityException {
String baseURI = XMLBaseSupport.getCascadedXMLBase(ref);
+ // System.err.println("baseURI: " + baseURI);
+ // System.err.println("URI: " + uri);
if ((baseURI == null) &&
(uri.startsWith("#")))
return document.getElementById(uri.substring(1));
ParsedURL purl = new ParsedURL(baseURI, uri);
+ // System.err.println("PURL: " + purl);
if (documentURI == null)
documentURI = document.getURL();
1.16 +26 -13 xml-batik/sources/org/apache/batik/util/ParsedURL.java
Index: ParsedURL.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/util/ParsedURL.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ParsedURL.java 11 Apr 2003 13:59:28 -0000 1.15
+++ ParsedURL.java 23 Apr 2003 00:46:11 -0000 1.16
@@ -444,18 +444,32 @@
*/
protected static String getProtocol(String urlStr) {
if (urlStr == null) return null;
+ int idx = 0, len = urlStr.length();
- int idx = urlStr.indexOf(':');
- if (idx == -1) return null;
+ if (len == 0) return null;
- // May have a protocol spec...
- String protocol = urlStr.substring(0, idx).toLowerCase();
- if (protocol.indexOf('/') != -1)
- // Got a slash in protocol probably means
- // no protocol given.
- return null;
-
- return protocol;
+ // Protocol is only allowed to include -+.a-zA-Z
+ // So as soon as we hit something else we know we
+ // are done (if it is a ':' then we have protocol otherwise
+ // we don't.
+ char ch = urlStr.charAt(idx);
+ while ((ch == '-') ||
+ (ch == '+') ||
+ (ch == '.') ||
+ ((ch >= 'a') && (ch <= 'z')) ||
+ ((ch >= 'A') && (ch <= 'Z'))) {
+ idx++;
+ if (idx == len) {
+ ch=0;
+ break;
+ }
+ ch = urlStr.charAt(idx);
+ }
+ if (ch == ':') {
+ // Has a protocol spec...
+ return urlStr.substring(0, idx).toLowerCase();
+ }
+ return null;
}
/**
@@ -488,8 +502,7 @@
String protocol = getProtocol(urlStr);
if (protocol == null)
protocol = baseURL.getProtocol();
-
ParsedURLProtocolHandler handler = getHandler(protocol);
- return handler.parseURL(baseURL, urlStr);
+ return handler.parseURL(baseURL, urlStr);
}
}
1.10 +3 -2 xml-batik/sources/org/apache/batik/util/ParsedURLData.java
Index: ParsedURLData.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/util/ParsedURLData.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ParsedURLData.java 11 Apr 2003 13:59:29 -0000 1.9
+++ ParsedURLData.java 23 Apr 2003 00:46:11 -0000 1.10
@@ -127,7 +127,7 @@
// System.out.println("File: " + file);
// if (ref != null)
// file += "#" + ref;
- // System.out.println("Building: " + protocol + " - " +
+ // System.err.println("Building: " + protocol + " - " +
// host + " - " + path);
if ((protocol != null) && (host != null)) {
@@ -140,6 +140,7 @@
return new URL(protocol, host, port, file);
}
+ // System.err.println("toString: " + toString());
return new URL(toString());
}
1.12 +50 -28 xml-batik/sources/org/apache/batik/util/ParsedURLDefaultProtocolHandler.java
Index: ParsedURLDefaultProtocolHandler.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/util/ParsedURLDefaultProtocolHandler.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ParsedURLDefaultProtocolHandler.java 11 Apr 2003 13:59:29 -0000 1.11
+++ ParsedURLDefaultProtocolHandler.java 23 Apr 2003 00:46:11 -0000 1.12
@@ -90,24 +90,31 @@
urlStr = urlStr.substring(0,idx);
}
- String prefix = urlStr;
- if ((idx = prefix.indexOf('/')) != -1)
- // Only check for ':' prior to first '/'
- // allows for foo/12:30 as a relative URL.
- prefix = prefix.substring(0, idx);
-
- idx = prefix.indexOf(':');
- if (idx != -1) {
- // May have a protocol spec...
- ret.protocol = urlStr.substring(pidx, idx).toLowerCase();
- if (ret.protocol.indexOf('/') == -1)
- pidx = idx+1;
- else {
- // Got a slash in protocol probably means
- // no protocol given, (host and port?)
- ret.protocol = null;
- pidx = 0;
+ if (urlStr.length() == 0)
+ return ret;
+
+ // Protocol is only allowed to include -+.a-zA-Z
+ // So as soon as we hit something else we know we
+ // are done (if it is a ':' then we have protocol otherwise
+ // we don't.
+ idx = 0;
+ char ch = urlStr.charAt(idx);
+ while ((ch == '-') ||
+ (ch == '+') ||
+ (ch == '.') ||
+ ((ch >= 'a') && (ch <= 'z')) ||
+ ((ch >= 'A') && (ch <= 'Z'))) {
+ idx++;
+ if (idx == len) {
+ ch=0;
+ break;
}
+ ch = urlStr.charAt(idx);
+ }
+ if (ch == ':') {
+ // Has a protocol spec...
+ ret.protocol = urlStr.substring(pidx, idx).toLowerCase();
+ pidx = idx+1; // Skip ':'
}
// See if we have host/port spec.
@@ -222,24 +229,39 @@
// System.err.println("Base: " + baseURL + "\n" +
// "Sub: " + urlStr);
- int idx;
- String prefix = urlStr;
- if ((idx = prefix.indexOf('/')) != -1)
- // Only check for ':' prior to first '/'
- // allows for foo/12:30 as a relative URL.
- prefix = prefix.substring(0, idx);
-
- idx = prefix.indexOf(':');
- if (idx != -1) {
- String protocol = prefix.substring(0,idx).toLowerCase();
+ int idx = 0, len = urlStr.length();
+ if (len == 0) return baseURL.data;
+ // Protocol is only allowed to include -+.a-zA-Z
+ // So as soon as we hit something else we know we
+ // are done (if it is a ':' then we have protocol otherwise
+ // we don't.
+ char ch = urlStr.charAt(idx);
+ while ((ch == '-') ||
+ (ch == '+') ||
+ (ch == '.') ||
+ ((ch >= 'a') && (ch <= 'z')) ||
+ ((ch >= 'A') && (ch <= 'Z'))) {
+ idx++;
+ if (idx == len) {
+ ch=0;
+ break;
+ }
+ ch = urlStr.charAt(idx);
+ }
+ String protocol = null;
+ if (ch == ':') {
+ // Has a protocol spec...
+ protocol = urlStr.substring(0, idx).toLowerCase();
+ }
+
+ if (protocol != null) {
// Temporary if we have a protocol then assume absolute
// URL. Technically this is the correct handling but much
// software supports relative URLs with a protocol that
// matches the base URL's protocol.
// if (true)
// return parseURL(urlStr);
-
if (!protocol.equals(baseURL.getProtocol()))
// Different protocols, assume absolute URL ignore base...
return parseURL(urlStr);
1.7 +19 -1 xml-batik/test-resources/org/apache/batik/util/unitTesting.xml
Index: unitTesting.xml
===================================================================
RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/util/unitTesting.xml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- unitTesting.xml 8 Feb 2003 13:25:12 -0000 1.6
+++ unitTesting.xml 23 Apr 2003 00:46:11 -0000 1.7
@@ -359,6 +359,24 @@
value="jar:file:dir/file.jar!/p/a/t/c/h/new.svg#foo" />
</test>
+ <test id="ParsedURL.28" class="org.apache.batik.util.ParsedURLTest">
+ <!-- Test relative path, relative jar -->
+ <arg class="java.lang.String"
+ value="#data:1" />
+ <arg class="java.lang.String"
+ value="#data:1" />
+ </test>
+
+ <test id="ParsedURL.29" class="org.apache.batik.util.ParsedURLTest">
+ <!-- Test relative path, relative jar -->
+ <arg class="java.lang.String"
+ value="http://foo.bar.com/path/test.svg" />
+ <arg class="java.lang.String"
+ value="#data:1" />
+ <arg class="java.lang.String"
+ value="http://foo.bar.com/path/test.svg#data:1" />
+ </test>
+
<test id="ParsedURLData.1" class="org.apache.batik.util.ParsedURLDataTest">
<!-- Test basic image base 64 data -->
<arg class="java.lang.String"
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org