@Override public <C> ContentHandle<C> newHandle(Class<C> type) { @SuppressWarnings("unchecked") ContentHandle<C> handle = isHandled(type) ? (ContentHandle<C>) new DOM4JHandle() : null; return handle; } };
/** * Provides a handle on XML content as a dom4j document structure. * @param content the XML document. */ public DOM4JHandle(Document content) { this(); set(content); }
/** * Returns the dom4j reader for XML content. * @return the dom4j reader. */ public SAXReader getReader() { if (reader == null) reader = makeReader(); return reader; } /**
/** * Creates a factory to create a DOM4JHandle instance for a dom4j document. * @return the factory */ static public ContentHandleFactory newFactory() { return new ContentHandleFactory() { @Override public Class<?>[] getHandledClasses() { return new Class<?>[]{ Document.class }; } @Override public boolean isHandled(Class<?> type) { return Document.class.isAssignableFrom(type); } @Override public <C> ContentHandle<C> newHandle(Class<C> type) { @SuppressWarnings("unchecked") ContentHandle<C> handle = isHandled(type) ? (ContentHandle<C>) new DOM4JHandle() : null; return handle; } }; }
/** * Zero-argument constructor. */ public DOM4JHandle() { super(); super.setFormat(Format.XML); setResendable(true); } /**
@Override public void fromBuffer(byte[] buffer) { if (buffer == null || buffer.length == 0) content = null; else receiveContent(new ByteArrayInputStream(buffer)); } @Override
/** * Returns the XML document as a string. */ @Override public String toString() { try { return new String(toBuffer(),"UTF-8"); } catch (UnsupportedEncodingException e) { throw new MarkLogicIOException(e); } }
@Override public byte[] toBuffer() { try { if (content == null) return null; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); write(buffer); return buffer.toByteArray(); } catch (IOException e) { throw new MarkLogicIOException(e); } }
@Override public void write(OutputStream out) throws IOException { Writer writer = new OutputStreamWriter(out, "UTF-8"); OutputFormat outputFormat = getOutputFormat(); if (outputFormat != null) { new XMLWriter(writer, outputFormat).write(content); } else { new XMLWriter(writer).write(content); } writer.flush(); } }
@Override public <C> ContentHandle<C> newHandle(Class<C> type) { @SuppressWarnings("unchecked") ContentHandle<C> handle = isHandled(type) ? (ContentHandle<C>) new DOM4JHandle() : null; return handle; } };
/** * Creates a factory to create a DOM4JHandle instance for a dom4j document. * @return the factory */ static public ContentHandleFactory newFactory() { return new ContentHandleFactory() { @Override public Class<?>[] getHandledClasses() { return new Class<?>[]{ Document.class }; } @Override public boolean isHandled(Class<?> type) { return Document.class.isAssignableFrom(type); } @Override public <C> ContentHandle<C> newHandle(Class<C> type) { @SuppressWarnings("unchecked") ContentHandle<C> handle = isHandled(type) ? (ContentHandle<C>) new DOM4JHandle() : null; return handle; } }; }
/** * Assigns an XML document structure as the content and returns the handle. * @param content the XML document. * @return the handle on the XML document. */ public DOM4JHandle with(Document content) { set(content); return this; }
/** * Returns the dom4j reader for XML content. * @return the dom4j reader. */ public SAXReader getReader() { if (reader == null) reader = makeReader(); return reader; } /**
/** * Zero-argument constructor. */ public DOM4JHandle() { super(); super.setFormat(Format.XML); setResendable(true); } /**
@Override public void fromBuffer(byte[] buffer) { if (buffer == null || buffer.length == 0) content = null; else receiveContent(new ByteArrayInputStream(buffer)); } @Override
/** * Returns the XML document as a string. */ @Override public String toString() { try { return new String(toBuffer(),"UTF-8"); } catch (UnsupportedEncodingException e) { throw new MarkLogicIOException(e); } }
@Override public byte[] toBuffer() { try { if (content == null) return null; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); write(buffer); return buffer.toByteArray(); } catch (IOException e) { throw new MarkLogicIOException(e); } }
@Override public void write(OutputStream out) throws IOException { Writer writer = new OutputStreamWriter(out, "UTF-8"); OutputFormat outputFormat = getOutputFormat(); if (outputFormat != null) { new XMLWriter(writer, outputFormat).write(content); } else { new XMLWriter(writer).write(content); } writer.flush(); } }
/** * Provides a handle on XML content as a dom4j document structure. * @param content the XML document. */ public DOM4JHandle(Document content) { this(); set(content); }
/** * Assigns an XML document structure as the content and returns the handle. * @param content the XML document. * @return the handle on the XML document. */ public DOM4JHandle with(Document content) { set(content); return this; }