Search in sources :

Example 41 with XmlOptions

use of org.apache.xmlbeans.XmlOptions in project poi by apache.

the class AgileEncryptor method marshallEncryptionDocument.

protected void marshallEncryptionDocument(EncryptionDocument ed, LittleEndianByteArrayOutputStream os) {
    XmlOptions xo = new XmlOptions();
    xo.setCharacterEncoding("UTF-8");
    Map<String, String> nsMap = new HashMap<String, String>();
    nsMap.put(passwordUri.toString(), "p");
    nsMap.put(certificateUri.toString(), "c");
    xo.setUseDefaultNamespace();
    xo.setSaveSuggestedPrefixes(nsMap);
    xo.setSaveNamespacesFirst();
    xo.setSaveAggressiveNamespaces();
    // setting standalone doesn't work with xmlbeans-2.3 & 2.6
    // ed.documentProperties().setStandalone(true);
    xo.setSaveNoXmlDecl();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        bos.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\r\n".getBytes("UTF-8"));
        ed.save(bos, xo);
        bos.writeTo(os);
    } catch (IOException e) {
        throw new EncryptedDocumentException("error marshalling encryption info document", e);
    }
}
Also used : EncryptedDocumentException(org.apache.poi.EncryptedDocumentException) HashMap(java.util.HashMap) XmlOptions(org.apache.xmlbeans.XmlOptions) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream) IOException(java.io.IOException)

Example 42 with XmlOptions

use of org.apache.xmlbeans.XmlOptions in project poi by apache.

the class XWPFSettings method commit.

@Override
protected void commit() throws IOException {
    if (ctSettings == null) {
        throw new IllegalStateException("Unable to write out settings that were never read in!");
    }
    XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
    xmlOptions.setSaveSyntheticDocumentElement(new QName(CTSettings.type.getName().getNamespaceURI(), "settings"));
    PackagePart part = getPackagePart();
    OutputStream out = part.getOutputStream();
    ctSettings.save(out, xmlOptions);
    out.close();
}
Also used : QName(javax.xml.namespace.QName) XmlOptions(org.apache.xmlbeans.XmlOptions) OutputStream(java.io.OutputStream) PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Example 43 with XmlOptions

use of org.apache.xmlbeans.XmlOptions in project poi by apache.

the class XWPFFootnotes method commit.

@Override
protected void commit() throws IOException {
    XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
    xmlOptions.setSaveSyntheticDocumentElement(new QName(CTFootnotes.type.getName().getNamespaceURI(), "footnotes"));
    PackagePart part = getPackagePart();
    OutputStream out = part.getOutputStream();
    ctFootnotes.save(out, xmlOptions);
    out.close();
}
Also used : QName(javax.xml.namespace.QName) XmlOptions(org.apache.xmlbeans.XmlOptions) OutputStream(java.io.OutputStream) PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Example 44 with XmlOptions

use of org.apache.xmlbeans.XmlOptions in project poi by apache.

the class XSSFChart method commit.

@Override
protected void commit() throws IOException {
    XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
    /*
		   Saved chart space must have the following namespaces set:
		   <c:chartSpace
		      xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"
		      xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
		      xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
		 */
    xmlOptions.setSaveSyntheticDocumentElement(new QName(CTChartSpace.type.getName().getNamespaceURI(), "chartSpace", "c"));
    PackagePart part = getPackagePart();
    OutputStream out = part.getOutputStream();
    chartSpace.save(out, xmlOptions);
    out.close();
}
Also used : QName(javax.xml.namespace.QName) XmlOptions(org.apache.xmlbeans.XmlOptions) OutputStream(java.io.OutputStream) PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Example 45 with XmlOptions

use of org.apache.xmlbeans.XmlOptions in project poi by apache.

the class SharedStringsTable method writeTo.

/**
     * Write this table out as XML.
     * 
     * @param out The stream to write to.
     * @throws IOException if an error occurs while writing.
     */
public void writeTo(OutputStream out) throws IOException {
    XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
    // the following two lines turn off writing CDATA
    // see Bugzilla 48936
    xmlOptions.setSaveCDataLengthThreshold(1000000);
    xmlOptions.setSaveCDataEntityCountThreshold(-1);
    //re-create the sst table every time saving a workbook
    CTSst sst = _sstDoc.getSst();
    sst.setCount(count);
    sst.setUniqueCount(uniqueCount);
    _sstDoc.save(out, xmlOptions);
}
Also used : CTSst(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSst) XmlOptions(org.apache.xmlbeans.XmlOptions)

Aggregations

XmlOptions (org.apache.xmlbeans.XmlOptions)63 QName (javax.xml.namespace.QName)20 OutputStream (java.io.OutputStream)18 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)17 ArrayList (java.util.ArrayList)12 XmlError (org.apache.xmlbeans.XmlError)11 XmlException (org.apache.xmlbeans.XmlException)11 IOException (java.io.IOException)9 Beta (org.apache.poi.util.Beta)7 Before (org.junit.Before)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 XmlObject (org.apache.xmlbeans.XmlObject)4 PackageDocument (com.centurylink.mdw.bpm.PackageDocument)3 PackageVO (com.centurylink.mdw.model.value.process.PackageVO)3 TaskVO (com.centurylink.mdw.model.value.task.TaskVO)3 EncodingException (org.n52.svalbard.encode.exception.EncodingException)3 MDWProcessDefinition (com.centurylink.mdw.bpm.MDWProcessDefinition)2 ProcessDefinitionDocument (com.centurylink.mdw.bpm.ProcessDefinitionDocument)2 AttributeVO (com.centurylink.mdw.model.value.attribute.AttributeVO)2 Attribute (com.centurylink.mdw.task.Attribute)2