Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Meiracle
spring-framework
提交
1ac8e48e
S
spring-framework
项目概览
Meiracle
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
1ac8e48e
编写于
10月 30, 2013
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing (backported from several master changes)
上级
d4f4225e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
121 addition
and
160 deletion
+121
-160
spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java
...a/org/springframework/beans/factory/BeanFactoryUtils.java
+2
-2
spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java
...rk/context/event/AbstractApplicationEventMulticaster.java
+7
-8
spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java
.../org/springframework/util/ConcurrentReferenceHashMap.java
+41
-57
spring-core/src/main/java/org/springframework/util/xml/StaxEventXMLReader.java
...java/org/springframework/util/xml/StaxEventXMLReader.java
+11
-21
spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java
...ava/org/springframework/util/xml/StaxStreamXMLReader.java
+52
-58
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java
...k/web/servlet/mvc/condition/PatternsRequestCondition.java
+8
-14
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java
浏览文件 @
1ac8e48e
...
...
@@ -139,7 +139,7 @@ public abstract class BeanFactoryUtils {
* @param type the type that beans must match
* @return the array of matching bean names, or an empty array if none
*/
public
static
String
[]
beanNamesForTypeIncludingAncestors
(
ListableBeanFactory
lbf
,
Class
type
)
{
public
static
String
[]
beanNamesForTypeIncludingAncestors
(
ListableBeanFactory
lbf
,
Class
<?>
type
)
{
Assert
.
notNull
(
lbf
,
"ListableBeanFactory must not be null"
);
String
[]
result
=
lbf
.
getBeanNamesForType
(
type
);
if
(
lbf
instanceof
HierarchicalBeanFactory
)
{
...
...
@@ -181,7 +181,7 @@ public abstract class BeanFactoryUtils {
* @return the array of matching bean names, or an empty array if none
*/
public
static
String
[]
beanNamesForTypeIncludingAncestors
(
ListableBeanFactory
lbf
,
Class
type
,
boolean
includeNonSingletons
,
boolean
allowEagerInit
)
{
ListableBeanFactory
lbf
,
Class
<?>
type
,
boolean
includeNonSingletons
,
boolean
allowEagerInit
)
{
Assert
.
notNull
(
lbf
,
"ListableBeanFactory must not be null"
);
String
[]
result
=
lbf
.
getBeanNamesForType
(
type
,
includeNonSingletons
,
allowEagerInit
);
...
...
spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java
浏览文件 @
1ac8e48e
...
...
@@ -130,7 +130,7 @@ public abstract class AbstractApplicationEventMulticaster implements Application
protected
Collection
<
ApplicationListener
>
getApplicationListeners
(
ApplicationEvent
event
)
{
Class
<?
extends
ApplicationEvent
>
eventType
=
event
.
getClass
();
Object
source
=
event
.
getSource
();
Class
sourceType
=
(
source
==
null
?
null
:
source
.
getClass
()
);
Class
<?>
sourceType
=
(
source
!=
null
?
source
.
getClass
()
:
null
);
ListenerCacheKey
cacheKey
=
new
ListenerCacheKey
(
eventType
,
sourceType
);
ListenerRetriever
retriever
=
this
.
retrieverCache
.
get
(
cacheKey
);
if
(
retriever
!=
null
)
{
...
...
@@ -193,11 +193,11 @@ public abstract class AbstractApplicationEventMulticaster implements Application
*/
private
static
class
ListenerCacheKey
{
private
final
Class
eventType
;
private
final
Class
<?>
eventType
;
private
final
Class
sourceType
;
private
final
Class
<?>
sourceType
;
public
ListenerCacheKey
(
Class
eventType
,
Class
sourceType
)
{
public
ListenerCacheKey
(
Class
<?>
eventType
,
Class
<?>
sourceType
)
{
this
.
eventType
=
eventType
;
this
.
sourceType
=
sourceType
;
}
...
...
@@ -208,14 +208,13 @@ public abstract class AbstractApplicationEventMulticaster implements Application
return
true
;
}
ListenerCacheKey
otherKey
=
(
ListenerCacheKey
)
other
;
return
ObjectUtils
.
nullSafeEquals
(
this
.
eventType
,
otherKey
.
eventType
)
&&
ObjectUtils
.
nullSafeEquals
(
this
.
sourceType
,
otherKey
.
sourceType
);
return
ObjectUtils
.
nullSafeEquals
(
this
.
eventType
,
otherKey
.
eventType
)
&&
ObjectUtils
.
nullSafeEquals
(
this
.
sourceType
,
otherKey
.
sourceType
);
}
@Override
public
int
hashCode
()
{
return
ObjectUtils
.
nullSafeHashCode
(
this
.
eventType
)
*
29
+
ObjectUtils
.
nullSafeHashCode
(
this
.
sourceType
);
return
ObjectUtils
.
nullSafeHashCode
(
this
.
eventType
)
*
29
+
ObjectUtils
.
nullSafeHashCode
(
this
.
sourceType
);
}
}
...
...
spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java
浏览文件 @
1ac8e48e
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
3
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.
...
...
@@ -48,7 +48,7 @@ import java.util.concurrent.locks.ReentrantLock;
* references at any time, so it may appear that an unknown thread is silently removing
* entries.
*
* <p>If not explicitly specified this implementation will use
* <p>If not explicitly specified
,
this implementation will use
* {@linkplain SoftReference soft entry references}.
*
* @param <K> The key type
...
...
@@ -56,8 +56,7 @@ import java.util.concurrent.locks.ReentrantLock;
* @author Phillip Webb
* @since 3.2
*/
public
class
ConcurrentReferenceHashMap
<
K
,
V
>
extends
AbstractMap
<
K
,
V
>
implements
ConcurrentMap
<
K
,
V
>
{
public
class
ConcurrentReferenceHashMap
<
K
,
V
>
extends
AbstractMap
<
K
,
V
>
implements
ConcurrentMap
<
K
,
V
>
{
private
static
final
int
DEFAULT_INITIAL_CAPACITY
=
16
;
...
...
@@ -82,6 +81,9 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
*/
private
final
float
loadFactor
;
/**
* The reference type: SOFT or WEAK.
*/
private
final
ReferenceType
referenceType
;
/**
...
...
@@ -99,8 +101,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
* Create a new {@code ConcurrentReferenceHashMap} instance.
*/
public
ConcurrentReferenceHashMap
()
{
this
(
DEFAULT_INITIAL_CAPACITY
,
DEFAULT_LOAD_FACTOR
,
DEFAULT_CONCURRENCY_LEVEL
,
DEFAULT_REFERENCE_TYPE
);
this
(
DEFAULT_INITIAL_CAPACITY
,
DEFAULT_LOAD_FACTOR
,
DEFAULT_CONCURRENCY_LEVEL
,
DEFAULT_REFERENCE_TYPE
);
}
/**
...
...
@@ -108,8 +109,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
* @param initialCapacity the initial capacity of the map
*/
public
ConcurrentReferenceHashMap
(
int
initialCapacity
)
{
this
(
initialCapacity
,
DEFAULT_LOAD_FACTOR
,
DEFAULT_CONCURRENCY_LEVEL
,
DEFAULT_REFERENCE_TYPE
);
this
(
initialCapacity
,
DEFAULT_LOAD_FACTOR
,
DEFAULT_CONCURRENCY_LEVEL
,
DEFAULT_REFERENCE_TYPE
);
}
/**
...
...
@@ -119,45 +119,44 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
* exceeds this value resize will be attempted
*/
public
ConcurrentReferenceHashMap
(
int
initialCapacity
,
float
loadFactor
)
{
this
(
initialCapacity
,
loadFactor
,
DEFAULT_CONCURRENCY_LEVEL
,
DEFAULT_REFERENCE_TYPE
);
this
(
initialCapacity
,
loadFactor
,
DEFAULT_CONCURRENCY_LEVEL
,
DEFAULT_REFERENCE_TYPE
);
}
/**
* Create a new {@code ConcurrentReferenceHashMap} instance.
* @param initialCapacity the initial capacity of the map
* @param concurrencyLevel the expected number of threads that will concurrently
write
*
to the map
* @param concurrencyLevel the expected number of threads that will concurrently
*
write
to the map
*/
public
ConcurrentReferenceHashMap
(
int
initialCapacity
,
int
concurrencyLevel
)
{
this
(
initialCapacity
,
DEFAULT_LOAD_FACTOR
,
concurrencyLevel
,
DEFAULT_REFERENCE_TYPE
);
this
(
initialCapacity
,
DEFAULT_LOAD_FACTOR
,
concurrencyLevel
,
DEFAULT_REFERENCE_TYPE
);
}
/**
* Create a new {@code ConcurrentReferenceHashMap} instance.
* @param initialCapacity the initial capacity of the map
* @param loadFactor the load factor. When the average number of references per
table
*
exceeds this value resize will be attempted
* @param concurrencyLevel the expected number of threads that will concurrently
write
*
to the map
* @param loadFactor the load factor. When the average number of references per
*
table exceeds this value, resize will be attempted.
* @param concurrencyLevel the expected number of threads that will concurrently
*
write
to the map
*/
public
ConcurrentReferenceHashMap
(
int
initialCapacity
,
float
loadFactor
,
int
concurrencyLevel
)
{
public
ConcurrentReferenceHashMap
(
int
initialCapacity
,
float
loadFactor
,
int
concurrencyLevel
)
{
this
(
initialCapacity
,
loadFactor
,
concurrencyLevel
,
DEFAULT_REFERENCE_TYPE
);
}
/**
* Create a new {@code ConcurrentReferenceHashMap} instance.
* @param initialCapacity the initial capacity of the map
* @param loadFactor the load factor. When the average number of references per
table
*
exceeds this value resize will be attempted
* @param concurrencyLevel the expected number of threads that will concurrently
write
*
to the map
* @param loadFactor the load factor. When the average number of references per
*
table exceeds this value, resize will be attempted.
* @param concurrencyLevel the expected number of threads that will concurrently
*
write
to the map
* @param referenceType the reference type used for entries
*/
public
ConcurrentReferenceHashMap
(
int
initialCapacity
,
float
loadFactor
,
int
concurrencyLevel
,
ReferenceType
referenceType
)
{
@SuppressWarnings
(
"unchecked"
)
public
ConcurrentReferenceHashMap
(
int
initialCapacity
,
float
loadFactor
,
int
concurrencyLevel
,
ReferenceType
referenceType
)
{
Assert
.
isTrue
(
concurrencyLevel
>
0
,
"ConcurrencyLevel must be positive"
);
Assert
.
isTrue
(
initialCapacity
>=
0
,
"InitialCapacity must not be negative"
);
Assert
.
isTrue
(
loadFactor
>
0
f
,
"LoadFactor must be positive"
);
...
...
@@ -167,17 +166,12 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
int
size
=
1
<<
this
.
shift
;
this
.
referenceType
=
referenceType
;
int
roundedUpSegmentCapactity
=
(
int
)
((
initialCapacity
+
size
-
1L
)
/
size
);
this
.
segments
=
createSegmentsArray
(
size
);
this
.
segments
=
(
Segment
[])
Array
.
newInstance
(
Segment
.
class
,
size
);
for
(
int
i
=
0
;
i
<
this
.
segments
.
length
;
i
++)
{
this
.
segments
[
i
]
=
new
Segment
(
roundedUpSegmentCapactity
);
}
}
@SuppressWarnings
(
"unchecked"
)
private
Segment
[]
createSegmentsArray
(
int
size
)
{
return
(
Segment
[])
Array
.
newInstance
(
Segment
.
class
,
size
);
}
protected
final
float
getLoadFactor
()
{
return
this
.
loadFactor
;
...
...
@@ -222,7 +216,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
public
V
get
(
Object
key
)
{
Reference
<
K
,
V
>
reference
=
getReference
(
key
,
Restructure
.
WHEN_NECESSARY
);
Entry
<
K
,
V
>
entry
=
(
reference
==
null
?
null
:
reference
.
get
());
return
(
entry
==
null
?
null
:
entry
.
getValue
()
);
return
(
entry
!=
null
?
entry
.
getValue
()
:
null
);
}
@Override
...
...
@@ -388,7 +382,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
/**
* Use {@link WeakReference}s.
*/
WEAK
;
WEAK
}
...
...
@@ -421,14 +415,12 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
*/
private
int
resizeThreshold
;
public
Segment
(
int
initialCapacity
)
{
this
.
referenceManager
=
createReferenceManager
();
this
.
initialSize
=
1
<<
calculateShift
(
initialCapacity
,
MAXIMUM_SEGMENT_SIZE
);
setReferences
(
createReferenceArray
(
this
.
initialSize
));
}
public
Reference
<
K
,
V
>
getReference
(
Object
key
,
int
hash
,
Restructure
restructure
)
{
if
(
restructure
==
Restructure
.
WHEN_NECESSARY
)
{
restructureIfNecessary
(
false
);
...
...
@@ -452,17 +444,13 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
* @return the result of the operation
*/
public
<
T
>
T
doTask
(
final
int
hash
,
final
Object
key
,
final
Task
<
T
>
task
)
{
boolean
resize
=
task
.
hasOption
(
TaskOption
.
RESIZE
);
if
(
task
.
hasOption
(
TaskOption
.
RESTRUCTURE_BEFORE
))
{
restructureIfNecessary
(
resize
);
}
if
(
task
.
hasOption
(
TaskOption
.
SKIP_IF_EMPTY
)
&&
(
this
.
count
==
0
))
{
return
task
.
execute
(
null
,
null
,
null
);
}
lock
();
try
{
final
int
index
=
getIndex
(
hash
,
this
.
references
);
...
...
@@ -480,7 +468,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
}
};
return
task
.
execute
(
reference
,
entry
,
entries
);
}
finally
{
}
finally
{
unlock
();
if
(
task
.
hasOption
(
TaskOption
.
RESTRUCTURE_AFTER
))
{
restructureIfNecessary
(
resize
);
...
...
@@ -569,8 +558,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
}
}
private
Reference
<
K
,
V
>
findInChain
(
Reference
<
K
,
V
>
reference
,
Object
key
,
int
hash
)
{
private
Reference
<
K
,
V
>
findInChain
(
Reference
<
K
,
V
>
reference
,
Object
key
,
int
hash
)
{
while
(
reference
!=
null
)
{
if
(
reference
.
getHash
()
==
hash
)
{
Entry
<
K
,
V
>
entry
=
reference
.
get
();
...
...
@@ -752,6 +740,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
* Various options supported by a {@link Task}.
*/
private
static
enum
TaskOption
{
RESTRUCTURE_BEFORE
,
RESTRUCTURE_AFTER
,
SKIP_IF_EMPTY
,
RESIZE
}
...
...
@@ -783,8 +772,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
public
boolean
contains
(
Object
o
)
{
if
(
o
!=
null
&&
o
instanceof
Map
.
Entry
<?,
?>)
{
Map
.
Entry
<?,
?>
entry
=
(
java
.
util
.
Map
.
Entry
<?,
?>)
o
;
Reference
<
K
,
V
>
reference
=
ConcurrentReferenceHashMap
.
this
.
getReference
(
entry
.
getKey
(),
Restructure
.
NEVER
);
Reference
<
K
,
V
>
reference
=
ConcurrentReferenceHashMap
.
this
.
getReference
(
entry
.
getKey
(),
Restructure
.
NEVER
);
Entry
<
K
,
V
>
other
=
(
reference
==
null
?
null
:
reference
.
get
());
if
(
other
!=
null
)
{
return
ObjectUtils
.
nullSafeEquals
(
entry
.
getValue
(),
other
.
getValue
());
...
...
@@ -797,8 +785,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
public
boolean
remove
(
Object
o
)
{
if
(
o
instanceof
Map
.
Entry
<?,
?>)
{
Map
.
Entry
<?,
?>
entry
=
(
Map
.
Entry
<?,
?>)
o
;
return
ConcurrentReferenceHashMap
.
this
.
remove
(
entry
.
getKey
(),
entry
.
getValue
());
return
ConcurrentReferenceHashMap
.
this
.
remove
(
entry
.
getKey
(),
entry
.
getValue
());
}
return
false
;
}
...
...
@@ -897,6 +884,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
* The types of restructuring that can be performed.
*/
protected
static
enum
Restructure
{
WHEN_NECESSARY
,
NEVER
}
...
...
@@ -916,8 +904,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
* @param next the next reference in the chain or {@code null}
* @return a new {@link Reference}
*/
public
Reference
<
K
,
V
>
createReference
(
Entry
<
K
,
V
>
entry
,
int
hash
,
Reference
<
K
,
V
>
next
)
{
public
Reference
<
K
,
V
>
createReference
(
Entry
<
K
,
V
>
entry
,
int
hash
,
Reference
<
K
,
V
>
next
)
{
if
(
ConcurrentReferenceHashMap
.
this
.
referenceType
==
ReferenceType
.
WEAK
)
{
return
new
WeakEntryReference
<
K
,
V
>(
entry
,
hash
,
next
,
this
.
queue
);
}
...
...
@@ -941,15 +928,13 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
/**
* Internal {@link Reference} implementation for {@link SoftReference}s.
*/
private
static
final
class
SoftEntryReference
<
K
,
V
>
extends
SoftReference
<
Entry
<
K
,
V
>>
implements
Reference
<
K
,
V
>
{
private
static
final
class
SoftEntryReference
<
K
,
V
>
extends
SoftReference
<
Entry
<
K
,
V
>>
implements
Reference
<
K
,
V
>
{
private
final
int
hash
;
private
final
Reference
<
K
,
V
>
nextReference
;
public
SoftEntryReference
(
Entry
<
K
,
V
>
entry
,
int
hash
,
Reference
<
K
,
V
>
next
,
ReferenceQueue
<
Entry
<
K
,
V
>>
queue
)
{
public
SoftEntryReference
(
Entry
<
K
,
V
>
entry
,
int
hash
,
Reference
<
K
,
V
>
next
,
ReferenceQueue
<
Entry
<
K
,
V
>>
queue
)
{
super
(
entry
,
queue
);
this
.
hash
=
hash
;
this
.
nextReference
=
next
;
...
...
@@ -973,15 +958,13 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
/**
* Internal {@link Reference} implementation for {@link WeakReference}s.
*/
private
static
final
class
WeakEntryReference
<
K
,
V
>
extends
WeakReference
<
Entry
<
K
,
V
>>
implements
Reference
<
K
,
V
>
{
private
static
final
class
WeakEntryReference
<
K
,
V
>
extends
WeakReference
<
Entry
<
K
,
V
>>
implements
Reference
<
K
,
V
>
{
private
final
int
hash
;
private
final
Reference
<
K
,
V
>
nextReference
;
public
WeakEntryReference
(
Entry
<
K
,
V
>
entry
,
int
hash
,
Reference
<
K
,
V
>
next
,
ReferenceQueue
<
Entry
<
K
,
V
>>
queue
)
{
public
WeakEntryReference
(
Entry
<
K
,
V
>
entry
,
int
hash
,
Reference
<
K
,
V
>
next
,
ReferenceQueue
<
Entry
<
K
,
V
>>
queue
)
{
super
(
entry
,
queue
);
this
.
hash
=
hash
;
this
.
nextReference
=
next
;
...
...
@@ -1000,4 +983,5 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
clear
();
}
}
}
spring-core/src/main/java/org/springframework/util/xml/StaxEventXMLReader.java
浏览文件 @
1ac8e48e
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
3
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.
...
...
@@ -51,12 +51,12 @@ import org.springframework.util.StringUtils;
* an {@code XMLEventReader}, and calls the corresponding methods on the SAX callback interfaces.
*
* @author Arjen Poutsma
* @since 3.0
* @see XMLEventReader
* @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
*/
class
StaxEventXMLReader
extends
AbstractStaxXMLReader
{
...
...
@@ -70,11 +70,11 @@ class StaxEventXMLReader extends AbstractStaxXMLReader {
private
String
encoding
;
/**
* Constructs a new instance of the {@code StaxEventXmlReader} that reads from the given
* {@code XMLEventReader}. The supplied event reader must be in {@code XMLStreamConstants.START_DOCUMENT} or
* {@code XMLStreamConstants.START_ELEMENT} state.
*
* @param reader the {@code XMLEventReader} to read from
* @throws IllegalStateException if the reader is not at the start of a document or element
*/
...
...
@@ -89,17 +89,17 @@ class StaxEventXMLReader extends AbstractStaxXMLReader {
catch
(
XMLStreamException
ex
)
{
throw
new
IllegalStateException
(
"Could not read first element: "
+
ex
.
getMessage
());
}
this
.
reader
=
reader
;
}
@Override
protected
void
parseInternal
()
throws
SAXException
,
XMLStreamException
{
boolean
documentStarted
=
false
;
boolean
documentEnded
=
false
;
int
elementDepth
=
0
;
while
(
reader
.
hasNext
()
&&
elementDepth
>=
0
)
{
XMLEvent
event
=
reader
.
nextEvent
();
while
(
this
.
reader
.
hasNext
()
&&
elementDepth
>=
0
)
{
XMLEvent
event
=
this
.
reader
.
nextEvent
();
if
(!
event
.
isStartDocument
()
&&
!
event
.
isEndDocument
()
&&
!
documentStarted
)
{
handleStartDocument
(
event
);
documentStarted
=
true
;
...
...
@@ -165,36 +165,28 @@ class StaxEventXMLReader extends AbstractStaxXMLReader {
this
.
encoding
=
startDocument
.
getCharacterEncodingScheme
();
}
}
if
(
getContentHandler
()
!=
null
)
{
final
Location
location
=
event
.
getLocation
();
getContentHandler
().
setDocumentLocator
(
new
Locator2
()
{
public
int
getColumnNumber
()
{
return
location
!=
null
?
location
.
getColumnNumber
()
:
-
1
;
return
(
location
!=
null
?
location
.
getColumnNumber
()
:
-
1
)
;
}
public
int
getLineNumber
()
{
return
location
!=
null
?
location
.
getLineNumber
()
:
-
1
;
return
(
location
!=
null
?
location
.
getLineNumber
()
:
-
1
)
;
}
public
String
getPublicId
()
{
return
location
!=
null
?
location
.
getPublicId
()
:
null
;
return
(
location
!=
null
?
location
.
getPublicId
()
:
null
)
;
}
public
String
getSystemId
()
{
return
location
!=
null
?
location
.
getSystemId
()
:
null
;
return
(
location
!=
null
?
location
.
getSystemId
()
:
null
)
;
}
public
String
getXMLVersion
()
{
return
xmlVersion
;
}
public
String
getEncoding
()
{
return
encoding
;
}
});
getContentHandler
().
startDocument
();
}
}
...
...
@@ -311,7 +303,6 @@ class StaxEventXMLReader extends AbstractStaxXMLReader {
private
Attributes
getAttributes
(
StartElement
event
)
{
AttributesImpl
attributes
=
new
AttributesImpl
();
for
(
Iterator
i
=
event
.
getAttributes
();
i
.
hasNext
();)
{
Attribute
attribute
=
(
Attribute
)
i
.
next
();
QName
qName
=
attribute
.
getName
();
...
...
@@ -323,8 +314,7 @@ class StaxEventXMLReader extends AbstractStaxXMLReader {
if
(
type
==
null
)
{
type
=
"CDATA"
;
}
attributes
.
addAttribute
(
namespace
,
qName
.
getLocalPart
(),
toQualifiedName
(
qName
),
type
,
attribute
.
getValue
());
attributes
.
addAttribute
(
namespace
,
qName
.
getLocalPart
(),
toQualifiedName
(
qName
),
type
,
attribute
.
getValue
());
}
if
(
hasNamespacePrefixesFeature
())
{
for
(
Iterator
i
=
event
.
getNamespaces
();
i
.
hasNext
();)
{
...
...
spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java
浏览文件 @
1ac8e48e
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
3
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.
...
...
@@ -31,16 +31,16 @@ import org.springframework.util.Assert;
import
org.springframework.util.StringUtils
;
/**
* SAX {@code XMLReader} that reads from a StAX {@code XMLStreamReader}.
Reads from an
* SAX {@code XMLReader} that reads from a StAX {@code XMLStreamReader}. Reads from an
* {@code XMLStreamReader}, and calls the corresponding methods on the SAX callback interfaces.
*
* @author Arjen Poutsma
* @since 3.0
* @see XMLStreamReader
* @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
*/
class
StaxStreamXMLReader
extends
AbstractStaxXMLReader
{
...
...
@@ -52,11 +52,11 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader {
private
String
encoding
;
/**
* Construct
s
a new instance of the {@code StaxStreamXmlReader} that reads from the given
* {@code XMLStreamReader}.
The supplied stream reader must be in {@code XMLStreamConstants.START_DOCUMENT}
* Construct a new instance of the {@code StaxStreamXmlReader} that reads from the given
* {@code XMLStreamReader}. The supplied stream reader must be in {@code XMLStreamConstants.START_DOCUMENT}
* or {@code XMLStreamConstants.START_ELEMENT} state.
*
* @param reader the {@code XMLEventReader} to read from
* @throws IllegalStateException if the reader is not at the start of a document or element
*/
...
...
@@ -69,12 +69,13 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader {
this
.
reader
=
reader
;
}
@Override
protected
void
parseInternal
()
throws
SAXException
,
XMLStreamException
{
boolean
documentStarted
=
false
;
boolean
documentEnded
=
false
;
int
elementDepth
=
0
;
int
eventType
=
reader
.
getEventType
();
int
eventType
=
this
.
reader
.
getEventType
();
while
(
true
)
{
if
(
eventType
!=
XMLStreamConstants
.
START_DOCUMENT
&&
eventType
!=
XMLStreamConstants
.
END_DOCUMENT
&&
!
documentStarted
)
{
...
...
@@ -118,8 +119,8 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader {
handleEntityReference
();
break
;
}
if
(
reader
.
hasNext
()
&&
elementDepth
>=
0
)
{
eventType
=
reader
.
next
();
if
(
this
.
reader
.
hasNext
()
&&
elementDepth
>=
0
)
{
eventType
=
this
.
reader
.
next
();
}
else
{
break
;
...
...
@@ -131,66 +132,58 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader {
}
private
void
handleStartDocument
()
throws
SAXException
{
if
(
XMLStreamConstants
.
START_DOCUMENT
==
reader
.
getEventType
())
{
String
xmlVersion
=
reader
.
getVersion
();
if
(
XMLStreamConstants
.
START_DOCUMENT
==
this
.
reader
.
getEventType
())
{
String
xmlVersion
=
this
.
reader
.
getVersion
();
if
(
StringUtils
.
hasLength
(
xmlVersion
))
{
this
.
xmlVersion
=
xmlVersion
;
}
this
.
encoding
=
reader
.
getCharacterEncodingScheme
();
this
.
encoding
=
this
.
reader
.
getCharacterEncodingScheme
();
}
if
(
getContentHandler
()
!=
null
)
{
final
Location
location
=
reader
.
getLocation
();
final
Location
location
=
this
.
reader
.
getLocation
();
getContentHandler
().
setDocumentLocator
(
new
Locator2
()
{
public
int
getColumnNumber
()
{
return
location
!=
null
?
location
.
getColumnNumber
()
:
-
1
;
return
(
location
!=
null
?
location
.
getColumnNumber
()
:
-
1
)
;
}
public
int
getLineNumber
()
{
return
location
!=
null
?
location
.
getLineNumber
()
:
-
1
;
return
(
location
!=
null
?
location
.
getLineNumber
()
:
-
1
)
;
}
public
String
getPublicId
()
{
return
location
!=
null
?
location
.
getPublicId
()
:
null
;
return
(
location
!=
null
?
location
.
getPublicId
()
:
null
)
;
}
public
String
getSystemId
()
{
return
location
!=
null
?
location
.
getSystemId
()
:
null
;
return
(
location
!=
null
?
location
.
getSystemId
()
:
null
)
;
}
public
String
getXMLVersion
()
{
return
xmlVersion
;
}
public
String
getEncoding
()
{
return
encoding
;
}
});
getContentHandler
().
startDocument
();
if
(
reader
.
standaloneSet
())
{
setStandalone
(
reader
.
isStandalone
());
if
(
this
.
reader
.
standaloneSet
())
{
setStandalone
(
this
.
reader
.
isStandalone
());
}
}
}
private
void
handleStartElement
()
throws
SAXException
{
if
(
getContentHandler
()
!=
null
)
{
QName
qName
=
reader
.
getName
();
QName
qName
=
this
.
reader
.
getName
();
if
(
hasNamespacesFeature
())
{
for
(
int
i
=
0
;
i
<
reader
.
getNamespaceCount
();
i
++)
{
startPrefixMapping
(
reader
.
getNamespacePrefix
(
i
),
reader
.
getNamespaceURI
(
i
));
for
(
int
i
=
0
;
i
<
this
.
reader
.
getNamespaceCount
();
i
++)
{
startPrefixMapping
(
this
.
reader
.
getNamespacePrefix
(
i
),
this
.
reader
.
getNamespaceURI
(
i
));
}
for
(
int
i
=
0
;
i
<
reader
.
getAttributeCount
();
i
++)
{
String
prefix
=
reader
.
getAttributePrefix
(
i
);
String
namespace
=
reader
.
getAttributeNamespace
(
i
);
for
(
int
i
=
0
;
i
<
this
.
reader
.
getAttributeCount
();
i
++)
{
String
prefix
=
this
.
reader
.
getAttributePrefix
(
i
);
String
namespace
=
this
.
reader
.
getAttributeNamespace
(
i
);
if
(
StringUtils
.
hasLength
(
namespace
))
{
startPrefixMapping
(
prefix
,
namespace
);
}
}
getContentHandler
().
startElement
(
qName
.
getNamespaceURI
(),
qName
.
getLocalPart
(),
toQualifiedName
(
qName
),
getAttributes
());
getContentHandler
().
startElement
(
qName
.
getNamespaceURI
(),
qName
.
getLocalPart
(),
toQualifiedName
(
qName
),
getAttributes
());
}
else
{
getContentHandler
().
startElement
(
""
,
""
,
toQualifiedName
(
qName
),
getAttributes
());
...
...
@@ -200,11 +193,11 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader {
private
void
handleEndElement
()
throws
SAXException
{
if
(
getContentHandler
()
!=
null
)
{
QName
qName
=
reader
.
getName
();
QName
qName
=
this
.
reader
.
getName
();
if
(
hasNamespacesFeature
())
{
getContentHandler
().
endElement
(
qName
.
getNamespaceURI
(),
qName
.
getLocalPart
(),
toQualifiedName
(
qName
));
for
(
int
i
=
0
;
i
<
reader
.
getNamespaceCount
();
i
++)
{
String
prefix
=
reader
.
getNamespacePrefix
(
i
);
for
(
int
i
=
0
;
i
<
this
.
reader
.
getNamespaceCount
();
i
++)
{
String
prefix
=
this
.
reader
.
getNamespacePrefix
(
i
);
if
(
prefix
==
null
)
{
prefix
=
""
;
}
...
...
@@ -218,31 +211,33 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader {
}
private
void
handleCharacters
()
throws
SAXException
{
if
(
getContentHandler
()
!=
null
&&
reader
.
isWhiteSpace
())
{
getContentHandler
()
.
ignorableWhitespace
(
reader
.
getTextCharacters
(),
reader
.
getTextStart
(),
reader
.
getTextLength
());
if
(
getContentHandler
()
!=
null
&&
this
.
reader
.
isWhiteSpace
())
{
getContentHandler
()
.
ignorableWhitespace
(
this
.
reader
.
getTextCharacters
(),
this
.
reader
.
getTextStart
(),
this
.
reader
.
getTextLength
());
return
;
}
if
(
XMLStreamConstants
.
CDATA
==
reader
.
getEventType
()
&&
getLexicalHandler
()
!=
null
)
{
if
(
XMLStreamConstants
.
CDATA
==
this
.
reader
.
getEventType
()
&&
getLexicalHandler
()
!=
null
)
{
getLexicalHandler
().
startCDATA
();
}
if
(
getContentHandler
()
!=
null
)
{
getContentHandler
().
characters
(
reader
.
getTextCharacters
(),
reader
.
getTextStart
(),
reader
.
getTextLength
());
getContentHandler
().
characters
(
this
.
reader
.
getTextCharacters
(),
this
.
reader
.
getTextStart
(),
this
.
reader
.
getTextLength
());
}
if
(
XMLStreamConstants
.
CDATA
==
reader
.
getEventType
()
&&
getLexicalHandler
()
!=
null
)
{
if
(
XMLStreamConstants
.
CDATA
==
this
.
reader
.
getEventType
()
&&
getLexicalHandler
()
!=
null
)
{
getLexicalHandler
().
endCDATA
();
}
}
private
void
handleComment
()
throws
SAXException
{
if
(
getLexicalHandler
()
!=
null
)
{
getLexicalHandler
().
comment
(
reader
.
getTextCharacters
(),
reader
.
getTextStart
(),
reader
.
getTextLength
());
getLexicalHandler
().
comment
(
this
.
reader
.
getTextCharacters
(),
this
.
reader
.
getTextStart
(),
this
.
reader
.
getTextLength
());
}
}
private
void
handleDtd
()
throws
SAXException
{
if
(
getLexicalHandler
()
!=
null
)
{
javax
.
xml
.
stream
.
Location
location
=
reader
.
getLocation
();
javax
.
xml
.
stream
.
Location
location
=
this
.
reader
.
getLocation
();
getLexicalHandler
().
startDTD
(
null
,
location
.
getPublicId
(),
location
.
getSystemId
());
}
if
(
getLexicalHandler
()
!=
null
)
{
...
...
@@ -252,10 +247,10 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader {
private
void
handleEntityReference
()
throws
SAXException
{
if
(
getLexicalHandler
()
!=
null
)
{
getLexicalHandler
().
startEntity
(
reader
.
getLocalName
());
getLexicalHandler
().
startEntity
(
this
.
reader
.
getLocalName
());
}
if
(
getLexicalHandler
()
!=
null
)
{
getLexicalHandler
().
endEntity
(
reader
.
getLocalName
());
getLexicalHandler
().
endEntity
(
this
.
reader
.
getLocalName
());
}
}
...
...
@@ -267,29 +262,28 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader {
private
void
handleProcessingInstruction
()
throws
SAXException
{
if
(
getContentHandler
()
!=
null
)
{
getContentHandler
().
processingInstruction
(
reader
.
getPITarget
(),
reader
.
getPIData
());
getContentHandler
().
processingInstruction
(
this
.
reader
.
getPITarget
(),
this
.
reader
.
getPIData
());
}
}
private
Attributes
getAttributes
()
{
AttributesImpl
attributes
=
new
AttributesImpl
();
for
(
int
i
=
0
;
i
<
reader
.
getAttributeCount
();
i
++)
{
String
namespace
=
reader
.
getAttributeNamespace
(
i
);
for
(
int
i
=
0
;
i
<
this
.
reader
.
getAttributeCount
();
i
++)
{
String
namespace
=
this
.
reader
.
getAttributeNamespace
(
i
);
if
(
namespace
==
null
||
!
hasNamespacesFeature
())
{
namespace
=
""
;
}
String
type
=
reader
.
getAttributeType
(
i
);
String
type
=
this
.
reader
.
getAttributeType
(
i
);
if
(
type
==
null
)
{
type
=
"CDATA"
;
}
attributes
.
addAttribute
(
namespace
,
reader
.
getAttributeLocalName
(
i
),
toQualifiedName
(
reader
.
getAttributeName
(
i
)),
type
,
reader
.
getAttributeValue
(
i
));
attributes
.
addAttribute
(
namespace
,
this
.
reader
.
getAttributeLocalName
(
i
),
toQualifiedName
(
this
.
reader
.
getAttributeName
(
i
)),
type
,
this
.
reader
.
getAttributeValue
(
i
));
}
if
(
hasNamespacePrefixesFeature
())
{
for
(
int
i
=
0
;
i
<
reader
.
getNamespaceCount
();
i
++)
{
String
prefix
=
reader
.
getNamespacePrefix
(
i
);
String
namespaceUri
=
reader
.
getNamespaceURI
(
i
);
for
(
int
i
=
0
;
i
<
this
.
reader
.
getNamespaceCount
();
i
++)
{
String
prefix
=
this
.
reader
.
getNamespacePrefix
(
i
);
String
namespaceUri
=
this
.
reader
.
getNamespaceURI
(
i
);
String
qName
;
if
(
StringUtils
.
hasLength
(
prefix
))
{
qName
=
"xmlns:"
+
prefix
;
...
...
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java
浏览文件 @
1ac8e48e
/*
* Copyright 2002-201
1
the original author or authors.
* Copyright 2002-201
3
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.
...
...
@@ -25,7 +25,6 @@ import java.util.Iterator;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Set
;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.util.AntPathMatcher
;
...
...
@@ -54,6 +53,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
private
final
List
<
String
>
fileExtensions
=
new
ArrayList
<
String
>();
/**
* Creates a new instance with the given URL patterns.
* Each pattern that is not empty and does not start with "/" is prepended with "/".
...
...
@@ -66,7 +66,6 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
/**
* Additional constructor with flags for using suffix pattern (.*) and
* trailing slash matches.
*
* @param patterns the URL patterns to use; if 0, the condition will match to every request.
* @param urlPathHelper for determining the lookup path of a request
* @param pathMatcher for path matching with patterns
...
...
@@ -98,7 +97,6 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
/**
* Private constructor accepting a collection of patterns.
* @param fileExtensionResolver
*/
private
PatternsRequestCondition
(
Collection
<
String
>
patterns
,
UrlPathHelper
urlPathHelper
,
PathMatcher
pathMatcher
,
boolean
useSuffixPatternMatch
,
boolean
useTrailingSlashMatch
,
...
...
@@ -119,8 +117,9 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
}
}
private
static
List
<
String
>
asList
(
String
...
patterns
)
{
return
patterns
!=
null
?
Arrays
.
asList
(
patterns
)
:
Collections
.<
String
>
emptyList
(
);
return
(
patterns
!=
null
?
Arrays
.
asList
(
patterns
)
:
Collections
.<
String
>
emptyList
()
);
}
private
static
Set
<
String
>
prependLeadingSlash
(
Collection
<
String
>
patterns
)
{
...
...
@@ -188,7 +187,6 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
* Checks if any of the patterns match the given request and returns an instance
* that is guaranteed to contain matching patterns, sorted via
* {@link PathMatcher#getPatternComparator(String)}.
*
* <p>A matching pattern is obtained by making checks in the following order:
* <ul>
* <li>Direct match
...
...
@@ -196,12 +194,10 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
* <li>Pattern match
* <li>Pattern match with "/" appended if the pattern doesn't already end in "/"
* </ul>
*
* @param request the current request
*
* @return the same instance if the condition contains no patterns;
*
or a new condition with sorted matching patterns;
*
or {@code null} if no patterns match.
* or a new condition with sorted matching patterns;
* or {@code null} if no patterns match.
*/
@Override
public
PatternsRequestCondition
getMatchingCondition
(
HttpServletRequest
request
)
{
...
...
@@ -210,9 +206,8 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
}
String
lookupPath
=
this
.
pathHelper
.
getLookupPathForRequest
(
request
);
List
<
String
>
matches
=
new
ArrayList
<
String
>();
for
(
String
pattern
:
patterns
)
{
for
(
String
pattern
:
this
.
patterns
)
{
String
match
=
getMatchingPattern
(
pattern
,
lookupPath
);
if
(
match
!=
null
)
{
matches
.
add
(
match
);
...
...
@@ -260,7 +255,6 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
* {@link PathMatcher#getPatternComparator(String)}. If all compared
* patterns match equally, but one instance has more patterns, it is
* considered a closer match.
*
* <p>It is assumed that both instances have been obtained via
* {@link #getMatchingCondition(HttpServletRequest)} to ensure they
* contain only patterns that match the request and are sorted with
...
...
@@ -271,7 +265,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
String
lookupPath
=
this
.
pathHelper
.
getLookupPathForRequest
(
request
);
Comparator
<
String
>
patternComparator
=
this
.
pathMatcher
.
getPatternComparator
(
lookupPath
);
Iterator
<
String
>
iterator
=
patterns
.
iterator
();
Iterator
<
String
>
iterator
=
this
.
patterns
.
iterator
();
Iterator
<
String
>
iteratorOther
=
other
.
patterns
.
iterator
();
while
(
iterator
.
hasNext
()
&&
iteratorOther
.
hasNext
())
{
int
result
=
patternComparator
.
compare
(
iterator
.
next
(),
iteratorOther
.
next
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录