Search in sources :

Example 36 with POIXMLException

use of org.apache.poi.POIXMLException in project poi by apache.

the class GeometrySection method getPath.

public Path2D.Double getPath(XDGFShape parent) {
    Iterator<GeometryRow> rows = getCombinedRows().iterator();
    // special cases
    GeometryRow first = rows.next();
    if (first instanceof Ellipse) {
        return ((Ellipse) first).getPath();
    } else if (first instanceof InfiniteLine) {
        return ((InfiniteLine) first).getPath();
    } else if (first instanceof SplineStart) {
        throw new POIXMLException("SplineStart must be preceded by another type");
    } else {
        // everything else is a path
        Path2D.Double path = new Path2D.Double();
        // dealing with splines makes this more complex
        SplineCollector renderer = null;
        GeometryRow row;
        while (true) {
            if (first != null) {
                row = first;
                first = null;
            } else {
                if (!rows.hasNext())
                    break;
                row = rows.next();
            }
            if (row instanceof SplineStart) {
                if (renderer != null)
                    throw new POIXMLException("SplineStart found multiple times!");
                renderer = new SplineCollector((SplineStart) row);
            } else if (row instanceof SplineKnot) {
                if (renderer == null)
                    throw new POIXMLException("SplineKnot found without SplineStart!");
                renderer.addKnot((SplineKnot) row);
            } else {
                if (renderer != null) {
                    renderer.addToPath(path, parent);
                    renderer = null;
                }
                row.addToPath(path, parent);
            }
        }
        // just in case we end iteration
        if (renderer != null)
            renderer.addToPath(path, parent);
        return path;
    }
}
Also used : GeometryRow(org.apache.poi.xdgf.usermodel.section.geometry.GeometryRow) SplineStart(org.apache.poi.xdgf.usermodel.section.geometry.SplineStart) Ellipse(org.apache.poi.xdgf.usermodel.section.geometry.Ellipse) Path2D(java.awt.geom.Path2D) POIXMLException(org.apache.poi.POIXMLException) SplineKnot(org.apache.poi.xdgf.usermodel.section.geometry.SplineKnot) InfiniteLine(org.apache.poi.xdgf.usermodel.section.geometry.InfiniteLine) SplineCollector(org.apache.poi.xdgf.geom.SplineCollector)

Example 37 with POIXMLException

use of org.apache.poi.POIXMLException in project poi by apache.

the class XDGFMasters method onDocumentRead.

@Override
protected void onDocumentRead() {
    try {
        try {
            _mastersObject = MastersDocument.Factory.parse(getPackagePart().getInputStream()).getMasters();
        } catch (XmlException e) {
            throw new POIXMLException(e);
        } catch (IOException e) {
            throw new POIXMLException(e);
        }
        Map<String, MasterType> masterSettings = new HashMap<String, MasterType>();
        for (MasterType master : _mastersObject.getMasterArray()) {
            masterSettings.put(master.getRel().getId(), master);
        }
        // create the masters
        for (RelationPart rp : getRelationParts()) {
            POIXMLDocumentPart part = rp.getDocumentPart();
            String relId = rp.getRelationship().getId();
            MasterType settings = masterSettings.get(relId);
            if (settings == null) {
                throw new POIXMLException("Master relationship for " + relId + " not found");
            }
            if (!(part instanceof XDGFMasterContents)) {
                throw new POIXMLException("Unexpected masters relationship for " + relId + ": " + part);
            }
            XDGFMasterContents contents = (XDGFMasterContents) part;
            contents.onDocumentRead();
            XDGFMaster master = new XDGFMaster(settings, contents, _document);
            _masters.put(master.getID(), master);
        }
    } catch (POIXMLException e) {
        throw XDGFException.wrap(this, e);
    }
}
Also used : HashMap(java.util.HashMap) XmlException(org.apache.xmlbeans.XmlException) POIXMLDocumentPart(org.apache.poi.POIXMLDocumentPart) POIXMLException(org.apache.poi.POIXMLException) IOException(java.io.IOException) MasterType(com.microsoft.schemas.office.visio.x2012.main.MasterType)

Example 38 with POIXMLException

use of org.apache.poi.POIXMLException in project poi by apache.

the class XDGFPage method getPageSize.

/**
     * @return width/height of page
     */
public Dimension2dDouble getPageSize() {
    XDGFCell w = _pageSheet.getCell("PageWidth");
    XDGFCell h = _pageSheet.getCell("PageHeight");
    if (w == null || h == null)
        throw new POIXMLException("Cannot determine page size");
    return new Dimension2dDouble(Double.parseDouble(w.getValue()), Double.parseDouble(h.getValue()));
}
Also used : Dimension2dDouble(org.apache.poi.xdgf.geom.Dimension2dDouble) POIXMLException(org.apache.poi.POIXMLException)

Example 39 with POIXMLException

use of org.apache.poi.POIXMLException in project poi by apache.

the class XWPFPictureData method getChecksum.

public Long getChecksum() {
    if (this.checksum == null) {
        InputStream is = null;
        byte[] data;
        try {
            is = getPackagePart().getInputStream();
            data = IOUtils.toByteArray(is);
        } catch (IOException e) {
            throw new POIXMLException(e);
        } finally {
            IOUtils.closeQuietly(is);
        }
        this.checksum = IOUtils.calculateChecksum(data);
    }
    return this.checksum;
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) POIXMLException(org.apache.poi.POIXMLException)

Example 40 with POIXMLException

use of org.apache.poi.POIXMLException in project poi by apache.

the class XWPFHeader method onDocumentRead.

/**
     * reads the document
     *
     * @throws IOException
     */
@Override
protected void onDocumentRead() throws IOException {
    super.onDocumentRead();
    HdrDocument hdrDocument = null;
    InputStream is = null;
    try {
        is = getPackagePart().getInputStream();
        hdrDocument = HdrDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
        headerFooter = hdrDocument.getHdr();
        // parse the document with cursor and add
        // the XmlObject to its lists
        XmlCursor cursor = headerFooter.newCursor();
        cursor.selectPath("./*");
        while (cursor.toNextSelection()) {
            XmlObject o = cursor.getObject();
            if (o instanceof CTP) {
                XWPFParagraph p = new XWPFParagraph((CTP) o, this);
                paragraphs.add(p);
                bodyElements.add(p);
            }
            if (o instanceof CTTbl) {
                XWPFTable t = new XWPFTable((CTTbl) o, this);
                tables.add(t);
                bodyElements.add(t);
            }
            if (o instanceof CTSdtBlock) {
                XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
                bodyElements.add(c);
            }
        }
        cursor.dispose();
    } catch (XmlException e) {
        throw new POIXMLException(e);
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
Also used : HdrDocument(org.openxmlformats.schemas.wordprocessingml.x2006.main.HdrDocument) InputStream(java.io.InputStream) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) POIXMLException(org.apache.poi.POIXMLException) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) XmlCursor(org.apache.xmlbeans.XmlCursor) CTSdtBlock(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)

Aggregations

POIXMLException (org.apache.poi.POIXMLException)50 XmlException (org.apache.xmlbeans.XmlException)19 IOException (java.io.IOException)18 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)11 InputStream (java.io.InputStream)9 POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)9 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)8 PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 OutputStream (java.io.OutputStream)6 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)6 XmlObject (org.apache.xmlbeans.XmlObject)6 PackagePartName (org.apache.poi.openxml4j.opc.PackagePartName)5 XmlCursor (org.apache.xmlbeans.XmlCursor)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)3 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)3 Workbook (org.apache.poi.ss.usermodel.Workbook)3