public void packFiles(ZipOutputStream zipOutput) throws IOException { // pack them together List<Bundle> bundles = framework.getAllBundles(); for (Bundle bundle : bundles) { if (!bundle.isFragment()) { List<Bundle> fragments = bundle.getFragments(); if (fragments != null) { for (Bundle fragment : fragments) { packBundle(zipOutput, fragment); } } } packBundle(zipOutput, bundle); } }
public void packDescription(ZipOutputStream zipOutput) throws IOException, ParserConfigurationException, TransformerException { ZipEntry entry = new ZipEntry("plugin.xml"); zipOutput.putNextEntry(entry); try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element documentRoot = document.createElement("plugin"); document.appendChild(documentRoot); List<Bundle> bundles = framework.getAllBundles(); for (Bundle bundle : bundles) { if (!bundle.isFragment()) { List<Bundle> fragments = bundle.getFragments(); if (fragments != null) { for (Bundle fragment : fragments) { Document description = fragment.getDescription(); if (description != null) { Node comment = document.createComment("import from " + fragment.getBundleID()); document.getDocumentElement().appendChild(comment); appendDescription(document, description); } } } } Document description = bundle.getDescription(); if (description != null) { Node comment = document.createComment("import from " + bundle.getBundleID()); document.getDocumentElement().appendChild(comment); appendDescription(document, description); } } // Prepare the DOM document for writing Source source = new DOMSource(document); // Prepare the output file Result result = new StreamResult(zipOutput); // Write the DOM document to the file Transformer xformer = TransformerFactory.newInstance().newTransformer(); xformer.transform(source, result); } finally { zipOutput.closeEntry(); } }