Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 297975
Collapse All | Expand All

(-)src/org/eclipse/wst/xml/xpath/core/util/NodeListImpl.java (+32 lines)
Added Link Here
1
package org.eclipse.wst.xml.xpath.core.util;
2
3
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
4
import org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType;
5
import org.eclipse.wst.xml.xpath2.processor.internal.types.NodeType;
6
import org.w3c.dom.Node;
7
import org.w3c.dom.NodeList;
8
9
/**
10
 * @since 1.1
11
 */
12
public class NodeListImpl implements NodeList {
13
14
	ResultSequence rs;
15
	
16
	public NodeListImpl(ResultSequence result) {
17
		rs = result;
18
	}
19
	
20
	public int getLength() {
21
		return rs.size();
22
	}
23
24
	public Node item(int arg0) {
25
		AnyType type = rs.get(arg0);
26
		if (type instanceof NodeType) {
27
			NodeType nodeType = (NodeType) type;
28
			return nodeType.node_value();
29
		}
30
		return null;
31
	}
32
}
(-).settings/org.eclipse.core.resources.prefs (-1 / +2 lines)
Lines 1-3 Link Here
1
#Tue Apr 04 03:36:32 EDT 2006
1
#Thu Dec 17 17:55:15 GMT-05:00 2009
2
eclipse.preferences.version=1
2
eclipse.preferences.version=1
3
encoding//src/org/eclipse/wst/xml/xpath/ui/internal/views/XPathComputer.java=UTF-8
3
encoding/<project>=ISO-8859-1
4
encoding/<project>=ISO-8859-1
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 19-25 Link Here
19
 org.eclipse.ui.forms;bundle-version="[3.3.100,4.0.0)",
19
 org.eclipse.ui.forms;bundle-version="[3.3.100,4.0.0)",
20
 org.eclipse.wst.xml.xpath.core;bundle-version="[1.0.0,2.0.0)",
20
 org.eclipse.wst.xml.xpath.core;bundle-version="[1.0.0,2.0.0)",
21
 org.eclipse.core.resources;bundle-version="3.5.0",
21
 org.eclipse.core.resources;bundle-version="3.5.0",
22
 org.apache.xalan;bundle-version="2.7.1"
22
 org.apache.xalan;bundle-version="2.7.1",
23
 org.eclipse.wst.xml.xpath2.processor;bundle-version="1.1.1"
23
Bundle-ActivationPolicy: lazy
24
Bundle-ActivationPolicy: lazy
24
Bundle-RequiredExecutionEnvironment: J2SE-1.5
25
Bundle-RequiredExecutionEnvironment: J2SE-1.5
25
Export-Package: org.eclipse.wst.xml.xpath.ui.internal;x-friends:="org.eclipse.wst.xsl.*",
26
Export-Package: org.eclipse.wst.xml.xpath.ui.internal;x-friends:="org.eclipse.wst.xsl.*",
(-)src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMNodeLabelProvider.java (-119 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005-2007 Orangevolt (www.orangevolt.com)
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Orangevolt (www.orangevolt.com) - XSLT support
10
 *     Jesper Steen Moller - refactored Orangevolt XSLT support into WST
11
 *     
12
 *******************************************************************************/
13
package org.eclipse.wst.xml.xpath.ui.views;
14
15
import org.eclipse.jface.viewers.LabelProvider;
16
import org.eclipse.swt.graphics.Image;
17
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper;
18
import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages;
19
import org.w3c.dom.Attr;
20
import org.w3c.dom.CDATASection;
21
import org.w3c.dom.Comment;
22
import org.w3c.dom.Document;
23
import org.w3c.dom.DocumentType;
24
import org.w3c.dom.Element;
25
import org.w3c.dom.Entity;
26
import org.w3c.dom.NamedNodeMap;
27
import org.w3c.dom.ProcessingInstruction;
28
import org.w3c.dom.Text;
29
30
/**
31
 * 
32
 * @deprecated
33
 */
34
@Deprecated
35
public class DOMNodeLabelProvider extends LabelProvider {
36
	/*
37
	 * (non-Javadoc)
38
	 * 
39
	 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
40
	 */
41
	public String getText(Object element) {
42
		if (element instanceof Document) {
43
			return element.toString();
44
		} else if (element instanceof Element) {
45
			StringBuffer sb = new StringBuffer(((Element) element).getTagName());
46
47
			NamedNodeMap attrs = ((Element) element).getAttributes();
48
			if (attrs.getLength() > 0) {
49
				sb.append("("); //$NON-NLS-1$
50
				for (int i = 0; i < attrs.getLength(); i++) {
51
					Attr attr = (Attr) attrs.item(i);
52
					sb.append('@').append(attr.getName())
53
							.append("=\"").append(attr.getValue()).append('\"'); //$NON-NLS-1$
54
					if (i < attrs.getLength() - 1) {
55
						sb.append(' ');
56
					}
57
				}
58
				sb.append(")"); //$NON-NLS-1$
59
			}
60
			return sb.toString();
61
		} else if (element instanceof Comment) {
62
			return element.toString();
63
		} else if (element instanceof Attr) {
64
			Attr attr = (Attr) element;
65
66
			return "@" + attr.getName() + "=\"" + attr.getValue() + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
67
		} else if (element instanceof CDATASection) {
68
			return element.toString();
69
		} else if (element instanceof Entity) {
70
			return element.toString();
71
		} else if (element instanceof ProcessingInstruction) {
72
			return element.toString();
73
		} else if (element instanceof DocumentType) {
74
			return element.toString();
75
		} else if (element instanceof Text) {
76
			return ((Text) element).getData();
77
		} else {
78
			return element.toString();
79
		}
80
	}
81
82
	/*
83
	 * (non-Javadoc)
84
	 * 
85
	 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
86
	 */
87
	public Image getImage(Object element) {
88
		if (element instanceof Document) {
89
			return XMLEditorPluginImageHelper.getInstance().getImage(
90
					XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC);
91
		} else if (element instanceof Element) {
92
			return XMLEditorPluginImageHelper.getInstance().getImage(
93
					XMLEditorPluginImages.IMG_OBJ_ELEMENT);
94
		} else if (element instanceof Comment) {
95
			return XMLEditorPluginImageHelper.getInstance().getImage(
96
					XMLEditorPluginImages.IMG_OBJ_COMMENT);
97
		} else if (element instanceof CDATASection) {
98
			return XMLEditorPluginImageHelper.getInstance().getImage(
99
					XMLEditorPluginImages.IMG_OBJ_CDATASECTION);
100
		} else if (element instanceof Entity) {
101
			return XMLEditorPluginImageHelper.getInstance().getImage(
102
					XMLEditorPluginImages.IMG_OBJ_ENTITY);
103
		} else if (element instanceof ProcessingInstruction) {
104
			return XMLEditorPluginImageHelper.getInstance().getImage(
105
					XMLEditorPluginImages.IMG_OBJ_PROCESSINGINSTRUCTION);
106
		} else if (element instanceof DocumentType) {
107
			return XMLEditorPluginImageHelper.getInstance().getImage(
108
					XMLEditorPluginImages.IMG_OBJ_DOCTYPE);
109
		} else if (element instanceof Attr) {
110
			return XMLEditorPluginImageHelper.getInstance().getImage(
111
					XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
112
		} else if (element instanceof Text) {
113
			return XMLEditorPluginImageHelper.getInstance().getImage(
114
					XMLEditorPluginImages.IMG_OBJ_TXTEXT);
115
		} else {
116
			return super.getImage(element);
117
		}
118
	}
119
}
(-)src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMTreeContentProvider.java (-64 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005-2007 Orangevolt (www.orangevolt.com)
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Orangevolt (www.orangevolt.com) - XSLT support
10
 *     Jesper Steen Moller - refactored Orangevolt XSLT support into WST
11
 *     
12
 *******************************************************************************/
13
package org.eclipse.wst.xml.xpath.ui.views;
14
15
import org.eclipse.jface.viewers.ITreeContentProvider;
16
import org.eclipse.jface.viewers.Viewer;
17
import org.w3c.dom.Document;
18
import org.w3c.dom.Element;
19
import org.w3c.dom.Node;
20
import org.w3c.dom.NodeList;
21
22
@Deprecated
23
public class DOMTreeContentProvider implements ITreeContentProvider {
24
	Node node = null;
25
26
	static final Object[] NOTHING = new Object[0];
27
28
	private Object[] nodeList2Array(NodeList nl) {
29
		Object[] oa = new Object[nl.getLength()];
30
		for (int i = 0; i < nl.getLength(); i++) {
31
			oa[i] = nl.item(i);
32
		}
33
34
		return oa;
35
	}
36
37
	public Object[] getChildren(Object parentElement) {
38
		return parentElement == null ? NOTHING
39
				: nodeList2Array(((Node) parentElement).getChildNodes());
40
	}
41
42
	public Object getParent(Object element) {
43
		return ((Node) element).getParentNode();
44
	}
45
46
	public boolean hasChildren(Object element) {
47
		return ((Node) element).hasChildNodes();
48
	}
49
50
	public Object[] getElements(Object inputElement) {
51
		return getChildren(inputElement);
52
	}
53
54
	public void dispose() {
55
	}
56
57
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
58
		if (newInput instanceof Element) {
59
			node = (Element) newInput;
60
		} else if (newInput instanceof Document) {
61
			node = ((Document) newInput).getDocumentElement();
62
		}
63
	}
64
}
(-)src-xpath/org/eclipse/wst/xml/xpath/ui/views/DOMViewerFilter.java (-32 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005-2007 Orangevolt (www.orangevolt.com)
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Orangevolt (www.orangevolt.com) - XSLT support
10
 *     Jesper Steen Moller - refactored Orangevolt XSLT support into WST
11
 *     
12
 *******************************************************************************/
13
package org.eclipse.wst.xml.xpath.ui.views;
14
15
import org.eclipse.jface.viewers.Viewer;
16
import org.eclipse.jface.viewers.ViewerFilter;
17
import org.w3c.dom.Text;
18
19
@Deprecated
20
public class DOMViewerFilter extends ViewerFilter {
21
	/*
22
	 * (non-Javadoc)
23
	 * 
24
	 * @see
25
	 * org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers
26
	 * .Viewer, java.lang.Object, java.lang.Object)
27
	 */
28
	public boolean select(Viewer viewer, Object parentElement, Object element) {
29
		return !((element instanceof Text) && ((((Text) element).getData())
30
				.trim().length() == 0));
31
	}
32
}
(-)src-xpath/org/eclipse/wst/xml/xpath/ui/views/XPathNavigator.java (-3 / +3 lines)
Lines 452-460 Link Here
452
		resultTabs.setLayoutData(data);
452
		resultTabs.setLayoutData(data);
453
453
454
		viewer = new TreeViewer(resultTabs, SWT.H_SCROLL | SWT.V_SCROLL);
454
		viewer = new TreeViewer(resultTabs, SWT.H_SCROLL | SWT.V_SCROLL);
455
		viewer.setLabelProvider(new DOMNodeLabelProvider());
455
//		viewer.setLabelProvider(new DOMNodeLabelProvider());
456
		viewer.setContentProvider(new DOMTreeContentProvider());
456
//		viewer.setContentProvider(new DOMTreeContentProvider());
457
		viewer.addFilter(new DOMViewerFilter());
457
//		viewer.addFilter(new DOMViewerFilter());
458
		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
458
		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
459
			/*
459
			/*
460
			 * (non-Javadoc)
460
			 * (non-Javadoc)
(-)src/org/eclipse/wst/xml/xpath/ui/internal/views/XPathComputer.java (-7 / +80 lines)
Lines 34-42 Link Here
34
import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo;
34
import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo;
35
import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable;
35
import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceTable;
36
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
36
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
37
import org.eclipse.wst.xml.xpath.core.util.NodeListImpl;
37
import org.eclipse.wst.xml.xpath.core.util.XSLTXPathHelper;
38
import org.eclipse.wst.xml.xpath.core.util.XSLTXPathHelper;
38
import org.eclipse.wst.xml.xpath.ui.internal.Messages;
39
import org.eclipse.wst.xml.xpath.ui.internal.Messages;
39
import org.eclipse.wst.xml.xpath.ui.internal.XPathUIPlugin;
40
import org.eclipse.wst.xml.xpath.ui.internal.XPathUIPlugin;
41
import org.eclipse.wst.xml.xpath2.processor.DefaultDynamicContext;
42
import org.eclipse.wst.xml.xpath2.processor.DefaultEvaluator;
43
import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
44
import org.eclipse.wst.xml.xpath2.processor.Evaluator;
45
import org.eclipse.wst.xml.xpath2.processor.JFlexCupParser;
46
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
47
import org.eclipse.wst.xml.xpath2.processor.StaticChecker;
48
import org.eclipse.wst.xml.xpath2.processor.StaticNameResolver;
49
import org.eclipse.wst.xml.xpath2.processor.XPathParser;
50
import org.eclipse.wst.xml.xpath2.processor.function.FnFunctionLibrary;
51
import org.eclipse.wst.xml.xpath2.processor.function.XSCtrLibrary;
40
import org.w3c.dom.Document;
52
import org.w3c.dom.Document;
41
import org.w3c.dom.Node;
53
import org.w3c.dom.Node;
42
import org.w3c.dom.NodeList;
54
import org.w3c.dom.NodeList;
Lines 44-49 Link Here
44
public class XPathComputer {
56
public class XPathComputer {
45
	private static final int UPDATE_DELAY = 500;
57
	private static final int UPDATE_DELAY = 500;
46
	private static final byte[] XPATH_LOCK = new byte[0];
58
	private static final byte[] XPATH_LOCK = new byte[0];
59
	private boolean xpath20 = true;
47
	private XPathView xpathView;
60
	private XPathView xpathView;
48
	private IModelStateListener modelStateListener = new IModelStateListener() {
61
	private IModelStateListener modelStateListener = new IModelStateListener() {
49
62
Lines 165-174 Link Here
165
		try {
178
		try {
166
			if ((xp != null) && (node != null)) {
179
			if ((xp != null) && (node != null)) {
167
				synchronized (XPATH_LOCK) {
180
				synchronized (XPATH_LOCK) {
168
				 status = evaluateXPath(xp);
181
					if (xpath20) {
182
						status = evaluateXPath2(xp);
183
					} else {
184
						status = evaluateXPath(xp);
185
					}
169
				}
186
				}
170
			}
187
			}
171
		}  catch (XPathExpressionException e) {
188
		} catch (XPathExpressionException e) {
172
			return Status.CANCEL_STATUS;
189
			return Status.CANCEL_STATUS;
173
		}
190
		}
174
		return status;
191
		return status;
Lines 180-202 Link Here
180
		if (node.getNodeType() == Node.DOCUMENT_NODE) {
197
		if (node.getNodeType() == Node.DOCUMENT_NODE) {
181
			doc = (IDOMDocument) node;
198
			doc = (IDOMDocument) node;
182
		} else {
199
		} else {
183
			doc = (IDOMDocument)node.getOwnerDocument();
200
			doc = (IDOMDocument) node.getOwnerDocument();
184
		}
201
		}
185
		final List<NamespaceInfo> namespaces = XPathUIPlugin.getDefault().getNamespaceInfo(doc);
202
		final List<NamespaceInfo> namespaces = XPathUIPlugin.getDefault()
203
				.getNamespaceInfo(doc);
186
		if (namespaces != null) {
204
		if (namespaces != null) {
187
			newXPath.setNamespaceContext(new DefaultNamespaceContext(namespaces));
205
			newXPath
206
					.setNamespaceContext(new DefaultNamespaceContext(namespaces));
188
		}
207
		}
189
		XPathExpression xpExp = newXPath.compile(xp);
208
		XPathExpression xpExp = newXPath.compile(xp);
190
209
191
		try {
210
		try {
192
			this.nodeList = (NodeList) xpExp.evaluate(node, XPathConstants.NODESET);
211
			this.nodeList = (NodeList) xpExp.evaluate(node,
212
					XPathConstants.NODESET);
193
		} catch (XPathExpressionException xee) {
213
		} catch (XPathExpressionException xee) {
194
			return Status.CANCEL_STATUS;
214
			return Status.CANCEL_STATUS;
195
		}
215
		}
196
		return Status.OK_STATUS;
216
		return Status.OK_STATUS;
197
	}
217
	}
198
218
199
	
219
	protected IStatus evaluateXPath2(String xp) throws XPathExpressionException {
220
221
		IDOMDocument doc;
222
		if (node.getNodeType() == Node.DOCUMENT_NODE) {
223
			doc = (IDOMDocument) node;
224
		} else {
225
			doc = (IDOMDocument) node.getOwnerDocument();
226
		}
227
228
		// Initializing the DynamicContext.
229
		DynamicContext dc = new DefaultDynamicContext(null, doc);
230
		final List<NamespaceInfo> namespaces = XPathUIPlugin.getDefault()
231
				.getNamespaceInfo(doc);
232
		dc.add_namespace("xs", "http://www.w3.org/2001/XMLSchema");
233
234
		if (namespaces != null) {
235
			// Add the defined namespaces
236
			for (NamespaceInfo namespaceinfo : namespaces) {
237
				dc.add_namespace(namespaceinfo.prefix, namespaceinfo.uri);
238
			}
239
		}
240
241
		dc.add_function_library(new FnFunctionLibrary());
242
		dc.add_function_library(new XSCtrLibrary());
243
		
244
		XPathParser xpp = new JFlexCupParser();
245
		
246
		 try {
247
			 // Parses the XPath expression.
248
			 org.eclipse.wst.xml.xpath2.processor.ast.XPath xpath = xpp.parse(xp);
249
			 
250
			 StaticChecker namecheck = new StaticNameResolver(dc);
251
			 namecheck.check(xpath);
252
			 
253
			 // Static Checking the Xpath expression ’Hello World!’ namecheck.check(xp);
254
			 /**
255
			  * Evaluate the XPath 2.0 expression
256
 			  */
257
			 
258
			 // Initializing the evaluator with DynamicContext and the name
259
			 // of the XML document XPexample.xml as parameters.
260
			 Evaluator eval = new DefaultEvaluator(dc, doc);
261
			 
262
			 ResultSequence rs = eval.evaluate(xpath);
263
			 
264
			 this.nodeList = new NodeListImpl(rs);
265
			 
266
		 } catch (Exception ex) {
267
			 throw new XPathExpressionException(ex);
268
		 }
269
270
		return Status.OK_STATUS;
271
	}
272
200
	public void dispose() {
273
	public void dispose() {
201
		if (model != null) {
274
		if (model != null) {
202
			model.removeModelStateListener(modelStateListener);
275
			model.removeModelStateListener(modelStateListener);

Return to bug 297975