if (charset == null) { charset = "utf-8"; }
// Make sure it's all characters
XdmSequenceIterator iter = body.axisIterator(Axis.CHILD);
while (iter.hasNext()) {
XdmNode node = (XdmNode) iter.next();
if (node.getNodeKind() != XdmNodeKind.TEXT) {
throw XProcException.stepError(28);
}
}
String escapedContent = decodeBase64(body, charset);
StringWriter writer = new StringWriter();
writer.write(escapedContent);
writer.close();
postContent = writer.toString();
} else {
if (jsonContentType(contentType)) {
postContent = XMLtoJSON.convert(body);
} else if (xmlContentType(contentType)) {
Serializer serializer = makeSerializer();
try {
S9apiUtils.assertDocumentContent(body.axisIterator(Axis.CHILD));
} catch (XProcException xe) {
throw XProcException.stepError(22);
}
Vector<XdmNode> content = new Vector<XdmNode> ();
XdmSequenceIterator iter = body.axisIterator(Axis.CHILD);
while (iter.hasNext()) {
XdmNode node = (XdmNode) iter.next();
content.add(node);
}
// FIXME: set serializer properties appropriately!
StringWriter writer = new StringWriter();
serializer.setOutputWriter(writer);
S9apiUtils.serialize(runtime, content, serializer);
writer.close();
postContent = writer.toString();
} else {
StringWriter writer = new StringWriter();
XdmSequenceIterator iter = body.axisIterator(Axis.CHILD);
while (iter.hasNext()) {
XdmNode node = (XdmNode) iter.next();
if (node.getNodeKind() != XdmNodeKind.TEXT) {
throw XProcException.stepError(28);
}
writer.write(node.getStringValue());
}
writer.close();
postContent = writer.toString();
}
}