Search in sources :

Example 1 with CTShapetype

use of com.microsoft.schemas.vml.CTShapetype in project poi by apache.

the class XSSFVMLDrawing method read.

@SuppressWarnings("resource")
protected void read(InputStream is) throws IOException, XmlException {
    Document doc;
    try {
        /*
             * This is a seriously sick fix for the fact that some .xlsx files contain raw bits
             * of HTML, without being escaped or properly turned into XML.
             * The result is that they contain things like >br<, which breaks the XML parsing.
             * This very sick InputStream wrapper attempts to spot these go past, and fix them.
             */
        doc = DocumentHelper.readDocument(new ReplacingInputStream(is, "<br>", "<br/>"));
    } catch (SAXException e) {
        throw new XmlException(e.getMessage(), e);
    }
    XmlObject root = XmlObject.Factory.parse(doc, DEFAULT_XML_OPTIONS);
    _qnames = new ArrayList<QName>();
    _items = new ArrayList<XmlObject>();
    for (XmlObject obj : root.selectPath("$this/xml/*")) {
        Node nd = obj.getDomNode();
        QName qname = new QName(nd.getNamespaceURI(), nd.getLocalName());
        if (qname.equals(QNAME_SHAPE_LAYOUT)) {
            _items.add(CTShapeLayout.Factory.parse(obj.xmlText(), DEFAULT_XML_OPTIONS));
        } else if (qname.equals(QNAME_SHAPE_TYPE)) {
            CTShapetype st = CTShapetype.Factory.parse(obj.xmlText(), DEFAULT_XML_OPTIONS);
            _items.add(st);
            _shapeTypeId = st.getId();
        } else if (qname.equals(QNAME_SHAPE)) {
            CTShape shape = CTShape.Factory.parse(obj.xmlText(), DEFAULT_XML_OPTIONS);
            String id = shape.getId();
            if (id != null) {
                Matcher m = ptrn_shapeId.matcher(id);
                if (m.find()) {
                    _shapeId = Math.max(_shapeId, Integer.parseInt(m.group(1)));
                }
            }
            _items.add(shape);
        } else {
            Document doc2;
            try {
                InputSource is2 = new InputSource(new StringReader(obj.xmlText()));
                doc2 = DocumentHelper.readDocument(is2);
            } catch (SAXException e) {
                throw new XmlException(e.getMessage(), e);
            }
            _items.add(XmlObject.Factory.parse(doc2, DEFAULT_XML_OPTIONS));
        }
        _qnames.add(qname);
    }
}
Also used : InputSource(org.xml.sax.InputSource) Matcher(java.util.regex.Matcher) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) CTShape(com.microsoft.schemas.vml.CTShape) Document(org.w3c.dom.Document) ReplacingInputStream(org.apache.poi.util.ReplacingInputStream) SAXException(org.xml.sax.SAXException) CTShapetype(com.microsoft.schemas.vml.CTShapetype) XmlException(org.apache.xmlbeans.XmlException) StringReader(java.io.StringReader) XmlObject(org.apache.xmlbeans.XmlObject)

Example 2 with CTShapetype

use of com.microsoft.schemas.vml.CTShapetype in project poi by apache.

the class XSSFVMLDrawing method newDrawing.

/**
     * Initialize a new Speadsheet VML drawing
     */
private void newDrawing() {
    CTShapeLayout layout = CTShapeLayout.Factory.newInstance();
    layout.setExt(STExt.EDIT);
    CTIdMap idmap = layout.addNewIdmap();
    idmap.setExt(STExt.EDIT);
    idmap.setData("1");
    _items.add(layout);
    _qnames.add(QNAME_SHAPE_LAYOUT);
    CTShapetype shapetype = CTShapetype.Factory.newInstance();
    _shapeTypeId = COMMENT_SHAPE_TYPE_ID;
    shapetype.setId(_shapeTypeId);
    shapetype.setCoordsize("21600,21600");
    shapetype.setSpt(202);
    shapetype.setPath2("m,l,21600r21600,l21600,xe");
    shapetype.addNewStroke().setJoinstyle(STStrokeJoinStyle.MITER);
    CTPath path = shapetype.addNewPath();
    path.setGradientshapeok(STTrueFalse.T);
    path.setConnecttype(STConnectType.RECT);
    _items.add(shapetype);
    _qnames.add(QNAME_SHAPE_TYPE);
}
Also used : CTShapetype(com.microsoft.schemas.vml.CTShapetype) CTIdMap(com.microsoft.schemas.office.office.CTIdMap) CTPath(com.microsoft.schemas.vml.CTPath) CTShapeLayout(com.microsoft.schemas.office.office.CTShapeLayout)

Example 3 with CTShapetype

use of com.microsoft.schemas.vml.CTShapetype in project poi by apache.

the class XWPFHeaderFooterPolicy method getWatermarkParagraph.

/*
     * This is the default Watermark paragraph; the only variable is the text message
     * TODO: manage all the other variables
     */
private XWPFParagraph getWatermarkParagraph(String text, int idx) {
    CTP p = CTP.Factory.newInstance();
    byte[] rsidr = doc.getDocument().getBody().getPArray(0).getRsidR();
    byte[] rsidrdefault = doc.getDocument().getBody().getPArray(0).getRsidRDefault();
    p.setRsidP(rsidr);
    p.setRsidRDefault(rsidrdefault);
    CTPPr pPr = p.addNewPPr();
    pPr.addNewPStyle().setVal("Header");
    // start watermark paragraph
    CTR r = p.addNewR();
    CTRPr rPr = r.addNewRPr();
    rPr.addNewNoProof();
    CTPicture pict = r.addNewPict();
    CTGroup group = CTGroup.Factory.newInstance();
    CTShapetype shapetype = group.addNewShapetype();
    shapetype.setId("_x0000_t136");
    shapetype.setCoordsize("1600,21600");
    shapetype.setSpt(136);
    shapetype.setAdj("10800");
    shapetype.setPath2("m@7,0l@8,0m@5,21600l@6,21600e");
    CTFormulas formulas = shapetype.addNewFormulas();
    formulas.addNewF().setEqn("sum #0 0 10800");
    formulas.addNewF().setEqn("prod #0 2 1");
    formulas.addNewF().setEqn("sum 21600 0 @1");
    formulas.addNewF().setEqn("sum 0 0 @2");
    formulas.addNewF().setEqn("sum 21600 0 @3");
    formulas.addNewF().setEqn("if @0 @3 0");
    formulas.addNewF().setEqn("if @0 21600 @1");
    formulas.addNewF().setEqn("if @0 0 @2");
    formulas.addNewF().setEqn("if @0 @4 21600");
    formulas.addNewF().setEqn("mid @5 @6");
    formulas.addNewF().setEqn("mid @8 @5");
    formulas.addNewF().setEqn("mid @7 @8");
    formulas.addNewF().setEqn("mid @6 @7");
    formulas.addNewF().setEqn("sum @6 0 @5");
    CTPath path = shapetype.addNewPath();
    path.setTextpathok(STTrueFalse.T);
    path.setConnecttype(STConnectType.CUSTOM);
    path.setConnectlocs("@9,0;@10,10800;@11,21600;@12,10800");
    path.setConnectangles("270,180,90,0");
    CTTextPath shapeTypeTextPath = shapetype.addNewTextpath();
    shapeTypeTextPath.setOn(STTrueFalse.T);
    shapeTypeTextPath.setFitshape(STTrueFalse.T);
    CTHandles handles = shapetype.addNewHandles();
    CTH h = handles.addNewH();
    h.setPosition("#0,bottomRight");
    h.setXrange("6629,14971");
    CTLock lock = shapetype.addNewLock();
    lock.setExt(STExt.EDIT);
    CTShape shape = group.addNewShape();
    shape.setId("PowerPlusWaterMarkObject" + idx);
    shape.setSpid("_x0000_s102" + (4 + idx));
    shape.setType("#_x0000_t136");
    shape.setStyle("position:absolute;margin-left:0;margin-top:0;width:415pt;height:207.5pt;z-index:-251654144;mso-wrap-edited:f;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin");
    shape.setWrapcoords("616 5068 390 16297 39 16921 -39 17155 7265 17545 7186 17467 -39 17467 18904 17467 10507 17467 8710 17545 18904 17077 18787 16843 18358 16297 18279 12554 19178 12476 20701 11774 20779 11228 21131 10059 21248 8811 21248 7563 20975 6316 20935 5380 19490 5146 14022 5068 2616 5068");
    shape.setFillcolor("black");
    shape.setStroked(STTrueFalse.FALSE);
    CTTextPath shapeTextPath = shape.addNewTextpath();
    shapeTextPath.setStyle("font-family:&quot;Cambria&quot;;font-size:1pt");
    shapeTextPath.setString(text);
    pict.set(group);
    // end watermark paragraph
    return new XWPFParagraph(p, doc);
}
Also used : CTR(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR) XWPFParagraph(org.apache.poi.xwpf.usermodel.XWPFParagraph) CTLock(com.microsoft.schemas.office.office.CTLock) CTShape(com.microsoft.schemas.vml.CTShape) CTFormulas(com.microsoft.schemas.vml.CTFormulas) CTPath(com.microsoft.schemas.vml.CTPath) CTTextPath(com.microsoft.schemas.vml.CTTextPath) CTRPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr) CTShapetype(com.microsoft.schemas.vml.CTShapetype) CTHandles(com.microsoft.schemas.vml.CTHandles) CTPPr(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr) CTH(com.microsoft.schemas.vml.CTH) CTGroup(com.microsoft.schemas.vml.CTGroup) CTPicture(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPicture) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)

Example 4 with CTShapetype

use of com.microsoft.schemas.vml.CTShapetype 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)

Aggregations

CTShapetype (com.microsoft.schemas.vml.CTShapetype)4 CTShape (com.microsoft.schemas.vml.CTShape)3 CTShapeLayout (com.microsoft.schemas.office.office.CTShapeLayout)2 CTPath (com.microsoft.schemas.vml.CTPath)2 XmlObject (org.apache.xmlbeans.XmlObject)2 CTClientData (com.microsoft.schemas.office.excel.CTClientData)1 STTrueFalseBlank (com.microsoft.schemas.office.excel.STTrueFalseBlank)1 CTIdMap (com.microsoft.schemas.office.office.CTIdMap)1 CTLock (com.microsoft.schemas.office.office.CTLock)1 CTFormulas (com.microsoft.schemas.vml.CTFormulas)1 CTGroup (com.microsoft.schemas.vml.CTGroup)1 CTH (com.microsoft.schemas.vml.CTH)1 CTHandles (com.microsoft.schemas.vml.CTHandles)1 CTShadow (com.microsoft.schemas.vml.CTShadow)1 CTTextPath (com.microsoft.schemas.vml.CTTextPath)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StringReader (java.io.StringReader)1 Matcher (java.util.regex.Matcher)1 QName (javax.xml.namespace.QName)1