Search in sources :

Example 91 with XmlObject

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

the class XWPFTableCell method insertNewTbl.

public XWPFTable insertNewTbl(final XmlCursor cursor) {
    if (isCursorInTableCell(cursor)) {
        String uri = CTTbl.type.getName().getNamespaceURI();
        String localPart = "tbl";
        cursor.beginElement(localPart, uri);
        cursor.toParent();
        CTTbl t = (CTTbl) cursor.getObject();
        XWPFTable newT = new XWPFTable(t, this);
        cursor.removeXmlContents();
        XmlObject o = null;
        while (!(o instanceof CTTbl) && (cursor.toPrevSibling())) {
            o = cursor.getObject();
        }
        if (!(o instanceof CTTbl)) {
            tables.add(0, newT);
        } else {
            int pos = tables.indexOf(getTable((CTTbl) o)) + 1;
            tables.add(pos, newT);
        }
        int i = 0;
        XmlCursor cursor2 = t.newCursor();
        while (cursor2.toPrevSibling()) {
            o = cursor2.getObject();
            if (o instanceof CTP || o instanceof CTTbl)
                i++;
        }
        cursor2.dispose();
        bodyElements.add(i, newT);
        cursor2 = t.newCursor();
        cursor.toCursor(cursor2);
        cursor.toEndToken();
        cursor2.dispose();
        return newT;
    }
    return null;
}
Also used : CTTbl(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl) XmlObject(org.apache.xmlbeans.XmlObject) CTP(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 92 with XmlObject

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

the class XWPFTableRow method getTableICells.

/**
     * create and return a list of all XWPFTableCell
     * who belongs to this row
     *
     * @return a list of {@link XWPFTableCell}
     */
public List<ICell> getTableICells() {
    List<ICell> cells = new ArrayList<ICell>();
    //Can't use ctRow.getTcList because that only gets table cells
    //Can't use ctRow.getSdtList because that only gets sdts that are at cell level
    XmlCursor cursor = ctRow.newCursor();
    cursor.selectPath("./*");
    while (cursor.toNextSelection()) {
        XmlObject o = cursor.getObject();
        if (o instanceof CTTc) {
            cells.add(new XWPFTableCell((CTTc) o, this, table.getBody()));
        } else if (o instanceof CTSdtCell) {
            cells.add(new XWPFSDTCell((CTSdtCell) o, this, table.getBody()));
        }
    }
    cursor.dispose();
    return cells;
}
Also used : ArrayList(java.util.ArrayList) XmlObject(org.apache.xmlbeans.XmlObject) CTSdtCell(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtCell) XmlCursor(org.apache.xmlbeans.XmlCursor) CTTc(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc)

Example 93 with XmlObject

use of org.apache.xmlbeans.XmlObject in project ocvn by devgateway.

the class XSSFBarChartData method createNewSerie.

@Override
protected CustomChartSeries createNewSerie(final int id, final int order, final ChartDataSource<?> categories, final ChartDataSource<? extends Number> values) {
    return new AbstractSeries(id, order, categories, values) {

        @Override
        public void addToChart(final XmlObject ctChart) {
            final CTBarChart ctBarChart = (CTBarChart) ctChart;
            final CTBarSer ctBarSer = ctBarChart.addNewSer();
            ctBarSer.addNewIdx().setVal(this.id);
            ctBarSer.addNewOrder().setVal(this.order);
            final CTAxDataSource catDS = ctBarSer.addNewCat();
            XSSFChartUtil.buildAxDataSource(catDS, this.categories);
            final CTNumDataSource valueDS = ctBarSer.addNewVal();
            XSSFChartUtil.buildNumDataSource(valueDS, this.values);
            if (isTitleSet()) {
                ctBarSer.setTx(getCTSerTx());
            }
        }
    };
}
Also used : CTNumDataSource(org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource) CTBarSer(org.openxmlformats.schemas.drawingml.x2006.chart.CTBarSer) XmlObject(org.apache.xmlbeans.XmlObject) CTBarChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTBarChart) CTAxDataSource(org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource)

Example 94 with XmlObject

use of org.apache.xmlbeans.XmlObject in project ocvn by devgateway.

the class XSSFScatterChartData method createNewSerie.

@Override
protected CustomChartSeries createNewSerie(final int id, final int order, final ChartDataSource<?> categories, final ChartDataSource<? extends Number> values) {
    return new AbstractSeries(id, order, categories, values) {

        @Override
        public void addToChart(final XmlObject ctChart) {
            final CTScatterChart ctScatterChart = (CTScatterChart) ctChart;
            final CTScatterSer scatterSer = ctScatterChart.addNewSer();
            scatterSer.addNewIdx().setVal(this.id);
            scatterSer.addNewOrder().setVal(this.order);
            final CTAxDataSource catDS = scatterSer.addNewXVal();
            XSSFChartUtil.buildAxDataSource(catDS, this.categories);
            final CTNumDataSource valueDS = scatterSer.addNewYVal();
            XSSFChartUtil.buildNumDataSource(valueDS, this.values);
            if (isTitleSet()) {
                scatterSer.setTx(getCTSerTx());
            }
        }
    };
}
Also used : CTScatterChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterChart) CTNumDataSource(org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource) CTScatterSer(org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterSer) XmlObject(org.apache.xmlbeans.XmlObject) CTAxDataSource(org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource)

Example 95 with XmlObject

use of org.apache.xmlbeans.XmlObject in project knime-core by knime.

the class PMMLPortObject method fixAttributeAtPath.

/**
 * @param pmml
 *            the PMML file we want to update
 * @param xpath
 *            the Xpath where we want to perform the update
 * @param attribute
 *            string the attribute we want to update
 * @param derivedFieldMap
 *            a map containing the derived field names for column names
 */
private void fixAttributeAtPath(final PMML pmml, final String xpath, final String attribute, final Map<String, String> derivedFieldMap) {
    for (Map.Entry<String, String> entry : derivedFieldMap.entrySet()) {
        String colName = entry.getKey();
        String mappedName = entry.getValue();
        String fullPath = NAMESPACE_DECLARATION + xpath + colName + PATH_END;
        try {
            XmlObject[] xmlDescendants = pmml.selectPath(fullPath);
            for (XmlObject xo : xmlDescendants) {
                XmlCursor xmlCursor = xo.newCursor();
                if (!xmlCursor.isStart()) {
                    throw new RuntimeException("Could not add transformations to the PMML file.");
                }
                xmlCursor.setAttributeText(new QName(attribute), mappedName);
                xmlCursor.dispose();
            }
        } catch (Exception e) {
            throw new RuntimeException("Could not add transformations to the PMML file.", e);
        }
    }
}
Also used : QName(javax.xml.namespace.QName) XmlObject(org.apache.xmlbeans.XmlObject) Map(java.util.Map) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) XmlException(org.apache.xmlbeans.XmlException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XmlCursor(org.apache.xmlbeans.XmlCursor)

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