1 package com.icl.saxon.functions; 2 import com.icl.saxon.*; 3 import com.icl.saxon.om.NodeInfo; 4 import com.icl.saxon.om.NodeEnumeration; 5 import com.icl.saxon.expr.*; 6 7 import java.util.*; 8 9 10 public class NamespaceURI extends Function { 11 12 15 16 public String getName() { 17 return "namespace-uri"; 18 }; 19 20 24 25 public int getDataType() { 26 return Value.STRING; 27 } 28 29 32 33 public Expression simplify() throws XPathException { 34 int numArgs = checkArgumentCount(0, 1); 35 if (numArgs==1) { 36 argument[0] = argument[0].simplify(); 37 } 38 return this; 39 } 40 41 44 45 public String evaluateAsString(Context c) throws XPathException { 46 String uri; 47 if (getNumberOfArguments()==1) { 48 NodeEnumeration enum = argument[0].enumerate(c, true); 49 if (enum.hasMoreElements()) { 50 uri = enum.nextElement().getURI(); 51 } else { 52 uri = null; 53 } 54 } else { 55 uri = c.getContextNodeInfo().getURI(); 56 } 57 return (uri==null ? "" : uri); 58 } 59 60 63 64 public Value evaluate(Context c) throws XPathException { 65 return new StringValue(evaluateAsString(c)); 66 } 67 68 71 72 public int getDependencies() { 73 if (getNumberOfArguments()==1) { 74 return argument[0].getDependencies(); 75 } else { 76 return Context.CONTEXT_NODE; 77 } 78 } 79 80 83 84 public Expression reduce(int dep, Context c) throws XPathException { 85 if (getNumberOfArguments()==1) { 86 NamespaceURI f = new NamespaceURI(); 87 f.addArgument(argument[0].reduce(dep, c)); 88 f.setStaticContext(getStaticContext()); 89 return f.simplify(); 90 } else { 91 if ((dep & Context.CONTEXT_NODE)!=0) { 92 return evaluate(c); 93 } else { 94 return this; 95 } 96 } 97 } 98 99 } 100 101 102 103 104 | Popular Tags |