use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class IOReferenceContent method getInputStream.
@Override
public InputStream getInputStream(String pluginID, String href, Locale locale) {
// it is an I/O provider reference
if (href.startsWith(IO_PROVIDERS_TOPIC_PATH)) {
String providerId = href.substring(IO_PROVIDERS_TOPIC_PATH.length());
// strip everything after a ?
int ind = providerId.indexOf('?');
if (ind >= 0) {
providerId = providerId.substring(0, ind);
}
// strip the .*htm? ending
if (providerId.endsWith("html") || providerId.endsWith("htm")) {
providerId = providerId.substring(0, providerId.lastIndexOf('.'));
}
try {
return getIOProviderContent(providerId);
} catch (Exception e) {
log.error("Error creating instance io info page.", e);
return null;
}
} else // should be an I/O provider overview by type
if (href.startsWith(OVERVIEW_TOPIC_PATH)) {
// extract provider type name
String providerType = href.substring(OVERVIEW_TOPIC_PATH.length());
// strip everything after a ?
int ind = providerType.indexOf('?');
if (ind >= 0) {
providerType = providerType.substring(0, ind);
}
// strip the .*htm? ending
if (providerType.endsWith("html") || providerType.endsWith("htm")) {
providerType = providerType.substring(0, providerType.lastIndexOf('.'));
}
Class<? extends IOProvider> providerClass = null;
switch(providerType) {
case "InstanceReader":
providerClass = InstanceReader.class;
break;
case "InstanceWriter":
providerClass = InstanceWriter.class;
break;
case "InstanceValidator":
providerClass = InstanceValidator.class;
break;
}
if (providerClass != null) {
final Class<? extends IOProvider> provider = providerClass;
try {
return getContentFromTemplate("overview." + providerType, TEMPLATE_OVERVIEW, new Callable<VelocityContext>() {
@Override
public VelocityContext call() throws Exception {
VelocityContext context = new VelocityContext();
// getProviderFactorries returns
// Collection<IOProviderDescriptor>
Collection<IOProviderDescriptor> writer = HaleIO.getProviderFactories(provider);
context.put("providers", writer);
context.put("providerType", provider.getSimpleName());
return context;
}
});
} catch (Exception e) {
log.error("Error creating provider overview", e);
return null;
}
}
return null;
}
return null;
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class GenerateDefaults method writeAlignment.
private void writeAlignment() throws Exception {
System.out.println("Writing alignment to " + context.getOut().getAbsolutePath());
// create alignment writer
IContentType contentType = HalePlatform.getContentTypeManager().getContentType(ALIGNMENT_CONTENT_TYPE);
IOProviderDescriptor factory = HaleIO.findIOProviderFactory(AlignmentWriter.class, contentType, null);
AlignmentWriter writer = (AlignmentWriter) factory.createExtensionObject();
// configure alignment writer
writer.setTargetSchema(new DefaultSchemaSpace().addSchema(schema));
writer.setTarget(new FileIOSupplier(context.getOut()));
writer.setAlignment(alignment);
IOReport report = writer.execute(new NullProgressIndicator());
if (!report.isSuccess() || !report.getErrors().isEmpty()) {
throw new IllegalStateException("Errors while writing the alignment.");
} else {
System.out.println("Completed successfully.");
}
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class GenerateDuplicates method writeAlignment.
private void writeAlignment() throws Exception {
System.out.println("Writing alignment to " + context.getOut().getAbsolutePath());
// create alignment writer
IContentType contentType = HalePlatform.getContentTypeManager().getContentType(ALIGNMENT_CONTENT_TYPE);
IOProviderDescriptor factory = HaleIO.findIOProviderFactory(AlignmentWriter.class, contentType, null);
AlignmentWriter writer = (AlignmentWriter) factory.createExtensionObject();
// configure alignment writer
writer.setSourceSchema(sourceSchema);
writer.setTargetSchema(targetSchema);
writer.setTarget(new FileIOSupplier(context.getOut()));
writer.setAlignment(alignment);
IOReport report = writer.execute(new NullProgressIndicator());
if (!report.isSuccess() || !report.getErrors().isEmpty()) {
throw new IllegalStateException("Errors while writing the alignment.");
} else {
System.out.println("Completed successfully.");
}
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class CityGMLPropagate method writeAlignment.
private void writeAlignment() throws Exception {
System.out.println("Writing alignment to " + context.getOut().getAbsolutePath());
// create alignment writer
IContentType contentType = HalePlatform.getContentTypeManager().getContentType(ALIGNMENT_CONTENT_TYPE);
IOProviderDescriptor factory = HaleIO.findIOProviderFactory(AlignmentWriter.class, contentType, null);
AlignmentWriter writer = (AlignmentWriter) factory.createExtensionObject();
// configure alignment writer
writer.setSourceSchema(sourceSchema);
writer.setTargetSchema(targetSchema);
writer.setTarget(new FileIOSupplier(context.getOut()));
writer.setAlignment(alignment);
IOReport report = writer.execute(new NullProgressIndicator());
if (!report.isSuccess() || !report.getErrors().isEmpty()) {
throw new IllegalStateException("Errors while writing the alignment.");
} else {
System.out.println("Completed successfully.");
}
}
use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.
the class HaleIO method findIOProviderAndId.
/**
* Find an I/O provider instance for the given input
*
* @param <T> the provider interface type
*
* @param providerType the provider type, usually an interface
* @param in the input supplier to use for testing, may be <code>null</code>
* if the file name is not <code>null</code>
* @param filename the file name, may be <code>null</code> if the input
* supplier is not <code>null</code>
* @return a pair with the I/O provider and the corresponding identifier,
* both are <code>null</code> if no matching I/O provider was found
*/
@SuppressWarnings("unchecked")
public static <T extends IOProvider> Pair<T, String> findIOProviderAndId(Class<T> providerType, InputSupplier<? extends InputStream> in, String filename) {
T reader = null;
String providerId = null;
IContentType contentType = HaleIO.findContentType(providerType, in, filename);
if (contentType != null) {
IOProviderDescriptor factory = HaleIO.findIOProviderFactory(providerType, contentType, null);
try {
reader = (T) factory.createExtensionObject();
providerId = factory.getIdentifier();
} catch (Exception e) {
throw new RuntimeException("Could not create I/O provider", e);
}
if (reader != null) {
reader.setContentType(contentType);
}
}
return new Pair<T, String>(reader, providerId);
}
Aggregations