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