use of eu.esdihumboldt.hale.io.xsd.reader.internal.ProgressURIResolver 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;
}
Aggregations