Search in sources :

Example 76 with XmlObject

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

the class XSSFChart method getTitleText.

/**
     * Returns the title static text, or null if none is set.
     * Note that a title formula may be set instead.
     * Empty text result is for backward compatibility, and could mean the title text is empty or there is a formula instead.
     * Check for a formula first, falling back on text for cleaner logic.
     * @return static title text if set, 
     *         null if there is no title, 
     *         empty string if the title text is empty or the title uses a formula instead
	 */
public XSSFRichTextString getTitleText() {
    if (!chart.isSetTitle()) {
        return null;
    }
    // TODO Do properly
    CTTitle title = chart.getTitle();
    StringBuffer text = new StringBuffer();
    XmlObject[] t = title.selectPath("declare namespace a='" + XSSFDrawing.NAMESPACE_A + "' .//a:t");
    for (int m = 0; m < t.length; m++) {
        NodeList kids = t[m].getDomNode().getChildNodes();
        final int count = kids.getLength();
        for (int n = 0; n < count; n++) {
            Node kid = kids.item(n);
            if (kid instanceof Text) {
                text.append(kid.getNodeValue());
            }
        }
    }
    return new XSSFRichTextString(text.toString());
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) XmlObject(org.apache.xmlbeans.XmlObject) Text(org.w3c.dom.Text) CTTitle(org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle)

Example 77 with XmlObject

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

the class TestXSSFVMLDrawing method testNew.

@Test
public void testNew() throws IOException, XmlException {
    XSSFVMLDrawing vml = new XSSFVMLDrawing();
    List<XmlObject> items = vml.getItems();
    assertEquals(2, items.size());
    assertTrue(items.get(0) instanceof CTShapeLayout);
    CTShapeLayout layout = (CTShapeLayout) items.get(0);
    assertEquals(STExt.EDIT, layout.getExt());
    assertEquals(STExt.EDIT, layout.getIdmap().getExt());
    assertEquals("1", layout.getIdmap().getData());
    assertTrue(items.get(1) instanceof CTShapetype);
    CTShapetype type = (CTShapetype) items.get(1);
    assertEquals("21600,21600", type.getCoordsize());
    assertEquals(202.0f, type.getSpt(), 0);
    assertEquals("m,l,21600r21600,l21600,xe", type.getPath2());
    assertEquals("_x0000_t202", type.getId());
    assertEquals(STTrueFalse.T, type.getPathArray(0).getGradientshapeok());
    assertEquals(STConnectType.RECT, type.getPathArray(0).getConnecttype());
    CTShape shape = vml.newCommentShape();
    assertEquals(3, items.size());
    assertSame(items.get(2), shape);
    assertEquals("#_x0000_t202", shape.getType());
    assertEquals("position:absolute; visibility:hidden", shape.getStyle());
    assertEquals("#ffffe1", shape.getFillcolor());
    assertEquals(STInsetMode.AUTO, shape.getInsetmode());
    assertEquals("#ffffe1", shape.getFillArray(0).getColor());
    CTShadow shadow = shape.getShadowArray(0);
    assertEquals(STTrueFalse.T, shadow.getOn());
    assertEquals("black", shadow.getColor());
    assertEquals(STTrueFalse.T, shadow.getObscured());
    assertEquals(STConnectType.NONE, shape.getPathArray(0).getConnecttype());
    assertEquals("mso-direction-alt:auto", shape.getTextboxArray(0).getStyle());
    CTClientData cldata = shape.getClientDataArray(0);
    assertEquals(STObjectType.NOTE, cldata.getObjectType());
    assertEquals(1, cldata.sizeOfMoveWithCellsArray());
    assertEquals(1, cldata.sizeOfSizeWithCellsArray());
    assertEquals("1, 15, 0, 2, 3, 15, 3, 16", cldata.getAnchorArray(0));
    assertEquals("False", cldata.getAutoFillArray(0).toString());
    assertEquals(0, cldata.getRowArray(0).intValue());
    assertEquals(0, cldata.getColumnArray(0).intValue());
    assertEquals("[]", cldata.getVisibleList().toString());
    cldata.setVisibleArray(new STTrueFalseBlank.Enum[] { STTrueFalseBlank.Enum.forString("True") });
    assertEquals("[True]", cldata.getVisibleList().toString());
    //serialize and read again
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    vml.write(out);
    XSSFVMLDrawing vml2 = new XSSFVMLDrawing();
    vml2.read(new ByteArrayInputStream(out.toByteArray()));
    List<XmlObject> items2 = vml2.getItems();
    assertEquals(3, items2.size());
    assertTrue(items2.get(0) instanceof CTShapeLayout);
    assertTrue(items2.get(1) instanceof CTShapetype);
    assertTrue(items2.get(2) instanceof CTShape);
}
Also used : STTrueFalseBlank(com.microsoft.schemas.office.excel.STTrueFalseBlank) CTShadow(com.microsoft.schemas.vml.CTShadow) CTShapetype(com.microsoft.schemas.vml.CTShapetype) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlObject(org.apache.xmlbeans.XmlObject) CTShape(com.microsoft.schemas.vml.CTShape) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CTShapeLayout(com.microsoft.schemas.office.office.CTShapeLayout) CTClientData(com.microsoft.schemas.office.excel.CTClientData) Test(org.junit.Test)

Example 78 with XmlObject

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

the class XSLFTheme method initialize.

private void initialize() {
    CTBaseStyles elems = _theme.getThemeElements();
    CTColorScheme scheme = elems.getClrScheme();
    // The color scheme is responsible for defining a list of twelve colors. 
    _schemeColors = new HashMap<String, CTColor>(12);
    for (XmlObject o : scheme.selectPath("*")) {
        CTColor c = (CTColor) o;
        String name = c.getDomNode().getLocalName();
        _schemeColors.put(name, c);
    }
}
Also used : CTColorScheme(org.openxmlformats.schemas.drawingml.x2006.main.CTColorScheme) CTBaseStyles(org.openxmlformats.schemas.drawingml.x2006.main.CTBaseStyles) XmlObject(org.apache.xmlbeans.XmlObject) CTColor(org.openxmlformats.schemas.drawingml.x2006.main.CTColor)

Example 79 with XmlObject

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

Example 80 with XmlObject

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

the class XSLFPictureShape method getBlipFill.

protected CTBlipFillProperties getBlipFill() {
    CTPicture ct = (CTPicture) getXmlObject();
    CTBlipFillProperties bfp = ct.getBlipFill();
    if (bfp != null) {
        return bfp;
    }
    String xquery = "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main'; " + "declare namespace mc='http://schemas.openxmlformats.org/markup-compatibility/2006' " + ".//mc:Fallback/p:blipFill";
    XmlObject xo = selectProperty(XmlObject.class, xquery);
    try {
        xo = CTPicture.Factory.parse(xo.getDomNode());
    } catch (XmlException xe) {
        return null;
    }
    return ((CTPicture) xo).getBlipFill();
}
Also used : CTBlipFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties) XmlException(org.apache.xmlbeans.XmlException) CTPicture(org.openxmlformats.schemas.presentationml.x2006.main.CTPicture) 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