ManifestBuilder { public DSSDocument build() { Document documentDom = DomUtils.buildDOM(); Element manifestDom = DomUtils.createElementNS(documentDom, xmldsigNamespace, XMLDSigElement.MANIFEST); manifestDom.setAttribute(XMLDSigAttribute.ID.getAttributeName(), manifestId); documentDom.appendChild(manifestDom); for (DSSDocument document : documents) { Element referenceDom = DomUtils.createElementNS(documentDom, xmldsigNamespace, XMLDSigElement.REFERENCE); manifestDom.appendChild(referenceDom); referenceDom.setAttribute(XMLDSigAttribute.URI.getAttributeName(), document.getName()); Element digestMethodDom = DomUtils.createElementNS(documentDom, xmldsigNamespace, XMLDSigElement.DIGEST_METHOD); referenceDom.appendChild(digestMethodDom); digestMethodDom.setAttribute(XMLDSigAttribute.ALGORITHM.getAttributeName(), digestAlgorithm.getUri()); Element digestValueDom = DomUtils.createElementNS(documentDom, xmldsigNamespace, XMLDSigElement.DIGEST_VALUE); referenceDom.appendChild(digestValueDom); Text textNode = documentDom.createTextNode(document.getDigest(digestAlgorithm)); digestValueDom.appendChild(textNode); } return DomUtils.createDssDocumentFromDomDocument(documentDom, manifestId); } ManifestBuilder(DigestAlgorithm digestAlgorithm, List<DSSDocument> documents);  ManifestBuilder(String manifestId, DigestAlgorithm digestAlgorithm, List<DSSDocument> documents);  ManifestBuilder(String manifestId, DigestAlgorithm digestAlgorithm, List<DSSDocument> documents, DSSNamespace xmldsigNamespace); DSSDocument build();  }
@Test public void testBuildManifest() throws IOException { List<DSSDocument> documents = new ArrayList<>(); FileDocument file1 = new FileDocument("src/test/resources/sample.png"); documents.add(file1); documents.add(new FileDocument("src/test/resources/sample.txt")); documents.add(new FileDocument("src/test/resources/sample.xml")); ManifestBuilder builder = new ManifestBuilder("manifest", DigestAlgorithm.SHA512, documents); DSSDocument document = builder.build(); assertNotNull(document); assertEquals(MimeType.XML, document.getMimeType()); try (InputStream is = document.openStream()) { String xmlContent = new String(Utils.toByteArray(is), "UTF-8"); assertTrue(xmlContent.contains(XMLDSigElement.MANIFEST.getTagName())); assertTrue(xmlContent.contains(file1.getName())); assertTrue(xmlContent.contains(file1.getDigest(DigestAlgorithm.SHA512))); LOG.info(xmlContent); } }