KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > functions > NamespaceForPrefix


1 package net.sf.saxon.functions;
2 import net.sf.saxon.expr.XPathContext;
3 import net.sf.saxon.om.InscopeNamespaceResolver;
4 import net.sf.saxon.om.Item;
5 import net.sf.saxon.om.NamespaceResolver;
6 import net.sf.saxon.om.NodeInfo;
7 import net.sf.saxon.trans.XPathException;
8 import net.sf.saxon.value.AnyURIValue;
9
10
11 /**
12 * This class supports the function namespace-uri-for-prefix()
13 */

14
15 public class NamespaceForPrefix extends SystemFunction {
16
17     /**
18      * Evaluate the function
19      * @param context the XPath dynamic context
20      * @return the URI corresponding to the prefix supplied in the first argument, or null
21      * if the prefix is not in scope
22      * @throws XPathException if a failure occurs evaluating the arguments
23      */

24
25     public Item evaluateItem(XPathContext context) throws XPathException {
26         NodeInfo element = (NodeInfo)argument[1].evaluateItem(context);
27         String JavaDoc prefix = argument[0].evaluateItem(context).getStringValue();
28         if (prefix == null) {
29             return null;
30         }
31         NamespaceResolver resolver = new InscopeNamespaceResolver(element);
32         String JavaDoc uri = resolver.getURIForPrefix(prefix, true);
33         if (uri == null) {
34             return null;
35         }
36         return new AnyURIValue(uri);
37     }
38
39 }
40
41 //
42
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
43
// you may not use this file except in compliance with the License. You may obtain a copy of the
44
// License at http://www.mozilla.org/MPL/
45
//
46
// Software distributed under the License is distributed on an "AS IS" basis,
47
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
48
// See the License for the specific language governing rights and limitations under the License.
49
//
50
// The Original Code is: all this file.
51
//
52
// The Initial Developer of the Original Code is Michael H. Kay
53
//
54
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
55
//
56
// Contributor(s): none.
57
//
58
Popular Tags