/*
* Copyright (c) 2002-2003 by OpenSymphony
* All rights reserved.
*/
package com.opensymphony.xwork2.util.finder;
import org.apache.commons.lang.StringUtils;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.*;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
/**
* @author David Blevins
* @version $Rev$ $Date$
*/
public class ResourceFinder {
private static final Logger LOG = LoggerFactory.getLogger(ResourceFinder.class);
private final URL[] urls;
private final String path;
private final ClassLoaderInterface classLoaderInterface;
private final List<String> resourcesNotLoaded = new ArrayList<String>();
public ResourceFinder(URL... urls) {
this(null, new ClassLoaderInterfaceDelegate(Thread.currentThread().getContextClassLoader()), urls);
}
public ResourceFinder(String path) {
this(path, new ClassLoaderInterfaceDelegate(Thread.currentThread().getContextClassLoader()), null);
}
public ResourceFinder(String path, URL... urls) {
this(path, new ClassLoaderInterfaceDelegate(Thread.currentThread().getContextClassLoader()), urls);
}
public ResourceFinder(String path, ClassLoaderInterface classLoaderInterface) {
this(path, classLoaderInterface, null);
}
public ResourceFinder(String path, ClassLoaderInterface classLoaderInterface, URL... urls) {
if (path == null){
path = "";
} else if (path.length() > 0 && !path.endsWith("/")) {
path += "/";
}
this.path = path;
this.classLoaderInterface = classLoaderInterface == null ? new ClassLoaderInterfaceDelegate(Thread.currentThread().getContextClassLoader()) : classLoaderInterface ;
for (int i = 0; urls != null && i < urls.length; i++) {
URL url = urls[i];
if (url == null || isDirectory(url) || "jar".equals(url.getProtocol())) {
continue;
}
try {
urls[i] = new URL("jar", "", -1, url.toString() + "!/");
} catch (MalformedURLException e) {
}
}
this.urls = (urls == null || urls.length == 0)? null : urls;
}
private static boolean isDirectory(URL url) {
String file = url.getFile();
return (file.length() > 0 && file.charAt(file.length() - 1) == '/');
}
/**
* Returns a list of resources that could not be loaded in the last invoked findAvailable* or
* mapAvailable* methods.
* <p/>
* The list will only contain entries of resources that match the requirements
* of the last invoked findAvailable* or mapAvailable* methods, but were unable to be
* loaded and included in their results.
* <p/>
* The list returned is unmodifiable and the results of this method will change
* after each invocation of a findAvailable* or mapAvailable* methods.
* <p/>
* This method is not thread safe.
*/
public List<String> getResourcesNotLoaded() {
return Collections.unmodifiableList(resourcesNotLoaded);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//
// Find
//
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
public URL find(String uri) throws IOException {
String fullUri = path + uri;
return getResource(fullUri);
}
public List<URL> findAll(String uri) throws IOException {
String fullUri = path + uri;
Enumeration<URL> resources = getResources(fullUri);
List<URL> list = new ArrayList<URL>();
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
list.add(url);
}
return list;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//
// Find String
//
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/**
* Reads the contents of the URL as a {@link String}'s and returns it.
*
* @param uri
* @return a stringified content of a resource
* @throws IOException if a resource pointed out by the uri param could not be find
* @see ClassLoader#getResource(String)
*/
public String findString(String uri) throws IOException {
String fullUri = path + uri;
URL resource = getResource(fullUri);
if (resource == null) {
throw new IOException("Could not find a resource in : " + fullUri);
}
return readContents(resource);
}
/**
* Reads the contents of the found URLs as a list of {@link String}'s and returns them.
*
* @param uri
* @return a list of the content of each resource URL found
* @throws IOException if any of the found URLs are unable to be read.
*/
public List<String> findAllStrings(String uri) throws IOException {
String fulluri = path + uri;
List<String> strings = new ArrayList<String>();
Enumeration<URL> resources = getResources(fulluri);
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
String string = readContents(url);
strings.add(string);
}
return strings;
}
/**
* Reads the contents of the found URLs as a Strings and returns them.
* Individual URLs that cannot be read are skipped and added to the
* list of 'resourcesNotLoaded'
*
* @param uri
* @return a list of the content of each resource URL found
* @throws IOException if classLoader.getResources throws an exception
*/
public List<String> findAvailableStrings(String uri) throws IOException {
resourcesNotLoaded.clear();
String fulluri = path + uri;
List<String> strings = new ArrayList<String>();
Enumeration<URL> resources = getResources(fulluri);
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
try {
String string = readContents(url);
strings.add(string);
} catch (IOException notAvailable) {
resourcesNotLoaded.add(url.toExternalForm());
}
}
return strings;
}
/**
* Reads the contents of all non-directory URLs immediately under the specified
* location and returns them in a map keyed by the file name.
* <p/>
* Any URLs that cannot be read will cause an exception to be thrown.
* <p/>
* Example classpath:
* <p/>
* META-INF/serializables/one
* META-INF/serializables/two
* META-INF/serializables/three
* META-INF/serializables/four/foo.txt
* <p/>
* ResourceFinder finder = new ResourceFinder("META-INF/");
* Map map = finder.mapAvailableStrings("serializables");
* map.contains("one"); // true
* map.contains("two"); // true
* map.contains("three"); // true
* map.contains("four"); // false
*
* @param uri
* @return a list of the content of each resource URL found
* @throws IOException if any of the urls cannot be read
*/
public Map<String, String> mapAllStrings(String uri) throws IOException {
Map<String, String> strings = new HashMap<String, String>();
Map<String, URL> resourcesMap = getResourcesMap(uri);
for (Map.Entry<String, URL> entry : resourcesMap.entrySet()) {
String name = entry.getKey();
URL url = entry.getValue();
String value = readContents(url);
strings.
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
struts2 依赖核心包 --xwork 源文件 (707个子文件)
xwork-2.1.3.dtd 3KB
xwork-2.1.dtd 3KB
xwork-2.0.dtd 2KB
xwork-1.1.2.dtd 2KB
xwork-1.1.1.dtd 2KB
xwork-1.1.dtd 2KB
xwork-1.0.dtd 2KB
xwork-validator-1.0.3.dtd 829B
xwork-validator-1.0.2.dtd 784B
xwork-validator-1.0.dtd 703B
xwork-validator-definition-1.0.dtd 446B
xwork-validator-config-1.0.dtd 409B
xwork-1.0.dtd 19B
package.html 555B
overview.html 140B
package.html 87B
package.html 62B
package.html 51B
package.html 50B
package.html 48B
package.html 48B
package.html 46B
package.html 45B
package.html 43B
package.html 42B
package.html 42B
package.html 42B
package.html 41B
package.html 40B
package.html 38B
package.html 36B
package.html 34B
package.html 33B
package.html 33B
xwork-mock-plugin.iml 3KB
xwork-plugins.iml 3KB
aspectjweaver-1.6.1.jar 1.5MB
testng-5.1.jar 676KB
javassist-3.7.ga.jar 531KB
spring-beans-2.5.6.jar 477KB
spring-context-2.5.6.jar 466KB
spring-aop-2.5.6.jar 318KB
cglib-nodep-2.1_3.jar 317KB
spring-core-2.5.6.jar 279KB
commons-lang-2.4.jar 256KB
ognl-2.7.3.jar 234KB
junit-4.5.jar 194KB
spring-web-2.5.6.jar 190KB
spring-test-2.5.6.jar 177KB
aspectjrt-1.6.1.jar 112KB
spring-context-support-2.5.6.jar 95KB
commons-logging-1.1.1.jar 59KB
asm-3.1.jar 42KB
asm-commons-3.1.jar 32KB
asm-tree-3.1.jar 21KB
spring-aspects-2.5.6.jar 20KB
aopalliance-1.0.jar 4KB
xwork - jar.jar 2KB
xwork-jar.jar 2KB
ResourceFinder.java 43KB
XmlConfigurationProvider.java 42KB
XWorkConverterTest.java 37KB
XWorkConverter.java 35KB
LocalizedTextUtil.java 34KB
ClassFinder.java 31KB
AnnotationValidationConfigurationBuilder.java 31KB
OgnlValueStackTest.java 28KB
XWorkBasicConverter.java 23KB
OgnlUtilTest.java 22KB
ParametersInterceptorTest.java 20KB
PackageConfig.java 20KB
AnnotationXWorkConverterTest.java 20KB
ContainerImpl.java 20KB
Validator.java 19KB
DefaultConfiguration.java 19KB
PropertiesReader.java 19KB
OgnlValueStack.java 18KB
ResolverUtil.java 17KB
ParametersInterceptor.java 17KB
DefaultActionInvocation.java 17KB
ReferenceMap.java 17KB
OgnlUtil.java 16KB
ContainerBuilder.java 16KB
AnnotationActionValidatorManager.java 16KB
AnnotationActionValidatorManagerTest.java 16KB
DefaultActionValidatorManager.java 15KB
WildcardHelper.java 15KB
UtilTimerStack.java 15KB
SpringObjectFactoryTest.java 15KB
DefaultActionValidatorManagerTest.java 14KB
DefaultObjectTypeDeterminer.java 14KB
LocationAttributes.java 13KB
InterceptorBuilderTest.java 13KB
DefaultTypeConverter.java 13KB
DomHelper.java 13KB
ActionSupportTest.java 12KB
TextProviderSupport.java 12KB
ConfigurationTest.java 12KB
LocationUtils.java 12KB
SetPropertiesTest.java 12KB
共 707 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
fh13760184
- 粉丝: 25
- 资源: 22
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- JavaScript《基于自动分析数据并给出营业建议的餐厅管理系统(接入AI) 》+源代码+项目说明及资料
- 355670834783295707ad04e-427f-4cde-9589-e578224a8459.zip
- 动态sql解析引擎,类似mybatis动态sql的功能
- EDA365-Skill-V2.5安装包,支持Allegro17.x版本
- C# 常用单词汇总,常用单词汇总
- 【ERP标准流程-标准流程-库内业务管理】(DOC 14页).doc
- Python《数据库期末作业-餐厅点单系统 》+源代码+设计资料
- 学生成绩管理系统(C++课程设计
- 双指针法判断链表有环-go语言实现
- MyBatis动态SQL是一种强大的特性,它允许我们在SQL语句中根据条件动态地添加或删除某些部分,从而实现更加灵活和高效的数据
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功