src/java.xml/share/classes/javax/xml/catalog/RewriteUri.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -70,10 +70,11 @@
* @return The uriStartString
*/
public String getURIStartString () {
return uriStartString;
}
+
/**
* Get the rewritePrefix attribute.
* @return The rewritePrefix attribute value.
*/
public URL getRewritePrefix() {
@@ -89,18 +90,24 @@
* @param currentMatch The length of uriStartString of previous match if any.
* @return The replacement URI if the match is successful, null if not.
*/
@Override
public String match(String systemId, int currentMatch) {
- if (uriStartString.length() <= systemId.length() &&
+ if (uriStartString.length() < systemId.length() &&
uriStartString.equals(systemId.substring(0, uriStartString.length()))) {
if (currentMatch < uriStartString.length()) {
String prefix = rewritePrefix.toExternalForm();
- if (!prefix.endsWith(SLASH) && !systemId.startsWith(SLASH)) {
- return prefix + SLASH + systemId.substring(uriStartString.length());
+ String sysId;
+ if (uriStartString.endsWith(SLASH)) {
+ sysId = systemId.substring(uriStartString.length());
+ } else {
+ sysId = systemId.substring(uriStartString.length() + 1);
+ }
+ if (prefix.endsWith(SLASH)) {
+ return prefix + sysId;
} else {
- return prefix + systemId.substring(uriStartString.length());
+ return prefix + SLASH + sysId;
}
}
}
return null;
}