Search in sources :

Example 6 with XmlException

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

the class Office2010SignatureFacet method postSign.

@Override
public void postSign(Document document) throws MarshalException {
    // check for XAdES-BES
    NodeList nl = document.getElementsByTagNameNS(XADES_132_NS, "QualifyingProperties");
    if (nl.getLength() != 1) {
        throw new MarshalException("no XAdES-BES extension present");
    }
    QualifyingPropertiesType qualProps;
    try {
        qualProps = QualifyingPropertiesType.Factory.parse(nl.item(0), DEFAULT_XML_OPTIONS);
    } catch (XmlException e) {
        throw new MarshalException(e);
    }
    // create basic XML container structure
    UnsignedPropertiesType unsignedProps = qualProps.getUnsignedProperties();
    if (unsignedProps == null) {
        unsignedProps = qualProps.addNewUnsignedProperties();
    }
    UnsignedSignaturePropertiesType unsignedSigProps = unsignedProps.getUnsignedSignatureProperties();
    if (unsignedSigProps == null) {
        /* unsignedSigProps = */
        unsignedProps.addNewUnsignedSignatureProperties();
    }
    Node n = document.importNode(qualProps.getDomNode().getFirstChild(), true);
    nl.item(0).getParentNode().replaceChild(n, nl.item(0));
}
Also used : UnsignedPropertiesType(org.etsi.uri.x01903.v13.UnsignedPropertiesType) MarshalException(javax.xml.crypto.MarshalException) QualifyingPropertiesType(org.etsi.uri.x01903.v13.QualifyingPropertiesType) XmlException(org.apache.xmlbeans.XmlException) UnsignedSignaturePropertiesType(org.etsi.uri.x01903.v13.UnsignedSignaturePropertiesType) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node)

Example 7 with XmlException

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

the class XDGFPageContents method onDocumentRead.

@Override
protected void onDocumentRead() {
    try {
        try {
            _pageContents = PageContentsDocument.Factory.parse(getPackagePart().getInputStream()).getPageContents();
        } catch (XmlException e) {
            throw new POIXMLException(e);
        } catch (IOException e) {
            throw new POIXMLException(e);
        }
        for (POIXMLDocumentPart part : getRelations()) {
            if (!(part instanceof XDGFMasterContents))
                continue;
            //throw new POIXMLException("Unexpected page relation: " + part);
            XDGFMaster master = ((XDGFMasterContents) part).getMaster();
            _masters.put(master.getID(), master);
        }
        super.onDocumentRead();
        for (XDGFShape shape : _shapes.values()) {
            if (shape.isTopmost())
                shape.setupMaster(this, null);
        }
    } catch (POIXMLException e) {
        throw XDGFException.wrap(this, e);
    }
}
Also used : XmlException(org.apache.xmlbeans.XmlException) POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) POIXMLException(org.apache.poi.POIXMLException) IOException(java.io.IOException)

Example 8 with XmlException

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

the class XDGFPages method onDocumentRead.

@Override
protected void onDocumentRead() {
    try {
        try {
            _pagesObject = PagesDocument.Factory.parse(getPackagePart().getInputStream()).getPages();
        } catch (XmlException e) {
            throw new POIXMLException(e);
        } catch (IOException e) {
            throw new POIXMLException(e);
        }
        // this iteration is ordered by page number
        for (PageType pageSettings : _pagesObject.getPageArray()) {
            String relId = pageSettings.getRel().getId();
            POIXMLDocumentPart pageContentsPart = getRelationById(relId);
            if (pageContentsPart == null)
                throw new POIXMLException("PageSettings relationship for " + relId + " not found");
            if (!(pageContentsPart instanceof XDGFPageContents))
                throw new POIXMLException("Unexpected pages relationship for " + relId + ": " + pageContentsPart);
            XDGFPageContents contents = (XDGFPageContents) pageContentsPart;
            XDGFPage page = new XDGFPage(pageSettings, contents, _document, this);
            contents.onDocumentRead();
            _pages.add(page);
        }
    } catch (POIXMLException e) {
        throw XDGFException.wrap(this, e);
    }
}
Also used : XmlException(org.apache.xmlbeans.XmlException) POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) POIXMLException(org.apache.poi.POIXMLException) IOException(java.io.IOException) PageType(com.microsoft.schemas.office.visio.x2012.main.PageType)

Example 9 with XmlException

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

the class ExtractorFactory method getEmbededDocsTextExtractors.

/**
     * Returns an array of text extractors, one for each of
     *  the embedded documents in the file (if there are any).
     * If there are no embedded documents, you'll get back an
     *  empty array. Otherwise, you'll get one open
     *  {@link POITextExtractor} for each embedded file.
     */
public static POITextExtractor[] getEmbededDocsTextExtractors(POIOLE2TextExtractor ext) throws IOException, OpenXML4JException, XmlException {
    // All the embedded directories we spotted
    ArrayList<Entry> dirs = new ArrayList<Entry>();
    // For anything else not directly held in as a POIFS directory
    ArrayList<InputStream> nonPOIFS = new ArrayList<InputStream>();
    // Find all the embedded directories
    DirectoryEntry root = ext.getRoot();
    if (root == null) {
        throw new IllegalStateException("The extractor didn't know which POIFS it came from!");
    }
    if (ext instanceof ExcelExtractor) {
        // These are in MBD... under the root
        Iterator<Entry> it = root.getEntries();
        while (it.hasNext()) {
            Entry entry = it.next();
            if (entry.getName().startsWith("MBD")) {
                dirs.add(entry);
            }
        }
    } else if (ext instanceof WordExtractor) {
        // These are in ObjectPool -> _... under the root
        try {
            DirectoryEntry op = (DirectoryEntry) root.getEntry("ObjectPool");
            Iterator<Entry> it = op.getEntries();
            while (it.hasNext()) {
                Entry entry = it.next();
                if (entry.getName().startsWith("_")) {
                    dirs.add(entry);
                }
            }
        } catch (FileNotFoundException e) {
            logger.log(POILogger.INFO, "Ignoring FileNotFoundException while extracting Word document", e.getLocalizedMessage());
        // ignored here
        }
    //} else if(ext instanceof PowerPointExtractor) {
    // Tricky, not stored directly in poifs
    // TODO
    } else if (ext instanceof OutlookTextExtactor) {
        // Stored in the Attachment blocks
        MAPIMessage msg = ((OutlookTextExtactor) ext).getMAPIMessage();
        for (AttachmentChunks attachment : msg.getAttachmentFiles()) {
            if (attachment.getAttachData() != null) {
                byte[] data = attachment.getAttachData().getValue();
                nonPOIFS.add(new ByteArrayInputStream(data));
            } else if (attachment.getAttachmentDirectory() != null) {
                dirs.add(attachment.getAttachmentDirectory().getDirectory());
            }
        }
    }
    // Create the extractors
    if (dirs.size() == 0 && nonPOIFS.size() == 0) {
        return new POITextExtractor[0];
    }
    ArrayList<POITextExtractor> textExtractors = new ArrayList<POITextExtractor>();
    for (Entry dir : dirs) {
        textExtractors.add(createExtractor((DirectoryNode) dir));
    }
    for (InputStream nonPOIF : nonPOIFS) {
        try {
            textExtractors.add(createExtractor(nonPOIF));
        } catch (IllegalArgumentException e) {
            // Ignore, just means it didn't contain
            //  a format we support as yet
            logger.log(POILogger.INFO, "Format not supported yet", e.getLocalizedMessage());
        } catch (XmlException e) {
            throw new IOException(e.getMessage(), e);
        } catch (OpenXML4JException e) {
            throw new IOException(e.getMessage(), e);
        }
    }
    return textExtractors.toArray(new POITextExtractor[textExtractors.size()]);
}
Also used : PushbackInputStream(java.io.PushbackInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) DirectoryNode(org.apache.poi.poifs.filesystem.DirectoryNode) IOException(java.io.IOException) DirectoryEntry(org.apache.poi.poifs.filesystem.DirectoryEntry) WordExtractor(org.apache.poi.hwpf.extractor.WordExtractor) XWPFWordExtractor(org.apache.poi.xwpf.extractor.XWPFWordExtractor) MAPIMessage(org.apache.poi.hsmf.MAPIMessage) Entry(org.apache.poi.poifs.filesystem.Entry) DirectoryEntry(org.apache.poi.poifs.filesystem.DirectoryEntry) OutlookTextExtactor(org.apache.poi.hsmf.extractor.OutlookTextExtactor) OpenXML4JException(org.apache.poi.openxml4j.exceptions.OpenXML4JException) ByteArrayInputStream(java.io.ByteArrayInputStream) POITextExtractor(org.apache.poi.POITextExtractor) XSSFExcelExtractor(org.apache.poi.xssf.extractor.XSSFExcelExtractor) ExcelExtractor(org.apache.poi.hssf.extractor.ExcelExtractor) XSSFEventBasedExcelExtractor(org.apache.poi.xssf.extractor.XSSFEventBasedExcelExtractor) XSSFBEventBasedExcelExtractor(org.apache.poi.xssf.extractor.XSSFBEventBasedExcelExtractor) XmlException(org.apache.xmlbeans.XmlException) Iterator(java.util.Iterator) AttachmentChunks(org.apache.poi.hsmf.datatypes.AttachmentChunks)

Example 10 with XmlException

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

the class ExtractorFactory method createExtractor.

public static POITextExtractor createExtractor(File f) throws IOException, OpenXML4JException, XmlException {
    NPOIFSFileSystem fs = null;
    try {
        fs = new NPOIFSFileSystem(f);
        POIOLE2TextExtractor extractor = createExtractor(fs);
        extractor.setFilesystem(fs);
        return extractor;
    } catch (OfficeXmlFileException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        return createExtractor(OPCPackage.open(f.toString(), PackageAccess.READ));
    } catch (NotOLE2FileException ne) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw new IllegalArgumentException("Your File was neither an OLE2 file, nor an OOXML file");
    } catch (OpenXML4JException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw e;
    } catch (XmlException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw e;
    } catch (IOException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw e;
    } catch (RuntimeException e) {
        // ensure file-handle release
        IOUtils.closeQuietly(fs);
        throw e;
    }
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) OpenXML4JException(org.apache.poi.openxml4j.exceptions.OpenXML4JException) OfficeXmlFileException(org.apache.poi.poifs.filesystem.OfficeXmlFileException) NotOLE2FileException(org.apache.poi.poifs.filesystem.NotOLE2FileException) XmlException(org.apache.xmlbeans.XmlException) IOException(java.io.IOException) POIOLE2TextExtractor(org.apache.poi.POIOLE2TextExtractor)

Aggregations

XmlException (org.apache.xmlbeans.XmlException)112 XmlObject (org.apache.xmlbeans.XmlObject)45 IOException (java.io.IOException)35 DecodingException (org.n52.svalbard.decode.exception.DecodingException)19 EncodingException (org.n52.svalbard.encode.exception.EncodingException)17 POIXMLException (org.apache.poi.POIXMLException)15 InputStream (java.io.InputStream)11 ArrayList (java.util.ArrayList)10 XmlCursor (org.apache.xmlbeans.XmlCursor)10 XmlOptions (org.apache.xmlbeans.XmlOptions)10 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)8 POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)7 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)7 Geometry (org.locationtech.jts.geom.Geometry)6 Document (org.w3c.dom.Document)6 Node (org.w3c.dom.Node)6 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 File (java.io.File)5