Search in sources :

Example 11 with XmlObject

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

the class XSLFSheet method removeShape.

/**
     * Removes the specified shape from this sheet, if it is present
     * (optional operation).  If this sheet does not contain the element,
     * it is unchanged.
     *
     * @param xShape shape to be removed from this sheet, if present
     * @return <tt>true</tt> if this sheet contained the specified element
     * @throws IllegalArgumentException if the type of the specified shape
     *         is incompatible with this sheet (optional)
     */
public boolean removeShape(XSLFShape xShape) {
    XmlObject obj = xShape.getXmlObject();
    CTGroupShape spTree = getSpTree();
    if (obj instanceof CTShape) {
        spTree.getSpList().remove(obj);
    } else if (obj instanceof CTGroupShape) {
        spTree.getGrpSpList().remove(obj);
    } else if (obj instanceof CTConnector) {
        spTree.getCxnSpList().remove(obj);
    } else if (obj instanceof CTGraphicalObjectFrame) {
        spTree.getGraphicFrameList().remove(obj);
    } else if (obj instanceof CTPicture) {
        XSLFPictureShape ps = (XSLFPictureShape) xShape;
        removePictureRelation(ps);
        spTree.getPicList().remove(obj);
    } else {
        throw new IllegalArgumentException("Unsupported shape: " + xShape);
    }
    return getShapes().remove(xShape);
}
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 12 with XmlObject

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

the class XSLFSheet method buildShapes.

protected static List<XSLFShape> buildShapes(CTGroupShape spTree, XSLFSheet sheet) {
    List<XSLFShape> shapes = new ArrayList<XSLFShape>();
    for (XmlObject ch : spTree.selectPath("*")) {
        if (ch instanceof CTShape) {
            // simple shape
            XSLFAutoShape shape = XSLFAutoShape.create((CTShape) ch, sheet);
            shapes.add(shape);
        } else if (ch instanceof CTGroupShape) {
            shapes.add(new XSLFGroupShape((CTGroupShape) ch, sheet));
        } else if (ch instanceof CTConnector) {
            shapes.add(new XSLFConnectorShape((CTConnector) ch, sheet));
        } else if (ch instanceof CTPicture) {
            shapes.add(new XSLFPictureShape((CTPicture) ch, sheet));
        } else if (ch instanceof CTGraphicalObjectFrame) {
            XSLFGraphicFrame shape = XSLFGraphicFrame.create((CTGraphicalObjectFrame) ch, sheet);
            shapes.add(shape);
        }
    }
    return shapes;
}
Also used : CTConnector(org.openxmlformats.schemas.presentationml.x2006.main.CTConnector) CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) ArrayList(java.util.ArrayList) CTShape(org.openxmlformats.schemas.presentationml.x2006.main.CTShape) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape) CTPicture(org.openxmlformats.schemas.presentationml.x2006.main.CTPicture) XmlObject(org.apache.xmlbeans.XmlObject)

Example 13 with XmlObject

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

the class XSLFSimpleShape method getLn.

private static CTLineProperties getLn(XSLFShape shape, boolean create) {
    XmlObject pr = shape.getShapeProperties();
    if (!(pr instanceof CTShapeProperties)) {
        LOG.log(POILogger.WARN, shape.getClass() + " doesn't have line properties");
        return null;
    }
    CTShapeProperties spr = (CTShapeProperties) pr;
    return (spr.isSetLn() || !create) ? spr.getLn() : spr.addNewLn();
}
Also used : CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) XmlObject(org.apache.xmlbeans.XmlObject)

Example 14 with XmlObject

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

the class XSLFShape method selectPaint.

protected static PaintStyle selectPaint(CTStyleMatrixReference fillRef, final XSLFTheme theme, boolean isLineStyle, boolean hasPlaceholder) {
    if (fillRef == null)
        return null;
    // The idx attribute refers to the index of a fill style or
    // background fill style within the presentation's style matrix, defined by the fmtScheme element.
    // value of 0 or 1000 indicates no background,
    // values 1-999 refer to the index of a fill style within the fillStyleLst element
    // values 1001 and above refer to the index of a background fill style within the bgFillStyleLst element.
    int idx = (int) fillRef.getIdx();
    CTStyleMatrix matrix = theme.getXmlObject().getThemeElements().getFmtScheme();
    final XmlObject styleLst;
    int childIdx;
    if (idx >= 1 && idx <= 999) {
        childIdx = idx - 1;
        styleLst = (isLineStyle) ? matrix.getLnStyleLst() : matrix.getFillStyleLst();
    } else if (idx >= 1001) {
        childIdx = idx - 1001;
        styleLst = matrix.getBgFillStyleLst();
    } else {
        return null;
    }
    XmlCursor cur = styleLst.newCursor();
    XSLFFillProperties fp = null;
    if (cur.toChild(childIdx)) {
        fp = XSLFPropertiesDelegate.getFillDelegate(cur.getObject());
    }
    cur.dispose();
    CTSchemeColor phClr = fillRef.getSchemeClr();
    PaintStyle res = selectPaint(fp, phClr, theme.getPackagePart(), theme, hasPlaceholder);
    // see http://officeopenxml.com/prSlide-color.php - "Color Placeholders within Themes"
    if (res != null || hasPlaceholder) {
        return res;
    }
    XSLFColor col = new XSLFColor(fillRef, theme, phClr);
    return DrawPaint.createSolidPaint(col.getColorStyle());
}
Also used : CTStyleMatrix(org.openxmlformats.schemas.drawingml.x2006.main.CTStyleMatrix) CTSchemeColor(org.openxmlformats.schemas.drawingml.x2006.main.CTSchemeColor) PaintStyle(org.apache.poi.sl.usermodel.PaintStyle) XmlObject(org.apache.xmlbeans.XmlObject) DrawPaint(org.apache.poi.sl.draw.DrawPaint) GradientPaint(org.apache.poi.sl.usermodel.PaintStyle.GradientPaint) TexturePaint(org.apache.poi.sl.usermodel.PaintStyle.TexturePaint) XSLFFillProperties(org.apache.poi.xslf.usermodel.XSLFPropertiesDelegate.XSLFFillProperties) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 15 with XmlObject

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

the class XSSFDump method dump.

public static void dump(ZipFile zip) throws Exception {
    String zipname = zip.getName();
    int sep = zipname.lastIndexOf('.');
    File root = new File(zipname.substring(0, sep));
    createDirIfMissing(root);
    System.out.println("Dumping to directory " + root);
    Enumeration<? extends ZipEntry> en = zip.entries();
    while (en.hasMoreElements()) {
        ZipEntry entry = en.nextElement();
        String name = entry.getName();
        int idx = name.lastIndexOf('/');
        if (idx != -1) {
            File bs = new File(root, name.substring(0, idx));
            recursivelyCreateDirIfMissing(bs);
        }
        File f = new File(root, entry.getName());
        OutputStream out = new FileOutputStream(f);
        try {
            if (entry.getName().endsWith(".xml") || entry.getName().endsWith(".vml") || entry.getName().endsWith(".rels")) {
                try {
                    Document doc = DocumentHelper.readDocument(zip.getInputStream(entry));
                    XmlObject xml = XmlObject.Factory.parse(doc, DEFAULT_XML_OPTIONS);
                    XmlOptions options = new XmlOptions();
                    options.setSavePrettyPrint();
                    xml.save(out, options);
                } catch (XmlException e) {
                    System.err.println("Failed to parse " + entry.getName() + ", dumping raw content");
                    IOUtils.copy(zip.getInputStream(entry), out);
                }
            } else {
                IOUtils.copy(zip.getInputStream(entry), out);
            }
        } finally {
            out.close();
        }
    }
}
Also used : XmlException(org.apache.xmlbeans.XmlException) ZipEntry(java.util.zip.ZipEntry) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) XmlOptions(org.apache.xmlbeans.XmlOptions) XmlObject(org.apache.xmlbeans.XmlObject) Document(org.w3c.dom.Document) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)87 XmlCursor (org.apache.xmlbeans.XmlCursor)42 Test (org.junit.Test)14 XmlException (org.apache.xmlbeans.XmlException)13 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)13 DefaultExchange (org.apache.camel.impl.DefaultExchange)10 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 POIXMLException (org.apache.poi.POIXMLException)6 CTAxDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource)6 CTNumDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource)6 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)6 CTGroupShape (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)6 ArrayList (java.util.ArrayList)5 QName (javax.xml.namespace.QName)5 CTGraphicalObjectFrame (org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame)5 Node (org.w3c.dom.Node)5 CTConnector (org.openxmlformats.schemas.presentationml.x2006.main.CTConnector)4 CTShape (org.openxmlformats.schemas.presentationml.x2006.main.CTShape)4