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;
}
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;
}
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());
}
}
};
}
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());
}
}
};
}
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);
}
}
}
Aggregations