use of org.apache.xmlbeans.XmlObject in project poi by apache.
the class XSSFChart method getTitleText.
/**
* Returns the title static text, or null if none is set.
* Note that a title formula may be set instead.
* Empty text result is for backward compatibility, and could mean the title text is empty or there is a formula instead.
* Check for a formula first, falling back on text for cleaner logic.
* @return static title text if set,
* null if there is no title,
* empty string if the title text is empty or the title uses a formula instead
*/
public XSSFRichTextString getTitleText() {
if (!chart.isSetTitle()) {
return null;
}
// TODO Do properly
CTTitle title = chart.getTitle();
StringBuffer text = new StringBuffer();
XmlObject[] t = title.selectPath("declare namespace a='" + XSSFDrawing.NAMESPACE_A + "' .//a:t");
for (int m = 0; m < t.length; m++) {
NodeList kids = t[m].getDomNode().getChildNodes();
final int count = kids.getLength();
for (int n = 0; n < count; n++) {
Node kid = kids.item(n);
if (kid instanceof Text) {
text.append(kid.getNodeValue());
}
}
}
return new XSSFRichTextString(text.toString());
}
use of org.apache.xmlbeans.XmlObject 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);
}
use of org.apache.xmlbeans.XmlObject in project poi by apache.
the class XSLFTheme method initialize.
private void initialize() {
CTBaseStyles elems = _theme.getThemeElements();
CTColorScheme scheme = elems.getClrScheme();
// The color scheme is responsible for defining a list of twelve colors.
_schemeColors = new HashMap<String, CTColor>(12);
for (XmlObject o : scheme.selectPath("*")) {
CTColor c = (CTColor) o;
String name = c.getDomNode().getLocalName();
_schemeColors.put(name, c);
}
}
use of org.apache.xmlbeans.XmlObject in project poi by apache.
the class XSSFSheet method readOleObject.
/**
* Determine the OleObject which links shapes with embedded resources
*
* @param shapeId the shape id
* @return the CTOleObject of the shape
*/
protected CTOleObject readOleObject(long shapeId) {
if (!getCTWorksheet().isSetOleObjects()) {
return null;
}
// we use a XmlCursor here to handle oleObject with-/out AlternateContent wrappers
String xquery = "declare namespace p='" + XSSFRelation.NS_SPREADSHEETML + "' .//p:oleObject";
XmlCursor cur = getCTWorksheet().getOleObjects().newCursor();
try {
cur.selectPath(xquery);
CTOleObject coo = null;
while (cur.toNextSelection()) {
String sId = cur.getAttributeText(new QName(null, "shapeId"));
if (sId == null || Long.parseLong(sId) != shapeId) {
continue;
}
XmlObject xObj = cur.getObject();
if (xObj instanceof CTOleObject) {
// the unusual case ...
coo = (CTOleObject) xObj;
} else {
XMLStreamReader reader = cur.newXMLStreamReader();
try {
CTOleObjects coos = CTOleObjects.Factory.parse(reader);
if (coos.sizeOfOleObjectArray() == 0) {
continue;
}
coo = coos.getOleObjectArray(0);
} catch (XmlException e) {
logger.log(POILogger.INFO, "can't parse CTOleObjects", e);
} finally {
try {
reader.close();
} catch (XMLStreamException e) {
logger.log(POILogger.INFO, "can't close reader", e);
}
}
}
// which is in the choice element
if (cur.toChild(XSSFRelation.NS_SPREADSHEETML, "objectPr")) {
break;
}
}
return (coo == null) ? null : coo;
} finally {
cur.dispose();
}
}
use of org.apache.xmlbeans.XmlObject in project poi by apache.
the class XSLFPictureShape method getBlipFill.
protected CTBlipFillProperties getBlipFill() {
CTPicture ct = (CTPicture) getXmlObject();
CTBlipFillProperties bfp = ct.getBlipFill();
if (bfp != null) {
return bfp;
}
String xquery = "declare namespace p='http://schemas.openxmlformats.org/presentationml/2006/main'; " + "declare namespace mc='http://schemas.openxmlformats.org/markup-compatibility/2006' " + ".//mc:Fallback/p:blipFill";
XmlObject xo = selectProperty(XmlObject.class, xquery);
try {
xo = CTPicture.Factory.parse(xo.getDomNode());
} catch (XmlException xe) {
return null;
}
return ((CTPicture) xo).getBlipFill();
}
Aggregations