Search in sources :

Example 81 with XmlObject

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

the class XSLFSheet method getSpTree.

protected CTGroupShape getSpTree() {
    if (_spTree == null) {
        XmlObject root = getXmlObject();
        XmlObject[] sp = root.selectPath("declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main' .//*/p:spTree");
        if (sp.length == 0)
            throw new IllegalStateException("CTGroupShape was not found");
        _spTree = (CTGroupShape) sp[0];
    }
    return _spTree;
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject)

Example 82 with XmlObject

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

the class XSLFSheet method appendContent.

/**
     * Append content to this sheet.
     *
     * @param src the source sheet
     * @return modified <code>this</code>.
     */
public XSLFSheet appendContent(XSLFSheet src) {
    CTGroupShape spTree = getSpTree();
    int numShapes = getShapes().size();
    CTGroupShape srcTree = src.getSpTree();
    for (XmlObject ch : srcTree.selectPath("*")) {
        if (ch instanceof CTShape) {
            // simple shape
            spTree.addNewSp().set(ch);
        } else if (ch instanceof CTGroupShape) {
            spTree.addNewGrpSp().set(ch);
        } else if (ch instanceof CTConnector) {
            spTree.addNewCxnSp().set(ch);
        } else if (ch instanceof CTPicture) {
            spTree.addNewPic().set(ch);
        } else if (ch instanceof CTGraphicalObjectFrame) {
            spTree.addNewGraphicFrame().set(ch);
        }
    }
    _shapes = null;
    _spTree = null;
    _drawing = null;
    _spTree = null;
    _placeholders = null;
    // recursively update each shape
    List<XSLFShape> tgtShapes = getShapes();
    List<XSLFShape> srcShapes = src.getShapes();
    for (int i = 0; i < srcShapes.size(); i++) {
        XSLFShape s1 = srcShapes.get(i);
        XSLFShape s2 = tgtShapes.get(numShapes + i);
        s2.copy(s1);
    }
    return this;
}
Also used : CTConnector(org.openxmlformats.schemas.presentationml.x2006.main.CTConnector) CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) CTPicture(org.openxmlformats.schemas.presentationml.x2006.main.CTPicture) XmlObject(org.apache.xmlbeans.XmlObject) CTShape(org.openxmlformats.schemas.presentationml.x2006.main.CTShape) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)

Example 83 with XmlObject

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

the class XSLFPictureShape method copy.

@Override
void copy(XSLFShape sh) {
    super.copy(sh);
    XSLFPictureShape p = (XSLFPictureShape) sh;
    String blipId = p.getBlipId();
    String relId = getSheet().importBlip(blipId, p.getSheet().getPackagePart());
    CTPicture ct = (CTPicture) getXmlObject();
    CTBlip blip = getBlipFill().getBlip();
    blip.setEmbed(relId);
    CTApplicationNonVisualDrawingProps nvPr = ct.getNvPicPr().getNvPr();
    if (nvPr.isSetCustDataLst()) {
        // discard any custom tags associated with the picture being copied
        nvPr.unsetCustDataLst();
    }
    if (blip.isSetExtLst()) {
        CTOfficeArtExtensionList extLst = blip.getExtLst();
        for (CTOfficeArtExtension ext : extLst.getExtArray()) {
            String xpath = "declare namespace a14='http://schemas.microsoft.com/office/drawing/2010/main' $this//a14:imgProps/a14:imgLayer";
            XmlObject[] obj = ext.selectPath(xpath);
            if (obj != null && obj.length == 1) {
                XmlCursor c = obj[0].newCursor();
                //selectPath("declare namespace r='http://schemas.openxmlformats.org/officeDocument/2006/relationships' $this//[@embed]");
                String id = c.getAttributeText(new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "embed"));
                String newId = getSheet().importBlip(id, p.getSheet().getPackagePart());
                c.setAttributeText(new QName("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "embed"), newId);
                c.dispose();
            }
        }
    }
}
Also used : CTBlip(org.openxmlformats.schemas.drawingml.x2006.main.CTBlip) QName(javax.xml.namespace.QName) CTPicture(org.openxmlformats.schemas.presentationml.x2006.main.CTPicture) CTApplicationNonVisualDrawingProps(org.openxmlformats.schemas.presentationml.x2006.main.CTApplicationNonVisualDrawingProps) CTOfficeArtExtension(org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeArtExtension) XmlObject(org.apache.xmlbeans.XmlObject) CTOfficeArtExtensionList(org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeArtExtensionList) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 84 with XmlObject

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

the class XSLFPropertiesDelegate method getDelegate.

@SuppressWarnings("unchecked")
private static <T> T getDelegate(Class<T> clazz, XmlObject props) {
    Object obj = null;
    if (props == null) {
        return null;
    } else if (props instanceof CTShapeProperties) {
        obj = new ShapeDelegate((CTShapeProperties) props);
    } else if (props instanceof CTBackgroundProperties) {
        obj = new BackgroundDelegate((CTBackgroundProperties) props);
    } else if (props instanceof CTStyleMatrixReference) {
        obj = new StyleMatrixDelegate((CTStyleMatrixReference) props);
    } else if (props instanceof CTTableCellProperties) {
        obj = new TableCellDelegate((CTTableCellProperties) props);
    } else if (props instanceof CTNoFillProperties || props instanceof CTSolidColorFillProperties || props instanceof CTGradientFillProperties || props instanceof CTBlipFillProperties || props instanceof CTPatternFillProperties || props instanceof CTGroupFillProperties) {
        obj = new FillPartDelegate(props);
    } else if (props instanceof CTFillProperties) {
        obj = new FillDelegate((CTFillProperties) props);
    } else if (props instanceof CTLineProperties) {
        obj = new LineStyleDelegate((CTLineProperties) props);
    } else if (props instanceof CTTextCharacterProperties) {
        obj = new TextCharDelegate((CTTextCharacterProperties) props);
    } else {
        LOG.log(POILogger.ERROR, props.getClass() + " is an unknown properties type");
        return null;
    }
    if (clazz.isInstance(obj)) {
        return (T) obj;
    }
    LOG.log(POILogger.WARN, obj.getClass() + " doesn't implement " + clazz);
    return null;
}
Also used : CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTNoFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTNoFillProperties) CTTextCharacterProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties) CTLineProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTLineProperties) CTBackgroundProperties(org.openxmlformats.schemas.presentationml.x2006.main.CTBackgroundProperties) CTTableCellProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTableCellProperties) CTPatternFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTPatternFillProperties) CTGradientFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTGradientFillProperties) CTBlipFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties) XmlObject(org.apache.xmlbeans.XmlObject) CTStyleMatrixReference(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrixReference) CTFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTFillProperties) CTSolidColorFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties) CTGroupFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTGroupFillProperties)

Example 85 with XmlObject

use of org.apache.xmlbeans.XmlObject 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

XmlObject (org.apache.xmlbeans.XmlObject)102 XmlCursor (org.apache.xmlbeans.XmlCursor)49 XmlException (org.apache.xmlbeans.XmlException)17 Test (org.junit.Test)14 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)13 CTAxDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource)12 CTNumDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource)12 DefaultExchange (org.apache.camel.impl.DefaultExchange)10 ArrayList (java.util.ArrayList)9 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)9 CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)9 CTPicture (org.openxmlformats.schemas.presentationml.x2006.main.CTPicture)7 IOException (java.io.IOException)6 QName (javax.xml.namespace.QName)6 POIXMLException (org.apache.poi.POIXMLException)6 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)6 CTGroupShape (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)6 CTGraphicalObjectFrame (org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame)5 Node (org.w3c.dom.Node)5 CTConnector (org.openxmlformats.schemas.presentationml.x2006.main.CTConnector)4