Search in sources :

Example 1 with XmlOptions

use of org.apache.xmlbeans.XmlOptions in project hackpad by dropbox.

the class XML method getOptions.

/**
     *
     * @return
     */
private XmlOptions getOptions() {
    XmlOptions options = new XmlOptions();
    if (lib.ignoreComments) {
        options.put(XmlOptions.LOAD_STRIP_COMMENTS);
    }
    if (lib.ignoreProcessingInstructions) {
        options.put(XmlOptions.LOAD_STRIP_PROCINSTS);
    }
    if (lib.ignoreWhitespace) {
        options.put(XmlOptions.LOAD_STRIP_WHITESPACE);
    }
    if (lib.prettyPrinting) {
        options.put(XmlOptions.SAVE_PRETTY_PRINT, null);
        options.put(XmlOptions.SAVE_PRETTY_PRINT_INDENT, new Integer(lib.prettyIndent));
    }
    return options;
}
Also used : XmlOptions(org.apache.xmlbeans.XmlOptions)

Example 2 with XmlOptions

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

the class XSSFDump method dump.

public static void dump(ZipFile zip) throws Exception {
    String zipname = zip.getName();
    int sep = zipname.lastIndexOf('.');
    File root = new File(zipname.substring(0, sep));
    createDirIfMissing(root);
    System.out.println("Dumping to directory " + root);
    Enumeration<? extends ZipEntry> en = zip.entries();
    while (en.hasMoreElements()) {
        ZipEntry entry = en.nextElement();
        String name = entry.getName();
        int idx = name.lastIndexOf('/');
        if (idx != -1) {
            File bs = new File(root, name.substring(0, idx));
            recursivelyCreateDirIfMissing(bs);
        }
        File f = new File(root, entry.getName());
        OutputStream out = new FileOutputStream(f);
        try {
            if (entry.getName().endsWith(".xml") || entry.getName().endsWith(".vml") || entry.getName().endsWith(".rels")) {
                try {
                    Document doc = DocumentHelper.readDocument(zip.getInputStream(entry));
                    XmlObject xml = XmlObject.Factory.parse(doc, DEFAULT_XML_OPTIONS);
                    XmlOptions options = new XmlOptions();
                    options.setSavePrettyPrint();
                    xml.save(out, options);
                } catch (XmlException e) {
                    System.err.println("Failed to parse " + entry.getName() + ", dumping raw content");
                    IOUtils.copy(zip.getInputStream(entry), out);
                }
            } else {
                IOUtils.copy(zip.getInputStream(entry), out);
            }
        } finally {
            out.close();
        }
    }
}
Also used : XmlException(org.apache.xmlbeans.XmlException) ZipEntry(java.util.zip.ZipEntry) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) XmlOptions(org.apache.xmlbeans.XmlOptions) XmlObject(org.apache.xmlbeans.XmlObject) Document(org.w3c.dom.Document) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 3 with XmlOptions

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

the class RelationshipTransformService method transform.

public Data transform(Data data, XMLCryptoContext context) throws TransformException {
    LOG.log(POILogger.DEBUG, "transform(data,context)");
    LOG.log(POILogger.DEBUG, "data java type: " + data.getClass().getName());
    OctetStreamData octetStreamData = (OctetStreamData) data;
    LOG.log(POILogger.DEBUG, "URI: " + octetStreamData.getURI());
    InputStream octetStream = octetStreamData.getOctetStream();
    RelationshipsDocument relDoc;
    try {
        relDoc = RelationshipsDocument.Factory.parse(octetStream, DEFAULT_XML_OPTIONS);
    } catch (Exception e) {
        throw new TransformException(e.getMessage(), e);
    }
    LOG.log(POILogger.DEBUG, "relationships document", relDoc);
    CTRelationships rels = relDoc.getRelationships();
    List<CTRelationship> relList = rels.getRelationshipList();
    Iterator<CTRelationship> relIter = rels.getRelationshipList().iterator();
    while (relIter.hasNext()) {
        CTRelationship rel = relIter.next();
        /*
             * See: ISO/IEC 29500-2:2008(E) - 13.2.4.24 Relationships Transform
             * Algorithm.
             */
        if (!this.sourceIds.contains(rel.getId())) {
            LOG.log(POILogger.DEBUG, "removing element: " + rel.getId());
            relIter.remove();
        } else {
            if (!rel.isSetTargetMode()) {
                rel.setTargetMode(STTargetMode.INTERNAL);
            }
        }
    }
    // TODO: remove non element nodes ???
    LOG.log(POILogger.DEBUG, "# Relationship elements", relList.size());
    XmlSort.sort(rels, new Comparator<XmlCursor>() {

        public int compare(XmlCursor c1, XmlCursor c2) {
            String id1 = ((CTRelationship) c1.getObject()).getId();
            String id2 = ((CTRelationship) c2.getObject()).getId();
            return id1.compareTo(id2);
        }
    });
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        XmlOptions xo = new XmlOptions();
        xo.setSaveNoXmlDecl();
        relDoc.save(bos, xo);
        return new OctetStreamData(new ByteArrayInputStream(bos.toByteArray()));
    } catch (IOException e) {
        throw new TransformException(e.getMessage(), e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XmlOptions(org.apache.xmlbeans.XmlOptions) TransformException(javax.xml.crypto.dsig.TransformException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) MarshalException(javax.xml.crypto.MarshalException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) TransformException(javax.xml.crypto.dsig.TransformException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) XmlCursor(org.apache.xmlbeans.XmlCursor) CTRelationship(org.openxmlformats.schemas.xpackage.x2006.relationships.CTRelationship) RelationshipsDocument(org.openxmlformats.schemas.xpackage.x2006.relationships.RelationshipsDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) CTRelationships(org.openxmlformats.schemas.xpackage.x2006.relationships.CTRelationships) OctetStreamData(javax.xml.crypto.OctetStreamData)

Example 4 with XmlOptions

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

the class XSSFChartSheet method write.

@Override
protected void write(OutputStream out) throws IOException {
    XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
    xmlOptions.setSaveSyntheticDocumentElement(new QName(CTChartsheet.type.getName().getNamespaceURI(), "chartsheet"));
    chartsheet.save(out, xmlOptions);
}
Also used : QName(javax.xml.namespace.QName) XmlOptions(org.apache.xmlbeans.XmlOptions)

Example 5 with XmlOptions

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

the class XSLFTheme method commit.

protected final void commit() throws IOException {
    XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
    xmlOptions.setSaveSyntheticDocumentElement(new QName("http://schemas.openxmlformats.org/drawingml/2006/main", "theme"));
    PackagePart part = getPackagePart();
    OutputStream out = part.getOutputStream();
    getXmlObject().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)

Aggregations

XmlOptions (org.apache.xmlbeans.XmlOptions)60 QName (javax.xml.namespace.QName)20 OutputStream (java.io.OutputStream)18 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)17 XmlException (org.apache.xmlbeans.XmlException)11 ArrayList (java.util.ArrayList)10 IOException (java.io.IOException)9 XmlError (org.apache.xmlbeans.XmlError)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