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 280555 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/wst/xml/xpath2/processor/internal/types/XSString.java (-14 / +11 lines)
Lines 9-14 Link Here
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0
10
 *     Mukul Gandhi - improved comparison of xs:string with other XDM types
10
 *     Mukul Gandhi - improved comparison of xs:string with other XDM types
11
 *  Jesper S Moller - bug 286061   correct handling of quoted string 
11
 *  Jesper S Moller - bug 286061   correct handling of quoted string 
12
 *  Jesper S Moller - bug 280555 - Add pluggable collation support
12
 *******************************************************************************/
13
 *******************************************************************************/
13
14
14
package org.eclipse.wst.xml.xpath2.processor.internal.types;
15
package org.eclipse.wst.xml.xpath2.processor.internal.types;
Lines 16-24 Link Here
16
import org.eclipse.wst.xml.xpath2.processor.DynamicError;
17
import org.eclipse.wst.xml.xpath2.processor.DynamicError;
17
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
18
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
18
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
19
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
19
import org.eclipse.wst.xml.xpath2.processor.internal.function.*;
20
import org.eclipse.wst.xml.xpath2.processor.internal.function.CmpEq;
20
21
import org.eclipse.wst.xml.xpath2.processor.internal.function.CmpGt;
21
import java.util.*;
22
import org.eclipse.wst.xml.xpath2.processor.internal.function.CmpLt;
22
23
23
/**
24
/**
24
 * A representation of the String datatype
25
 * A representation of the String datatype
Lines 113-132 Link Here
113
114
114
	// 666 indicates death [compare returned empty seq]
115
	// 666 indicates death [compare returned empty seq]
115
	private int do_compare(AnyType arg) throws DynamicError {
116
	private int do_compare(AnyType arg) throws DynamicError {
116
		Collection args = new ArrayList();
117
118
		ResultSequence rs = ResultSequenceFactory.create_new(this);
119
		args.add(rs);
120
		args.add(ResultSequenceFactory.create_new(new 
121
				                       XSString(arg.string_value())));
122
		rs = FnCompare.compare(args);
123
117
124
		if (rs.empty())
118
		ResultSequence rs = ResultSequenceFactory.create_new();
125
			return 666;
119
		// XXX: This can't happen, I guess
120
		if (arg == null) return 666;
126
121
127
		XSInteger i = (XSInteger) rs.first();
122
		// XXX: This must be addressed
123
		// fn:compare need the dynamic context, and we don't have that here (yet!)
124
//		rs = FnCompare.compare_string(collationUri, this, arg, dynamicContext);
128
125
129
		return i.int_value().intValue();
126
		return _value.compareTo(arg.string_value());
130
	}
127
	}
131
128
132
	/**
129
	/**
(-)src/org/eclipse/wst/xml/xpath2/processor/DynamicError.java (-1 / +20 lines)
Lines 12-17 Link Here
12
 *     Jesper Steen Moeller - bug 28149 - add more fn:error info
12
 *     Jesper Steen Moeller - bug 28149 - add more fn:error info
13
 *     Jesper Steen Moller  - bug 281159 - fix document loading and resolving URIs 
13
 *     Jesper Steen Moller  - bug 281159 - fix document loading and resolving URIs 
14
 *     Jesper Steen Moller  - Bug 286062 - Add FOAR0002  
14
 *     Jesper Steen Moller  - Bug 286062 - Add FOAR0002  
15
 *     Jesper Steen Moller  - bug 280555 - Add pluggable collation support
15
 *******************************************************************************/
16
 *******************************************************************************/
16
17
17
package org.eclipse.wst.xml.xpath2.processor;
18
package org.eclipse.wst.xml.xpath2.processor;
Lines 199-205 Link Here
199
200
200
		return new DynamicError("FOCH0001", error);
201
		return new DynamicError("FOCH0001", error);
201
	}
202
	}
202
	
203
204
	/**
205
	 * Returns the dynamic error for an unsupported normalization form
206
	 * 
207
	 * @param collationName
208
	 *            is the error
209
	 * @return the DynamicError.
210
	 * @since 1.1
211
	 * 
212
	 */
213
	public static DynamicError unsupported_collation(String collationName) {
214
		String error = "Unsupported collation URI. ";
215
216
		if (collationName != null)
217
			error += " " + collationName;
218
219
		return new DynamicError("FOCH0002", error);
220
	}
221
203
	/**
222
	/**
204
	 * Returns the dynamic error for an unsupported normalization form
223
	 * Returns the dynamic error for an unsupported normalization form
205
	 * 
224
	 * 
(-)src/org/eclipse/wst/xml/xpath2/processor/DefaultDynamicContext.java (+30 lines)
Lines 13-18 Link Here
13
 *     Jesper Moller- bug 281159 - fix document loading and resolving URIs 
13
 *     Jesper Moller- bug 281159 - fix document loading and resolving URIs 
14
 *     Jesper Moller- bug 286452 - always return the stable date/time from dynamic context
14
 *     Jesper Moller- bug 286452 - always return the stable date/time from dynamic context
15
 *     Jesper Moller- bug 275610 - Avoid big time and memory overhead for externals
15
 *     Jesper Moller- bug 275610 - Avoid big time and memory overhead for externals
16
 *     Jesper Moller- bug 280555 - Add pluggable collation support
16
 *******************************************************************************/
17
 *******************************************************************************/
17
18
18
package org.eclipse.wst.xml.xpath2.processor;
19
package org.eclipse.wst.xml.xpath2.processor;
Lines 23-28 Link Here
23
import org.eclipse.wst.xml.xpath2.processor.internal.function.*;
24
import org.eclipse.wst.xml.xpath2.processor.internal.function.*;
24
import org.eclipse.wst.xml.xpath2.processor.internal.types.*;
25
import org.eclipse.wst.xml.xpath2.processor.internal.types.*;
25
26
27
import java.text.Collator;
26
import java.util.*;
28
import java.util.*;
27
29
28
import org.w3c.dom.*;
30
import org.w3c.dom.*;
Lines 44-49 Link Here
44
	private XSDuration _tz;
46
	private XSDuration _tz;
45
	private Map _loaded_documents;
47
	private Map _loaded_documents;
46
	private GregorianCalendar _current_date_time;
48
	private GregorianCalendar _current_date_time;
49
	private String _default_collation_name = CODEPOINT_COLLATION;
50
	private CollationProvider _collation_provider;
47
51
48
	/**
52
	/**
49
	 * Constructor.
53
	 * Constructor.
Lines 242-245 Link Here
242
		super.set_variable(var, val);
246
		super.set_variable(var, val);
243
	}
247
	}
244
248
249
	public void set_default_collation(String _default_collation) {
250
		this._default_collation_name = _default_collation;
251
	}
252
253
	public String default_collation_name() {
254
		return _default_collation_name;
255
	}
256
257
	// We are explicitly NOT using generics here, in anticipation of JDK1.4 compatibility
258
	private static Comparator CODEPOINT_COMPARATOR = new Comparator() {
259
		
260
		public int compare(Object o1, Object o2) {
261
			return ((String)o1).compareTo((String)o2);
262
		}
263
	};
264
	
265
	public Comparator<Object> get_collation(String uri) {
266
		if (CODEPOINT_COLLATION.equals(uri)) return CODEPOINT_COMPARATOR;
267
		
268
		return _collation_provider != null ? _collation_provider.get_collation(uri) : null;
269
	}
270
	
271
	void set_collation_provider(CollationProvider provider) {
272
		this._collation_provider = provider;
273
	}
274
	
245
}
275
}
(-)src/org/eclipse/wst/xml/xpath2/processor/DynamicContext.java (-6 / +29 lines)
Lines 12-27 Link Here
12
 *     Jesper Moller- bug 281159 - fix document loading and resolving URIs 
12
 *     Jesper Moller- bug 281159 - fix document loading and resolving URIs 
13
 *     Jesper Moller- bug 286452 - always return the stable date/time from dynamic context
13
 *     Jesper Moller- bug 286452 - always return the stable date/time from dynamic context
14
 *     Jesper Moller- bug 275610 - Avoid big time and memory overhead for externals
14
 *     Jesper Moller- bug 275610 - Avoid big time and memory overhead for externals
15
 *     Jesper Moller- bug 280555 - Add pluggable collation support
15
 *******************************************************************************/
16
 *******************************************************************************/
16
17
17
package org.eclipse.wst.xml.xpath2.processor;
18
package org.eclipse.wst.xml.xpath2.processor;
18
19
19
import org.eclipse.wst.xml.xpath2.processor.internal.Focus;
20
import org.eclipse.wst.xml.xpath2.processor.internal.types.*;
21
22
import java.net.URI;
20
import java.net.URI;
23
import java.util.*;
21
import java.util.Collection;
24
import org.w3c.dom.*;
22
import java.util.Comparator;
23
import java.util.GregorianCalendar;
24
25
import org.eclipse.wst.xml.xpath2.processor.internal.Focus;
26
import org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType;
27
import org.eclipse.wst.xml.xpath2.processor.internal.types.QName;
28
import org.eclipse.wst.xml.xpath2.processor.internal.types.XSDuration;
25
29
26
/**
30
/**
27
 * Interface for dynamic context.
31
 * Interface for dynamic context.
Lines 29-34 Link Here
29
public interface DynamicContext extends StaticContext {
33
public interface DynamicContext extends StaticContext {
30
34
31
	/**
35
	/**
36
	 * The default collation which is guaranteed to always be implemented
37
	 */
38
	public static final String CODEPOINT_COLLATION = "http://www.w3.org/2005/xpath-functions/collation/codepoint";
39
40
	/**
32
	 * Get context item.
41
	 * Get context item.
33
	 * 
42
	 * 
34
	 * @return the context item.
43
	 * @return the context item.
Lines 138-143 Link Here
138
	 * @return Focus
147
	 * @return Focus
139
	 */
148
	 */
140
	public Focus focus();
149
	public Focus focus();
141
150
	
151
	/**
152
	 * Return a useful collator for the specified URI
153
	 * 
154
	 * @param uri
155
	 * @return A Jaa collator, or null, if no such Collator exists 
156
	 */
157
	public Comparator<Object> get_collation(String uri); 
158
	
159
	/**
160
	 * Returns the current default collator
161
	 * 
162
	 * @return The default name to use as the collator
163
	 */
164
	public String default_collation_name();
142
165
143
}
166
}
(-)src/org/eclipse/wst/xml/xpath2/processor/internal/function/FnCompare.java (-20 / +36 lines)
Lines 8-17 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0 
9
 *     Andrea Bittau - initial API and implementation from the PsychoPath XPath 2.0 
10
 *     Jesper Steen Moeller - bug 285145 - implement full arity checking
10
 *     Jesper Steen Moeller - bug 285145 - implement full arity checking
11
 *     Jesper Steen Moeller - bug 280555 - Add pluggable collation support
11
 *******************************************************************************/
12
 *******************************************************************************/
12
13
13
package org.eclipse.wst.xml.xpath2.processor.internal.function;
14
package org.eclipse.wst.xml.xpath2.processor.internal.function;
14
15
16
import org.eclipse.wst.xml.xpath2.processor.DynamicContext;
15
import org.eclipse.wst.xml.xpath2.processor.DynamicError;
17
import org.eclipse.wst.xml.xpath2.processor.DynamicError;
16
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
18
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
17
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
19
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
Lines 58-65 Link Here
58
	 * Constructor of FnCompare.
60
	 * Constructor of FnCompare.
59
	 */
61
	 */
60
	public FnCompare() {
62
	public FnCompare() {
61
		// XXX: This should be 2-3 when compare learns how to deal with collations
63
		super(new QName("compare"), 2, 3);
62
		super(new QName("compare"), 2);
63
	}
64
	}
64
65
65
	/**
66
	/**
Lines 73-117 Link Here
73
	 */
74
	 */
74
	@Override
75
	@Override
75
	public ResultSequence evaluate(Collection args) throws DynamicError {
76
	public ResultSequence evaluate(Collection args) throws DynamicError {
76
		return compare(args);
77
		return compare(args, dynamic_context());
77
	}
78
	}
78
79
79
	/**
80
	/**
80
	 * Compare the arguments.
81
	 * Compare the arguments.
81
	 * 
82
	 * 
82
	 * @param args
83
	 * @param args
83
	 *            are compared.
84
	 *            are compared (optional 3rd argument is the collation)
85
	 * @param dynamicContext
86
	 * 	       Current dynamic context 
84
	 * @throws DynamicError
87
	 * @throws DynamicError
85
	 *             Dynamic error.
88
	 *             Dynamic error.
86
	 * @return The result of the comparison of the arguments.
89
	 * @return The result of the comparison of the arguments.
87
	 */
90
	 */
88
	public static ResultSequence compare(Collection args) throws DynamicError {
91
	public static ResultSequence compare(Collection args, DynamicContext dynamicContext) throws DynamicError {
89
		Collection cargs = Function.convert_arguments(args, expected_args());
92
		Collection cargs = Function.convert_arguments(args, expected_args());
90
93
91
		ResultSequence rs = ResultSequenceFactory.create_new();
92
93
		Iterator argiter = cargs.iterator();
94
		Iterator argiter = cargs.iterator();
94
		ResultSequence arg1 = (ResultSequence) argiter.next();
95
		ResultSequence arg1 = (ResultSequence) argiter.next();
95
		if (arg1.empty())
96
			return rs;
97
		ResultSequence arg2 = (ResultSequence) argiter.next();
96
		ResultSequence arg2 = (ResultSequence) argiter.next();
98
		if (arg2.empty())
99
			return rs;
100
97
101
		XSString xstr1 = (XSString) arg1.first();
98
		String collationUri = dynamicContext.default_collation_name();
102
		XSString xstr2 = (XSString) arg2.first();
99
		if (argiter.hasNext()) {
100
			ResultSequence collArg = (ResultSequence) argiter.next();
101
			collationUri = collArg.first().string_value();
102
		}
103
103
104
		// XXX collations!!!
104
		XSString xstr1 = arg1.empty() ? null : (XSString) arg1.first();
105
		int ret = xstr1.value().compareTo(xstr2.value());
105
		XSString xstr2 = arg2.empty() ? null : (XSString) arg2.first();
106
107
		BigInteger result = compare_string(collationUri, xstr1, xstr2, dynamicContext);
108
		if (result != null) {
109
			return ResultSequenceFactory.create_new(new XSInteger(result));
110
		} else {
111
			return ResultSequenceFactory.create_new();			
112
		}
113
	}
114
115
	public static BigInteger compare_string(String collationUri, XSString xstr1,
116
			XSString xstr2, DynamicContext dynamicContext) throws DynamicError {
117
		Comparator collator = dynamicContext.get_collation(collationUri);
118
		if (collator == null) throw DynamicError.unsupported_collation(collationUri);
119
120
		if (xstr1 == null || xstr2 == null) return null;
121
		
122
		int ret = collator.compare(xstr1.value(), xstr2.value());
106
123
107
		if (ret == 0)
124
		if (ret == 0)
108
			rs.add(new XSInteger(BigInteger.valueOf(0)));
125
			return BigInteger.ZERO;
109
		else if (ret < 0)
126
		else if (ret < 0)
110
			rs.add(new XSInteger(BigInteger.valueOf(-1)));
127
			return BigInteger.valueOf(-1);
111
		else
128
		else
112
			rs.add(new XSInteger(BigInteger.valueOf(1)));
129
			return BigInteger.ONE;
113
114
		return rs;
115
	}
130
	}
116
131
117
	/**
132
	/**
Lines 125-130 Link Here
125
			SeqType arg = new SeqType(new XSString(), SeqType.OCC_QMARK);
140
			SeqType arg = new SeqType(new XSString(), SeqType.OCC_QMARK);
126
			_expected_args.add(arg);
141
			_expected_args.add(arg);
127
			_expected_args.add(arg);
142
			_expected_args.add(arg);
143
			_expected_args.add(new SeqType(new XSString(), SeqType.OCC_NONE));
128
		}
144
		}
129
145
130
		return _expected_args;
146
		return _expected_args;
(-)src/org/eclipse/wst/xml/xpath2/processor/internal/function/FnDefaultCollation.java (-4 / +2 lines)
Lines 8-13 Link Here
8
 * Contributors:
8
 * Contributors:
9
 *     David Carver (STAR) - initial API and implementation
9
 *     David Carver (STAR) - initial API and implementation
10
 *     Jesper Steen Moeller - bug 285145 - implement full arity checking
10
 *     Jesper Steen Moeller - bug 285145 - implement full arity checking
11
 *     Jesper Steen Moeller - bug 280555 - Add pluggable collation support
11
 *******************************************************************************/
12
 *******************************************************************************/
12
package org.eclipse.wst.xml.xpath2.processor.internal.function;
13
package org.eclipse.wst.xml.xpath2.processor.internal.function;
13
14
Lines 17-23 Link Here
17
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
18
import org.eclipse.wst.xml.xpath2.processor.ResultSequence;
18
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
19
import org.eclipse.wst.xml.xpath2.processor.ResultSequenceFactory;
19
import org.eclipse.wst.xml.xpath2.processor.internal.types.QName;
20
import org.eclipse.wst.xml.xpath2.processor.internal.types.QName;
20
import org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean;
21
import org.eclipse.wst.xml.xpath2.processor.internal.types.XSString;
21
import org.eclipse.wst.xml.xpath2.processor.internal.types.XSString;
22
22
23
/**
23
/**
Lines 43-50 Link Here
43
 */
43
 */
44
public class FnDefaultCollation extends Function {
44
public class FnDefaultCollation extends Function {
45
45
46
	private static final String DEFAULT_COLLATION = "http://www.w3.org/2005/xpath-functions/collation/codepoint";
47
48
	public FnDefaultCollation() {
46
	public FnDefaultCollation() {
49
		super(new QName("default-collation"), 0);
47
		super(new QName("default-collation"), 0);
50
	}
48
	}
Lines 53-59 Link Here
53
	public ResultSequence evaluate(Collection args) throws DynamicError {
51
	public ResultSequence evaluate(Collection args) throws DynamicError {
54
		assert args.size() >= min_arity() && args.size() <= max_arity();
52
		assert args.size() >= min_arity() && args.size() <= max_arity();
55
		ResultSequence rs = ResultSequenceFactory.create_new();
53
		ResultSequence rs = ResultSequenceFactory.create_new();
56
		rs.add(new XSString(DEFAULT_COLLATION));
54
		rs.add(new XSString(dynamic_context().default_collation_name()));
57
		return rs;
55
		return rs;
58
	}
56
	}
59
57
(-)src/org/eclipse/wst/xml/xpath2/processor/CollationProvider.java (+28 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Jesper Moller, and others
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
 *     Jesper Moller - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.wst.xml.xpath2.processor;
13
14
import java.util.Comparator;
15
16
/**
17
 * Service provider interface for looking up collations from within the dynamic context.
18
 */
19
public interface CollationProvider {
20
	/**
21
	 * Gets the named collator. W3C does not define collation names (yet?) so we are constrained to using an
22
	 * implementation-defined naming scheme.
23
	 * 
24
	 * @param name A URI designating the collation to use
25
	 * @return The collation to use, or null if no such collation exists by this provider
26
	 */
27
	Comparator get_collation(String name);
28
}

Return to bug 280555