InputStream is = null;
try
{
Manifest mf = null;
if (manifest.getProtocol().equals("jar") || manifest.getProtocol().equals("zip") ||
manifest.getProtocol().equals("wsjar"))
{
if (manifest.getPath().startsWith("http://"))
{
// protocol formats:
// jar:http:<path>!<manifest-file>, zip:http:<path>!<manifest-file>
// e.g jar:http://<host>[:port]/[app-path]/jpox-java5.jar!/plugin.xml
JarURLConnection jarConnection = (JarURLConnection) manifest.openConnection();
URL url = jarConnection.getJarFileURL();
mf = jarConnection.getManifest();
if (mf == null)
{
return null;
}
return registerBundle(mf, url);
}
else
{
int begin = 4;
if (manifest.getProtocol().equals("wsjar"))
{
begin = 6;
}
// protocol formats:
// jar:<path>!<manifest-file>, zip:<path>!<manifest-file>
// jar:file:<path>!<manifest-file>, zip:file:<path>!<manifest-file>
String path = StringUtils.getDecodedStringFromURLString(manifest.toExternalForm());
int index = path.indexOf(JAR_SEPARATOR);
String jarPath = path.substring(begin, index);
if (jarPath.startsWith("file:"))
{
// remove "file:" from path, so we can use in File constructor
jarPath = jarPath.substring(5);
}
File jarFile = new File(jarPath);
mf = new JarFile(jarFile).getManifest();
if (mf == null)
{
return null;
}
return registerBundle(mf, jarFile.toURI().toURL());
}
}
else if (manifest.getProtocol().equals("rar") || manifest.getProtocol().equals("war"))
{
// protocol formats:
// rar:<rar-path>!<jar-path>!<manifest-file>, war:<war-path>!<jar-path>!<manifest-file>
String path = StringUtils.getDecodedStringFromURLString(manifest.toExternalForm());
int index = path.indexOf(JAR_SEPARATOR);
String rarPath = path.substring(4, index);
File file = new File(rarPath);
URL rarUrl = file.toURI().toURL();
String jarPath = path.substring(index+1, path.indexOf(JAR_SEPARATOR,index+1));
JarFile rarFile = new JarFile(file);
JarInputStream jis = new JarInputStream(rarFile.getInputStream(rarFile.getEntry(jarPath)));
try
{
mf = jis.getManifest();
if (mf == null)
{
return null;
}
}
finally
{
jis.close();
}
return registerBundle(mf, rarUrl);
}
else if (manifest.getProtocol().equals("vfsfile") || manifest.getProtocol().equals("vfsjar") ||
manifest.getProtocol().equals("vfszip") || manifest.getProtocol().equals("vfs") )
{
// protocol formats:
// vfsfile:<path>!<manifest-file>, vfsjar:<path>!<manifest-file>, vfszip:<path>!<manifest-file>
String path = StringUtils.getDecodedStringFromURLString(manifest.toExternalForm());
int index = path.indexOf(JAR_SEPARATOR);
if (index < 0)
{
NucleusLogger.PLUGIN.warn("Unable to find jar bundle for " + path + " so ignoring");
return null;
}
else
{
String jarPath = path.substring(0, index);
URL jarUrl = new URL(jarPath);
JarInputStream jis = null;
InputStream inputStream = jarUrl.openConnection().getInputStream();
// JBoss 6 returns a JarInputStream instead of FileInputStream as previous versions
// which won't return the manifest below if we use it to construct a new JarInputStream,
// so we just use it.
if ( inputStream instanceof JarInputStream )
{
jis = (JarInputStream) inputStream;
}
else
{
jis = new JarInputStream(inputStream);
}
try
{
mf = jis.getManifest();
if (mf == null)
{
return null;
}
}
finally
{
jis.close();
}
return registerBundle(mf, jarUrl);
}
}
else
{
is = manifest.openStream();
mf = new Manifest(is);
return registerBundle(mf,manifest);
}
}
catch (IOException e)
{