You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by "Pavel Kryl (JIRA)" <xm...@xml.apache.org> on 2010/04/13 16:32:55 UTC
[jira] Created: (XMLBEANS-435) StscImporter.resolve() should do
additional normalization
StscImporter.resolve() should do additional normalization
---------------------------------------------------------
Key: XMLBEANS-435
URL: https://issues.apache.org/jira/browse/XMLBEANS-435
Project: XMLBeans
Issue Type: Improvement
Affects Versions: Version 2.3, Version 2.3.1, Version 2.4 , Version 2.4.1 , Version 2.5, Version 2.5.1
Environment: all environments
Reporter: Pavel Kryl
Priority: Minor
Motivation: I want to parse XML schemas in rutnime present on classpath, therefore I do the following:
URL resourceUrl = getClass().getResource(resourceSchemaPath);
InputStream resourceStream = getClass().getResourceAsStream(resourceSchemaPath);
XmlObject schemaDoc = XmlObject.Factory.parse(resourceStream, (new XmlOptions()).setLoadLineNumbers().setLoadMessageDigest());
// adjust location of the stream to enable XML beans read XML schemas from classpath
XmlDocumentProperties documentProperties = schemaDoc.documentProperties();
documentProperties.setSourceName(resourceUrl.toURI().toString());
now when the code gets to resolving imports in the resourceSchemaPath and the schema on classpath contains relative reference './artifactIndex.xsd' reading this resource fails because StscImporter does not normalize the URI before connection is opened on it. The resulting URI is something like:
jar:file:/opt/develop/m2/repository/com/mylib/4.0.0-SNAPSHOT/mylib-4.0.0-SNAPSHOT.jar!/sdm/xsd/./artifactIndex.xsd
Opening this URI fails, because java is not able to cope with the dot segment in the path. There is already a workaround for Sun bug # 4723726 (/.. segments), I suggest to add another workaround for single dot segments. Something like this (naive):
--- /usr/local/java/xmlbeans-2.3.0/src//org/apache/xmlbeans/impl/schema/StscImporter.java 2010-04-13 16:27:42.064242055 +0200
+++ StscImporter.java 2010-04-13 16:14:13.000000000 +0200
@@ -291,6 +291,13 @@
}
slashDotDotIndex = r.indexOf("/..", exclPointSlashIndex);
}
+ int slashDotIndex = r.indexOf("/./", exclPointSlashIndex);
+ while (slashDotIndex > 0)
+ {
+ String temp = r.substring(slashDotIndex + 2);
+ r = r.substring(0, slashDotIndex).concat(temp);
+ slashDotIndex = r.indexOf("/./", exclPointSlashIndex);
+ }
}
return URI.create(r);
}
Also please note, that it is quite dangerous to look for "/.." and discard it, because this would give invalid results on names like '/..hiddendir' - but this is not the subject of this bug.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org