1 50 51 package org.openlaszlo.iv.flash.xml.apache; 52 53 import org.openlaszlo.iv.flash.api.*; 54 import org.openlaszlo.iv.flash.util.*; 55 56 import org.openlaszlo.iv.flash.xml.XMLHelper; 57 import org.openlaszlo.iv.flash.context.*; 58 59 import java.util.*; 60 61 import javax.xml.transform.TransformerException ; 62 63 import org.w3c.dom.*; 64 import org.w3c.dom.traversal.NodeIterator; 65 66 import org.apache.xpath.*; 67 import org.apache.xpath.objects.XObject; 68 69 76 77 public class XMLContextImpl extends XMLContext { 78 79 private XPathContext xpathContext; 80 81 87 88 public XMLContextImpl( Context parent, Node node ) { 89 super(parent, node); 90 this.xpathContext = new XPathContext(); 91 } 92 93 100 public String getValue( String path ) { 101 103 try { 105 XObject xo = XPathHelper.evalXPath(xpathContext, node, path); 106 107 String res = XPathHelper.getXObjectData(xo); if( res != null ) { 110 return res; 112 } 113 } catch( TransformerException e ) { 114 } catch( Exception e ) { 118 Log.logRB(e); 119 } 120 121 String res = getValueFromParent( path ); 123 return res; 125 } 126 127 135 public List getValueList( String path ) { 136 138 try { 140 NodeList nlist = XPathHelper.selectNodeList(xpathContext, node, path); 142 143 int l = nlist.getLength(); 144 if( l > 0 ) { 145 ArrayList list = new ArrayList(l); 146 for( int i=0; i<l; i++ ) { 148 Node node = nlist.item(i); 149 list.add( new XMLContextImpl( this, node ) ); 151 } 152 153 return list; 154 } else { 155 159 return getValueListFromParent( path ); 160 } 161 } catch ( TransformerException e ) { 162 165 Log.logRB( e ); 166 return getValueListFromParent( path ); 167 } 168 } 169 170 177 184 191 197 204 219 } 220 | Popular Tags |