01: package net.sf.saxon.functions;
02:
03: import net.sf.saxon.expr.XPathContext;
04: import net.sf.saxon.om.*;
05: import net.sf.saxon.trans.XPathException;
06: import net.sf.saxon.value.StringValue;
07: import net.sf.saxon.value.RestrictedStringValue;
08: import net.sf.saxon.style.StandardNames;
09:
10: import java.util.ArrayList;
11: import java.util.Iterator;
12: import java.util.List;
13:
14: /**
15: * This class supports fuctions get-in-scope-prefixes()
16: */
17:
18: public class InScopePrefixes extends SystemFunction {
19:
20: /**
21: * Iterator over the results of the expression
22: */
23:
24: public SequenceIterator iterate(XPathContext context)
25: throws XPathException {
26: NodeInfo element = (NodeInfo) argument[0].evaluateItem(context);
27: NamespaceResolver resolver = new InscopeNamespaceResolver(
28: element);
29: Iterator iter = resolver.iteratePrefixes();
30: List list = new ArrayList(10);
31: while (iter.hasNext()) {
32: String prefix = (String) iter.next();
33: if (prefix.equals("")) {
34: list.add(StringValue.EMPTY_STRING);
35: } else {
36: list.add(RestrictedStringValue.makeRestrictedString(
37: prefix, StandardNames.XS_NCNAME, null));
38: }
39: }
40: return new ListIterator(list);
41:
42: }
43:
44: }
45:
46: //
47: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
48: // you may not use this file except in compliance with the License. You may obtain a copy of the
49: // License at http://www.mozilla.org/MPL/
50: //
51: // Software distributed under the License is distributed on an "AS IS" basis,
52: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
53: // See the License for the specific language governing rights and limitations under the License.
54: //
55: // The Original Code is: all this file.
56: //
57: // The Initial Developer of the Original Code is Michael H. Kay
58: //
59: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
60: //
61: // Contributor(s): none.
62: //
|