1 package com.icl.saxon.functions; 2 import com.icl.saxon.*; 3 import com.icl.saxon.om.Name; 4 import com.icl.saxon.om.Namespace; 5 import com.icl.saxon.expr.*; 6 7 import java.util.*; 8 import java.lang.Math ; 9 import java.text.*; 10 11 12 13 public class SystemProperty extends Function { 14 15 public String getName() { 16 return "system-property"; 17 }; 18 19 23 24 public int getDataType() { 25 return Value.ANY; 26 } 27 28 31 32 public Expression simplify() throws XPathException { 33 checkArgumentCount(1, 1); 34 argument[0] = argument[0].simplify(); 35 if (argument[0] instanceof Value) { 36 return evaluate(null); 37 } 38 return this; 39 } 40 41 44 45 public Value evaluate(Context context) throws XPathException { 46 String name = argument[0].evaluateAsString(context); 47 if (!Name.isQName(name)) { 48 throw new XPathException("Argument " + name + " is not a valid QName"); 49 } 50 String prefix = Name.getPrefix(name); 51 String lname = Name.getLocalName(name); 52 String uri; 53 if (prefix.equals("")) { 54 uri = ""; 55 } else { 56 uri = getStaticContext().getURIForPrefix(prefix); 57 } 58 return getProperty(uri, lname); 59 } 60 61 64 65 public static Value getProperty(String uri, String local) { 66 if (uri.equals(Namespace.XSLT)) { 67 if (local.equals("version")) 68 return new NumericValue(Version.getXSLVersion()); 69 if (local.equals("vendor")) 70 return new StringValue(Version.getProductName()); 71 if (local.equals("vendor-url")) 72 return new StringValue(Version.getWebSiteAddress()); 73 return new StringValue(""); 74 75 } else if (uri.equals("")) { 76 String val = System.getProperty(local); 77 if (val==null) val=""; 78 return new StringValue(val); 79 } else { 80 return new StringValue(""); 81 } 82 } 83 84 87 88 public int getDependencies() { 89 return argument[0].getDependencies(); 90 } 91 92 95 96 public Expression reduce(int dep, Context c) throws XPathException { 97 SystemProperty f = new SystemProperty(); 98 f.addArgument(argument[0].reduce(dep, c)); 99 f.setStaticContext(getStaticContext()); 100 return f; 101 } 102 103 104 } 105 106 107 | Popular Tags |