Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
cbb90236
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,体验更适合开发者的 AI 搜索 >>
提交
cbb90236
编写于
6月 11, 2010
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polished VFS support (SPR-7197)
上级
53ed9b28
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
74 addition
and
61 deletion
+74
-61
org.springframework.core/src/main/java/org/springframework/core/io/VfsResource.java
...rc/main/java/org/springframework/core/io/VfsResource.java
+21
-14
org.springframework.core/src/main/java/org/springframework/core/io/VfsUtils.java
...e/src/main/java/org/springframework/core/io/VfsUtils.java
+37
-34
org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java
.../core/io/support/PathMatchingResourcePatternResolver.java
+9
-7
org.springframework.core/src/main/java/org/springframework/core/io/support/VfsPatternUtils.java
.../org/springframework/core/io/support/VfsPatternUtils.java
+7
-6
未找到文件。
org.springframework.core/src/main/java/org/springframework/core/io/VfsResource.java
浏览文件 @
cbb90236
...
...
@@ -27,6 +27,7 @@ import org.springframework.util.Assert;
/**
* VFS based {@link Resource} implementation.
* Supports the corresponding VFS API versions on JBoss AS 5.x as well as 6.x.
*
* @author Ales Justin
* @author Juergen Hoeller
...
...
@@ -39,53 +40,58 @@ public class VfsResource extends AbstractResource {
private
final
Object
resource
;
public
VfsResource
(
Object
resources
)
{
Assert
.
notNull
(
resources
,
"VirtualFile must not be null"
);
this
.
resource
=
resources
;
}
public
boolean
exists
()
{
return
VfsUtils
.
exists
(
resource
);
return
VfsUtils
.
exists
(
this
.
resource
);
}
public
boolean
isReadable
()
{
return
VfsUtils
.
isReadable
(
resource
);
return
VfsUtils
.
isReadable
(
this
.
resource
);
}
public
long
lastModified
()
throws
IOException
{
return
VfsUtils
.
getLastModified
(
resource
);
return
VfsUtils
.
getLastModified
(
this
.
resource
);
}
public
InputStream
getInputStream
()
throws
IOException
{
return
VfsUtils
.
getInputStream
(
resource
);
return
VfsUtils
.
getInputStream
(
this
.
resource
);
}
public
URL
getURL
()
throws
IOException
{
try
{
return
VfsUtils
.
getURL
(
resource
);
}
catch
(
Exception
ex
)
{
return
VfsUtils
.
getURL
(
this
.
resource
);
}
catch
(
Exception
ex
)
{
throw
new
NestedIOException
(
"Failed to obtain URL for file "
+
this
.
resource
,
ex
);
}
}
public
URI
getURI
()
throws
IOException
{
try
{
return
VfsUtils
.
getURI
(
resource
);
}
catch
(
Exception
ex
)
{
return
VfsUtils
.
getURI
(
this
.
resource
);
}
catch
(
Exception
ex
)
{
throw
new
NestedIOException
(
"Failed to obtain URI for "
+
this
.
resource
,
ex
);
}
}
public
File
getFile
()
throws
IOException
{
return
VfsUtils
.
getFile
(
resource
);
return
VfsUtils
.
getFile
(
this
.
resource
);
}
public
Resource
createRelative
(
String
relativePath
)
throws
IOException
{
if
(!
relativePath
.
startsWith
(
"."
)
&&
relativePath
.
contains
(
"/"
))
{
try
{
return
new
VfsResource
(
VfsUtils
.
getChild
(
resource
,
relativePath
));
}
catch
(
IOException
ex
)
{
// fall back to #getRelative
return
new
VfsResource
(
VfsUtils
.
getChild
(
this
.
resource
,
relativePath
));
}
catch
(
IOException
ex
)
{
// fall back to getRelative
}
}
...
...
@@ -93,7 +99,7 @@ public class VfsResource extends AbstractResource {
}
public
String
getFilename
()
{
return
VfsUtils
.
getName
(
resource
);
return
VfsUtils
.
getName
(
this
.
resource
);
}
public
String
getDescription
()
{
...
...
@@ -109,4 +115,5 @@ public class VfsResource extends AbstractResource {
public
int
hashCode
()
{
return
this
.
resource
.
hashCode
();
}
}
\ No newline at end of file
}
org.springframework.core/src/main/java/org/springframework/core/io/VfsUtils.java
浏览文件 @
cbb90236
/*
* Copyright 2010 the original author or authors.
* Copyright 20
02-20
10 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.
...
...
@@ -32,29 +32,27 @@ import org.springframework.util.ReflectionUtils;
/**
* Utility for detecting the JBoss VFS version available in the classpath.
* JBoss AS 5+ uses VFS 2.x (package <code>org.jboss.virtual</code>) while JBoss AS 6+ uses
* VFS 3.x (package <code>org.jboss.vfs</code>).
*
* <p/>
* Thanks go to Marius Bogoevici for the initial patch.
* JBoss AS 5+ uses VFS 2.x (package <code>org.jboss.virtual</code>) while
* JBoss AS 6+ uses VFS 3.x (package <code>org.jboss.vfs</code>).
*
* <p>Thanks go to Marius Bogoevici for the initial patch.
*
* <b>Note:</b> This is an internal class and should not be used outside the framework.
*
*
* @author Costin Leau
* @since 3.0.3
*/
public
abstract
class
VfsUtils
{
private
static
final
Log
log
=
LogFactory
.
getLog
(
VfsUtils
.
class
);
private
static
final
Log
log
ger
=
LogFactory
.
getLog
(
VfsUtils
.
class
);
private
static
final
String
VFS2_PKG
=
"org.jboss.virtual."
;
private
static
final
String
VFS3_PKG
=
"org.jboss.vfs."
;
private
static
final
String
VFS_NAME
=
"VFS"
;
private
static
enum
VFS_VER
{
V2
,
V3
}
private
static
enum
VFS_VER
{
V2
,
V3
}
private
static
VFS_VER
version
=
null
;
private
static
VFS_VER
version
;
private
static
Method
VFS_METHOD_GET_ROOT_URL
=
null
;
private
static
Method
VFS_METHOD_GET_ROOT_URI
=
null
;
...
...
@@ -71,7 +69,6 @@ public abstract class VfsUtils {
protected
static
Class
<?>
VIRTUAL_FILE_VISITOR_INTERFACE
;
protected
static
Method
VIRTUAL_FILE_METHOD_VISIT
;
private
static
Method
VFS_UTILS_METHOD_IS_NESTED_FILE
=
null
;
private
static
Method
VFS_UTILS_METHOD_GET_COMPATIBLE_URI
=
null
;
private
static
Field
VISITOR_ATTRIBUTES_FIELD_RECURSE
=
null
;
...
...
@@ -79,33 +76,33 @@ public abstract class VfsUtils {
static
{
ClassLoader
loader
=
VfsUtils
.
class
.
getClassLoader
();
String
pkg
;
Class
<?>
vfsClass
;
String
pkg
=
""
;
Class
<?>
vfsClass
=
null
;
// check JBoss 6
// check for JBoss 6
try
{
vfsClass
=
loader
.
loadClass
(
VFS3_PKG
+
VFS_NAME
);
version
=
VFS_VER
.
V3
;
pkg
=
VFS3_PKG
;
if
(
log
.
isDebugEnabled
())
log
.
debug
(
"JBoss VFS packages for JBoss AS 6 found"
);
}
catch
(
ClassNotFoundException
ex
)
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"JBoss VFS packages for JBoss AS 6 found"
);
}
}
catch
(
ClassNotFoundException
ex
)
{
// fallback to JBoss 5
if
(
log
.
isDebugEnabled
())
log
.
debug
(
"JBoss VFS packages for JBoss AS 6 not found; falling back to JBoss AS 5 packages"
);
if
(
log
ger
.
isDebugEnabled
())
log
ger
.
debug
(
"JBoss VFS packages for JBoss AS 6 not found; falling back to JBoss AS 5 packages"
);
try
{
vfsClass
=
loader
.
loadClass
(
VFS2_PKG
+
VFS_NAME
);
version
=
VFS_VER
.
V2
;
pkg
=
VFS2_PKG
;
if
(
log
.
isDebugEnabled
())
log
.
debug
(
"JBoss VFS packages for JBoss AS 5 found"
);
if
(
log
ger
.
isDebugEnabled
())
log
ger
.
debug
(
"JBoss VFS packages for JBoss AS 5 found"
);
}
catch
(
ClassNotFoundException
ex1
)
{
log
.
error
(
"JBoss VFS packages (for both JBoss AS 5 and 6) were not found - JBoss VFS support disabled"
);
log
ger
.
error
(
"JBoss VFS packages (for both JBoss AS 5 and 6) were not found - JBoss VFS support disabled"
);
throw
new
IllegalStateException
(
"Cannot detect JBoss VFS packages"
,
ex1
);
}
}
...
...
@@ -144,8 +141,8 @@ public abstract class VfsUtils {
Class
<?>
visitorAttributesClass
=
loader
.
loadClass
(
pkg
+
"VisitorAttributes"
);
VISITOR_ATTRIBUTES_FIELD_RECURSE
=
ReflectionUtils
.
findField
(
visitorAttributesClass
,
"RECURSE"
);
}
catch
(
ClassNotFoundException
ex
)
{
}
catch
(
ClassNotFoundException
ex
)
{
throw
new
IllegalStateException
(
"Could not detect the JBoss VFS infrastructure"
,
ex
);
}
}
...
...
@@ -153,13 +150,15 @@ public abstract class VfsUtils {
protected
static
Object
invokeVfsMethod
(
Method
method
,
Object
target
,
Object
...
args
)
throws
IOException
{
try
{
return
method
.
invoke
(
target
,
args
);
}
catch
(
InvocationTargetException
ex
)
{
}
catch
(
InvocationTargetException
ex
)
{
Throwable
targetEx
=
ex
.
getTargetException
();
if
(
targetEx
instanceof
IOException
)
{
throw
(
IOException
)
targetEx
;
}
ReflectionUtils
.
handleInvocationTargetException
(
ex
);
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
ReflectionUtils
.
handleReflectionException
(
ex
);
}
...
...
@@ -169,7 +168,8 @@ public abstract class VfsUtils {
static
boolean
exists
(
Object
vfsResource
)
{
try
{
return
(
Boolean
)
invokeVfsMethod
(
VIRTUAL_FILE_METHOD_EXISTS
,
vfsResource
);
}
catch
(
IOException
ex
)
{
}
catch
(
IOException
ex
)
{
return
false
;
}
}
...
...
@@ -177,7 +177,8 @@ public abstract class VfsUtils {
static
boolean
isReadable
(
Object
vfsResource
)
{
try
{
return
((
Long
)
invokeVfsMethod
(
VIRTUAL_FILE_METHOD_GET_SIZE
,
vfsResource
)
>
0
);
}
catch
(
IOException
ex
)
{
}
catch
(
IOException
ex
)
{
return
false
;
}
}
...
...
@@ -201,7 +202,8 @@ public abstract class VfsUtils {
static
String
getName
(
Object
vfsResource
)
{
try
{
return
(
String
)
invokeVfsMethod
(
VIRTUAL_FILE_METHOD_GET_NAME
,
vfsResource
);
}
catch
(
IOException
ex
)
{
}
catch
(
IOException
ex
)
{
throw
new
IllegalStateException
(
"Cannot get resource name"
,
ex
);
}
}
...
...
@@ -221,7 +223,8 @@ public abstract class VfsUtils {
}
try
{
return
new
File
((
URI
)
invokeVfsMethod
(
VFS_UTILS_METHOD_GET_COMPATIBLE_URI
,
null
,
vfsResource
));
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
throw
new
NestedIOException
(
"Failed to obtain File reference for "
+
vfsResource
,
ex
);
}
}
...
...
org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java
浏览文件 @
cbb90236
...
...
@@ -33,6 +33,7 @@ import java.util.jar.JarFile;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.core.io.DefaultResourceLoader
;
import
org.springframework.core.io.FileSystemResource
;
import
org.springframework.core.io.Resource
;
...
...
@@ -645,10 +646,11 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
*/
private
static
class
VfsResourceMatchingDelegate
{
public
static
Set
<
Resource
>
findMatchingResources
(
Resource
rootResource
,
String
locationPattern
,
PathMatcher
pathMatcher
)
throws
IOException
{
public
static
Set
<
Resource
>
findMatchingResources
(
Resource
rootResource
,
String
locationPattern
,
PathMatcher
pathMatcher
)
throws
IOException
{
Object
root
=
VfsPatternUtils
.
findRoot
(
rootResource
.
getURL
());
PatternVirtualFileVisitor
visitor
=
new
PatternVirtualFileVisitor
(
VfsPatternUtils
.
getPath
(
root
),
locationPattern
,
pathMatcher
);
PatternVirtualFileVisitor
visitor
=
new
PatternVirtualFileVisitor
(
VfsPatternUtils
.
getPath
(
root
),
locationPattern
,
pathMatcher
);
VfsPatternUtils
.
visit
(
root
,
visitor
);
return
visitor
.
getResources
();
}
...
...
@@ -674,7 +676,6 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
this
.
rootPath
=
(
rootPath
.
length
()
==
0
||
rootPath
.
endsWith
(
"/"
)
?
rootPath
:
rootPath
+
"/"
);
}
public
Object
invoke
(
Object
proxy
,
Method
method
,
Object
[]
args
)
throws
Throwable
{
String
methodName
=
method
.
getName
();
if
(
Object
.
class
.
equals
(
method
.
getDeclaringClass
()))
{
...
...
@@ -701,8 +702,8 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
}
public
void
visit
(
Object
vfsResource
)
{
if
(
this
.
pathMatcher
.
match
(
this
.
subPattern
,
VfsPatternUtils
.
getPath
(
vfsResource
).
substring
(
this
.
rootPath
.
length
())))
{
if
(
this
.
pathMatcher
.
match
(
this
.
subPattern
,
VfsPatternUtils
.
getPath
(
vfsResource
).
substring
(
this
.
rootPath
.
length
())))
{
this
.
resources
.
add
(
new
VfsResource
(
vfsResource
));
}
}
...
...
@@ -727,4 +728,5 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
return
sb
.
toString
();
}
}
}
\ No newline at end of file
}
org.springframework.core/src/main/java/org/springframework/core/io/support/VfsPatternUtils.java
浏览文件 @
cbb90236
/*
* Copyright 2002-20
09
the original author or authors.
* Copyright 2002-20
10
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.
...
...
@@ -24,13 +24,14 @@ import java.net.URL;
import
org.springframework.core.io.VfsUtils
;
/**
* Artificial class used for accessing the {@link VfsUtils} methods without exposing them
* to the entire world.
*
* @author Costin Leau
* Artificial class used for accessing the {@link VfsUtils} methods
* without exposing them to the entire world.
*
* @author Costin Leau
* @since 3.0.3
*/
abstract
class
VfsPatternUtils
extends
VfsUtils
{
static
Object
getVisitorAttribute
()
{
return
doGetVisitorAttribute
();
}
...
...
@@ -46,7 +47,7 @@ abstract class VfsPatternUtils extends VfsUtils {
static
void
visit
(
Object
resource
,
InvocationHandler
visitor
)
throws
IOException
{
Object
visitorProxy
=
Proxy
.
newProxyInstance
(
VIRTUAL_FILE_VISITOR_INTERFACE
.
getClassLoader
(),
new
Class
<?>[]
{
VIRTUAL_FILE_VISITOR_INTERFACE
},
visitor
);
invokeVfsMethod
(
VIRTUAL_FILE_METHOD_VISIT
,
resource
,
visitorProxy
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录