use of org.apache.xmlbeans.XmlObject in project hackpad by dropbox.
the class XML method createEmptyXML.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Public factories for creating a XScript XML object given an XBean cursor.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static XML createEmptyXML(XMLLibImpl lib) {
XScriptAnnotation anno;
XmlObject xo = XmlObject.Factory.newInstance();
XmlCursor curs = xo.newCursor();
try {
anno = new XScriptAnnotation(curs);
curs.setBookmark(anno);
} finally {
curs.dispose();
}
return new XML(lib, anno);
}
use of org.apache.xmlbeans.XmlObject in project hackpad by dropbox.
the class XML method getXmlObject.
XmlObject getXmlObject() {
XmlObject xo;
XmlCursor cursor = newCursor();
try {
xo = cursor.getObject();
} finally {
cursor.dispose();
}
return xo;
}
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 camel by apache.
the class XmlBeansConverterTest method toXmlObjectFromFile.
@Test
public void toXmlObjectFromFile() throws Exception {
XmlObject result = XmlBeansConverter.toXmlObject(new File("src/test/data/buyStocks.xml"), new DefaultExchange(new DefaultCamelContext()));
assertBuyStocks(result);
}
Aggregations