DomUtils { public static Document buildDOM() { try { return dbFactory.newDocumentBuilder().newDocument(); } catch (ParserConfigurationException e) { throw new DSSException(e); } } private  DomUtils(); static void enableFeature(String feature); static void disableFeature(String feature); static boolean registerNamespace(final DSSNamespace namespace); static TransformerFactory getSecureTransformerFactory(); static Transformer getSecureTransformer(); static Document buildDOM(); static Document buildDOM(final String xmlString); static Document buildDOM(final byte[] bytes); static Document buildDOM(final DSSDocument dssDocument); static boolean isDOM(final byte[] bytes); static Document buildDOM(final InputStream inputStream); static void setAttributeNS(Element element, DSSNamespace namespace, DSSAttribute attribute, String value); static Element addElement(final Document document, final Element parentDom, final DSSNamespace namespace, final DSSElement element); static XPathExpression createXPathExpression(final String xpathString); static String getValue(final Node xmlNode, final String xPathString); static NodeList getNodeList(final Node xmlNode, final String xPathString); static Node getNode(final Node xmlNode, final String xPathString); static Element getElement(final Node xmlNode, final String xPathString); static boolean isNotEmpty(final Node xmlNode, final String xPathString); static Element addTextElement(final Document document, final Element parentDom, final DSSNamespace namespace, final DSSElement element, final String value); static void setTextNode(final Document document, final Element parentDom, final String text); static XMLGregorianCalendar createXMLGregorianCalendar(final Date date); static Date getDate(final String text); static List<String> getChildrenNames(final Node xmlNode, final String xPathString); static void writeDocumentTo(final Document dom, final OutputStream os); static DSSDocument createDssDocumentFromDomDocument(Document document, String name); static String xmlToString(final Node node); static Map<String, String> getCurrentNamespaces(); static String getXPathByIdAttribute(String uri); static String getId(String uri); static boolean isElementReference(String uri); static boolean isXPointerQuery(String uriValue); static Element createElementNS(Document documentDom, DSSNamespace namespace, DSSElement element); static void addNamespaceAttribute(Element element, DSSNamespace namespace); static final int TRANSFORMER_INDENT_NUMBER; }
@Test public void testNoHeader() { InputStream is = new ByteArrayInputStream(XML_TEXT.getBytes()); assertNotNull(DomUtils.buildDOM(is)); assertNotNull(DomUtils.buildDOM(XML_TEXT)); assertNotNull(DomUtils.buildDOM(new InMemoryDocument(XML_TEXT.getBytes(), "my xml"))); }
@Test public void testNoHeaderError() { Exception exception = assertThrows(DSSException.class, () -> { DomUtils.buildDOM(INCORRECT_XML_TEXT); }); assertEquals("Unable to parse content (XML expected)", exception.getMessage()); }
@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 public void testHeaderError() { Exception exception = assertThrows(DSSException.class, () -> { DomUtils.buildDOM(XML_HEADER + INCORRECT_XML_TEXT); }); assertEquals("Unable to parse content (XML expected)", exception.getMessage()); }
@Test public void testExpansionXml() throws IOException { try (FileInputStream fis = new FileInputStream("src/test/resources/xml_expansion.xml")) { Exception exception = assertThrows(DSSException.class, () -> DomUtils.buildDOM(fis)); assertEquals("Unable to parse content (XML expected)", exception.getMessage()); } }
@Test public void testEntityXml() throws IOException { try (FileInputStream fis = new FileInputStream("src/test/resources/xml_entity.xml")) { Exception exception = assertThrows(DSSException.class, () -> DomUtils.buildDOM(fis)); assertEquals("Unable to parse content (XML expected)", exception.getMessage()); } }