Search in sources :

Example 16 with XmlException

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

the class XWPFRun method getCTPictures.

private List<CTPicture> getCTPictures(XmlObject o) {
    List<CTPicture> pics = new ArrayList<CTPicture>();
    XmlObject[] picts = o.selectPath("declare namespace pic='" + CTPicture.type.getName().getNamespaceURI() + "' .//pic:pic");
    for (XmlObject pict : picts) {
        if (pict instanceof XmlAnyTypeImpl) {
            // Pesky XmlBeans bug - see Bugzilla #49934
            try {
                pict = CTPicture.Factory.parse(pict.toString(), DEFAULT_XML_OPTIONS);
            } catch (XmlException e) {
                throw new POIXMLException(e);
            }
        }
        if (pict instanceof CTPicture) {
            pics.add((CTPicture) pict);
        }
    }
    return pics;
}
Also used : XmlException(org.apache.xmlbeans.XmlException) ArrayList(java.util.ArrayList) CTPicture(org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture) XmlAnyTypeImpl(org.apache.xmlbeans.impl.values.XmlAnyTypeImpl) XmlObject(org.apache.xmlbeans.XmlObject) POIXMLException(org.apache.poi.POIXMLException)

Example 17 with XmlException

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

the class XWPFStyles method onDocumentRead.

/**
     * Read document
     */
@Override
protected void onDocumentRead() throws IOException {
    StylesDocument stylesDoc;
    InputStream is = getPackagePart().getInputStream();
    try {
        stylesDoc = StylesDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
        setStyles(stylesDoc.getStyles());
        latentStyles = new XWPFLatentStyles(ctStyles.getLatentStyles(), this);
    } catch (XmlException e) {
        throw new POIXMLException("Unable to read styles", e);
    } finally {
        is.close();
    }
}
Also used : StylesDocument(org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument) InputStream(java.io.InputStream) XmlException(org.apache.xmlbeans.XmlException) POIXMLException(org.apache.poi.POIXMLException)

Example 18 with XmlException

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

the class XMLSlideShow method onDocumentRead.

@Override
protected void onDocumentRead() throws IOException {
    try {
        PresentationDocument doc = PresentationDocument.Factory.parse(getCorePart().getInputStream(), DEFAULT_XML_OPTIONS);
        _presentation = doc.getPresentation();
        Map<String, XSLFSlideMaster> masterMap = new HashMap<String, XSLFSlideMaster>();
        Map<String, XSLFSlide> shIdMap = new HashMap<String, XSLFSlide>();
        for (RelationPart rp : getRelationParts()) {
            POIXMLDocumentPart p = rp.getDocumentPart();
            if (p instanceof XSLFSlide) {
                shIdMap.put(rp.getRelationship().getId(), (XSLFSlide) p);
            } else if (p instanceof XSLFSlideMaster) {
                masterMap.put(getRelationId(p), (XSLFSlideMaster) p);
            } else if (p instanceof XSLFTableStyles) {
                _tableStyles = (XSLFTableStyles) p;
            } else if (p instanceof XSLFNotesMaster) {
                _notesMaster = (XSLFNotesMaster) p;
            } else if (p instanceof XSLFCommentAuthors) {
                _commentAuthors = (XSLFCommentAuthors) p;
            }
        }
        _masters = new ArrayList<XSLFSlideMaster>(masterMap.size());
        for (CTSlideMasterIdListEntry masterId : _presentation.getSldMasterIdLst().getSldMasterIdList()) {
            XSLFSlideMaster master = masterMap.get(masterId.getId2());
            _masters.add(master);
        }
        _slides = new ArrayList<XSLFSlide>(shIdMap.size());
        if (_presentation.isSetSldIdLst()) {
            for (CTSlideIdListEntry slId : _presentation.getSldIdLst().getSldIdList()) {
                XSLFSlide sh = shIdMap.get(slId.getId2());
                if (sh == null) {
                    LOG.log(POILogger.WARN, "Slide with r:id " + slId.getId() + " was defined, but didn't exist in package, skipping");
                    continue;
                }
                _slides.add(sh);
            }
        }
    } catch (XmlException e) {
        throw new POIXMLException(e);
    }
}
Also used : HashMap(java.util.HashMap) POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) POIXMLException(org.apache.poi.POIXMLException) CTSlideMasterIdListEntry(org.openxmlformats.schemas.presentationml.x2006.main.CTSlideMasterIdListEntry) CTSlideIdListEntry(org.openxmlformats.schemas.presentationml.x2006.main.CTSlideIdListEntry) XmlException(org.apache.xmlbeans.XmlException) PresentationDocument(org.openxmlformats.schemas.presentationml.x2006.main.PresentationDocument)

Example 19 with XmlException

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

the class XSSFSheet method read.

protected void read(InputStream is) throws IOException {
    try {
        worksheet = WorksheetDocument.Factory.parse(is, DEFAULT_XML_OPTIONS).getWorksheet();
    } catch (XmlException e) {
        throw new POIXMLException(e);
    }
    initRows(worksheet);
    columnHelper = new ColumnHelper(worksheet);
    // Look for bits we're interested in
    for (RelationPart rp : getRelationParts()) {
        POIXMLDocumentPart p = rp.getDocumentPart();
        if (p instanceof CommentsTable) {
            sheetComments = (CommentsTable) p;
        }
        if (p instanceof XSSFTable) {
            tables.put(rp.getRelationship().getId(), (XSSFTable) p);
        }
        if (p instanceof XSSFPivotTable) {
            getWorkbook().getPivotTables().add((XSSFPivotTable) p);
        }
    }
    // Process external hyperlinks for the sheet, if there are any
    initHyperlinks();
}
Also used : ColumnHelper(org.apache.poi.xssf.usermodel.helpers.ColumnHelper) XmlException(org.apache.xmlbeans.XmlException) POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) POIXMLException(org.apache.poi.POIXMLException) CommentsTable(org.apache.poi.xssf.model.CommentsTable)

Example 20 with XmlException

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

the class XSSFTable method readFrom.

/**
     * read table XML
     * @param is
     * @throws IOException
     */
public void readFrom(InputStream is) throws IOException {
    try {
        TableDocument doc = TableDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
        ctTable = doc.getTable();
    } catch (XmlException e) {
        throw new IOException(e.getLocalizedMessage());
    }
}
Also used : TableDocument(org.openxmlformats.schemas.spreadsheetml.x2006.main.TableDocument) XmlException(org.apache.xmlbeans.XmlException) IOException(java.io.IOException)

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