if (runtime.getConfiguration().foProcessor != null) {
foClasses.add(runtime.getConfiguration().foProcessor);
}
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);
break;
} catch (NoClassDefFoundError ncdfe) {
pexcept = ncdfe;
provider = null;
} catch (Exception e) {
pexcept = e;
provider = null;
}
}
}
if (provider == null) {
throw new XProcException(step.getNode(), "Failed to instantiate FO provider", pexcept);
}
final String contentType;
if (getOption(_content_type) != null) {
contentType = getOption(_content_type).getString();
} else {
contentType = "application/octet-stream";
}
String base = getOption(_href).getBaseURI().toASCIIString();
String href = getOption(_href).getString();
try {
final FoProcessor processor = provider;
DataStore store = runtime.getDataStore();
URI id = store.writeEntry(href, base, contentType, new DataWriter() {
public void store(OutputStream content) throws IOException {
OutputStream out = new BufferedOutputStream(content);
try {
processor.format(source.read(),out,contentType);
} catch (SaxonApiException e) {
throw new XProcException(step.getNode(), "Failed to process FO document", e);
} finally {
out.close();
}