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());
}
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;
}
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());
}
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());
}
Aggregations