Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2004-2015 the Seasar Foundation and the Others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package org.seasar.framework.util;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.seasar.framework.log.Logger;
import org.seasar.framework.util.ClassTraversal.ClassHandler;
import org.seasar.framework.util.ResourceTraversal.ResourceHandler;
/**
* ファイルシステム上やJarファイル中に展開されているリソースの集まりを扱うユーティリティクラスです。
*
* 次のプロトコルをサポートしています。
*
*
*
file
*
jar
*
wsjar(WebShpere独自プロトコル、jarの別名)
*
zip(WebLogic独自プロトコル)
*
code-source(Oracle AS(OC4J)独自プロトコル)
*
vfsfile(JBossAS5独自プロトコル、fileの別名)
*
vfszip(JBossAS5独自プロトコル)
*
*
* @author koichik
* @see URLUtil#toCanonicalProtocol(String)
*/
public class ResourcesUtil {
/** 空の{@link Resources}の配列です。 */
protected static final Resources[] EMPTY_ARRAY = new Resources[0];
private static final Logger logger = Logger.getLogger(ResourcesUtil.class);
/** URLのプロトコルをキー、{@link ResourcesFactory}を値とするマッピングです。 */
protected static final Map resourcesTypeFactories = new HashMap<>();
static {
addResourcesFactory("file", new ResourcesFactory() {
@Override
public Resources create(final URL url, final String rootPackage,
final String rootDir) {
return new FileSystemResources(getBaseDir(url, rootDir),
rootPackage, rootDir);
}
});
addResourcesFactory("jar", new ResourcesFactory() {
@Override
public Resources create(final URL url, final String rootPackage,
final String rootDir) {
return new JarFileResources(url, rootPackage, rootDir);
}
});
addResourcesFactory("zip", new ResourcesFactory() {
@Override
public Resources create(final URL url, final String rootPackage,
final String rootDir) {
return new JarFileResources(JarFileUtil.create(new File(
ZipFileUtil.toZipFilePath(url))), rootPackage, rootDir);
}
});
addResourcesFactory("code-source", new ResourcesFactory() {
@Override
public Resources create(final URL url, final String rootPackage,
final String rootDir) {
return new JarFileResources(URLUtil.create("jar:file:"
+ url.getPath()), rootPackage, rootDir);
}
});
addResourcesFactory("vfszip", new ResourcesFactory() {
@Override
public Resources create(final URL url, final String rootPackage,
final String rootDir) {
return new VfsZipResources(url, rootPackage, rootDir);
}
});
}
/**
* {@link ResourcesFactory}を追加します。
*
* @param protocol
* URLのプロトコル
* @param factory
* プロトコルに対応する{@link Resources}のファクトリ
*/
public static void addResourcesFactory(final String protocol,
ResourcesFactory factory) {
resourcesTypeFactories.put(protocol, factory);
}
/**
* 指定のクラスを基点とするリソースの集まりを扱う{@link Resources}を返します。
*