Search in sources :

Example 6 with HumboldtURIResolver

use of eu.esdihumboldt.hale.io.xsd.reader.internal.HumboldtURIResolver in project hale by halestudio.

the class HumboldtURIResolverTest method testHttpRelative1.

@SuppressWarnings("javadoc")
@Test
public void testHttpRelative1() {
    String baseUri = "http://schemas.opengis.net/gml/3.2.1/gml.xsd";
    String location = "feature.xsd";
    String expected = "http://schemas.opengis.net/gml/3.2.1/feature.xsd";
    HumboldtURIResolver resolver = new HumboldtURIResolver();
    InputSource source = resolver.resolveEntity("ns", location, baseUri);
    assertEquals(expected, source.getSystemId());
}
Also used : InputSource(org.xml.sax.InputSource) HumboldtURIResolver(eu.esdihumboldt.hale.io.xsd.reader.internal.HumboldtURIResolver) Test(org.junit.Test)

Example 7 with HumboldtURIResolver

use of eu.esdihumboldt.hale.io.xsd.reader.internal.HumboldtURIResolver in project hale by halestudio.

the class XmlSchemaReader method execute.

/**
 * @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
 */
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    // $NON-NLS-1$
    progress.begin(Messages.getString("ApacheSchemaProvider.21"), ProgressIndicator.UNKNOWN);
    this.reporter = reporter;
    XmlSchema xmlSchema = null;
    XmlSchemaCollection schemaCol = new XmlSchemaCollection();
    // Check if the file is located on web
    URI location = getSource().getLocation();
    if (location.getHost() == null) {
        schemaCol.setSchemaResolver(new ProgressURIResolver(new HumboldtURIResolver(), progress));
        schemaCol.setBaseUri(findBaseUri(location));
    } else if (location.getScheme().equals("bundleresource")) {
        // $NON-NLS-1$
        schemaCol.setSchemaResolver(new ProgressURIResolver(new HumboldtURIResolver(), progress));
        // $NON-NLS-1$
        schemaCol.setBaseUri(findBaseUri(location) + "/");
    } else {
        schemaCol.setSchemaResolver(new ProgressURIResolver(new HumboldtURIResolver(), progress));
        // $NON-NLS-1$
        schemaCol.setBaseUri(findBaseUri(location) + "/");
    }
    InputStream is = null;
    // try resolving using (local) Resources
    InputSupplier<? extends InputStream> input = Resources.tryResolve(location, Resources.RESOURCE_TYPE_XML_SCHEMA);
    if (input != null) {
        try {
            is = input.getInput();
        } catch (Exception e) {
        // ignore
        }
    }
    if (is == null) {
        is = getSource().getInput();
    }
    StreamSource ss = new StreamSource(is);
    ss.setSystemId(location.toString());
    xmlSchema = schemaCol.read(ss, null);
    is.close();
    String namespace = xmlSchema.getTargetNamespace();
    if (namespace == null) {
        namespace = XMLConstants.NULL_NS_URI;
    }
    xmlSchema.setSourceURI(location.toString());
    // create index
    index = new XmlIndex(namespace, location);
    // create group counter
    groupCounter = new TObjectIntHashMap<String>();
    Set<String> imports = new HashSet<String>();
    imports.add(location.toString());
    // load XML Schema schema (for base type definitions)
    try {
        is = XmlSchemaReader.class.getResourceAsStream("/schemas/XMLSchema.xsd");
        ss = new StreamSource(is);
        schemaCol.setSchemaResolver(new ProgressURIResolver(new HumboldtURIResolver(), progress));
        schemaCol.setBaseUri(findBaseUri(XmlSchemaReader.class.getResource("/schemas/XMLSchema.xsd").toURI()) + "/");
        XmlSchema xsSchema = schemaCol.read(ss, null);
        is.close();
        xsSchema.setSourceURI("http://www.w3.org/2001/XMLSchema.xsd");
        XmlSchemaImport xmlSchemaImport = new XmlSchemaImport();
        xmlSchemaImport.setSchema(xsSchema);
        // add it to includes as XmlSchemaImport (not XmlSchemaInclude!)
        xmlSchema.getIncludes().add(xmlSchemaImport);
    } catch (Exception e) {
        _log.error("Exception while loading XML Schema schema", e);
    }
    loadSchema(location.toString(), xmlSchema, imports, progress, true);
    groupCounter.clear();
    // post processing
    applyRelevantElements(index);
    applyCustomTypeContent(index);
    reporter.setSuccess(true);
    return reporter;
}
Also used : ProgressURIResolver(eu.esdihumboldt.hale.io.xsd.reader.internal.ProgressURIResolver) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) URI(java.net.URI) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaImport(org.apache.ws.commons.schema.XmlSchemaImport) HumboldtURIResolver(eu.esdihumboldt.hale.io.xsd.reader.internal.HumboldtURIResolver) HashSet(java.util.HashSet)

Example 8 with HumboldtURIResolver

use of eu.esdihumboldt.hale.io.xsd.reader.internal.HumboldtURIResolver in project hale by halestudio.

the class HumboldtURIResolverTest method testFileRelative2.

@SuppressWarnings("javadoc")
@Test
public void testFileRelative2() {
    String baseUri = "C:/Test/gml/3.2.1/feature.xsd";
    String location = "gml.xsd";
    String expected = "C:/Test/gml/3.2.1/gml.xsd";
    HumboldtURIResolver resolver = new HumboldtURIResolver();
    InputSource source = resolver.resolveEntity("ns", location, baseUri);
    assertEquals(expected, source.getSystemId());
}
Also used : InputSource(org.xml.sax.InputSource) HumboldtURIResolver(eu.esdihumboldt.hale.io.xsd.reader.internal.HumboldtURIResolver) Test(org.junit.Test)

Example 9 with HumboldtURIResolver

use of eu.esdihumboldt.hale.io.xsd.reader.internal.HumboldtURIResolver in project hale by halestudio.

the class HumboldtURIResolverTest method testHttpAbsoluteOtherFile.

@SuppressWarnings("javadoc")
@Test
public void testHttpAbsoluteOtherFile() {
    String baseUri = "http://schemas.opengis.net/gml/3.2.1/gml.xsd";
    String location = "file:///C:/Test/gml/3.2.1/feature.xsd";
    String expected = location;
    HumboldtURIResolver resolver = new HumboldtURIResolver();
    InputSource source = resolver.resolveEntity("ns", location, baseUri);
    assertEquals(expected, source.getSystemId());
}
Also used : InputSource(org.xml.sax.InputSource) HumboldtURIResolver(eu.esdihumboldt.hale.io.xsd.reader.internal.HumboldtURIResolver) Test(org.junit.Test)

Aggregations

HumboldtURIResolver (eu.esdihumboldt.hale.io.xsd.reader.internal.HumboldtURIResolver)9 Test (org.junit.Test)8 InputSource (org.xml.sax.InputSource)8 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)1 XmlIndex (eu.esdihumboldt.hale.io.xsd.model.XmlIndex)1 ProgressURIResolver (eu.esdihumboldt.hale.io.xsd.reader.internal.ProgressURIResolver)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashSet (java.util.HashSet)1 StreamSource (javax.xml.transform.stream.StreamSource)1 XmlSchema (org.apache.ws.commons.schema.XmlSchema)1 XmlSchemaCollection (org.apache.ws.commons.schema.XmlSchemaCollection)1 XmlSchemaImport (org.apache.ws.commons.schema.XmlSchemaImport)1