Search in sources :

Example 36 with InputSource

use of org.xml.sax.InputSource in project liquibase by liquibase.

the class LiquibaseSchemaResolver method getInputSourceFromXsd.

private InputSource getInputSourceFromXsd(NamespaceDetails namespaceDetails) {
    if (systemId == null) {
        return null;
    }
    LOGGER.debug("Found namespace details class " + namespaceDetails.getClass().getName() + " for " + systemId);
    String xsdFile = namespaceDetails.getLocalPath(systemId);
    LOGGER.debug("Local path for " + systemId + " is " + xsdFile);
    if (xsdFile == null) {
        return null;
    }
    try {
        InputStream resourceAsStream = resourceAccessorXsdStreamResolver.getResourceAsStream(xsdFile);
        if (resourceAsStream == null) {
            LOGGER.debug("Could not find " + xsdFile + " locally");
            return null;
        }
        LOGGER.debug("Successfully loaded XSD from " + xsdFile);
        org.xml.sax.InputSource source = new org.xml.sax.InputSource(resourceAsStream);
        source.setPublicId(publicId);
        source.setSystemId(systemId);
        return source;
    } catch (Exception ex) {
        LOGGER.debug("Error loading XSD", ex);
        // We don't have the schema, try the network
        return null;
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream)

Example 37 with InputSource

use of org.xml.sax.InputSource in project liquibase by liquibase.

the class LiquibaseEntityResolverTest method resolveEntityWithOnlyPublicIdAndSystemIdDelegatesToSchemResolver.

@Test
public void resolveEntityWithOnlyPublicIdAndSystemIdDelegatesToSchemResolver() throws IOException, SAXException {
    InputSource result = liquibaseEntityResolver.resolveEntity(PUBLIC_ID, SYSTEM_ID);
    assertThat(result).isSameAs(inputSource);
}
Also used : InputSource(org.xml.sax.InputSource) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 38 with InputSource

use of org.xml.sax.InputSource in project liquibase by liquibase.

the class LiquibaseEntityResolverTest method getExternalSubsetShouldReturnNull.

@Test
public void getExternalSubsetShouldReturnNull() throws IOException, SAXException {
    InputSource externalSubset = liquibaseEntityResolver.getExternalSubset(NAME, BASE_URI);
    assertThat(externalSubset).isNull();
}
Also used : InputSource(org.xml.sax.InputSource) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 39 with InputSource

use of org.xml.sax.InputSource in project liquibase by liquibase.

the class LiquibaseEntityResolverTest method shouldReturnNullSystemIdIsNull.

@Test
public void shouldReturnNullSystemIdIsNull() throws Exception {
    InputSource result = liquibaseEntityResolver.resolveEntity(NAME, PUBLIC_ID, BASE_URI, null);
    assertThat(result).isNull();
}
Also used : InputSource(org.xml.sax.InputSource) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 40 with InputSource

use of org.xml.sax.InputSource in project liquibase by liquibase.

the class LiquibaseEntityResolverTest method whenSystemIdIsNotXsdAndResourceExceptionOccursReturnNull.

@Test
public void whenSystemIdIsNotXsdAndResourceExceptionOccursReturnNull() throws IOException, SAXException {
    PowerMockito.when(StreamUtil.singleInputStream(PATH_AND_SYSTEM_ID, resourceAccessor)).thenThrow(new RuntimeException());
    InputSource result = liquibaseEntityResolver.resolveEntity(NAME, PUBLIC_ID, BASE_URI, FILE_SYSTEM_ID);
    assertThat(result).isEqualTo(null);
}
Also used : InputSource(org.xml.sax.InputSource) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

InputSource (org.xml.sax.InputSource)1126 StringReader (java.io.StringReader)403 IOException (java.io.IOException)304 Document (org.w3c.dom.Document)282 SAXException (org.xml.sax.SAXException)281 DocumentBuilder (javax.xml.parsers.DocumentBuilder)263 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)214 XMLReader (org.xml.sax.XMLReader)194 Test (org.junit.Test)160 InputStream (java.io.InputStream)158 NodeList (org.w3c.dom.NodeList)146 Element (org.w3c.dom.Element)144 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)143 ByteArrayInputStream (java.io.ByteArrayInputStream)103 SAXParser (javax.xml.parsers.SAXParser)103 SAXSource (javax.xml.transform.sax.SAXSource)95 SAXParserFactory (javax.xml.parsers.SAXParserFactory)90 File (java.io.File)82 Node (org.w3c.dom.Node)82 URL (java.net.URL)65