| Method from org.hibernate.ejb.packaging.JarVisitor Detail: |
protected final void addElement(String entryName,
InputStream is,
InputStream secondIs) throws IOException {
if ( entryName.endsWith( "package-info.class" ) ) {
String name = entryName.substring( 0, entryName.length() - ".package-info.class".length() )
.replace( '/", '." );
executeJavaElementFilter( name, packageFilters, is, secondIs );
}
else if ( entryName.endsWith( ".class" ) ) {
String name = entryName.substring( 0, entryName.length() - ".class".length() ).replace( '/", '." );
log.debug( "Filtering: " + name );
executeJavaElementFilter( name, classFilters, is, secondIs );
}
else {
String name = entryName;
boolean accepted = false;
for ( FileFilter filter : fileFilters ) {
if ( filter.accept( name ) ) {
accepted = true;
InputStream localIs;
if ( filter.getStream() ) {
localIs = secondIs;
}
else {
localIs = null;
secondIs.close();
}
is.close();
log.debug( "File Filter matched for " + name );
Entry entry = new Entry( name, localIs );
int index = this.filters.indexOf( filter );
this.entries[index].add( entry );
}
}
if (!accepted) {
//not accepted free resources
is.close();
secondIs.close();
}
}
}
|
abstract protected void doProcessElements() throws IOException
|
public JarVisitor.Filter[] getFilters() {
return filters.toArray( new Filter[ filters.size() ] );
}
|
public static final URL getJarURLFromURLEntry(URL url,
String entry) throws IllegalArgumentException {
URL jarUrl;
String file = url.getFile();
if ( ! entry.startsWith( "/" ) ) entry = "/" + entry;
file = file.substring( 0, file.length() - entry.length() );
if ( file.endsWith( "!" ) ) file = file.substring( 0, file.length() - 1 );
try {
String protocol = url.getProtocol();
if ( "jar".equals( protocol )
|| "wsjar".equals( protocol ) ) { //Websphere has it's own way
//Original URL is like jar:protocol
jarUrl = new URL( file );
if ( "file".equals( jarUrl.getProtocol() ) ) {
//Do some voodoo magic because WAS doesn't think escaping URL is an interesting feature
if ( file.indexOf( ' " ) != -1 ) {
//not escaped, need to voodoo
jarUrl = new File( jarUrl.getFile() ).toURI().toURL(); //goes by toURI to escape the path
}
} //otherwise left as is
}
else if ( "zip".equals( protocol ) //Weblogic has it's own way
|| "code-source".equals( url.getProtocol() ) ) { //OC4J prevent ejb.jar access (ie everything without path)
//we have extracted the zip file, so it should be read as a file
//Just in case some containers are as stupid as WAS: luckily WAS is closed source so nobody will dupe the bug
if ( file.indexOf( ' " ) != -1 ) {
//not escaped, need to voodoo
jarUrl = new File(file).toURI().toURL(); //goes by toURI to escape the path
}
else {
jarUrl = new File(file).toURL();
}
}
else {
jarUrl = new URL( protocol, url.getHost(), url.getPort(), file );
}
}
catch (MalformedURLException e) {
throw new IllegalArgumentException(
"Unable to determine JAR Url from " + url + ". Cause: " + e.getMessage()
);
}
log.trace("JAR URL from URL Entry: " + url + " > > " + jarUrl);
return jarUrl;
}
Get the JAR URL of the JAR containing the given entry |
public final Set[] getMatchingEntries() throws IOException {
if ( !done ) {
//avoid url access and so on
if ( filters.size() > 0 ) doProcessElements();
done = true;
}
return entries;
}
Return the matching entries for each filter in the same order the filter where passed |
public String getUnqualifiedJarName() {
return unqualifiedJarName;
}
Get the unqualified Jar name (ie wo path and wo extension) |
public static final JarVisitor getVisitor(URL jarUrl,
JarVisitor.Filter[] filters) throws IllegalArgumentException {
String protocol = jarUrl.getProtocol();
if ( "jar".equals( protocol ) ) {
//FIXME remove this code, this should not happen
return new InputStreamZippedJarVisitor( jarUrl, filters );
}
else if ( StringHelper.isEmpty( protocol ) || "file".equals( protocol ) ) {
File file;
try {
file = new File( jarUrl.toURI().getSchemeSpecificPart() );
}
catch (URISyntaxException e) {
throw new IllegalArgumentException(
"Unable to visit JAR " + jarUrl + ". Cause: " + e.getMessage()
);
}
if ( file.isDirectory() ) {
return new ExplodedJarVisitor( jarUrl, filters );
}
else {
return new FileZippedJarVisitor( jarUrl, filters );
}
}
else {
//let's assume the url can return the jar as a zip stream
return new InputStreamZippedJarVisitor( jarUrl, filters );
}
}
Build a JarVisitor on the given JAR URL applying th given filters |
public static final JarVisitor getVisitor(String jarPath,
JarVisitor.Filter[] filters) throws IllegalArgumentException {
File file = new File( jarPath );
if ( file.isFile() ) {
return new InputStreamZippedJarVisitor( jarPath, filters );
}
else {
return new ExplodedJarVisitor( jarPath, filters );
}
}
Get a JarVisitor to the jar jarPath applying the given filters |
protected void unqualify() {
//FIXME weak algorithm subject to AOOBE
String fileName = jarUrl.getFile();
int slash = fileName.lastIndexOf( "/" );
if ( slash != -1 ) {
fileName = fileName.substring(
fileName.lastIndexOf( "/" ) + 1,
fileName.length()
);
}
if ( fileName.length() > 4 && fileName.endsWith( "ar" ) && fileName.charAt( fileName.length() - 4 ) == '." ) {
fileName = fileName.substring( 0, fileName.length() - 4 );
}
unqualifiedJarName = fileName;
log.debug( "Searching mapped entities in jar/par: " + jarUrl );
}
|