Search in sources :

Example 1 with XmlObject

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

Example 2 with XmlObject

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

Example 3 with XmlObject

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

Example 4 with XmlObject

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

Example 5 with XmlObject

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

Aggregations

XmlObject (org.apache.xmlbeans.XmlObject)87 XmlCursor (org.apache.xmlbeans.XmlCursor)42 Test (org.junit.Test)14 XmlException (org.apache.xmlbeans.XmlException)13 CTTbl (org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)13 DefaultExchange (org.apache.camel.impl.DefaultExchange)10 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 POIXMLException (org.apache.poi.POIXMLException)6 CTAxDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource)6 CTNumDataSource (org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource)6 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)6 CTGroupShape (org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape)6 ArrayList (java.util.ArrayList)5 QName (javax.xml.namespace.QName)5 CTGraphicalObjectFrame (org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame)5 Node (org.w3c.dom.Node)5 CTConnector (org.openxmlformats.schemas.presentationml.x2006.main.CTConnector)4 CTShape (org.openxmlformats.schemas.presentationml.x2006.main.CTShape)4