Search in sources :

Example 16 with XMLNode

use of org.openntf.domino.utils.xml.XMLNode in project org.openntf.domino by OpenNTF.

the class DesignColumn method setFormula.

@Override
public void setFormula(final String formula) {
    // $NON-NLS-1$
    XMLNode formulaNode = node_.selectSingleNode("code[@event='value']/formula");
    if (formulaNode != null) {
        formulaNode.setTextContent(formula);
    } else {
        // $NON-NLS-1$
        XMLNode code = node_.addChildElement("code");
        // $NON-NLS-1$ //$NON-NLS-2$
        code.setAttribute("event", "value");
        // $NON-NLS-1$
        formulaNode = code.addChildElement("formula");
        formulaNode.setTextContent(formula);
    }
}
Also used : XMLNode(org.openntf.domino.utils.xml.XMLNode)

Example 17 with XMLNode

use of org.openntf.domino.utils.xml.XMLNode in project org.openntf.domino by OpenNTF.

the class DXLItemRaw method create.

protected static DXLItemRaw create(final XMLNode node, final int dupItemId) {
    // $NON-NLS-1$
    XMLNode rawitemdata = node.selectSingleNode("rawitemdata");
    // $NON-NLS-1$
    int typeCode = Integer.parseInt(rawitemdata.getAttribute("type"), 16);
    Type type = Type.valueOf(typeCode);
    switch(type) {
        case COMPOSITE:
            return new DXLItemComposite(node, dupItemId);
        case NOTEREF_LIST:
            return new DXLItemRefList(node, dupItemId);
        case MIME_PART:
            return new DXLItemMIMEPart(node, dupItemId);
        case COLLATION:
            return new DXLItemCollation(node, dupItemId);
        case VIEW_FORMAT:
            return new DXLItemViewFormat(node, dupItemId);
        default:
            return new DXLItemRaw(node, dupItemId);
    }
}
Also used : XMLNode(org.openntf.domino.utils.xml.XMLNode)

Example 18 with XMLNode

use of org.openntf.domino.utils.xml.XMLNode in project org.openntf.domino by OpenNTF.

the class AbstractDesignFileResource method setFileData.

@Override
public void setFileData(final byte[] data) {
    switch(getDxlFormat(true)) {
        case DXL:
            // $NON-NLS-1$
            XMLNode filedata = getDxl().selectSingleNode("//filedata");
            if (filedata == null) {
                // $NON-NLS-1$ //$NON-NLS-2$
                filedata = getDxl().selectSingleNode("/*").addChildElement("filedata");
            }
            filedata.setText(printBase64Binary(data));
        default:
            setFileDataRaw(DEFAULT_FILEDATA_FIELD, data);
    }
}
Also used : XMLNode(org.openntf.domino.utils.xml.XMLNode)

Example 19 with XMLNode

use of org.openntf.domino.utils.xml.XMLNode in project org.openntf.domino by OpenNTF.

the class AbstractDesignFileResource method setFileDataRaw.

protected void setFileDataRaw(final String itemName, final byte[] fileData) {
    // To set the file content, first clear out existing content
    // $NON-NLS-1$ //$NON-NLS-2$
    List<XMLNode> fileDataNodes = getDxl().selectNodes("//item[@name='" + XMLDocument.escapeXPathValue(itemName) + "']");
    for (int i = fileDataNodes.size() - 1; i >= 0; i--) {
        fileDataNodes.get(i).getParentNode().removeChild(fileDataNodes.get(i));
    }
    // Now create a CD record for the file data
    // CDResourceFile record = CDResourceFile.fromFileData(fileData, "");
    // byte[] reconData = record.getBytes();
    // $NON-NLS-1$
    CDResourceFile record = new CDResourceFile("");
    record.setFileData(fileData);
    byte[] reconData = record.getData().array();
    // Write out the first chunk
    int firstChunk = reconData.length > 20544 ? 20544 : reconData.length;
    String firstChunkData = printBase64Binary(Arrays.copyOfRange(reconData, 0, firstChunk));
    // $NON-NLS-1$
    XMLNode documentNode = getDxl().selectSingleNode("//note");
    // $NON-NLS-1$
    XMLNode fileDataNode = documentNode.addChildElement("item");
    // $NON-NLS-1$
    fileDataNode.setAttribute("name", itemName);
    // $NON-NLS-1$
    fileDataNode = fileDataNode.addChildElement("rawitemdata");
    // $NON-NLS-1$ //$NON-NLS-2$
    fileDataNode.setAttribute("type", "1");
    fileDataNode.setText(firstChunkData);
    // Write out any remaining chunks
    int remaining = reconData.length - firstChunk;
    int chunks = remaining / 20516;
    if (remaining % 20516 > 0) {
        chunks++;
    }
    int offset = firstChunk;
    for (int i = 0; i < chunks; i++) {
        int chunkSize = remaining > 20516 ? 20516 : remaining;
        String chunkData = printBase64Binary(Arrays.copyOfRange(reconData, offset, offset + chunkSize));
        // $NON-NLS-1$
        fileDataNode = documentNode.addChildElement("item");
        // $NON-NLS-1$
        fileDataNode.setAttribute("name", itemName);
        // $NON-NLS-1$
        fileDataNode = fileDataNode.addChildElement("rawitemdata");
        // $NON-NLS-1$ //$NON-NLS-2$
        fileDataNode.setAttribute("type", "1");
        fileDataNode.setText(chunkData);
        remaining -= 20516;
        offset += chunkSize;
    }
    // Also set the file size if we're setting the main field
    if (DEFAULT_FILEDATA_FIELD.equals(itemName)) {
        // $NON-NLS-1$
        setItemValue("$FileSize", String.valueOf(fileData.length), FLAG_SIGN_SUMMARY);
    }
}
Also used : XMLNode(org.openntf.domino.utils.xml.XMLNode) CDResourceFile(org.openntf.domino.nsfdata.structs.obj.CDResourceFile)

Example 20 with XMLNode

use of org.openntf.domino.utils.xml.XMLNode 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

XMLNode (org.openntf.domino.utils.xml.XMLNode)35 ArrayList (java.util.ArrayList)7 XMLNodeList (org.openntf.domino.utils.xml.XMLNodeList)3 CDResourceFile (org.openntf.domino.nsfdata.structs.obj.CDResourceFile)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Database (org.openntf.domino.Database)1 DxlExporter (org.openntf.domino.DxlExporter)1 DatabaseDesign (org.openntf.domino.design.DatabaseDesign)1 FormField (org.openntf.domino.design.FormField)1 OpenNTFNotesException (org.openntf.domino.exceptions.OpenNTFNotesException)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