Skip to content

Commit

Permalink
Resolve issue #35, make sure NPE is reported (and attempt to avoid NPE)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndw committed Mar 15, 2012
1 parent a115352 commit f230bc5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
11 changes: 4 additions & 7 deletions src/com/xmlcalabash/library/XSLFormatter.java
Expand Up @@ -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;
Expand Down
39 changes: 25 additions & 14 deletions src/com/xmlcalabash/util/XProcURIResolver.java
Expand Up @@ -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);
}
Expand Down

0 comments on commit f230bc5

Please sign in to comment.