use of org.apache.xmlbeans.XmlObject in project hackpad by dropbox.
the class XML method newCursor.
/**
*
* @return
*/
private XmlCursor newCursor() {
XmlCursor curs;
if (_anno != null) {
curs = _anno.createCursor();
if (curs == null) {
// Orphaned case.
XmlObject doc = XmlObject.Factory.newInstance();
curs = doc.newCursor();
if (_anno._name != null) {
curs.toNextToken();
curs.insertElement(_anno._name);
curs.toPrevSibling();
}
curs.setBookmark(_anno);
}
} else {
XmlObject doc = XmlObject.Factory.newInstance();
curs = doc.newCursor();
}
return curs;
}
use of org.apache.xmlbeans.XmlObject in project hackpad by dropbox.
the class XMLLibImpl method escapeTextValue.
/**
* Escapes the reserved characters in a value of a text node
*
* @param value Unescaped text
* @return The escaped text
*/
public String escapeTextValue(Object value) {
if (value instanceof XMLObjectImpl) {
return ((XMLObjectImpl) value).toXMLString(0);
}
String text = ScriptRuntime.toString(value);
if (text.length() == 0)
return text;
XmlObject xo = XmlObject.Factory.newInstance();
XmlCursor cursor = xo.newCursor();
cursor.toNextToken();
cursor.beginElement("a");
cursor.insertChars(text);
cursor.dispose();
String elementText = xo.toString();
int begin = elementText.indexOf('>') + 1;
int end = elementText.lastIndexOf('<');
return (begin < end) ? elementText.substring(begin, end) : "";
}
use of org.apache.xmlbeans.XmlObject in project poi by apache.
the class XSLFColor method getRawValue.
private int getRawValue(String elem) {
String query = "declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' $this//a:" + elem;
XmlObject[] obj;
// first ask the context color and if not found, ask the actual color bean
if (_phClr != null) {
obj = _phClr.selectPath(query);
if (obj.length == 1) {
Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
if (attr != null) {
return Integer.parseInt(attr.getNodeValue());
}
}
}
obj = _xmlObject.selectPath(query);
if (obj.length == 1) {
Node attr = obj[0].getDomNode().getAttributes().getNamedItem("val");
if (attr != null) {
return Integer.parseInt(attr.getNodeValue());
}
}
return -1;
}
use of org.apache.xmlbeans.XmlObject in project poi by apache.
the class XSLFSheet method removeShape.
/**
* Removes the specified shape from this sheet, if it is present
* (optional operation). If this sheet does not contain the element,
* it is unchanged.
*
* @param xShape shape to be removed from this sheet, if present
* @return <tt>true</tt> if this sheet contained the specified element
* @throws IllegalArgumentException if the type of the specified shape
* is incompatible with this sheet (optional)
*/
public boolean removeShape(XSLFShape xShape) {
XmlObject obj = xShape.getXmlObject();
CTGroupShape spTree = getSpTree();
if (obj instanceof CTShape) {
spTree.getSpList().remove(obj);
} else if (obj instanceof CTGroupShape) {
spTree.getGrpSpList().remove(obj);
} else if (obj instanceof CTConnector) {
spTree.getCxnSpList().remove(obj);
} else if (obj instanceof CTGraphicalObjectFrame) {
spTree.getGraphicFrameList().remove(obj);
} else if (obj instanceof CTPicture) {
XSLFPictureShape ps = (XSLFPictureShape) xShape;
removePictureRelation(ps);
spTree.getPicList().remove(obj);
} else {
throw new IllegalArgumentException("Unsupported shape: " + xShape);
}
return getShapes().remove(xShape);
}
use of org.apache.xmlbeans.XmlObject in project poi by apache.
the class XSLFSheet method buildShapes.
protected static List<XSLFShape> buildShapes(CTGroupShape spTree, XSLFSheet sheet) {
List<XSLFShape> shapes = new ArrayList<XSLFShape>();
for (XmlObject ch : spTree.selectPath("*")) {
if (ch instanceof CTShape) {
// simple shape
XSLFAutoShape shape = XSLFAutoShape.create((CTShape) ch, sheet);
shapes.add(shape);
} else if (ch instanceof CTGroupShape) {
shapes.add(new XSLFGroupShape((CTGroupShape) ch, sheet));
} else if (ch instanceof CTConnector) {
shapes.add(new XSLFConnectorShape((CTConnector) ch, sheet));
} else if (ch instanceof CTPicture) {
shapes.add(new XSLFPictureShape((CTPicture) ch, sheet));
} else if (ch instanceof CTGraphicalObjectFrame) {
XSLFGraphicFrame shape = XSLFGraphicFrame.create((CTGraphicalObjectFrame) ch, sheet);
shapes.add(shape);
}
}
return shapes;
}
Aggregations