Search in sources :

Example 66 with XmlException

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

the class SharedStringsTable method readFrom.

/**
     * Read this shared strings table from an XML file.
     * 
     * @param is The input stream containing the XML document.
     * @throws IOException if an error occurs while reading.
     */
public void readFrom(InputStream is) throws IOException {
    try {
        int cnt = 0;
        _sstDoc = SstDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
        CTSst sst = _sstDoc.getSst();
        count = (int) sst.getCount();
        uniqueCount = (int) sst.getUniqueCount();
        for (CTRst st : sst.getSiArray()) {
            stmap.put(getKey(st), cnt);
            strings.add(st);
            cnt++;
        }
    } catch (XmlException e) {
        throw new IOException("unable to parse shared strings table", e);
    }
}
Also used : CTSst(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSst) CTRst(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst) XmlException(org.apache.xmlbeans.XmlException) IOException(java.io.IOException)

Example 67 with XmlException

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

the class MapInfo method readFrom.

public void readFrom(InputStream is) throws IOException {
    try {
        MapInfoDocument doc = MapInfoDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
        mapInfo = doc.getMapInfo();
        maps = new HashMap<Integer, XSSFMap>();
        for (CTMap map : mapInfo.getMapArray()) {
            maps.put((int) map.getID(), new XSSFMap(map, this));
        }
    } catch (XmlException e) {
        throw new IOException(e.getLocalizedMessage());
    }
}
Also used : XmlException(org.apache.xmlbeans.XmlException) XSSFMap(org.apache.poi.xssf.usermodel.XSSFMap) MapInfoDocument(org.openxmlformats.schemas.spreadsheetml.x2006.main.MapInfoDocument) IOException(java.io.IOException) CTMap(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMap)

Example 68 with XmlException

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

the class SingleXmlCells method readFrom.

public void readFrom(InputStream is) throws IOException {
    try {
        SingleXmlCellsDocument doc = SingleXmlCellsDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
        singleXMLCells = doc.getSingleXmlCells();
    } catch (XmlException e) {
        throw new IOException(e.getLocalizedMessage());
    }
}
Also used : SingleXmlCellsDocument(org.openxmlformats.schemas.spreadsheetml.x2006.main.SingleXmlCellsDocument) XmlException(org.apache.xmlbeans.XmlException) IOException(java.io.IOException)

Example 69 with XmlException

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

the class ExternalLinksTable method readFrom.

public void readFrom(InputStream is) throws IOException {
    try {
        ExternalLinkDocument doc = ExternalLinkDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
        link = doc.getExternalLink();
    } catch (XmlException e) {
        throw new IOException(e.getLocalizedMessage());
    }
}
Also used : ExternalLinkDocument(org.openxmlformats.schemas.spreadsheetml.x2006.main.ExternalLinkDocument) XmlException(org.apache.xmlbeans.XmlException) IOException(java.io.IOException)

Example 70 with XmlException

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

the class XSSFSheet method readOleObject.

/**
     * Determine the OleObject which links shapes with embedded resources
     *
     * @param shapeId the shape id
     * @return the CTOleObject of the shape
     */
protected CTOleObject readOleObject(long shapeId) {
    if (!getCTWorksheet().isSetOleObjects()) {
        return null;
    }
    // we use a XmlCursor here to handle oleObject with-/out AlternateContent wrappers
    String xquery = "declare namespace p='" + XSSFRelation.NS_SPREADSHEETML + "' .//p:oleObject";
    XmlCursor cur = getCTWorksheet().getOleObjects().newCursor();
    try {
        cur.selectPath(xquery);
        CTOleObject coo = null;
        while (cur.toNextSelection()) {
            String sId = cur.getAttributeText(new QName(null, "shapeId"));
            if (sId == null || Long.parseLong(sId) != shapeId) {
                continue;
            }
            XmlObject xObj = cur.getObject();
            if (xObj instanceof CTOleObject) {
                // the unusual case ...
                coo = (CTOleObject) xObj;
            } else {
                XMLStreamReader reader = cur.newXMLStreamReader();
                try {
                    CTOleObjects coos = CTOleObjects.Factory.parse(reader);
                    if (coos.sizeOfOleObjectArray() == 0) {
                        continue;
                    }
                    coo = coos.getOleObjectArray(0);
                } catch (XmlException e) {
                    logger.log(POILogger.INFO, "can't parse CTOleObjects", e);
                } finally {
                    try {
                        reader.close();
                    } catch (XMLStreamException e) {
                        logger.log(POILogger.INFO, "can't close reader", e);
                    }
                }
            }
            // which is in the choice element
            if (cur.toChild(XSSFRelation.NS_SPREADSHEETML, "objectPr")) {
                break;
            }
        }
        return (coo == null) ? null : coo;
    } finally {
        cur.dispose();
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) QName(javax.xml.namespace.QName) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor)

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