static ByteArrayOutputStream serialize(Node node) throws TransformerException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Result rslt = new StreamResult(bos); Source src = new DOMSource(node); Transformer transformer = getTransformerFactory().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(src, rslt); return bos; }
@Override public String getContentAsString() throws UnsupportedEncodingException { return toString(); }
@Override public Content createContent(String uri, ContentCreateOptions options, boolean copyCollections, boolean copyMetadata, boolean copyQuality) throws IOException { if (copyCollections || copyMetadata || copyQuality) { setContentOptions(options, copyCollections, copyMetadata, copyQuality); } return ContentFactory.newContent(uri, getContentAsMarkLogicNode().get(), options); } }
public String toString() { if (rootNodeKind == NodeKind.TEXT) { TextImpl textNode = (TextImpl) doc.getFirstChild(); if (textNode != null) { return textNode.getTextContent(); } } try { ByteArrayOutputStream bos = serialize(doc); return bos.toString(); } catch (TransformerException ex) { LOG.error("Error serializing document", ex); } return null; }
case NodeKind.PI: case NodeKind.COMMENT: doc = new DOMDocument(tree); break; case NodeKind.ARRAY:
@Override public byte[] getContentAsByteArray() { if (rootNodeKind == NodeKind.TEXT) { TextImpl textNode = (TextImpl) doc.getFirstChild(); if (textNode != null) { return textNode.getTextContent().getBytes(); } } try { ByteArrayOutputStream bos = serialize(doc); return bos.toByteArray(); } catch (TransformerException ex) { LOG.error("Error serializing document", ex); } return null; }
@Override public Text getContentAsText() { return new Text(toString()); }