*/
// If the web bundle has its symbolic name and context path in
// MANIFEST.MF file, use them at first.
URL warURL = new URL(warUri);
Jar jar = new Jar(warURL.getPath(), new File(warURL.getPath()));
Manifest manifest = jar.getManifest();
String symbolicName = manifest.getMainAttributes().getValue(
Constants.BUNDLE_SYMBOLICNAME);
String contextPath = manifest.getMainAttributes().getValue(
"Web-ContextPath");
if (symbolicName != null && symbolicName.trim().length() > 0)
instructions.put(Constants.BUNDLE_SYMBOLICNAME, symbolicName);
if (contextPath != null && contextPath.trim().length() > 0)
instructions.put("Web-ContextPath", contextPath);
// OSGi-Spec 128.3.1 WAB Definition
// The Context Path must always begin with a forward slash ( ?/?).
if (instructions.get("Web-ContextPath") != null) {
String ctxtPath = (String) instructions.get("Web-ContextPath");
if (!ctxtPath.startsWith("/")) {
ctxtPath = "/" + ctxtPath;
instructions.setProperty("Web-ContextPath", ctxtPath);
}
}
// If not found bundle symblic name, use default.
if (instructions.get(Constants.BUNDLE_SYMBOLICNAME) == null) {
String defSymblicName = jar.getSource().getName();
defSymblicName = defSymblicName.replaceAll("[^a-zA-Z_0-9.-]", "_")
.replaceAll("(^|\\.)(\\d+)", "$1_$2");
instructions.put(Constants.BUNDLE_SYMBOLICNAME, defSymblicName);
}