use of eu.esdihumboldt.hale.common.core.io.supplier.Locatable in project hale by halestudio.
the class HaleConnectProjectReader method createReporter.
/**
* @see eu.esdihumboldt.hale.common.core.io.impl.AbstractImportProvider#createReporter()
*/
@Override
public IOReporter createReporter() {
if (!(getSource() instanceof HaleConnectInputSupplier) || !HaleConnectUrnBuilder.isValidProjectUrn(getSource().getLocation())) {
return super.createReporter();
}
try {
BasePathResolver resolver = ((HaleConnectInputSupplier) getSource()).getBasePathResolver();
URI sourceUri = getSource().getLocation();
Owner owner = HaleConnectUrnBuilder.extractProjectOwner(sourceUri);
String projectId = HaleConnectUrnBuilder.extractProjectId(sourceUri);
String clientBasePath = resolver.getBasePath(HaleConnectServices.WEB_CLIENT);
Locatable prettifiedTarget = new LocatableURI(HaleConnectUrnBuilder.buildClientAccessUrl(clientBasePath, owner, projectId));
return new DefaultIOReporter(prettifiedTarget, MessageFormat.format("{0} import", getTypeName()), getActionId(), true);
} catch (Throwable t) {
return super.createReporter();
}
}
use of eu.esdihumboldt.hale.common.core.io.supplier.Locatable in project hale by halestudio.
the class XmlInstanceValidator method execute.
/**
* @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
*/
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
progress.begin("Validating XML", ProgressIndicator.UNKNOWN);
List<URI> schemaLocations = new ArrayList<URI>();
for (Locatable schema : getSchemas()) {
URI loc = schema.getLocation();
if (loc != null) {
schemaLocations.add(loc);
} else {
reporter.warn(new IOMessageImpl("No location for schema, may cause validation to fail.", null));
}
}
Validator val = ValidatorFactory.getInstance().createValidator(schemaLocations.toArray(new URI[schemaLocations.size()]));
InputStream in = getSource().getInput();
try {
Report report = val.validate(in);
// use the report information to populate reporter
for (SAXParseException warning : report.getWarnings()) {
reporter.warn(new //
IOMessageImpl(//
warning.getLocalizedMessage(), //
warning, //
warning.getLineNumber(), warning.getColumnNumber()));
}
for (SAXParseException error : report.getErrors()) {
reporter.error(new //
IOMessageImpl(//
error.getLocalizedMessage(), //
error, //
error.getLineNumber(), error.getColumnNumber()));
}
reporter.setSuccess(report.isValid());
return reporter;
} finally {
in.close();
progress.end();
}
}
use of eu.esdihumboldt.hale.common.core.io.supplier.Locatable in project hale by halestudio.
the class StreamGmlWriterTest method validate.
/**
* Validate an XML file against the given schemas.
*
* @param xmlLocation the location of the XML file
* @param validationSchemas schemas needed for validation
* @return the validation report
* @throws IOProviderConfigurationException if the validator is not
* configured correctly
* @throws IOException if I/O operations fail
*/
public static IOReport validate(URI xmlLocation, List<? extends Locatable> validationSchemas) throws IOProviderConfigurationException, IOException {
XmlInstanceValidator validator = new XmlInstanceValidator();
validator.setSchemas(validationSchemas.toArray(new Locatable[validationSchemas.size()]));
validator.setSource(new DefaultInputSupplier(xmlLocation));
return validator.execute(null);
}
use of eu.esdihumboldt.hale.common.core.io.supplier.Locatable in project hale by halestudio.
the class StreamGmlWriter method getValidationSchemas.
@Override
public List<? extends Locatable> getValidationSchemas() {
List<Locatable> result = new ArrayList<Locatable>();
result.addAll(super.getValidationSchemas());
for (Locatable schema : additionalSchemas.values()) {
result.add(schema);
}
return result;
}
use of eu.esdihumboldt.hale.common.core.io.supplier.Locatable in project hale by halestudio.
the class ExecTransformation method setupValidators.
private void setupValidators() {
if (context.getValidateProviderIds() != null && !context.getValidateProviderIds().isEmpty()) {
for (int i = 0; i < context.getValidateProviderIds().size(); i++) {
String validateProviderId = context.getValidateProviderIds().get(i);
if (!validateProviderId.trim().isEmpty()) {
final InstanceValidator validator = HaleIO.createIOProvider(InstanceValidator.class, null, validateProviderId);
if (validator == null) {
throw fail("Instance validator with ID " + validateProviderId + " not found");
}
// load validator settings
validator.loadConfiguration(context.getValidateSettings().get(i));
// set schemas
List<? extends Locatable> schemas = target.getValidationSchemas();
validator.setSchemas(schemas.toArray(new Locatable[schemas.size()]));
// set source
validator.setSource(new DefaultInputSupplier(context.getTarget()));
// apply target content type
validator.setContentType(target.getContentType());
this.validators.add(validator);
}
}
}
}
Aggregations