/*
* 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-core-2.1.8.1 xwork-core-2.1.6源码
共696个文件
java:669个
html:27个
5星 · 超过95%的资源 需积分: 10 253 下载量 105 浏览量
2010-07-29
22:43:07
上传
评论 2
收藏 1.01MB RAR 举报
温馨提示
struts2最新版本struts2-core-2.1.8.1与xwork-core-2.1.6 源码
资源推荐
资源详情
资源评论
收起资源包目录
struts2-core-2.1.8.1 xwork-core-2.1.6源码 (696个子文件)
package.html 2KB
package.html 964B
package.html 949B
package.html 943B
package.html 937B
package.html 927B
package.html 919B
package.html 555B
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
ResourceFinder.java 43KB
XmlConfigurationProvider.java 42KB
UIBean.java 38KB
XWorkConverter.java 36KB
LocalizedTextUtil.java 34KB
ClassFinder.java 31KB
Dispatcher.java 31KB
AnnotationValidationConfigurationBuilder.java 31KB
VelocityManager.java 23KB
XWorkBasicConverter.java 23KB
DefaultActionMapper.java 20KB
PackageConfig.java 20KB
ContainerImpl.java 20KB
OptionTransferSelect.java 19KB
Validator.java 19KB
DefaultConfiguration.java 19KB
PropertiesReader.java 19KB
OgnlValueStack.java 18KB
DebuggingInterceptor.java 18KB
Component.java 18KB
DoubleListUIBean.java 18KB
ResolverUtil.java 17KB
ParametersInterceptor.java 17KB
FileUploadInterceptor.java 17KB
DefaultActionInvocation.java 17KB
ReferenceMap.java 17KB
OgnlUtil.java 16KB
ExecuteAndWaitInterceptor.java 16KB
ContainerBuilder.java 16KB
AnnotationActionValidatorManager.java 16KB
FilterDispatcher.java 16KB
ScopeInterceptor.java 15KB
DefaultActionValidatorManager.java 15KB
WildcardHelper.java 15KB
IteratorComponent.java 15KB
UtilTimerStack.java 15KB
FreemarkerManager.java 15KB
XSLTResult.java 15KB
ServletUrlRenderer.java 14KB
UrlHelper.java 14KB
BeanSelectionProvider.java 14KB
Include.java 14KB
DefaultObjectTypeDeterminer.java 14KB
LocationAttributes.java 13KB
Date.java 13KB
MessageStoreInterceptor.java 13KB
DefaultTypeConverter.java 13KB
ActionComponent.java 13KB
DomHelper.java 13KB
DefaultStaticContentLoader.java 12KB
TextProviderSupport.java 12KB
Form.java 12KB
FreemarkerResult.java 12KB
LocationUtils.java 12KB
StreamResult.java 11KB
CookieInterceptor.java 11KB
StrutsConstants.java 11KB
ActionConfig.java 11KB
JakartaMultiPartRequest.java 11KB
ExceptionMappingInterceptor.java 11KB
Settings.java 11KB
AbstractAdapterNode.java 11KB
ValidatorFactory.java 10KB
ActionContext.java 10KB
InputTransferSelect.java 10KB
ObjectFactory.java 10KB
StrutsModels.java 10KB
DefaultValidatorFileParser.java 10KB
FileManager.java 10KB
SpringObjectFactory.java 10KB
TextParseUtil.java 10KB
SubsetIteratorTag.java 10KB
CompoundRootAccessor.java 10KB
共 696 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
Hiker_2010
- 粉丝: 12
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页