![]() |
![]() |
xbean_xpath-2.4.016:54:56.018 INFO jd.cli.Main - Decompiling xbean_xpath-2.4.0.jar package org.apache.xmlbeans.impl.xpath.saxon; import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import javax.xml.transform.TransformerException; import javax.xml.transform.dom.DOMSource; import net.sf.saxon.Configuration; import net.sf.saxon.dom.NodeWrapper; import net.sf.saxon.om.Item; import net.sf.saxon.om.NodeInfo; import net.sf.saxon.om.VirtualNode; import net.sf.saxon.sxpath.IndependentContext; import net.sf.saxon.sxpath.XPathDynamicContext; import net.sf.saxon.sxpath.XPathEvaluator; import net.sf.saxon.sxpath.XPathExpression; import net.sf.saxon.sxpath.XPathVariable; import net.sf.saxon.value.Value; import org.apache.xmlbeans.impl.store.PathDelegate.SelectPathInterface; import org.w3c.dom.Node; public class XBeansXPath implements PathDelegate.SelectPathInterface { private Object[] namespaceMap; private String path; private String contextVar; private String defaultNS; public XBeansXPath(String path, String contextVar, Map namespaceMap, String defaultNS) { this.path = path; this.contextVar = contextVar; this.defaultNS = defaultNS; this.namespaceMap = namespaceMap.entrySet().toArray(); } public List selectNodes(Object node) { try { Node contextNode = (Node)node; XPathEvaluator xpe = new XPathEvaluator(); Configuration config = new Configuration(); config.setDOMLevel(2); config.setTreeModel(0); IndependentContext sc = new IndependentContext(config); if (defaultNS != null) { sc.setDefaultElementNamespace(defaultNS); } for (int i = 0; i < namespaceMap.length; i++) { Map.Entry entry = (Map.Entry)namespaceMap[i]; sc.declareNamespace((String)entry.getKey(), (String)entry.getValue()); } xpe.setStaticContext(sc); XPathVariable thisVar = xpe.declareVariable("", contextVar); XPathExpression xpath = xpe.createExpression(path); NodeInfo contextItem = config.unravel(new DOMSource(contextNode)); XPathDynamicContext dc = xpath.createDynamicContext(null); dc.setContextItem(contextItem); dc.setVariable(thisVar, contextItem); List saxonNodes = xpath.evaluate(dc); for (ListIterator it = saxonNodes.listIterator(); it.hasNext();) { Object o = it.next(); if ((o instanceof NodeInfo)) { if ((o instanceof NodeWrapper)) { Node n = getUnderlyingNode((NodeWrapper)o); it.set(n); } else { it.set(((NodeInfo)o).getStringValue()); } } else if ((o instanceof Item)) { it.set(Value.convertToJava((Item)o)); } } return saxonNodes; } catch (TransformerException e) { throw new RuntimeException(e); } } public List selectPath(Object node) { return selectNodes(node); } private static Node getUnderlyingNode(VirtualNode v) { Object o = v; while ((o instanceof VirtualNode)) { o = ((VirtualNode)o).getUnderlyingNode(); } return (Node)o; } } /* Location: * Qualified Name: org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath * Java Class Version: 1.4 (48.0) * JD-Core Version: 0.7.1 */ package org.apache.xmlbeans.impl.xquery.saxon; import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import javax.xml.transform.TransformerException; import javax.xml.transform.dom.DOMSource; import net.sf.saxon.Configuration; import net.sf.saxon.dom.NodeOverNodeInfo; import net.sf.saxon.om.NodeInfo; import net.sf.saxon.query.DynamicQueryContext; import net.sf.saxon.query.StaticQueryContext; import net.sf.saxon.query.XQueryExpression; import org.apache.xmlbeans.XmlRuntimeException; import org.apache.xmlbeans.XmlTokenSource; import org.apache.xmlbeans.impl.store.QueryDelegate.QueryInterface; import org.w3c.dom.Node; public class XBeansXQuery implements QueryDelegate.QueryInterface { private XQueryExpression xquery; private String contextVar; private Configuration config; public XBeansXQuery(String query, String contextVar, Integer boundary) { config = new Configuration(); config.setDOMLevel(2); config.setTreeModel(0); StaticQueryContext sc = new StaticQueryContext(config); this.contextVar = contextVar; int bdry = boundary.intValue(); query = query.substring(0, bdry) + "declare variable $" + contextVar + " external;" + query.substring(bdry); try { xquery = sc.compileQuery(query); } catch (TransformerException e) { throw new XmlRuntimeException(e); } } public List execQuery(Object node, Map variableBindings) { try { Node contextNode = (Node)node; NodeInfo contextItem = config.buildDocument(new DOMSource(contextNode)); DynamicQueryContext dc = new DynamicQueryContext(config); dc.setContextItem(contextItem); dc.setParameter(contextVar, contextItem); if (variableBindings != null) { Iterator it = variableBindings.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry)it.next(); String key = (String)entry.getKey(); Object value = entry.getValue(); if ((value instanceof XmlTokenSource)) { Node paramObject = ((XmlTokenSource)value).getDomNode(); dc.setParameter(key, paramObject); } else if ((value instanceof String)) { dc.setParameter(key, value); } } } List saxonNodes = xquery.evaluate(dc); for (ListIterator it = saxonNodes.listIterator(); it.hasNext();) { Object o = it.next(); if ((o instanceof NodeInfo)) { Node n = NodeOverNodeInfo.wrap((NodeInfo)o); it.set(n); } } return saxonNodes; } catch (TransformerException e) { throw new RuntimeException("Error binding " + contextVar, e); } } } /* Location: * Qualified Name: org.apache.xmlbeans.impl.xquery.saxon.XBeansXQuery * Java Class Version: 1.4 (48.0) * JD-Core Version: 0.7.1 */ Further reading...For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.New!JAR listings
|