Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
d7fe92d0
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d7fe92d0
编写于
3月 16, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Abstract(Stax)XMLReader recognizes standard features as not supported
Issue: SPR-14056 (cherry picked from commit
35eb52e5
)
上级
3b7ca7e7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
62 addition
and
43 deletion
+62
-43
spring-core/src/main/java/org/springframework/util/xml/AbstractStaxXMLReader.java
...a/org/springframework/util/xml/AbstractStaxXMLReader.java
+19
-15
spring-core/src/main/java/org/springframework/util/xml/AbstractXMLReader.java
.../java/org/springframework/util/xml/AbstractXMLReader.java
+43
-28
未找到文件。
spring-core/src/main/java/org/springframework/util/xml/AbstractStaxXMLReader.java
浏览文件 @
d7fe92d0
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
6
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -35,6 +35,7 @@ import org.springframework.util.StringUtils;
* Abstract base class for SAX {@code XMLReader} implementations that use StAX as a basis.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @since 3.0
* @see #setContentHandler(org.xml.sax.ContentHandler)
* @see #setDTDHandler(org.xml.sax.DTDHandler)
...
...
@@ -58,6 +59,7 @@ abstract class AbstractStaxXMLReader extends AbstractXMLReader {
private
final
Map
<
String
,
String
>
namespaces
=
new
LinkedHashMap
<
String
,
String
>();
@Override
public
boolean
getFeature
(
String
name
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
if
(
NAMESPACES_FEATURE_NAME
.
equals
(
name
))
{
...
...
@@ -170,12 +172,13 @@ abstract class AbstractStaxXMLReader extends AbstractXMLReader {
}
/**
* Template
-
method that parses the StAX reader passed at construction-time.
* Template
method that parses the StAX reader passed at construction-time.
*/
protected
abstract
void
parseInternal
()
throws
SAXException
,
XMLStreamException
;
/**
* Start
s
the prefix mapping for the given prefix.
* Start the prefix mapping for the given prefix.
* @see org.xml.sax.ContentHandler#startPrefixMapping(String, String)
*/
protected
void
startPrefixMapping
(
String
prefix
,
String
namespace
)
throws
SAXException
{
...
...
@@ -186,57 +189,58 @@ abstract class AbstractStaxXMLReader extends AbstractXMLReader {
if
(!
StringUtils
.
hasLength
(
namespace
))
{
return
;
}
if
(!
namespace
.
equals
(
namespaces
.
get
(
prefix
)))
{
if
(!
namespace
.
equals
(
this
.
namespaces
.
get
(
prefix
)))
{
getContentHandler
().
startPrefixMapping
(
prefix
,
namespace
);
namespaces
.
put
(
prefix
,
namespace
);
this
.
namespaces
.
put
(
prefix
,
namespace
);
}
}
}
/**
* End
s
the prefix mapping for the given prefix.
* End the prefix mapping for the given prefix.
* @see org.xml.sax.ContentHandler#endPrefixMapping(String)
*/
protected
void
endPrefixMapping
(
String
prefix
)
throws
SAXException
{
if
(
getContentHandler
()
!=
null
)
{
if
(
namespaces
.
containsKey
(
prefix
))
{
if
(
this
.
namespaces
.
containsKey
(
prefix
))
{
getContentHandler
().
endPrefixMapping
(
prefix
);
namespaces
.
remove
(
prefix
);
this
.
namespaces
.
remove
(
prefix
);
}
}
}
/**
* Implementation of the {@code Locator} interface
that is based on a
StAX {@code Location}.
* Implementation of the {@code Locator} interface
based on a given
StAX {@code Location}.
* @see Locator
* @see Location
*/
private
static
class
StaxLocator
implements
Locator
{
private
Location
location
;
private
final
Location
location
;
p
rotected
StaxLocator
(
Location
location
)
{
p
ublic
StaxLocator
(
Location
location
)
{
this
.
location
=
location
;
}
@Override
public
String
getPublicId
()
{
return
location
.
getPublicId
();
return
this
.
location
.
getPublicId
();
}
@Override
public
String
getSystemId
()
{
return
location
.
getSystemId
();
return
this
.
location
.
getSystemId
();
}
@Override
public
int
getLineNumber
()
{
return
location
.
getLineNumber
();
return
this
.
location
.
getLineNumber
();
}
@Override
public
int
getColumnNumber
()
{
return
location
.
getColumnNumber
();
return
this
.
location
.
getColumnNumber
();
}
}
...
...
spring-core/src/main/java/org/springframework/util/xml/AbstractXMLReader.java
浏览文件 @
d7fe92d0
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
6
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -26,15 +26,16 @@ import org.xml.sax.XMLReader;
import
org.xml.sax.ext.LexicalHandler
;
/**
* Abstract base class for SAX {@code XMLReader} implementations.
Contains properties as defined in {@link
* XMLReader}, and does not recognize any features.
* Abstract base class for SAX {@code XMLReader} implementations.
*
Contains properties as defined in {@link
XMLReader}, and does not recognize any features.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @since 3.0
* @see #setContentHandler(org.xml.sax.ContentHandler)
* @see #setDTDHandler(org.xml.sax.DTDHandler)
* @see #setEntityResolver(org.xml.sax.EntityResolver)
* @see #setErrorHandler(org.xml.sax.ErrorHandler)
* @since 3.0
*/
abstract
class
AbstractXMLReader
implements
XMLReader
{
...
...
@@ -48,10 +49,6 @@ abstract class AbstractXMLReader implements XMLReader {
private
LexicalHandler
lexicalHandler
;
@Override
public
ContentHandler
getContentHandler
()
{
return
contentHandler
;
}
@Override
public
void
setContentHandler
(
ContentHandler
contentHandler
)
{
...
...
@@ -59,18 +56,18 @@ abstract class AbstractXMLReader implements XMLReader {
}
@Override
public
void
setDTDHandler
(
DTDHandler
dtdHandler
)
{
this
.
dtdHandler
=
dtd
Handler
;
public
ContentHandler
getContentHandler
(
)
{
return
this
.
content
Handler
;
}
@Override
public
DTDHandler
getDTDHandler
(
)
{
return
dtdHandler
;
public
void
setDTDHandler
(
DTDHandler
dtdHandler
)
{
this
.
dtdHandler
=
dtdHandler
;
}
@Override
public
EntityResolver
getEntityResolv
er
()
{
return
entityResolv
er
;
public
DTDHandler
getDTDHandl
er
()
{
return
this
.
dtdHandl
er
;
}
@Override
...
...
@@ -79,8 +76,8 @@ abstract class AbstractXMLReader implements XMLReader {
}
@Override
public
E
rrorHandler
getErrorHandl
er
()
{
return
errorHandl
er
;
public
E
ntityResolver
getEntityResolv
er
()
{
return
this
.
entityResolv
er
;
}
@Override
...
...
@@ -88,29 +85,46 @@ abstract class AbstractXMLReader implements XMLReader {
this
.
errorHandler
=
errorHandler
;
}
@Override
public
ErrorHandler
getErrorHandler
()
{
return
this
.
errorHandler
;
}
protected
LexicalHandler
getLexicalHandler
()
{
return
lexicalHandler
;
return
this
.
lexicalHandler
;
}
/**
* Throws a {@code SAXNotRecognizedException} exception.
*
* @throws org.xml.sax.SAXNotRecognizedException
* always
* This implementation throws a {@code SAXNotRecognizedException} exception
* for any feature outside of the "http://xml.org/sax/features/" namespace
* and returns {@code false} for any feature within.
*/
@Override
public
boolean
getFeature
(
String
name
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
throw
new
SAXNotRecognizedException
(
name
);
if
(
name
.
startsWith
(
"http://xml.org/sax/features/"
))
{
return
false
;
}
else
{
throw
new
SAXNotRecognizedException
(
name
);
}
}
/**
* Th
rows a {@code SAXNotRecognizedException} exception.
*
*
@throws SAXNotRecognizedException always
* Th
is implementation throws a {@code SAXNotRecognizedException} exception
*
for any feature outside of the "http://xml.org/sax/features/" namespace
*
and accepts a {@code false} value for any feature within.
*/
@Override
public
void
setFeature
(
String
name
,
boolean
value
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
throw
new
SAXNotRecognizedException
(
name
);
if
(
name
.
startsWith
(
"http://xml.org/sax/features/"
))
{
if
(
value
)
{
throw
new
SAXNotSupportedException
(
name
);
}
}
else
{
throw
new
SAXNotRecognizedException
(
name
);
}
}
/**
...
...
@@ -120,7 +134,7 @@ abstract class AbstractXMLReader implements XMLReader {
@Override
public
Object
getProperty
(
String
name
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
if
(
"http://xml.org/sax/properties/lexical-handler"
.
equals
(
name
))
{
return
lexicalHandler
;
return
this
.
lexicalHandler
;
}
else
{
throw
new
SAXNotRecognizedException
(
name
);
...
...
@@ -134,10 +148,11 @@ abstract class AbstractXMLReader implements XMLReader {
@Override
public
void
setProperty
(
String
name
,
Object
value
)
throws
SAXNotRecognizedException
,
SAXNotSupportedException
{
if
(
"http://xml.org/sax/properties/lexical-handler"
.
equals
(
name
))
{
lexicalHandler
=
(
LexicalHandler
)
value
;
this
.
lexicalHandler
=
(
LexicalHandler
)
value
;
}
else
{
throw
new
SAXNotRecognizedException
(
name
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录