Search in sources :

Example 1 with CDObject

use of org.openntf.domino.nsfdata.structs.obj.CDObject in project org.openntf.domino by OpenNTF.

the class AbstractDesignFileResource method getFileDataRaw.

/**
 * Reads a FileData Item in RAW-mode
 *
 * @param itemName
 * @return
 */
protected byte[] getFileDataRaw(final String itemName) {
    try {
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        for (XMLNode rawitemdata : // 
        getDxl().selectNodes("//item[@name='" + XMLDocument.escapeXPathValue(itemName) + "']/rawitemdata")) {
            // $NON-NLS-1$ //$NON-NLS-2$
            String rawData = rawitemdata.getText();
            byte[] thisData = parseBase64Binary(rawData);
            byteStream.write(thisData);
        }
        if (byteStream.size() > 0) {
            byte[] data = byteStream.toByteArray();
            CData cdata = new CData(data);
            CDObject obj = CDObject.create(cdata);
            // Files may be attached either as FILE or as EVENT... (ssjs for example) Damn. This makes everything quite complex
            if (obj instanceof CDResourceFile)
                return ((CDResourceFile) obj).getFileData();
            if (obj instanceof CDResourceEvent)
                return ((CDResourceEvent) obj).getFileData();
            // $NON-NLS-1$
            throw new IllegalStateException("Cannot decode " + obj.getClass().getName());
        } else {
            byteStream = new ByteArrayOutputStream();
            for (XMLNode rawitemdata : // 
            getDxl().selectNodes("//file[@name='" + XMLDocument.escapeXPathValue(itemName) + "']/filedata")) {
                // $NON-NLS-1$ //$NON-NLS-2$
                String rawData = rawitemdata.getText();
                byte[] thisData = parseBase64Binary(rawData);
                byteStream.write(thisData);
            }
            return byteStream.toByteArray();
        }
    } catch (IOException ioe) {
        DominoUtils.handleException(ioe);
        return null;
    }
}
Also used : CDResourceEvent(org.openntf.domino.nsfdata.structs.obj.CDResourceEvent) XMLNode(org.openntf.domino.utils.xml.XMLNode) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) CDObject(org.openntf.domino.nsfdata.structs.obj.CDObject) CData(org.openntf.domino.nsfdata.structs.cd.CData) CDResourceFile(org.openntf.domino.nsfdata.structs.obj.CDResourceFile)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 CData (org.openntf.domino.nsfdata.structs.cd.CData)1 CDObject (org.openntf.domino.nsfdata.structs.obj.CDObject)1 CDResourceEvent (org.openntf.domino.nsfdata.structs.obj.CDResourceEvent)1 CDResourceFile (org.openntf.domino.nsfdata.structs.obj.CDResourceFile)1 XMLNode (org.openntf.domino.utils.xml.XMLNode)1