UCFPackage extends ODFJaxb implements Cloneable { public void removeResource(String path) { if (!odfPackage.contains(path)) return; if (path.endsWith("/")) for (ResourceEntry childEntry : listResources(path).values()) removeResource(childEntry.getPath()); odfPackage.remove(path); } UCFPackage();  UCFPackage(File containerFile);  UCFPackage(InputStream inputStream); String getPackageMediaType(); void setPackageMediaType(String mediaType); void save(File packageFile); void addResource(String stringValue, String path, String mediaType); void addResource(byte[] bytesValue, String path, String mediaType); void addResource(Document document, String path, String mediaType); void addResource(InputStream inputStream, String path,
			String mediaType); void addResource(URI uri, String path, String mediaType); String getResourceAsString(String path); byte[] getResourceAsBytes(String path); InputStream getResourceAsInputStream(String path); Map<String, ResourceEntry> listResources(); Map<String, ResourceEntry> listResources(String folderPath); void removeResource(String path); Map<String, ResourceEntry> listAllResources(); void setRootFile(String path); @SuppressWarnings("rawtypes") void setRootFile(String path, String version); @SuppressWarnings("rawtypes") List<ResourceEntry> getRootFiles(); ResourceEntry getResourceEntry(String path); @SuppressWarnings("rawtypes") void unsetRootFile(String path); void save(OutputStream output); OutputStream addResourceUsingOutputStream(String path,
			String mediaType); @Override UCFPackage clone(); String getRootFileVersion(String rootFile); static final String MIME_BINARY; static final String MIME_TEXT_PLAIN; static final String MIME_TEXT_XML; static final String MIME_RDF; static final String MIME_EPUB; static final String MIME_WORKFLOW_BUNDLE; static final String MIME_DATA_BUNDLE; static final String MIME_WORKFLOW_RUN_BUNDLE; static final String MIME_SERVICE_BUNDLE; }
@Test public void removeResource() throws Exception { UCFPackage container = new UCFPackage(); container.setPackageMediaType(UCFPackage.MIME_WORKFLOW_BUNDLE); container.addResource("Soup for everyone", "soup.txt", "text/plain"); container.addResource("Sub-folder entry 1", "sub/1.txt", "text/plain"); container.addResource("Sub-folder entry 2", "sub/2.txt", "text/plain"); container.addResource("Sub-folder entry 2", "sub/3/woho.txt", "text/plain"); assertTrue(container.listAllResources().keySet().contains("soup.txt")); container.removeResource("soup.txt"); assertFalse(container.listAllResources().keySet().contains("soup.txt")); try { container.getResourceAsString("soup.txt"); fail("Could still retrieve soup.txt"); } catch (Exception ex) { } container.save(tmpFile); UCFPackage container2 = new UCFPackage(tmpFile); assertTrue(container2.listAllResources().keySet().contains("sub/")); container2.removeResource("sub"); assertTrue(container2.listAllResources().keySet().contains("sub/")); assertTrue(container2.listAllResources().keySet().contains("sub/1.txt")); container2.removeResource("sub/"); assertFalse(container2.listAllResources().keySet().contains("sub/")); assertFalse(container2.listAllResources().keySet() .contains("sub/1.txt")); container2.save(tmpFile); ZipFile zipFile = new ZipFile(tmpFile); assertNull("soup.txt still in zip file", zipFile.getEntry("soup.txt")); assertNull("sub/1.txt still in zip file", zipFile.getEntry("sub/1.txt")); assertNull("sub/2.txt still in zip file", zipFile.getEntry("sub/2.txt")); assertNull("sub/3.txt still in zip file", zipFile.getEntry("sub/3.txt")); assertNull("sub/ still in zip file", zipFile.getEntry("sub/")); zipFile.close(); UCFPackage loaded = new UCFPackage(tmpFile); assertFalse(loaded.listAllResources().keySet().contains("soup.txt")); assertFalse(loaded.listAllResources().keySet().contains("sub/")); assertFalse(loaded.listAllResources().keySet().contains("sub/1.txt")); try { loaded.getResourceAsString("sub/1.txt"); fail("Could still retrieve soup.txt"); } catch (Exception ex) { } loaded.save(tmpFile); }