X4Document Interfaces
Process components, i. e. instances of, for example, an adapter can read and issue many document types: XML documents, as well as text or binary data. With the X4Document
interface, adapters can access documents or generate with X4DocumentFactory
an output document as result of the adapter operation. This can be an X4Document
instance of a dom4j tree, a java.io.InputStream
or a byte array.
Character encoding problems can be avoided, if XSL transformations get a DOM-based input within X4 processes. For byte-based documents the byte array is passed to the XML parser without additional information.
X4Document Methods
de.softproject.integration.util.x4documents.X4Document | ||
---|---|---|
public byte[] getAsByteArray() | Returns the content as byte array | |
public byte[] getAsByteArray(String encoding) | Returns the content as byte array with the encoding specified within | |
public java.io.InputStream getAsInputStream() | Returns the InputStream of the access to the document content | |
public org.dom4j.Document getAsDocument() throws org.dom4j.DocumentException | Returns the content as dom4J DOM tree | |
public org.dom4j.Document getAsDocument(String encoding) throws org.dom4j.DocumentException, java.io.UnsupportedEncodingException | Returns the content as dom4J DOM tree with the encoding specified within | |
public void parseWithHandler (ContentHandler chandler) throws SAXException, IOException | Passes the content to the provided org.sax.ContentHandler instance (flush) | |
public String getMimeType() | Returns the MIME type of the document | |
public String getEncoding() | Returns the encoding of the document | |
public void setMimeType(String mimeType) | Sets the MIME type of the document | |
public void setEncoding(String encoding) | Sets the encoding of the document |
X4DocumentFactory Methods
| ||
---|---|---|
public static X4Document createX4Document(byte[] bytes, String encoding, String mimeType) | Outputs the | |
public static X4Document createDocument(Documentdoc, String encoding, String mimeType) | Outputs the | |
public static X4Document createX4Document(InputStream is, String encoding, String mimeType) throws X4DocumentException | Outputs the |
Example
public class X4DocumentTest {
public static void main(String[] args) {
InputStream is = null;
try {
is = new FileInputStream("Sample.xml");
// create a new X4Document
X4Document x4doc = X4DocumentFactory.createX4Document(is,
"cp-1252", "text/xml");
// get content as a dom4j document
System.out.println(x4doc.getAsDocument().asXML() + "\n");
// get content as a byte array
System.out.println(new String(x4doc.getAsByteArray())
+ "\n");
// parse the x4document's content
SAXContentHandler chandler = new SAXContentHandler();
x4doc.parseWithHandler(chandler);
System.out.println(chandler.getDocument().asXML() + "\n");
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (is != null)
try {
is.close();
} catch (IOException ioex) {
}
}
}
}