/** * This method returns true if the binaries contains a {@link org.w3c.dom.Document} * * @param bytes * the binaries to be tested * @return true if the binaries is a XML */ public static boolean isDOM(final byte[] bytes) { try { final Document dom = buildDOM(bytes); return dom != null; } catch (DSSException e) { // NOT DOM return false; } }
/** * This method returns the {@link org.w3c.dom.Document} created based on byte array. * * @param bytes * The bytes array representing the dssDocument to be created. * @return a new {@link org.w3c.dom.Document} with the bytes content */ public static Document buildDOM(final byte[] bytes) { return buildDOM(new ByteArrayInputStream(bytes)); }
/** * This method returns the {@link org.w3c.dom.Document} created based on the XML string. * * @param xmlString * The string representing the dssDocument to be created. * @return a new {@link org.w3c.dom.Document} with the xmlString content */ public static Document buildDOM(final String xmlString) { return buildDOM(xmlString.getBytes(StandardCharsets.UTF_8)); }
private Element loadManifestXml() { return DomUtils.buildDOM(manifestFile).getDocumentElement(); }
/** * This method returns the {@link org.w3c.dom.Document} created based on the {@link eu.europa.esig.dss.DSSDocument}. * * @param dssDocument * The DSS representation of the document from which the dssDocument is created. * @return a new {@link org.w3c.dom.Document} from {@link eu.europa.esig.dss.DSSDocument} */ public static Document buildDOM(final DSSDocument dssDocument) { return buildDOM(dssDocument.openStream()); }
private DSSDocument surroundWithXadesXmlTag(DSSDocument signedDocument) { logger.debug("Surrounding signature document with xades tag"); Document signatureDom = DomUtils.buildDOM(signedDocument); Element signatureElement = signatureDom.getDocumentElement(); Document document = XmlDomCreator.createDocument(ASiCNamespace.NS, XmlDomCreator.ASICS_NS, signatureElement); byte[] documentBytes = DSSXMLUtils.serializeNode(document); return new InMemoryDocument(documentBytes); }
@Test(expected = DSSException.class) public void testNoHeaderError() { DomUtils.buildDOM(INCORRECT_XML_TEXT); }
@Test(expected = DSSException.class) public void testEntityXml() throws Exception { // Should ignore the URL embedded in the DTD DomUtils.buildDOM(new FileInputStream("src/test/resources/xml_entity.xml")); }
@Test(expected = DSSException.class) public void testHeaderError() { DomUtils.buildDOM(XML_HEADER + INCORRECT_XML_TEXT); }
@Test public void testHeader() { InputStream is = new ByteArrayInputStream((XML_HEADER + XML_TEXT).getBytes()); assertNotNull(DomUtils.buildDOM(is)); assertNotNull(DomUtils.buildDOM(XML_HEADER + XML_TEXT)); assertNotNull(DomUtils.buildDOM(new InMemoryDocument((XML_HEADER + XML_TEXT).getBytes(), "my xml"))); }
@Test(expected = DSSException.class) public void testExpansionXml() throws Exception { assertNotNull(DomUtils.buildDOM(new FileInputStream("src/test/resources/xml_expansion.xml"))); }