Search in sources :

Example 1 with XmlAnyTypeImpl

use of org.apache.xmlbeans.impl.values.XmlAnyTypeImpl in project poi by apache.

the class XSSFDrawing method addShapes.

private void addShapes(XmlCursor cur, List<XSSFShape> lst) {
    try {
        do {
            cur.push();
            if (cur.toFirstChild()) {
                do {
                    XmlObject obj = cur.getObject();
                    XSSFShape shape;
                    if (obj instanceof CTMarker) {
                        // ignore anchor elements
                        continue;
                    } else if (obj instanceof CTPicture) {
                        shape = new XSSFPicture(this, (CTPicture) obj);
                    } else if (obj instanceof CTConnector) {
                        shape = new XSSFConnector(this, (CTConnector) obj);
                    } else if (obj instanceof CTShape) {
                        shape = hasOleLink(obj) ? new XSSFObjectData(this, (CTShape) obj) : new XSSFSimpleShape(this, (CTShape) obj);
                    } else if (obj instanceof CTGraphicalObjectFrame) {
                        shape = new XSSFGraphicFrame(this, (CTGraphicalObjectFrame) obj);
                    } else if (obj instanceof CTGroupShape) {
                        shape = new XSSFShapeGroup(this, (CTGroupShape) obj);
                    } else if (obj instanceof XmlAnyTypeImpl) {
                        LOG.log(POILogger.WARN, "trying to parse AlternateContent, " + "this unlinks the returned Shapes from the underlying xml content, " + "so those shapes can't be used to modify the drawing, " + "i.e. modifications will be ignored!");
                        // XmlAnyTypeImpl is returned for AlternateContent parts, which might contain a CTDrawing
                        cur.push();
                        cur.toFirstChild();
                        XmlCursor cur2 = null;
                        try {
                            // need to parse AlternateContent again, otherwise the child elements aren't typed,
                            // but also XmlAnyTypes
                            CTDrawing alterWS = CTDrawing.Factory.parse(cur.newXMLStreamReader());
                            cur2 = alterWS.newCursor();
                            if (cur2.toFirstChild()) {
                                addShapes(cur2, lst);
                            }
                        } catch (XmlException e) {
                            LOG.log(POILogger.WARN, "unable to parse CTDrawing in alternate content.", e);
                        } finally {
                            if (cur2 != null) {
                                cur2.dispose();
                            }
                            cur.pop();
                        }
                        continue;
                    } else {
                        // ignore anything else
                        continue;
                    }
                    assert (shape != null);
                    shape.anchor = getAnchorFromParent(obj);
                    lst.add(shape);
                } while (cur.toNextSibling());
            }
            cur.pop();
        } while (cur.toNextSibling());
    } finally {
        cur.dispose();
    }
}
Also used : CTMarker(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker) CTConnector(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector) CTGraphicalObjectFrame(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame) CTDrawing(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing) CTShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape) CTGroupShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape) XmlCursor(org.apache.xmlbeans.XmlCursor) XmlException(org.apache.xmlbeans.XmlException) CTPicture(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture) XmlAnyTypeImpl(org.apache.xmlbeans.impl.values.XmlAnyTypeImpl) XmlObject(org.apache.xmlbeans.XmlObject)

Example 2 with XmlAnyTypeImpl

use of org.apache.xmlbeans.impl.values.XmlAnyTypeImpl 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 3 with XmlAnyTypeImpl

use of org.apache.xmlbeans.impl.values.XmlAnyTypeImpl in project poi by apache.

the class XSLFCommonSlideData method getDrawingText.

public List<DrawingTextBody> getDrawingText() {
    CTGroupShape gs = data.getSpTree();
    List<DrawingTextBody> out = new ArrayList<DrawingTextBody>();
    processShape(gs, out);
    for (CTGroupShape shape : gs.getGrpSpArray()) {
        processShape(shape, out);
    }
    for (CTGraphicalObjectFrame frame : gs.getGraphicFrameArray()) {
        CTGraphicalObjectData data = frame.getGraphic().getGraphicData();
        XmlCursor c = data.newCursor();
        c.selectPath("declare namespace pic='" + CTTable.type.getName().getNamespaceURI() + "' .//pic:tbl");
        while (c.toNextSelection()) {
            XmlObject o = c.getObject();
            if (o instanceof XmlAnyTypeImpl) {
                // Pesky XmlBeans bug - see Bugzilla #49934
                try {
                    o = CTTable.Factory.parse(o.toString(), DEFAULT_XML_OPTIONS);
                } catch (XmlException e) {
                    throw new POIXMLException(e);
                }
            }
            if (o instanceof CTTable) {
                DrawingTable table = new DrawingTable((CTTable) o);
                for (DrawingTableRow row : table.getRows()) {
                    for (DrawingTableCell cell : row.getCells()) {
                        DrawingTextBody textBody = cell.getTextBody();
                        out.add(textBody);
                    }
                }
            }
        }
        c.dispose();
    }
    return out;
}
Also used : CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) ArrayList(java.util.ArrayList) POIXMLException(org.apache.poi.POIXMLException) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape) XmlCursor(org.apache.xmlbeans.XmlCursor) CTGraphicalObjectData(org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData) XmlException(org.apache.xmlbeans.XmlException) CTTable(org.openxmlformats.schemas.drawingml.x2006.main.CTTable) XmlAnyTypeImpl(org.apache.xmlbeans.impl.values.XmlAnyTypeImpl) XmlObject(org.apache.xmlbeans.XmlObject)

Aggregations

XmlException (org.apache.xmlbeans.XmlException)3 XmlObject (org.apache.xmlbeans.XmlObject)3 XmlAnyTypeImpl (org.apache.xmlbeans.impl.values.XmlAnyTypeImpl)3 ArrayList (java.util.ArrayList)2 POIXMLException (org.apache.poi.POIXMLException)2 XmlCursor (org.apache.xmlbeans.XmlCursor)2 CTGraphicalObjectData (org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData)1 CTTable (org.openxmlformats.schemas.drawingml.x2006.main.CTTable)1 CTPicture (org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture)1 CTConnector (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector)1 CTDrawing (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTDrawing)1 CTGraphicalObjectFrame (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame)1 CTGroupShape (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape)1 CTMarker (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker)1 CTPicture (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture)1 CTShape (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape)1 CTGraphicalObjectFrame (org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame)1 CTGroupShape (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)1