if (metadataAllowed) {
xmlWrapMetadata(prefix, document);
}
StringBuilder suffix = new StringBuilder();
ContentEncoding documentContentEncoding = null;
ContentEncoding alternateEncoding = null;
if (contentAllowed) {
// Determine the content encoding to specify.
String documentContentEncodingStr = DocUtils.getOptionalString(
document, SpiConstants.PROPNAME_CONTENT_ENCODING);
if (!Strings.isNullOrEmpty(documentContentEncodingStr)) {
documentContentEncoding =
ContentEncoding.findContentEncoding(documentContentEncodingStr);
if (documentContentEncoding == ContentEncoding.ERROR
|| supportedEncodings.indexOf(documentContentEncodingStr) < 0) {
String message =
"Unsupported content encoding: " + documentContentEncodingStr;
LOGGER.log(Level.WARNING, message);
throw new RepositoryDocumentException(message);
}
}
alternateEncoding = (documentContentEncoding == null)
? contentEncoding : documentContentEncoding;
// If including document content, wrap it with <content> tags.
prefix.append("<");
prefix.append(XML_CONTENT);
XmlUtils.xmlAppendAttr(XML_ENCODING,
alternateEncoding.toString(), prefix);
prefix.append(">\n");
suffix.append('\n');
XmlUtils.xmlAppendEndTag(XML_CONTENT, suffix);
}