Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
5825b33b
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5825b33b
编写于
10月 24, 2013
作者:
J
joehw
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8004476: XSLT Extension Functions Don't Work in WebStart
Reviewed-by: dfuchs, lancea, alanb
上级
c48482e2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
656 addition
and
0 deletion
+656
-0
test/javax/xml/jaxp/transform/jdk8004476/SecureProcessingTest.xml
...ax/xml/jaxp/transform/jdk8004476/SecureProcessingTest.xml
+2
-0
test/javax/xml/jaxp/transform/jdk8004476/TestBase.java
test/javax/xml/jaxp/transform/jdk8004476/TestBase.java
+82
-0
test/javax/xml/jaxp/transform/jdk8004476/XPathExFuncTest.java
.../javax/xml/jaxp/transform/jdk8004476/XPathExFuncTest.java
+287
-0
test/javax/xml/jaxp/transform/jdk8004476/XSLTExFuncTest.java
test/javax/xml/jaxp/transform/jdk8004476/XSLTExFuncTest.java
+248
-0
test/javax/xml/jaxp/transform/jdk8004476/tokenize.xml
test/javax/xml/jaxp/transform/jdk8004476/tokenize.xml
+7
-0
test/javax/xml/jaxp/transform/jdk8004476/tokenize.xsl
test/javax/xml/jaxp/transform/jdk8004476/tokenize.xsl
+30
-0
未找到文件。
test/javax/xml/jaxp/transform/jdk8004476/SecureProcessingTest.xml
0 → 100644
浏览文件 @
5825b33b
<?xml version="1.0"?>
<helloWorld/>
test/javax/xml/jaxp/transform/jdk8004476/TestBase.java
0 → 100644
浏览文件 @
5825b33b
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
import
java.security.Policy
;
/**
*
*
* @author huizhe.wang@oracle.com
*/
public
class
TestBase
{
public
static
boolean
isWindows
=
false
;
static
{
if
(
System
.
getProperty
(
"os.name"
).
indexOf
(
"Windows"
)>-
1
)
{
isWindows
=
true
;
}
};
String
filepath
;
boolean
hasSM
;
String
curDir
;
Policy
origPolicy
;
String
testName
;
static
String
errMessage
;
int
passed
=
0
,
failed
=
0
;
/**
* Creates a new instance of StreamReader
*/
public
TestBase
(
String
name
)
{
testName
=
name
;
}
//junit @Override
protected
void
setUp
()
{
if
(
System
.
getSecurityManager
()
!=
null
)
{
hasSM
=
true
;
System
.
setSecurityManager
(
null
);
}
filepath
=
System
.
getProperty
(
"test.src"
);
if
(
filepath
==
null
)
{
//current directory
filepath
=
System
.
getProperty
(
"user.dir"
);
}
origPolicy
=
Policy
.
getPolicy
();
}
//junit @Override
public
void
tearDown
()
{
// turn off security manager and restore policy
System
.
setSecurityManager
(
null
);
Policy
.
setPolicy
(
origPolicy
);
if
(
hasSM
)
{
System
.
setSecurityManager
(
new
SecurityManager
());
}
System
.
out
.
println
(
"\nNumber of tests passed: "
+
passed
);
System
.
out
.
println
(
"Number of tests failed: "
+
failed
+
"\n"
);
if
(
errMessage
!=
null
)
{
throw
new
RuntimeException
(
errMessage
);
}
}
void
fail
(
String
errMsg
)
{
if
(
errMessage
==
null
)
{
errMessage
=
errMsg
;
}
else
{
errMessage
=
errMessage
+
"\n"
+
errMsg
;
}
failed
++;
}
void
success
(
String
msg
)
{
passed
++;
System
.
out
.
println
(
msg
);
}
}
test/javax/xml/jaxp/transform/jdk8004476/XPathExFuncTest.java
0 → 100644
浏览文件 @
5825b33b
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8004476
* @summary test XPath extension functions
* @run main/othervm XPathExFuncTest
*/
import
java.io.FileInputStream
;
import
java.io.InputStream
;
import
java.security.AllPermission
;
import
java.security.CodeSource
;
import
java.security.Permission
;
import
java.security.PermissionCollection
;
import
java.security.Permissions
;
import
java.security.Policy
;
import
java.security.ProtectionDomain
;
import
java.util.Iterator
;
import
java.util.List
;
import
javax.xml.XMLConstants
;
import
javax.xml.namespace.NamespaceContext
;
import
javax.xml.namespace.QName
;
import
javax.xml.parsers.DocumentBuilder
;
import
javax.xml.parsers.DocumentBuilderFactory
;
import
javax.xml.xpath.XPath
;
import
javax.xml.xpath.XPathExpressionException
;
import
javax.xml.xpath.XPathFactory
;
import
javax.xml.xpath.XPathFactoryConfigurationException
;
import
javax.xml.xpath.XPathFunction
;
import
javax.xml.xpath.XPathFunctionException
;
import
javax.xml.xpath.XPathFunctionResolver
;
import
org.w3c.dom.Document
;
/**
* test XPath extension functions
*
* @author huizhe.wang@oracle.com
*/
public
class
XPathExFuncTest
extends
TestBase
{
final
static
String
ENABLE_EXTENSION_FUNCTIONS
=
"http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions"
;
final
static
String
CLASSNAME
=
"DocumentBuilderFactoryImpl"
;
final
String
XPATH_EXPRESSION
=
"ext:helloWorld()"
;
/**
* Creates a new instance of StreamReader
*/
public
XPathExFuncTest
(
String
name
)
{
super
(
name
);
}
boolean
hasSM
;
String
xslFile
,
xslFileId
;
String
xmlFile
,
xmlFileId
;
protected
void
setUp
()
{
super
.
setUp
();
xmlFile
=
filepath
+
"/SecureProcessingTest.xml"
;
}
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
[]
args
)
{
XPathExFuncTest
test
=
new
XPathExFuncTest
(
"OneTest"
);
test
.
setUp
();
test
.
testExtFunc
();
test
.
testExtFuncNotAllowed
();
test
.
testEnableExtFunc
();
test
.
tearDown
();
}
/**
* by default, extension function is enabled
*/
public
void
testExtFunc
()
{
try
{
evaluate
(
false
);
System
.
out
.
println
(
"testExtFunc: OK"
);
}
catch
(
XPathFactoryConfigurationException
e
)
{
fail
(
e
.
getMessage
());
}
catch
(
XPathExpressionException
e
)
{
fail
(
e
.
getMessage
());
}
}
/**
* Security is enabled, extension function not allowed
*/
public
void
testExtFuncNotAllowed
()
{
Policy
p
=
new
SimplePolicy
(
new
AllPermission
());
Policy
.
setPolicy
(
p
);
System
.
setSecurityManager
(
new
SecurityManager
());
try
{
evaluate
(
false
);
}
catch
(
XPathFactoryConfigurationException
e
)
{
fail
(
e
.
getMessage
());
}
catch
(
XPathExpressionException
ex
)
{
//expected since extension function is disallowed
System
.
out
.
println
(
"testExtFuncNotAllowed: OK"
);
}
finally
{
System
.
setSecurityManager
(
null
);
}
}
/**
* Security is enabled, use new feature: enableExtensionFunctions
*/
public
void
testEnableExtFunc
()
{
Policy
p
=
new
SimplePolicy
(
new
AllPermission
());
Policy
.
setPolicy
(
p
);
System
.
setSecurityManager
(
new
SecurityManager
());
try
{
evaluate
(
true
);
System
.
out
.
println
(
"testEnableExt: OK"
);
}
catch
(
XPathFactoryConfigurationException
e
)
{
fail
(
e
.
getMessage
());
}
catch
(
XPathExpressionException
e
)
{
fail
(
e
.
getMessage
());
}
finally
{
System
.
setSecurityManager
(
null
);
}
}
Document
getDocument
()
{
// the xml source
DocumentBuilderFactory
documentBuilderFactory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
documentBuilder
=
null
;
Document
document
=
null
;
try
{
documentBuilder
=
documentBuilderFactory
.
newDocumentBuilder
();
InputStream
xmlStream
=
new
FileInputStream
(
xmlFile
);
document
=
documentBuilder
.
parse
(
xmlStream
);
}
catch
(
Exception
e
)
{
fail
(
e
.
toString
());
}
return
document
;
}
void
evaluate
(
boolean
enableExt
)
throws
XPathFactoryConfigurationException
,
XPathExpressionException
{
Document
document
=
getDocument
();
XPathFactory
xPathFactory
=
XPathFactory
.
newInstance
();
/**
* Use of the extension function 'http://exslt.org/strings:tokenize' is
* not allowed when the secure processing feature is set to true.
* Attempt to use the new property to enable extension function
*/
if
(
enableExt
)
{
boolean
isExtensionSupported
=
enableExtensionFunction
(
xPathFactory
);
}
xPathFactory
.
setXPathFunctionResolver
(
new
MyXPathFunctionResolver
());
if
(
System
.
getSecurityManager
()
==
null
)
{
xPathFactory
.
setFeature
(
XMLConstants
.
FEATURE_SECURE_PROCESSING
,
false
);
}
XPath
xPath
=
xPathFactory
.
newXPath
();
xPath
.
setNamespaceContext
(
new
MyNamespaceContext
());
String
xPathResult
=
xPath
.
evaluate
(
XPATH_EXPRESSION
,
document
);
System
.
out
.
println
(
"XPath result (enableExtensionFunction == "
+
enableExt
+
") = \""
+
xPathResult
+
"\""
);
}
public
class
MyXPathFunctionResolver
implements
XPathFunctionResolver
{
public
XPathFunction
resolveFunction
(
QName
functionName
,
int
arity
)
{
// not a real ewsolver, always return a default XPathFunction
return
new
MyXPathFunction
();
}
}
public
class
MyXPathFunction
implements
XPathFunction
{
public
Object
evaluate
(
List
list
)
throws
XPathFunctionException
{
return
"Hello World"
;
}
}
public
class
MyNamespaceContext
implements
NamespaceContext
{
public
String
getNamespaceURI
(
String
prefix
)
{
if
(
prefix
==
null
)
{
throw
new
IllegalArgumentException
(
"The prefix cannot be null."
);
}
if
(
prefix
.
equals
(
"ext"
))
{
return
"http://ext.com"
;
}
else
{
return
null
;
}
}
public
String
getPrefix
(
String
namespace
)
{
if
(
namespace
==
null
)
{
throw
new
IllegalArgumentException
(
"The namespace uri cannot be null."
);
}
if
(
namespace
.
equals
(
"http://ext.com"
))
{
return
"ext"
;
}
else
{
return
null
;
}
}
public
Iterator
getPrefixes
(
String
namespace
)
{
return
null
;
}
}
boolean
enableExtensionFunction
(
XPathFactory
factory
)
{
boolean
isSupported
=
true
;
try
{
factory
.
setFeature
(
ENABLE_EXTENSION_FUNCTIONS
,
true
);
}
catch
(
XPathFactoryConfigurationException
ex
)
{
isSupported
=
false
;
}
return
isSupported
;
}
class
SimplePolicy
extends
Policy
{
private
final
Permissions
perms
;
public
SimplePolicy
(
Permission
...
permissions
)
{
perms
=
new
Permissions
();
for
(
Permission
permission
:
permissions
)
{
perms
.
add
(
permission
);
}
}
@Override
public
PermissionCollection
getPermissions
(
CodeSource
cs
)
{
return
perms
;
}
@Override
public
PermissionCollection
getPermissions
(
ProtectionDomain
pd
)
{
return
perms
;
}
@Override
public
boolean
implies
(
ProtectionDomain
pd
,
Permission
p
)
{
return
perms
.
implies
(
p
);
}
//for older jdk
@Override
public
void
refresh
()
{
}
}
}
test/javax/xml/jaxp/transform/jdk8004476/XSLTExFuncTest.java
0 → 100644
浏览文件 @
5825b33b
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8004476
* @summary test XSLT extension functions
* @run main/othervm XSLTExFuncTest
*/
import
java.io.StringWriter
;
import
java.security.AllPermission
;
import
java.security.CodeSource
;
import
java.security.Permission
;
import
java.security.PermissionCollection
;
import
java.security.Permissions
;
import
java.security.Policy
;
import
java.security.ProtectionDomain
;
import
javax.xml.transform.*
;
import
javax.xml.transform.sax.SAXSource
;
import
javax.xml.transform.stream.StreamResult
;
import
org.xml.sax.InputSource
;
/**
* test XSLT extension functions
*
* @author huizhe.wang@oracle.com
*/
public
class
XSLTExFuncTest
extends
TestBase
{
final
static
String
ENABLE_EXTENSION_FUNCTIONS
=
"http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions"
;
final
static
String
CLASSNAME
=
"DocumentBuilderFactoryImpl"
;
/**
* Creates a new instance of StreamReader
*/
public
XSLTExFuncTest
(
String
name
)
{
super
(
name
);
}
boolean
hasSM
;
String
xslFile
,
xslFileId
;
String
xmlFile
,
xmlFileId
;
protected
void
setUp
()
{
super
.
setUp
();
xmlFile
=
filepath
+
"/tokenize.xml"
;
xslFile
=
filepath
+
"/tokenize.xsl"
;
/**
* if (isWindows) { xslFile = "/" + xslFile; }
*
*/
xslFileId
=
"file://"
+
xslFile
;
}
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
[]
args
)
{
XSLTExFuncTest
test
=
new
XSLTExFuncTest
(
"OneTest"
);
test
.
setUp
();
test
.
testExtFunc
();
test
.
testExtFuncNotAllowed
();
test
.
testEnableExtFunc
();
test
.
testTemplatesEnableExtFunc
();
test
.
tearDown
();
}
/**
* by default, extension function is enabled
*/
public
void
testExtFunc
()
{
TransformerFactory
factory
=
TransformerFactory
.
newInstance
();
try
{
transform
(
factory
);
System
.
out
.
println
(
"testExtFunc: OK"
);
}
catch
(
TransformerConfigurationException
e
)
{
fail
(
e
.
getMessage
());
}
catch
(
TransformerException
ex
)
{
fail
(
ex
.
getMessage
());
}
}
/**
* Security is enabled, extension function not allowed
*/
public
void
testExtFuncNotAllowed
()
{
Policy
p
=
new
SimplePolicy
(
new
AllPermission
());
Policy
.
setPolicy
(
p
);
System
.
setSecurityManager
(
new
SecurityManager
());
TransformerFactory
factory
=
TransformerFactory
.
newInstance
();
try
{
transform
(
factory
);
}
catch
(
TransformerConfigurationException
e
)
{
fail
(
e
.
getMessage
());
}
catch
(
TransformerException
ex
)
{
//expected since extension function is disallowed
System
.
out
.
println
(
"testExtFuncNotAllowed: OK"
);
}
finally
{
System
.
setSecurityManager
(
null
);
}
}
/**
* Security is enabled, use new feature: enableExtensionFunctions
*/
public
void
testEnableExtFunc
()
{
Policy
p
=
new
SimplePolicy
(
new
AllPermission
());
Policy
.
setPolicy
(
p
);
System
.
setSecurityManager
(
new
SecurityManager
());
TransformerFactory
factory
=
TransformerFactory
.
newInstance
();
/**
* Use of the extension function 'http://exslt.org/strings:tokenize' is
* not allowed when the secure processing feature is set to true.
* Attempt to use the new property to enable extension function
*/
boolean
isExtensionSupported
=
enableExtensionFunction
(
factory
);
try
{
transform
(
factory
);
System
.
out
.
println
(
"testEnableExt: OK"
);
}
catch
(
TransformerConfigurationException
e
)
{
fail
(
e
.
getMessage
());
}
catch
(
TransformerException
e
)
{
fail
(
e
.
getMessage
());
}
finally
{
System
.
setSecurityManager
(
null
);
}
}
/**
* use Templates template = factory.newTemplates(new StreamSource( new
* FileInputStream(xslFilename))); // Use the template to create a
* transformer Transformer xformer = template.newTransformer();
*
* @param factory
* @return
*/
/**
* Security is enabled, use new feature: enableExtensionFunctions Use the
* template to create a transformer
*/
public
void
testTemplatesEnableExtFunc
()
{
Policy
p
=
new
SimplePolicy
(
new
AllPermission
());
Policy
.
setPolicy
(
p
);
System
.
setSecurityManager
(
new
SecurityManager
());
TransformerFactory
factory
=
TransformerFactory
.
newInstance
();
/**
* Use of the extension function 'http://exslt.org/strings:tokenize' is
* not allowed when the secure processing feature is set to true.
* Attempt to use the new property to enable extension function
*/
boolean
isExtensionSupported
=
enableExtensionFunction
(
factory
);
try
{
SAXSource
xslSource
=
new
SAXSource
(
new
InputSource
(
xslFile
));
xslSource
.
setSystemId
(
xslFileId
);
Templates
template
=
factory
.
newTemplates
(
xslSource
);
Transformer
transformer
=
template
.
newTransformer
();
StringWriter
stringResult
=
new
StringWriter
();
Result
result
=
new
StreamResult
(
stringResult
);
transformer
.
transform
(
new
SAXSource
(
new
InputSource
(
xmlFile
)),
result
);
System
.
out
.
println
(
"testTemplatesEnableExtFunc: OK"
);
}
catch
(
TransformerConfigurationException
e
)
{
fail
(
e
.
getMessage
());
}
catch
(
TransformerException
e
)
{
fail
(
e
.
getMessage
());
}
finally
{
System
.
setSecurityManager
(
null
);
}
}
boolean
enableExtensionFunction
(
TransformerFactory
factory
)
{
boolean
isSupported
=
true
;
try
{
factory
.
setFeature
(
ENABLE_EXTENSION_FUNCTIONS
,
true
);
}
catch
(
TransformerConfigurationException
ex
)
{
isSupported
=
false
;
}
return
isSupported
;
}
void
transform
(
TransformerFactory
factory
)
throws
TransformerConfigurationException
,
TransformerException
{
SAXSource
xslSource
=
new
SAXSource
(
new
InputSource
(
xslFile
));
xslSource
.
setSystemId
(
xslFileId
);
Transformer
transformer
=
factory
.
newTransformer
(
xslSource
);
StringWriter
stringResult
=
new
StringWriter
();
Result
result
=
new
StreamResult
(
stringResult
);
transformer
.
transform
(
new
SAXSource
(
new
InputSource
(
xmlFile
)),
result
);
}
class
SimplePolicy
extends
Policy
{
private
final
Permissions
perms
;
public
SimplePolicy
(
Permission
...
permissions
)
{
perms
=
new
Permissions
();
for
(
Permission
permission
:
permissions
)
{
perms
.
add
(
permission
);
}
}
@Override
public
PermissionCollection
getPermissions
(
CodeSource
cs
)
{
return
perms
;
}
@Override
public
PermissionCollection
getPermissions
(
ProtectionDomain
pd
)
{
return
perms
;
}
@Override
public
boolean
implies
(
ProtectionDomain
pd
,
Permission
p
)
{
return
perms
.
implies
(
p
);
}
//for older jdk
@Override
public
void
refresh
()
{
}
}
}
test/javax/xml/jaxp/transform/jdk8004476/tokenize.xml
0 → 100644
浏览文件 @
5825b33b
<?xml version="1.0" encoding="UTF-8" ?>
<html>
<a>
<b>
Is this EXSLT? No. no
</b>
<c>
Is this EXSLT? No. no
</c>
</a>
</html>
\ No newline at end of file
test/javax/xml/jaxp/transform/jdk8004476/tokenize.xsl
0 → 100644
浏览文件 @
5825b33b
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform"
xmlns:str=
"http://exslt.org/strings"
xmlns:xalan=
"http://xml.apache.org/xalan"
version=
"1.0"
>
<xsl:template
match=
"a"
>
<xsl:apply-templates
/>
</xsl:template>
<xsl:template
match=
"//a/c"
>
<xsl:value-of
select=
"."
/>
-
<xsl:value-of
select=
"str:tokenize(string(.), ' ')"
/>
<xsl:value-of
select=
"str:tokenize(string(.), '')"
/>
<xsl:for-each
select=
"str:tokenize(string(.), ' ')"
>
<xsl:value-of
select=
"."
/>
</xsl:for-each>
<xsl:apply-templates
select=
"*"
/>
</xsl:template>
<xsl:template
match=
"//a/b"
>
<xsl:value-of
select=
"."
/>
-
<xsl:value-of
select=
"xalan:tokenize(string(.), ' ')"
/>
<xsl:value-of
select=
"xalan:tokenize(string(.), '')"
/>
<xsl:for-each
select=
"xalan:tokenize(string(.), ' ')"
>
<xsl:value-of
select=
"."
/>
</xsl:for-each>
<xsl:apply-templates
select=
"*"
/>
</xsl:template>
</xsl:stylesheet>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录