try {
docstring = stream.toString("UTF-8");
} catch (UnsupportedEncodingException uee) {
// This can't happen...
throw new XProcException(uee);
}
} else if ("text".equals(format)) {
docstring = doc.getStringValue();
} else {
if ("base64".equals(root.getAttributeValue(_encoding))) {
docbinary = Base64.decode(doc.getStringValue());
} else if (root.getAttributeValue(_encoding) == null) {
docstring = root.getStringValue();
} else {
throw new UnsupportedOperationException("Binary content must be base64 encoded.");
}
}
ContentCreateOptions options = ContentCreateOptions.newXmlInstance();
if ("xml".equals(format)) {
options.setFormatXml();
options.setEncoding("UTF-8");
}
if ("text".equals(format)) {
options.setFormatText();
options.setEncoding("UTF-8");
}
if ("binary".equals(format)) {
options.setFormatBinary();
}
if (getOption(_bufferSize) != null) {
options.setBufferSize(getOption(_bufferSize).getInt());
}
if (getOption(_collections) != null) {
String[] collections = getOption(_collections).getString().split("\\s+");
options.setCollections(collections);
}
if (getOption(_language) != null) {
options.setLanguage(getOption(_language).getString());
}
if (getOption(_locale) != null) {
String value = getOption(_locale).getString();
Locale locale = new Locale(value);
options.setLocale(locale);
}
String dburi = getOption(_uri).getString();
Content content = null;
if (docbinary == null) {
content = ContentFactory.newContent(dburi, docstring, options);
} else {
content = ContentFactory.newContent(dburi, docbinary, options);
}
ContentSource contentSource;
try {
if ("".equals(contentBase)) {
contentSource = ContentSourceFactory.newContentSource(host, port, user, password);
} else {
contentSource = ContentSourceFactory.newContentSource(host, port, user, password, contentBase);
}
} catch (Exception e) {
throw new XProcException(e);
}
if ("basic".equals(getOption(_auth_method, ""))) {
contentSource.setAuthenticationPreemptive(true);
}
Session session;
try {
session = contentSource.newSession ();
session.insertContent(content);
session.close();
} catch (Exception e) {
throw new XProcException(e);
}
TreeWriter tree = new TreeWriter(runtime);
tree.startDocument(step.getNode().getBaseURI());
tree.addStartElement(XProcConstants.c_result);