Permalink
Browse files

Resolve issue #35, make sure NPE is reported (and attempt to avoid NPE)

  • Loading branch information...
ndw committed Mar 15, 2012
1 parent a115352 commit f230bc5824dec6abc5fe06917e6fad369a3822d0
Showing with 29 additions and 21 deletions.
  1. +4 −7 src/com/xmlcalabash/library/XSLFormatter.java
  2. +25 −14 src/com/xmlcalabash/util/XProcURIResolver.java
@@ -71,27 +71,24 @@ public void run() throws SaxonApiException {
foClasses.add("com.xmlcalabash.util.FoFOP");
FoProcessor provider = null;
+ Throwable pexcept = null;
for (String className : foClasses) {
if (provider == null) {
try {
provider = (FoProcessor) Class.forName(className).newInstance();
provider.initialize(runtime,step,options);
} catch (NoClassDefFoundError ncdfe) {
- if (runtime.getDebug()) {
- ncdfe.printStackTrace();
- }
+ pexcept = ncdfe;
provider = null;
} catch (Exception e) {
- if (runtime.getDebug()) {
- e.printStackTrace();
- }
+ pexcept = e;
provider = null;
}
}
}
if (provider == null) {
- throw new XProcException(step.getNode(), "Failed to instantiate FO provider");
+ throw new XProcException(step.getNode(), "Failed to instantiate FO provider", pexcept);
}
String contentType = null;
@@ -72,29 +72,40 @@ public void cache(XdmNode doc, URI baseURI) {
public Source resolve(String href, String base) throws TransformerException {
runtime.finest(null,null,"URIResolver(" + href + "," + base + ")");
- try {
- URI baseURI = new URI(base);
- String uri = baseURI.resolve(href).toASCIIString();
- if (cache.containsKey(uri)) {
- runtime.finest(null ,null,"Returning cached document.");
- return cache.get(uri).asSource();
+ String uri = null;
+ if (base == null) {
+ try {
+ URL url = new URL(href);
+ uri = url.toURI().toASCIIString();
+ } catch (MalformedURLException mue) {
+ runtime.finest(null,null,"MalformedURLException on " + href);
+ } catch (URISyntaxException use) {
+ runtime.finest(null,null,"URISyntaxException on " + href);
}
-
- /* This is clearly not right because with it you can't even load pipelines from the local disk...
- if (runtime.getSafeMode() && uri.startsWith("file:")) {
- throw XProcException.dynamicError(21);
+ } else {
+ try {
+ URI baseURI = new URI(base);
+ uri = baseURI.resolve(href).toASCIIString();
+ } catch (URISyntaxException use) {
+ runtime.finest(null,null,"URISyntaxException resolving base and href: " + base + " : " + href);
}
- */
- } catch (URISyntaxException use) {
- runtime.finest(null,null,"URISyntaxException resolving base and href?");
+ }
+
+ if (cache.containsKey(uri)) {
+ runtime.finest(null ,null,"Returning cached document.");
+ return cache.get(uri).asSource();
}
if (uriResolver != null) {
URL absoluteURI = null;
// This is an attempt to deal with jar: URIs, pipelines run from inside jar files.
try {
- absoluteURI = new URL(new URL(base), href);
+ if (base == null) {
+ absoluteURI = new URL(href);
+ } else {
+ absoluteURI = new URL(new URL(base), href);
+ }
} catch (MalformedURLException mue) {
throw new XProcException(mue);
}

0 comments on commit f230bc5

Please sign in to comment.