in spring/src/main/java/org/apache/servicemix/kernel/spring/SpringTransformer.java [61:120]
public static void transform(URL url, OutputStream os) throws Exception {
// Build dom document
Document doc = parse(url);
// Heuristicly retrieve name and version
String name = url.getPath();
int idx = name.lastIndexOf('/');
if (idx >= 0) {
name = name.substring(idx + 1);
}
String[] str = extractNameVersionType(name);
// Create manifest
Manifest m = new Manifest();
m.getMainAttributes().putValue("Manifest-Version", "2");
m.getMainAttributes().putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
m.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, str[0]);
m.getMainAttributes().putValue(Constants.BUNDLE_VERSION, str[1]);
m.getMainAttributes().putValue("Spring-Context", "*;publish-context:=false;create-asynchronously:=true");
String importPkgs = getImportPackages(analyze(new DOMSource(doc)));
if (importPkgs != null && importPkgs.length() > 0) {
m.getMainAttributes().putValue(Constants.IMPORT_PACKAGE, importPkgs);
}
m.getMainAttributes().putValue(Constants.DYNAMICIMPORT_PACKAGE, "*");
// Extract manifest entries from the DOM
NodeList l = doc.getElementsByTagName("manifest");
if (l != null) {
for (int i = 0; i < l.getLength(); i++) {
Element e = (Element) l.item(i);
String text = e.getTextContent();
Properties props = new Properties();
props.load(new ByteArrayInputStream(text.trim().getBytes()));
Enumeration en = props.propertyNames();
while (en.hasMoreElements()) {
String k = (String) en.nextElement();
String v = props.getProperty(k);
m.getMainAttributes().putValue(k, v);
}
e.getParentNode().removeChild(e);
}
}
JarOutputStream out = new JarOutputStream(os);
ZipEntry e = new ZipEntry(JarFile.MANIFEST_NAME);
out.putNextEntry(e);
m.write(out);
out.closeEntry();
e = new ZipEntry("META-INF/");
out.putNextEntry(e);
e = new ZipEntry("META-INF/spring/");
out.putNextEntry(e);
out.closeEntry();
e = new ZipEntry("META-INF/spring/" + name);
out.putNextEntry(e);
// Copy the new DOM
if (tf == null) {
tf = TransformerFactory.newInstance();
}
tf.newTransformer().transform(new DOMSource(doc), new StreamResult(out));
out.closeEntry();
out.close();
}