Search in sources :

Example 66 with XmlObject

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

the class XWPFFootnote method init.

private void init() {
    XmlCursor cursor = ctFtnEdn.newCursor();
    //copied from XWPFDocument...should centralize this code
    //to avoid duplication
    cursor.selectPath("./*");
    while (cursor.toNextSelection()) {
        XmlObject o = cursor.getObject();
        if (o instanceof CTP) {
            XWPFParagraph p = new XWPFParagraph((CTP) o, this);
            bodyElements.add(p);
            paragraphs.add(p);
        } else if (o instanceof CTTbl) {
            XWPFTable t = new XWPFTable((CTTbl) o, this);
            bodyElements.add(t);
            tables.add(t);
        } else if (o instanceof CTSdtBlock) {
            XWPFSDT c = new XWPFSDT((CTSdtBlock) o, this);
            bodyElements.add(c);
        }
    }
    cursor.dispose();
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) XmlCursor(org.apache.xmlbeans.XmlCursor) CTSdtBlock(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock)

Example 67 with XmlObject

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

the class XSLFSimpleShape method getXfrm.

protected CTTransform2D getXfrm(boolean create) {
    PropertyFetcher<CTTransform2D> fetcher = new PropertyFetcher<CTTransform2D>() {

        @Override
        public boolean fetch(XSLFShape shape) {
            XmlObject xo = shape.getShapeProperties();
            if (xo instanceof CTShapeProperties && ((CTShapeProperties) xo).isSetXfrm()) {
                setValue(((CTShapeProperties) xo).getXfrm());
                return true;
            }
            return false;
        }
    };
    fetchShapeProperty(fetcher);
    CTTransform2D xfrm = fetcher.getValue();
    if (!create || xfrm != null) {
        return xfrm;
    } else {
        XmlObject xo = getShapeProperties();
        if (xo instanceof CTShapeProperties) {
            return ((CTShapeProperties) xo).addNewXfrm();
        } else {
            // ... group shapes have their own getXfrm()
            LOG.log(POILogger.WARN, getClass() + " doesn't have xfrm element.");
            return null;
        }
    }
}
Also used : CTTransform2D(org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) PropertyFetcher(org.apache.poi.xslf.model.PropertyFetcher) XmlObject(org.apache.xmlbeans.XmlObject)

Example 68 with XmlObject

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

the class XSSFWorkbook method setSheetOrder.

/**
     * sets the order of appearance for a given sheet.
     *
     * @param sheetname the name of the sheet to reorder
     * @param pos the position that we want to insert the sheet into (0 based)
     */
@Override
public void setSheetOrder(String sheetname, int pos) {
    int idx = getSheetIndex(sheetname);
    sheets.add(pos, sheets.remove(idx));
    // Reorder CTSheets
    CTSheets ct = workbook.getSheets();
    XmlObject cts = ct.getSheetArray(idx).copy();
    workbook.getSheets().removeSheet(idx);
    CTSheet newcts = ct.insertNewSheet(pos);
    newcts.set(cts);
    //notify sheets
    CTSheet[] sheetArray = ct.getSheetArray();
    for (int i = 0; i < sheetArray.length; i++) {
        sheets.get(i).sheet = sheetArray[i];
    }
    updateNamedRangesAfterSheetReorder(idx, pos);
    updateActiveSheetAfterSheetReorder(idx, pos);
}
Also used : CTSheets(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheets) CTSheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet) XmlObject(org.apache.xmlbeans.XmlObject)

Example 69 with XmlObject

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

the class TestXSSFComment method setString.

@Test
public void setString() {
    XSSFWorkbook wb = new XSSFWorkbook();
    XSSFSheet sh = wb.createSheet();
    XSSFComment comment = sh.createDrawingPatriarch().createCellComment(new XSSFClientAnchor());
    //passing HSSFRichTextString is incorrect
    try {
        comment.setString(new HSSFRichTextString(TEST_RICHTEXTSTRING));
        fail("expected exception");
    } catch (IllegalArgumentException e) {
        assertEquals("Only XSSFRichTextString argument is supported", e.getMessage());
    }
    //simple string argument
    comment.setString(TEST_RICHTEXTSTRING);
    assertEquals(TEST_RICHTEXTSTRING, comment.getString().getString());
    //if the text is already set, it should be overridden, not added twice!
    comment.setString(TEST_RICHTEXTSTRING);
    CTComment ctComment = comment.getCTComment();
    XmlObject[] obj = ctComment.selectPath("declare namespace w='" + NS_SPREADSHEETML + "' .//w:text");
    assertEquals(1, obj.length);
    assertEquals(TEST_RICHTEXTSTRING, comment.getString().getString());
    //sequential call of comment.getString() should return the same XSSFRichTextString object
    assertSame(comment.getString(), comment.getString());
    XSSFRichTextString richText = new XSSFRichTextString(TEST_RICHTEXTSTRING);
    XSSFFont font1 = wb.createFont();
    font1.setFontName("Tahoma");
    font1.setFontHeight(8.5);
    font1.setItalic(true);
    font1.setColor(IndexedColors.BLUE_GREY.getIndex());
    richText.applyFont(0, 5, font1);
    //check the low-level stuff
    comment.setString(richText);
    obj = ctComment.selectPath("declare namespace w='" + NS_SPREADSHEETML + "' .//w:text");
    assertEquals(1, obj.length);
    assertSame(comment.getString(), richText);
    //check that the rich text is set in the comment
    CTRPrElt rPr = richText.getCTRst().getRArray(0).getRPr();
    assertEquals(true, rPr.getIArray(0).getVal());
    assertEquals(8.5, rPr.getSzArray(0).getVal(), 0);
    assertEquals(IndexedColors.BLUE_GREY.getIndex(), rPr.getColorArray(0).getIndexed());
    assertEquals("Tahoma", rPr.getRFontArray(0).getVal());
    assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
}
Also used : HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) CTComment(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) CTRPrElt(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt) XmlObject(org.apache.xmlbeans.XmlObject) Test(org.junit.Test)

Example 70 with XmlObject

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

the class RelationshipTransformService method init.

@Override
public void init(XMLStructure parent, XMLCryptoContext context) throws InvalidAlgorithmParameterException {
    LOG.log(POILogger.DEBUG, "init(parent,context)");
    LOG.log(POILogger.DEBUG, "parent java type: " + parent.getClass().getName());
    DOMStructure domParent = (DOMStructure) parent;
    Node parentNode = domParent.getNode();
    try {
        TransformDocument transDoc = TransformDocument.Factory.parse(parentNode, DEFAULT_XML_OPTIONS);
        XmlObject[] xoList = transDoc.getTransform().selectChildren(RelationshipReferenceDocument.type.getDocumentElementName());
        if (xoList.length == 0) {
            LOG.log(POILogger.WARN, "no RelationshipReference/@SourceId parameters present");
        }
        for (XmlObject xo : xoList) {
            String sourceId = ((CTRelationshipReference) xo).getSourceId();
            LOG.log(POILogger.DEBUG, "sourceId: ", sourceId);
            this.sourceIds.add(sourceId);
        }
    } catch (XmlException e) {
        throw new InvalidAlgorithmParameterException(e);
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) XmlException(org.apache.xmlbeans.XmlException) Node(org.w3c.dom.Node) DOMStructure(javax.xml.crypto.dom.DOMStructure) TransformDocument(org.w3.x2000.x09.xmldsig.TransformDocument) XmlObject(org.apache.xmlbeans.XmlObject) CTRelationshipReference(org.openxmlformats.schemas.xpackage.x2006.digitalSignature.CTRelationshipReference)

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