1 16 19 package org.apache.xpath.functions; 20 21 import java.io.BufferedInputStream ; 22 import java.io.InputStream ; 23 import java.util.Properties ; 24 25 import org.apache.xpath.XPathContext; 26 import org.apache.xpath.objects.XNumber; 27 import org.apache.xpath.objects.XObject; 28 import org.apache.xpath.objects.XString; 29 import org.apache.xpath.res.XPATHErrorResources; 30 31 35 public class FuncSystemProperty extends FunctionOneArg 36 { 37 42 static String XSLT_PROPERTIES = "org/apache/xalan/res/XSLTInfo.properties"; 43 44 52 public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException 53 { 54 55 String fullName = m_arg0.execute(xctxt).str(); 56 int indexOfNSSep = fullName.indexOf(':'); 57 String result; 58 String propName = ""; 59 60 Properties xsltInfo = new Properties (); 63 64 loadPropertyFile(XSLT_PROPERTIES, xsltInfo); 65 66 if (indexOfNSSep > 0) 67 { 68 String prefix = (indexOfNSSep >= 0) 69 ? fullName.substring(0, indexOfNSSep) : ""; 70 String namespace; 71 72 namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix); 73 propName = (indexOfNSSep < 0) 74 ? fullName : fullName.substring(indexOfNSSep + 1); 75 76 if (namespace.startsWith("http://www.w3.org/XSL/Transform") 77 || namespace.equals("http://www.w3.org/1999/XSL/Transform")) 78 { 79 result = xsltInfo.getProperty(propName); 80 81 if (null == result) 82 { 83 warn(xctxt, XPATHErrorResources.WG_PROPERTY_NOT_SUPPORTED, 84 new Object []{ fullName }); 86 return XString.EMPTYSTRING; 87 } 88 } 89 else 90 { 91 warn(xctxt, XPATHErrorResources.WG_DONT_DO_ANYTHING_WITH_NS, 92 new Object []{ namespace, 93 fullName }); 95 try 96 { 97 result = System.getProperty(propName); 98 99 if (null == result) 100 { 101 102 return XString.EMPTYSTRING; 104 } 105 } 106 catch (SecurityException se) 107 { 108 warn(xctxt, XPATHErrorResources.WG_SECURITY_EXCEPTION, 109 new Object []{ fullName }); 111 return XString.EMPTYSTRING; 112 } 113 } 114 } 115 else 116 { 117 try 118 { 119 result = System.getProperty(fullName); 120 121 if (null == result) 122 { 123 124 return XString.EMPTYSTRING; 126 } 127 } 128 catch (SecurityException se) 129 { 130 warn(xctxt, XPATHErrorResources.WG_SECURITY_EXCEPTION, 131 new Object []{ fullName }); 133 return XString.EMPTYSTRING; 134 } 135 } 136 137 if (propName.equals("version") && result.length() > 0) 138 { 139 try 140 { 141 return new XNumber(1.0); 143 } 144 catch (Exception ex) 145 { 146 return new XString(result); 147 } 148 } 149 else 150 return new XString(result); 151 } 152 153 160 public void loadPropertyFile(String file, Properties target) 161 { 162 try 163 { 164 SecuritySupport ss = SecuritySupport.getInstance(); 166 167 InputStream is = ss.getResourceAsStream(ObjectFactory.findClassLoader(), 168 file); 169 170 BufferedInputStream bis = new BufferedInputStream (is); 172 173 target.load(bis); bis.close(); } 176 catch (Exception ex) 177 { 178 throw new org.apache.xml.utils.WrappedRuntimeException(ex); 180 } 181 } 182 } 183 | Popular Tags |