Permalink
Browse files

Added extension to store text documents

  • Loading branch information...
ndw committed Oct 29, 2013
1 parent c872492 commit 90ac89de6d37a5aa7a7aa0e67f4082d2fcdd62db
Showing with 24 additions and 0 deletions.
  1. +24 −0 src/com/xmlcalabash/library/Store.java
@@ -123,6 +123,11 @@ public void run() throws SaxonApiException {
|| ("".equals(root.getNodeName().getNamespaceURI())
&& "base64".equals(root.getAttributeValue(c_encoding))))) {
storeBinary(doc, href);
+ } else if (("true".equals(decode) || "1".equals(decode))
+ && XProcConstants.c_result.equals(root.getNodeName())
+ && root.getAttributeValue(_content_type) != null
+ && root.getAttributeValue(_content_type).startsWith("text/")) {
+ storeText(doc, href);
} else if (runtime.transparentJSON()
&& (((c_body.equals(root.getNodeName())
&& ("application/json".equals(root.getAttributeValue(_content_type))
@@ -229,6 +234,25 @@ private void storeBinary(XdmNode doc, URI href) {
}
}
+ private void storeText(XdmNode doc, URI href) {
+ try {
+ File output = new File(href);
+
+ File path = new File(output.getParent());
+ if (!path.isDirectory()) {
+ if (!path.mkdirs()) {
+ throw XProcException.stepError(50);
+ }
+ }
+
+ OutputStream outstr = new FileOutputStream(output);
+ outstr.write(doc.getStringValue().getBytes());
+ outstr.close();
+ } catch (IOException ioe) {
+ throw new XProcException(ioe);
+ }
+ }
+
private void storeJSON(XdmNode doc, URI href) throws SaxonApiException {
try {
OutputStream outstr = null;

0 comments on commit 90ac89d

Please sign in to comment.