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);
mf = new JarInputStream(rarFile.getInputStream(rarFile.getEntry(jarPath))).getManifest();
if (mf == null)
{
return null;
}
return registerBundle(mf, rarUrl);
}
else
{
is = manifest.openStream();
mf = new Manifest(is);
return registerBundle(mf,manifest);
}
}
catch (IOException e)
{