author | dfuchs |
Thu, 25 Jun 2015 20:06:37 +0200 | |
changeset 31287 | d6581a7c221f |
parent 31284 | e9b8469adb9a |
child 44797 | 8b3b3b911b8a |
permissions | -rw-r--r-- |
6 | 1 |
/* |
2 |
* reserved comment block |
|
3 |
* DO NOT REMOVE OR ALTER! |
|
4 |
*/ |
|
5 |
/* |
|
6 |
* Copyright 1999-2004 The Apache Software Foundation. |
|
7 |
* |
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9 |
* you may not use this file except in compliance with the License. |
|
10 |
* You may obtain a copy of the License at |
|
11 |
* |
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13 |
* |
|
14 |
* Unless required by applicable law or agreed to in writing, software |
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17 |
* See the License for the specific language governing permissions and |
|
18 |
* limitations under the License. |
|
19 |
*/ |
|
20 |
/* |
|
21 |
* $Id: FuncSystemProperty.java,v 1.2.4.2 2005/09/14 20:18:45 jeffsuttor Exp $ |
|
22 |
*/ |
|
23 |
package com.sun.org.apache.xpath.internal.functions; |
|
24 |
||
25 |
import java.io.BufferedInputStream; |
|
26 |
import java.io.InputStream; |
|
27 |
import java.util.Properties; |
|
28 |
||
29 |
import com.sun.org.apache.xpath.internal.XPathContext; |
|
30 |
import com.sun.org.apache.xpath.internal.objects.XObject; |
|
31 |
import com.sun.org.apache.xpath.internal.objects.XString; |
|
32 |
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources; |
|
12458 | 33 |
import com.sun.org.apache.xalan.internal.utils.SecuritySupport; |
6 | 34 |
|
35 |
/** |
|
36 |
* Execute the SystemProperty() function. |
|
37 |
* @xsl.usage advanced |
|
38 |
*/ |
|
39 |
public class FuncSystemProperty extends FunctionOneArg |
|
40 |
{ |
|
41 |
static final long serialVersionUID = 3694874980992204867L; |
|
42 |
/** |
|
43 |
* The path/filename of the property file: XSLTInfo.properties |
|
44 |
* Maintenance note: see also |
|
45 |
* com.sun.org.apache.xalan.internal.processor.TransformerFactoryImpl.XSLT_PROPERTIES |
|
46 |
*/ |
|
47 |
static final String XSLT_PROPERTIES = |
|
48 |
"com/sun/org/apache/xalan/internal/res/XSLTInfo.properties"; |
|
49 |
||
50 |
/** |
|
51 |
* Execute the function. The function must return |
|
52 |
* a valid object. |
|
53 |
* @param xctxt The current execution context. |
|
54 |
* @return A valid XObject. |
|
55 |
* |
|
56 |
* @throws javax.xml.transform.TransformerException |
|
57 |
*/ |
|
58 |
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException |
|
59 |
{ |
|
60 |
||
61 |
String fullName = m_arg0.execute(xctxt).str(); |
|
62 |
int indexOfNSSep = fullName.indexOf(':'); |
|
63 |
String result; |
|
64 |
String propName = ""; |
|
65 |
||
66 |
// List of properties where the name of the |
|
67 |
// property argument is to be looked for. |
|
68 |
Properties xsltInfo = new Properties(); |
|
69 |
||
31284
e9b8469adb9a
8129572: Cleanup usage of getResourceAsStream in jaxp
dfuchs
parents:
25868
diff
changeset
|
70 |
loadPropertyFile(xsltInfo); |
6 | 71 |
|
72 |
if (indexOfNSSep > 0) |
|
73 |
{ |
|
74 |
String prefix = (indexOfNSSep >= 0) |
|
75 |
? fullName.substring(0, indexOfNSSep) : ""; |
|
76 |
String namespace; |
|
77 |
||
78 |
namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix); |
|
79 |
propName = (indexOfNSSep < 0) |
|
80 |
? fullName : fullName.substring(indexOfNSSep + 1); |
|
81 |
||
82 |
if (namespace.startsWith("http://www.w3.org/XSL/Transform") |
|
83 |
|| namespace.equals("http://www.w3.org/1999/XSL/Transform")) |
|
84 |
{ |
|
85 |
result = xsltInfo.getProperty(propName); |
|
86 |
||
87 |
if (null == result) |
|
88 |
{ |
|
89 |
warn(xctxt, XPATHErrorResources.WG_PROPERTY_NOT_SUPPORTED, |
|
90 |
new Object[]{ fullName }); //"XSL Property not supported: "+fullName); |
|
91 |
||
92 |
return XString.EMPTYSTRING; |
|
93 |
} |
|
94 |
} |
|
95 |
else |
|
96 |
{ |
|
97 |
warn(xctxt, XPATHErrorResources.WG_DONT_DO_ANYTHING_WITH_NS, |
|
98 |
new Object[]{ namespace, |
|
99 |
fullName }); //"Don't currently do anything with namespace "+namespace+" in property: "+fullName); |
|
100 |
||
101 |
try |
|
102 |
{ |
|
16953 | 103 |
result = SecuritySupport.getSystemProperty(propName); |
6 | 104 |
|
105 |
if (null == result) |
|
106 |
{ |
|
107 |
||
108 |
// result = System.getenv(propName); |
|
109 |
return XString.EMPTYSTRING; |
|
110 |
} |
|
111 |
} |
|
112 |
catch (SecurityException se) |
|
113 |
{ |
|
114 |
warn(xctxt, XPATHErrorResources.WG_SECURITY_EXCEPTION, |
|
115 |
new Object[]{ fullName }); //"SecurityException when trying to access XSL system property: "+fullName); |
|
116 |
||
117 |
return XString.EMPTYSTRING; |
|
118 |
} |
|
119 |
} |
|
120 |
} |
|
121 |
else |
|
122 |
{ |
|
123 |
try |
|
124 |
{ |
|
16953 | 125 |
result = SecuritySupport.getSystemProperty(fullName); |
6 | 126 |
|
127 |
if (null == result) |
|
128 |
{ |
|
129 |
||
130 |
// result = System.getenv(fullName); |
|
131 |
return XString.EMPTYSTRING; |
|
132 |
} |
|
133 |
} |
|
134 |
catch (SecurityException se) |
|
135 |
{ |
|
136 |
warn(xctxt, XPATHErrorResources.WG_SECURITY_EXCEPTION, |
|
137 |
new Object[]{ fullName }); //"SecurityException when trying to access XSL system property: "+fullName); |
|
138 |
||
139 |
return XString.EMPTYSTRING; |
|
140 |
} |
|
141 |
} |
|
142 |
||
143 |
if (propName.equals("version") && result.length() > 0) |
|
144 |
{ |
|
145 |
try |
|
146 |
{ |
|
147 |
// Needs to return the version number of the spec we conform to. |
|
148 |
return new XString("1.0"); |
|
149 |
} |
|
150 |
catch (Exception ex) |
|
151 |
{ |
|
152 |
return new XString(result); |
|
153 |
} |
|
154 |
} |
|
155 |
else |
|
156 |
return new XString(result); |
|
157 |
} |
|
158 |
||
159 |
/** |
|
31287
d6581a7c221f
8129880: Cleanup usage of Class.getResource in jaxp
dfuchs
parents:
31284
diff
changeset
|
160 |
* Retrieve a property bundle from XSLT_PROPERTIES |
6 | 161 |
* |
162 |
* @param target The target property bag the file will be placed into. |
|
163 |
*/ |
|
31284
e9b8469adb9a
8129572: Cleanup usage of getResourceAsStream in jaxp
dfuchs
parents:
25868
diff
changeset
|
164 |
private void loadPropertyFile(Properties target) |
6 | 165 |
{ |
166 |
try |
|
167 |
{ |
|
31284
e9b8469adb9a
8129572: Cleanup usage of getResourceAsStream in jaxp
dfuchs
parents:
25868
diff
changeset
|
168 |
// Use SecuritySupport class to provide privileged access to property file |
e9b8469adb9a
8129572: Cleanup usage of getResourceAsStream in jaxp
dfuchs
parents:
25868
diff
changeset
|
169 |
InputStream is = SecuritySupport.getResourceAsStream(XSLT_PROPERTIES); |
6 | 170 |
|
171 |
// get a buffered version |
|
31284
e9b8469adb9a
8129572: Cleanup usage of getResourceAsStream in jaxp
dfuchs
parents:
25868
diff
changeset
|
172 |
try (BufferedInputStream bis = new BufferedInputStream(is)) { |
e9b8469adb9a
8129572: Cleanup usage of getResourceAsStream in jaxp
dfuchs
parents:
25868
diff
changeset
|
173 |
target.load(bis); // and load up the property bag from this |
e9b8469adb9a
8129572: Cleanup usage of getResourceAsStream in jaxp
dfuchs
parents:
25868
diff
changeset
|
174 |
} |
6 | 175 |
} |
176 |
catch (Exception ex) |
|
177 |
{ |
|
178 |
// ex.printStackTrace(); |
|
179 |
throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(ex); |
|
180 |
} |
|
181 |
} |
|
182 |
} |