Search in sources :

Example 51 with XmlObject

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);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) BytesSource(org.apache.camel.BytesSource) XmlObject(org.apache.xmlbeans.XmlObject) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 52 with XmlObject

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);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) XmlObject(org.apache.xmlbeans.XmlObject) FileInputStream(java.io.FileInputStream) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 53 with XmlObject

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);
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) XmlObject(org.apache.xmlbeans.XmlObject) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 54 with XmlObject

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;
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) XmlException(org.apache.xmlbeans.XmlException) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 55 with XmlObject

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);
}
Also used : XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor)

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)102 XmlCursor (org.apache.xmlbeans.XmlCursor)49 XmlException (org.apache.xmlbeans.XmlException)17 Test (org.junit.Test)14 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)13 CTAxDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource)12 CTNumDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource)12 DefaultExchange (org.apache.camel.impl.DefaultExchange)10 ArrayList (java.util.ArrayList)9 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)9 CTP (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP)9 CTPicture (org.openxmlformats.schemas.presentationml.x2006.main.CTPicture)7 IOException (java.io.IOException)6 QName (javax.xml.namespace.QName)6 POIXMLException (org.apache.poi.POIXMLException)6 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)6 CTGroupShape (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)6 CTGraphicalObjectFrame (org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame)5 Node (org.w3c.dom.Node)5 CTConnector (org.openxmlformats.schemas.presentationml.x2006.main.CTConnector)4