use of org.apache.xmlbeans.XmlObject in project camel by apache.
the class XmlBeansConverterTest method toXmlObjectFromSource.
@Test
public void toXmlObjectFromSource() throws Exception {
XmlObject result = XmlBeansConverter.toXmlObject(new BytesSource(PAYLOAD.getBytes()), new DefaultExchange(new DefaultCamelContext()));
assertBuyStocks(result);
}
use of org.apache.xmlbeans.XmlObject in project camel by apache.
the class XmlBeansConverterTest method toXmlObjectFromInputStream.
@Test
public void toXmlObjectFromInputStream() throws Exception {
XmlObject result = XmlBeansConverter.toXmlObject(new FileInputStream("src/test/data/buyStocks.xml"), new DefaultExchange(new DefaultCamelContext()));
assertBuyStocks(result);
}
use of org.apache.xmlbeans.XmlObject in project camel by apache.
the class XmlBeansConverterTest method toXmlObjectFromByteBuffer.
@Test
public void toXmlObjectFromByteBuffer() throws Exception {
XmlObject result = XmlBeansConverter.toXmlObject(ByteBuffer.wrap(PAYLOAD.getBytes()), new DefaultExchange(new DefaultCamelContext()));
assertBuyStocks(result);
}
use of org.apache.xmlbeans.XmlObject in project hackpad by dropbox.
the class XML method copy.
/**
*
* @param cursToCopy
* @return
*/
private XmlCursor copy(XmlCursor cursToCopy) {
XmlObject xo = XmlObject.Factory.newInstance();
XmlCursor copyCurs = null;
if (cursToCopy.currentTokenType().isText()) {
try {
// Try just as a textnode, to do that we need to wrap the text in a special fragment tag
// that is not visible from the XmlCursor.
copyCurs = XmlObject.Factory.parse("<x:fragment xmlns:x=\"http://www.openuri.org/fragment\">" + cursToCopy.getChars() + "</x:fragment>").newCursor();
if (!cursToCopy.toNextSibling()) {
if (cursToCopy.currentTokenType().isText()) {
// It's not an element it's text so skip it.
cursToCopy.toNextToken();
}
}
} catch (Exception ex) {
throw ScriptRuntime.typeError(ex.getMessage());
}
} else {
copyCurs = xo.newCursor();
copyCurs.toFirstContentToken();
if (cursToCopy.currentTokenType() == XmlCursor.TokenType.STARTDOC) {
cursToCopy.toNextToken();
}
cursToCopy.copyXml(copyCurs);
if (// If element skip element.
!cursToCopy.toNextSibling()) {
if (cursToCopy.currentTokenType().isText()) {
// It's not an element it's text so skip it.
cursToCopy.toNextToken();
}
}
}
copyCurs.toStartDoc();
copyCurs.toFirstContentToken();
return copyCurs;
}
use of org.apache.xmlbeans.XmlObject in project hackpad by dropbox.
the class XMLLibImpl method escapeAttributeValue.
/**
* Escapes the reserved characters in a value of an attribute
*
* @param value Unescaped text
* @return The escaped text
*/
public String escapeAttributeValue(Object value) {
String text = ScriptRuntime.toString(value);
if (text.length() == 0)
return "";
XmlObject xo = XmlObject.Factory.newInstance();
XmlCursor cursor = xo.newCursor();
cursor.toNextToken();
cursor.beginElement("a");
cursor.insertAttributeWithValue("a", text);
cursor.dispose();
String elementText = xo.toString();
int begin = elementText.indexOf('"');
int end = elementText.lastIndexOf('"');
return elementText.substring(begin + 1, end);
}
Aggregations