Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 154725 Details for
Bug 297975
[xpath] Need to enhance the XPath View to support XPath 2.0
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Adds rudementry support for XPath 2.0 Processor
xpath20processor.patch (text/plain), 17.80 KB, created by
David Carver
on 2009-12-17 18:57:30 EST
(
hide
)
Description:
Adds rudementry support for XPath 2.0 Processor
Filename:
MIME Type:
Creator:
David Carver
Created:
2009-12-17 18:57:30 EST
Size:
17.80 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.wst.xml.xpath.core >Index: src/org/eclipse/wst/xml/xpath/core/util/NodeListImpl.java >=================================================================== >RCS file: src/org/eclipse/wst/xml/xpath/core/util/NodeListImpl.java >diff -N src/org/eclipse/wst/xml/xpath/core/util/NodeListImpl.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/xml/xpath/core/util/NodeListImpl.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,32 @@ >+package org.eclipse.wst.xml.xpath.core.util; >+ >+import org.eclipse.wst.xml.xpath2.processor.ResultSequence; >+import org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType; >+import org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType; >+import org.w3c.dom.Node; >+import org.w3c.dom.NodeList; >+ >+/** >+ * @since 1.1 >+ */ >+public class NodeListImpl implements NodeList { >+ >+ ResultSequence rs; >+ >+ public NodeListImpl(ResultSequence result) { >+ rs = result; >+ } >+ >+ public int getLength() { >+ return rs.size(); >+ } >+ >+ public Node item(int arg0) { >+ AnyType type = rs.get(arg0); >+ if (type instanceof NodeType) { >+ NodeType nodeType = (NodeType) type; >+ return nodeType.node_value(); >+ } >+ return null; >+ } >+} >#P org.eclipse.wst.xml.xpath.ui >Index: .settings/org.eclipse.core.resources.prefs >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.xpath.ui/.settings/org.eclipse.core.resources.prefs,v >retrieving revision 1.1 >diff -u -r1.1 org.eclipse.core.resources.prefs >--- .settings/org.eclipse.core.resources.prefs 21 Nov 2007 01:46:45 -0000 1.1 >+++ .settings/org.eclipse.core.resources.prefs 17 Dec 2009 23:58:00 -0000 >@@ -1,3 +1,4 @@ >-#Tue Apr 04 03:36:32 EDT 2006 >+#Thu Dec 17 17:55:15 GMT-05:00 2009 > eclipse.preferences.version=1 >+encoding//src/org/eclipse/wst/xml/xpath/ui/internal/views/XPathComputer.java=UTF-8 > encoding/<project>=ISO-8859-1 >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.xpath.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.17 >diff -u -r1.17 MANIFEST.MF >--- META-INF/MANIFEST.MF 17 Dec 2009 16:41:53 -0000 1.17 >+++ META-INF/MANIFEST.MF 17 Dec 2009 23:58:00 -0000 >@@ -19,7 +19,8 @@ > org.eclipse.ui.forms;bundle-version="[3.3.100,4.0.0)", > org.eclipse.wst.xml.xpath.core;bundle-version="[1.0.0,2.0.0)", > org.eclipse.core.resources;bundle-version="3.5.0", >- org.apache.xalan;bundle-version="2.7.1" >+ org.apache.xalan;bundle-version="2.7.1", >+ org.eclipse.wst.xml.xpath2.processor;bundle-version="1.1.1" > Bundle-ActivationPolicy: lazy > Bundle-RequiredExecutionEnvironment: J2SE-1.5 > Export-Package: org.eclipse.wst.xml.xpath.ui.internal;x-friends:="org.eclipse.wst.xsl.*", >Index: src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMNodeLabelProvider.java >=================================================================== >RCS file: src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMNodeLabelProvider.java >diff -N src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMNodeLabelProvider.java >--- src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMNodeLabelProvider.java 17 Dec 2009 16:42:26 -0000 1.4 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,119 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005-2007 Orangevolt (www.orangevolt.com) >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * Orangevolt (www.orangevolt.com) - XSLT support >- * Jesper Steen Moller - refactored Orangevolt XSLT support into WST >- * >- *******************************************************************************/ >-package org.eclipse.wst.xml.xpath.ui.views; >- >-import org.eclipse.jface.viewers.LabelProvider; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; >-import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; >-import org.w3c.dom.Attr; >-import org.w3c.dom.CDATASection; >-import org.w3c.dom.Comment; >-import org.w3c.dom.Document; >-import org.w3c.dom.DocumentType; >-import org.w3c.dom.Element; >-import org.w3c.dom.Entity; >-import org.w3c.dom.NamedNodeMap; >-import org.w3c.dom.ProcessingInstruction; >-import org.w3c.dom.Text; >- >-/** >- * >- * @deprecated >- */ >-@Deprecated >-public class DOMNodeLabelProvider extends LabelProvider { >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) >- */ >- public String getText(Object element) { >- if (element instanceof Document) { >- return element.toString(); >- } else if (element instanceof Element) { >- StringBuffer sb = new StringBuffer(((Element) element).getTagName()); >- >- NamedNodeMap attrs = ((Element) element).getAttributes(); >- if (attrs.getLength() > 0) { >- sb.append("("); //$NON-NLS-1$ >- for (int i = 0; i < attrs.getLength(); i++) { >- Attr attr = (Attr) attrs.item(i); >- sb.append('@').append(attr.getName()) >- .append("=\"").append(attr.getValue()).append('\"'); //$NON-NLS-1$ >- if (i < attrs.getLength() - 1) { >- sb.append(' '); >- } >- } >- sb.append(")"); //$NON-NLS-1$ >- } >- return sb.toString(); >- } else if (element instanceof Comment) { >- return element.toString(); >- } else if (element instanceof Attr) { >- Attr attr = (Attr) element; >- >- return "@" + attr.getName() + "=\"" + attr.getValue() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >- } else if (element instanceof CDATASection) { >- return element.toString(); >- } else if (element instanceof Entity) { >- return element.toString(); >- } else if (element instanceof ProcessingInstruction) { >- return element.toString(); >- } else if (element instanceof DocumentType) { >- return element.toString(); >- } else if (element instanceof Text) { >- return ((Text) element).getData(); >- } else { >- return element.toString(); >- } >- } >- >- /* >- * (non-Javadoc) >- * >- * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) >- */ >- public Image getImage(Object element) { >- if (element instanceof Document) { >- return XMLEditorPluginImageHelper.getInstance().getImage( >- XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC); >- } else if (element instanceof Element) { >- return XMLEditorPluginImageHelper.getInstance().getImage( >- XMLEditorPluginImages.IMG_OBJ_ELEMENT); >- } else if (element instanceof Comment) { >- return XMLEditorPluginImageHelper.getInstance().getImage( >- XMLEditorPluginImages.IMG_OBJ_COMMENT); >- } else if (element instanceof CDATASection) { >- return XMLEditorPluginImageHelper.getInstance().getImage( >- XMLEditorPluginImages.IMG_OBJ_CDATASECTION); >- } else if (element instanceof Entity) { >- return XMLEditorPluginImageHelper.getInstance().getImage( >- XMLEditorPluginImages.IMG_OBJ_ENTITY); >- } else if (element instanceof ProcessingInstruction) { >- return XMLEditorPluginImageHelper.getInstance().getImage( >- XMLEditorPluginImages.IMG_OBJ_PROCESSINGINSTRUCTION); >- } else if (element instanceof DocumentType) { >- return XMLEditorPluginImageHelper.getInstance().getImage( >- XMLEditorPluginImages.IMG_OBJ_DOCTYPE); >- } else if (element instanceof Attr) { >- return XMLEditorPluginImageHelper.getInstance().getImage( >- XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE); >- } else if (element instanceof Text) { >- return XMLEditorPluginImageHelper.getInstance().getImage( >- XMLEditorPluginImages.IMG_OBJ_TXTEXT); >- } else { >- return super.getImage(element); >- } >- } >-} >Index: src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMTreeContentProvider.java >=================================================================== >RCS file: src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMTreeContentProvider.java >diff -N src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMTreeContentProvider.java >--- src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMTreeContentProvider.java 17 Dec 2009 16:41:53 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,64 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005-2007 Orangevolt (www.orangevolt.com) >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * Orangevolt (www.orangevolt.com) - XSLT support >- * Jesper Steen Moller - refactored Orangevolt XSLT support into WST >- * >- *******************************************************************************/ >-package org.eclipse.wst.xml.xpath.ui.views; >- >-import org.eclipse.jface.viewers.ITreeContentProvider; >-import org.eclipse.jface.viewers.Viewer; >-import org.w3c.dom.Document; >-import org.w3c.dom.Element; >-import org.w3c.dom.Node; >-import org.w3c.dom.NodeList; >- >-@Deprecated >-public class DOMTreeContentProvider implements ITreeContentProvider { >- Node node = null; >- >- static final Object[] NOTHING = new Object[0]; >- >- private Object[] nodeList2Array(NodeList nl) { >- Object[] oa = new Object[nl.getLength()]; >- for (int i = 0; i < nl.getLength(); i++) { >- oa[i] = nl.item(i); >- } >- >- return oa; >- } >- >- public Object[] getChildren(Object parentElement) { >- return parentElement == null ? NOTHING >- : nodeList2Array(((Node) parentElement).getChildNodes()); >- } >- >- public Object getParent(Object element) { >- return ((Node) element).getParentNode(); >- } >- >- public boolean hasChildren(Object element) { >- return ((Node) element).hasChildNodes(); >- } >- >- public Object[] getElements(Object inputElement) { >- return getChildren(inputElement); >- } >- >- public void dispose() { >- } >- >- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >- if (newInput instanceof Element) { >- node = (Element) newInput; >- } else if (newInput instanceof Document) { >- node = ((Document) newInput).getDocumentElement(); >- } >- } >-} >\ No newline at end of file >Index: src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMViewerFilter.java >=================================================================== >RCS file: src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMViewerFilter.java >diff -N src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMViewerFilter.java >--- src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMViewerFilter.java 17 Dec 2009 16:41:53 -0000 1.3 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,32 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005-2007 Orangevolt (www.orangevolt.com) >- * All rights reserved. This program and the accompanying materials >- * are made available under the terms of the Eclipse Public License v1.0 >- * which accompanies this distribution, and is available at >- * http://www.eclipse.org/legal/epl-v10.html >- * >- * Contributors: >- * Orangevolt (www.orangevolt.com) - XSLT support >- * Jesper Steen Moller - refactored Orangevolt XSLT support into WST >- * >- *******************************************************************************/ >-package org.eclipse.wst.xml.xpath.ui.views; >- >-import org.eclipse.jface.viewers.Viewer; >-import org.eclipse.jface.viewers.ViewerFilter; >-import org.w3c.dom.Text; >- >-@Deprecated >-public class DOMViewerFilter extends ViewerFilter { >- /* >- * (non-Javadoc) >- * >- * @see >- * org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers >- * .Viewer, java.lang.Object, java.lang.Object) >- */ >- public boolean select(Viewer viewer, Object parentElement, Object element) { >- return !((element instanceof Text) && ((((Text) element).getData()) >- .trim().length() == 0)); >- } >-} >Index: src-xpath/org/eclipse/wst/xml/xpath/ui/views/XPathNavigator.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.xpath.ui/src-xpath/org/eclipse/wst/xml/xpath/ui/views/XPathNavigator.java,v >retrieving revision 1.10 >diff -u -r1.10 XPathNavigator.java >--- src-xpath/org/eclipse/wst/xml/xpath/ui/views/XPathNavigator.java 17 Dec 2009 16:41:53 -0000 1.10 >+++ src-xpath/org/eclipse/wst/xml/xpath/ui/views/XPathNavigator.java 17 Dec 2009 23:58:00 -0000 >@@ -452,9 +452,9 @@ > resultTabs.setLayoutData(data); > > viewer = new TreeViewer(resultTabs, SWT.H_SCROLL | SWT.V_SCROLL); >- viewer.setLabelProvider(new DOMNodeLabelProvider()); >- viewer.setContentProvider(new DOMTreeContentProvider()); >- viewer.addFilter(new DOMViewerFilter()); >+// viewer.setLabelProvider(new DOMNodeLabelProvider()); >+// viewer.setContentProvider(new DOMTreeContentProvider()); >+// viewer.addFilter(new DOMViewerFilter()); > viewer.addSelectionChangedListener(new ISelectionChangedListener() { > /* > * (non-Javadoc) >Index: src/org/eclipse/wst/xml/xpath/ui/internal/views/XPathComputer.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.xpath.ui/src/org/eclipse/wst/xml/xpath/ui/internal/views/XPathComputer.java,v >retrieving revision 1.8 >diff -u -r1.8 XPathComputer.java >--- src/org/eclipse/wst/xml/xpath/ui/internal/views/XPathComputer.java 17 Dec 2009 16:41:52 -0000 1.8 >+++ src/org/eclipse/wst/xml/xpath/ui/internal/views/XPathComputer.java 17 Dec 2009 23:58:00 -0000 >@@ -34,9 +34,21 @@ > import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; > import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable; > import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument; >+import org.eclipse.wst.xml.xpath.core.util.NodeListImpl; > import org.eclipse.wst.xml.xpath.core.util.XSLTXPathHelper; > import org.eclipse.wst.xml.xpath.ui.internal.Messages; > import org.eclipse.wst.xml.xpath.ui.internal.XPathUIPlugin; >+import org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext; >+import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator; >+import org.eclipse.wst.xml.xpath2.processor.DynamicContext; >+import org.eclipse.wst.xml.xpath2.processor.Evaluator; >+import org.eclipse.wst.xml.xpath2.processor.JFlexCupParser; >+import org.eclipse.wst.xml.xpath2.processor.ResultSequence; >+import org.eclipse.wst.xml.xpath2.processor.StaticChecker; >+import org.eclipse.wst.xml.xpath2.processor.StaticNameResolver; >+import org.eclipse.wst.xml.xpath2.processor.XPathParser; >+import org.eclipse.wst.xml.xpath2.processor.function.FnFunctionLibrary; >+import org.eclipse.wst.xml.xpath2.processor.function.XSCtrLibrary; > import org.w3c.dom.Document; > import org.w3c.dom.Node; > import org.w3c.dom.NodeList; >@@ -44,6 +56,7 @@ > public class XPathComputer { > private static final int UPDATE_DELAY = 500; > private static final byte[] XPATH_LOCK = new byte[0]; >+ private boolean xpath20 = true; > private XPathView xpathView; > private IModelStateListener modelStateListener = new IModelStateListener() { > >@@ -165,10 +178,14 @@ > try { > if ((xp != null) && (node != null)) { > synchronized (XPATH_LOCK) { >- status = evaluateXPath(xp); >+ if (xpath20) { >+ status = evaluateXPath2(xp); >+ } else { >+ status = evaluateXPath(xp); >+ } > } > } >- } catch (XPathExpressionException e) { >+ } catch (XPathExpressionException e) { > return Status.CANCEL_STATUS; > } > return status; >@@ -180,23 +197,79 @@ > if (node.getNodeType() == Node.DOCUMENT_NODE) { > doc = (IDOMDocument) node; > } else { >- doc = (IDOMDocument)node.getOwnerDocument(); >+ doc = (IDOMDocument) node.getOwnerDocument(); > } >- final List<NamespaceInfo> namespaces = XPathUIPlugin.getDefault().getNamespaceInfo(doc); >+ final List<NamespaceInfo> namespaces = XPathUIPlugin.getDefault() >+ .getNamespaceInfo(doc); > if (namespaces != null) { >- newXPath.setNamespaceContext(new DefaultNamespaceContext(namespaces)); >+ newXPath >+ .setNamespaceContext(new DefaultNamespaceContext(namespaces)); > } > XPathExpression xpExp = newXPath.compile(xp); > > try { >- this.nodeList = (NodeList) xpExp.evaluate(node, XPathConstants.NODESET); >+ this.nodeList = (NodeList) xpExp.evaluate(node, >+ XPathConstants.NODESET); > } catch (XPathExpressionException xee) { > return Status.CANCEL_STATUS; > } > return Status.OK_STATUS; > } > >- >+ protected IStatus evaluateXPath2(String xp) throws XPathExpressionException { >+ >+ IDOMDocument doc; >+ if (node.getNodeType() == Node.DOCUMENT_NODE) { >+ doc = (IDOMDocument) node; >+ } else { >+ doc = (IDOMDocument) node.getOwnerDocument(); >+ } >+ >+ // Initializing the DynamicContext. >+ DynamicContext dc = new DefaultDynamicContext(null, doc); >+ final List<NamespaceInfo> namespaces = XPathUIPlugin.getDefault() >+ .getNamespaceInfo(doc); >+ dc.add_namespace("xs", "http://www.w3.org/2001/XMLSchema"); >+ >+ if (namespaces != null) { >+ // Add the defined namespaces >+ for (NamespaceInfo namespaceinfo : namespaces) { >+ dc.add_namespace(namespaceinfo.prefix, namespaceinfo.uri); >+ } >+ } >+ >+ dc.add_function_library(new FnFunctionLibrary()); >+ dc.add_function_library(new XSCtrLibrary()); >+ >+ XPathParser xpp = new JFlexCupParser(); >+ >+ try { >+ // Parses the XPath expression. >+ org.eclipse.wst.xml.xpath2.processor.ast.XPath xpath = xpp.parse(xp); >+ >+ StaticChecker namecheck = new StaticNameResolver(dc); >+ namecheck.check(xpath); >+ >+ // Static Checking the Xpath expression âHello World!â namecheck.check(xp); >+ /** >+ * Evaluate the XPath 2.0 expression >+ */ >+ >+ // Initializing the evaluator with DynamicContext and the name >+ // of the XML document XPexample.xml as parameters. >+ Evaluator eval = new DefaultEvaluator(dc, doc); >+ >+ ResultSequence rs = eval.evaluate(xpath); >+ >+ this.nodeList = new NodeListImpl(rs); >+ >+ } catch (Exception ex) { >+ throw new XPathExpressionException(ex); >+ } >+ >+ return Status.OK_STATUS; >+ } >+ > public void dispose() { > if (model != null) { > model.removeModelStateListener(modelStateListener);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 297975
: 154725 |
154726