use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.
the class StreamGmlWriterTest method testGeometryPrimitive_32_MultiLineString_Curve1.
/**
* Test writing a {@link MultiLineString} to a GML 3.2 geometry primitive
* type
*
* @throws Exception if an error occurs
*/
@Test
public void testGeometryPrimitive_32_MultiLineString_Curve1() throws Exception {
// create the geometry
MultiLineString mls = geomFactory.createMultiLineString(new LineString[] { createLineString(0.0) });
Map<List<QName>, Object> values = new HashMap<List<QName>, Object>();
// $NON-NLS-1$
values.put(GEOMETRY_PROPERTY, mls);
IOReport report = fillFeatureTest(// $NON-NLS-1$
"PrimitiveTest", // $NON-NLS-1$
getClass().getResource("/data/geom_schema/geom-gml32.xsd").toURI(), // $NON-NLS-1$
values, // $NON-NLS-1$
"geometryPrimitive_32_MultiLineString", // $NON-NLS-1$
DEF_SRS_NAME, true, false);
// $NON-NLS-1$
assertTrue("Expected GML output to be valid", report.isSuccess());
}
use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.
the class StreamGmlWriter method findDefaultContainter.
/**
* Find the default container element.
*
* @param targetIndex the target type index
* @param reporter the reporter, may be <code>null</code>
* @return the container XML element or <code>null</code>
*/
protected XmlElement findDefaultContainter(XmlIndex targetIndex, IOReporter reporter) {
if (useFeatureCollection) {
// try to find FeatureCollection element
Iterator<XmlElement> it = targetIndex.getElements().values().iterator();
Collection<XmlElement> fcElements = new HashSet<XmlElement>();
while (it.hasNext()) {
XmlElement el = it.next();
if (isFeatureCollection(el)) {
fcElements.add(el);
}
}
if (fcElements.isEmpty() && gmlNs != null && gmlNs.equals(NS_GML)) {
// include WFS 1.0.0 for the FeatureCollection element
try {
URI location = StreamGmlWriter.class.getResource("/schemas/wfs/1.0.0/WFS-basic.xsd").toURI();
XmlSchemaReader schemaReader = new XmlSchemaReader();
schemaReader.setSource(new DefaultInputSupplier(location));
// FIXME to work with the extra schema it must be integrated
// with the main schema
// schemaReader.setSharedTypes(sharedTypes);
IOReport report = schemaReader.execute(null);
if (report.isSuccess()) {
XmlIndex wfsSchema = schemaReader.getSchema();
// look for FeatureCollection element
for (XmlElement el : wfsSchema.getElements().values()) {
if (isFeatureCollection(el)) {
fcElements.add(el);
}
}
// add as additional schema, replace location for
// verification
additionalSchemas.put(wfsSchema.getNamespace(), new SchemaDecorator(wfsSchema) {
@Override
public URI getLocation() {
return URI.create("http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd");
}
});
// add namespace
// $NON-NLS-1$
GmlWriterUtil.addNamespace(writer, wfsSchema.getNamespace(), "wfs");
}
} catch (Exception e) {
// $NON-NLS-1$
log.warn("Using WFS schema for the FeatureCollection definition failed", e);
}
}
if (fcElements.isEmpty() && reporter != null) {
reporter.warn(// $NON-NLS-1$
new IOMessageImpl("No element describing a FeatureCollection found", null));
} else {
// select fc element TODO priorized selection (root element
// parameters)
XmlElement fcElement = fcElements.iterator().next();
log.info(// $NON-NLS-1$ //$NON-NLS-2$
"Found " + fcElements.size() + " possible FeatureCollection elements" + ", using element " + // $NON-NLS-1$
fcElement.getName());
return fcElement;
}
}
return null;
}
use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.
the class ExamplesContent method executeProvider.
/**
* Execute the I/O provider given or specified by the given provider ID.
*
* @param advisor the advisor to use for configuration of the provider and
* handling the results
* @param providerId the ID of the provider to execute, may be
* <code>null</code> if provider is set
* @param provider the provider to execute
* @throws Exception if executing the provider fails or if a provider with
* the given ID is not found
*/
@SuppressWarnings("unchecked")
private void executeProvider(@SuppressWarnings("rawtypes") IOAdvisor advisor, String providerId, IOProvider provider) throws Exception {
if (provider == null) {
// find and create the provider
IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(providerId);
if (descriptor != null) {
provider = descriptor.createExtensionObject();
} else {
throw new IllegalStateException("I/O provider with ID " + providerId + " not found");
}
}
// use advisor to configure provider
advisor.prepareProvider(provider);
advisor.updateConfiguration(provider);
// execute
IOReport report = provider.execute(null);
// handle results
if (report.isSuccess()) {
advisor.handleResults(provider);
}
}
use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.
the class GenerateDefaults method loadSchema.
private void loadSchema() throws IOProviderConfigurationException, IOException {
System.out.println("Loading schema...");
LocatableInputSupplier<? extends InputStream> schemaIn = new DefaultInputSupplier(context.getSchema());
SchemaReader schemaReader = HaleIO.findIOProvider(SchemaReader.class, schemaIn, context.getSchema().getPath());
schemaReader.setSource(schemaIn);
IOReport report = schemaReader.execute(new NullProgressIndicator());
if (!report.isSuccess() || !report.getErrors().isEmpty()) {
throw new IllegalStateException("Failed to load schema");
}
schema = schemaReader.getSchema();
}
use of eu.esdihumboldt.hale.common.core.io.report.IOReport 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.");
}
}
Aggregations