1 17 package org.apache.servicemix.expression; 18 19 import org.apache.xmlbeans.XmlCursor; 20 import org.apache.xmlbeans.XmlObject; 21 import org.apache.xmlbeans.XmlOptions; 22 23 29 public class XMLBeansStringXPathExpression extends XMLBeansXPathExpression { 30 public XMLBeansStringXPathExpression(String xpath) { 31 super(xpath); 32 } 33 34 protected Object evaluateXPath(XmlObject object, String xpath, XmlOptions options) { 35 XmlObject[] xmlObjects = object.selectPath(xpath); 36 if (xmlObjects == null || xmlObjects.length == 0) { 37 return ""; 38 } 39 else if (xmlObjects.length == 1) { 40 return asString(xmlObjects[0]); 41 } 42 else { 43 StringBuffer buffer = new StringBuffer (); 44 for (int i = 0; i < xmlObjects.length; i++) { 45 XmlObject xmlObject = xmlObjects[i]; 46 buffer.append(asString(xmlObject)); 47 } 48 return buffer.toString(); 49 } 50 } 51 52 protected String asString(XmlObject xmlObject) { 53 XmlCursor cursor = xmlObject.newCursor(); 54 return cursor.getTextValue(); 55 } 56 } 57 | Popular Tags |