use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class XmlTypeUtil method configureSimpleTypeUnion.
/**
* Configure a type definition for a simple type based on a simple type
* union.
*
* @param type the type definition
* @param union the simple type union
* @param index the XML index for resolving type definitions
* @param reporter the report
*/
private static void configureSimpleTypeUnion(XmlTypeDefinition type, XmlSchemaSimpleTypeUnion union, XmlIndex index, IOReporter reporter) {
XmlSchemaObjectCollection baseTypes = union.getBaseTypes();
// collect type definitions
Set<TypeDefinition> unionTypes = new HashSet<TypeDefinition>();
if (union.getMemberTypesQNames() != null) {
for (QName unionMember : union.getMemberTypesQNames()) unionTypes.add(index.getOrCreateType(unionMember));
}
// base type definitions
if (baseTypes != null && baseTypes.getCount() > 0) {
for (int i = 0; i < baseTypes.getCount(); i++) {
XmlSchemaObject baseType = baseTypes.getItem(i);
if (baseType instanceof XmlSchemaSimpleType) {
XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) baseType;
// Here it is a xs:localSimpleTypes, name attribute is
// prohibited!
// So it always is a anonymous type.
QName baseName = new QName(type.getName().getNamespaceURI() + "/" + type.getName().getLocalPart(), // $NON-NLS-1$ //$NON-NLS-2$
"AnonymousType" + i);
XmlTypeDefinition baseDef = new AnonymousXmlType(baseName);
configureSimpleType(baseDef, simpleType, index, reporter);
unionTypes.add(baseDef);
} else {
reporter.error(new IOMessageImpl("Unrecognized base type for simple type union", null, union.getLineNumber(), union.getLinePosition()));
}
}
}
// binding constraint
type.setConstraint(new UnionBinding(unionTypes));
// enumeration constraint
type.setConstraint(new UnionEnumeration(unionTypes));
// validation constraint
type.setConstraint(new UnionValidationConstraint(unionTypes));
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class HtmlMappingExporter method saveImageToFile.
private void saveImageToFile(final Cell cell, File filesDir) {
Display display;
if (Display.getCurrent() != null) {
// use the current display if available
display = Display.getCurrent();
} else {
try {
// use workbench display if available
display = PlatformUI.getWorkbench().getDisplay();
} catch (Throwable e) {
// use a dedicated display thread if no workbench is
// available
display = DisplayThread.getInstance().getDisplay();
}
}
// creates a unique id for each cell
String cellId = cellIds.getId(cell);
final File file = new File(filesDir, "img_" + cellId + ".png");
display.syncExec(new Runnable() {
@Override
public void run() {
OffscreenGraph offscreenGraph = new OffscreenGraph(600, 200) {
@Override
protected void configureViewer(GraphViewer viewer) {
IContentProvider contentProvider = new CellGraphContentProvider();
GraphLabelProvider labelProvider = new GraphLabelProvider(null, HaleUI.getServiceProvider());
viewer.setContentProvider(contentProvider);
viewer.setLabelProvider(labelProvider);
viewer.setInput(cell);
}
};
Graph graph = offscreenGraph.getGraph();
Dimension dimension = computeSize(graph);
// minimum width = 600
offscreenGraph.resize(dimension.width > 600 ? dimension.width : 600, dimension.height);
try {
offscreenGraph.saveImage(new BufferedOutputStream(new FileOutputStream(file)), null);
} catch (Exception e) {
reporter.error(new IOMessageImpl("Can not create image", e));
} finally {
offscreenGraph.dispose();
}
}
});
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class HtmlMappingExporter method reportError.
private IOReport reportError(IOReporter reporter, String message, Exception e) {
reporter.error(new IOMessageImpl(message, e));
reporter.setSuccess(false);
return reporter;
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class StreamGmlReader method execute.
/**
* @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
*/
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
progress.begin("Prepare loading of " + getTypeName(), ProgressIndicator.UNKNOWN);
try {
boolean ignoreRoot = getParameter(PARAM_IGNORE_ROOT).as(Boolean.class, true);
boolean strict = getParameter(PARAM_STRICT).as(Boolean.class, false);
boolean ignoreNamespaces = getParameter(PARAM_IGNORE_NAMESPACES).as(Boolean.class, false);
boolean paginateRequest = getParameter(PARAM_PAGINATE_REQUEST).as(Boolean.class, false);
boolean ignoreNumberMatched = getParameter(PARAM_IGNORE_NUMBER_MATCHED).as(Boolean.class, false);
int featuresPerRequest;
if (paginateRequest) {
featuresPerRequest = getParameter(PARAM_FEATURES_PER_WFS_REQUEST).as(Integer.class, 1000);
} else {
featuresPerRequest = WfsBackedGmlInstanceCollection.UNLIMITED;
}
LocatableInputSupplier<? extends InputStream> source = getSource();
String scheme = null;
String query = null;
if (source.getLocation() != null) {
scheme = source.getLocation().getScheme();
query = source.getLocation().getQuery();
}
if (query != null && scheme != null && query.toLowerCase().contains("request=getfeature") && (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https"))) {
// check if WFS is reachable and responds?
instances = new WfsBackedGmlInstanceCollection(getSource(), getSourceSchema(), restrictToFeatures, ignoreRoot, strict, ignoreNamespaces, getCrsProvider(), this, featuresPerRequest, ignoreNumberMatched);
} else {
instances = new GmlInstanceCollection(getSource(), getSourceSchema(), restrictToFeatures, ignoreRoot, strict, ignoreNamespaces, getCrsProvider(), this);
}
// TODO any kind of analysis on file? e.g. types and size - would
// also give feedback to the user if the file can be loaded
reporter.setSuccess(true);
} catch (Throwable e) {
reporter.error(new IOMessageImpl(e.getMessage(), e));
reporter.setSuccess(false);
}
return reporter;
}
use of eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl in project hale by halestudio.
the class InspireInstanceWriter method writeAdditionalElements.
/**
* @see StreamGmlWriter#writeAdditionalElements(XMLStreamWriter,
* TypeDefinition, IOReporter)
*/
@Override
protected void writeAdditionalElements(XMLStreamWriter writer, TypeDefinition containerDefinition, IOReporter reporter) throws XMLStreamException {
super.writeAdditionalElements(writer, containerDefinition, reporter);
// determine INSPIRE identifier and metadata names
Path<Definition<?>> localIdPath = new DefinitionAccessor(containerDefinition).findChildren("identifier").findChildren("Identifier").findChildren("localId").eval(false);
QName identifierName = localIdPath.getElements().get(1).getName();
Definition<?> internalIdentifierDef = localIdPath.getElements().get(2);
QName internalIdentifierName = internalIdentifierDef.getName();
QName localIdName = localIdPath.getElements().get(3).getName();
Path<Definition<?>> namespacePath = new DefinitionAccessor(internalIdentifierDef).findChildren("namespace").eval(false);
QName namespaceName = namespacePath.getElements().get(1).getName();
Path<Definition<?>> metadataPath = new DefinitionAccessor(containerDefinition).findChildren("metadata").eval(false);
QName metadataName = metadataPath.getElements().get(1).getName();
// write INSPIRE identifier
writer.writeStartElement(identifierName.getNamespaceURI(), identifierName.getLocalPart());
writer.writeStartElement(internalIdentifierName.getNamespaceURI(), internalIdentifierName.getLocalPart());
writer.writeStartElement(localIdName.getNamespaceURI(), localIdName.getLocalPart());
writer.writeCharacters(getParameter(PARAM_SPATIAL_DATA_SET_LOCALID).as(String.class, ""));
writer.writeEndElement();
writer.writeStartElement(namespaceName.getNamespaceURI(), namespaceName.getLocalPart());
writer.writeCharacters(getParameter(PARAM_SPATIAL_DATA_SET_NAMESPACE).as(String.class, ""));
writer.writeEndElement();
writer.writeEndElement();
writer.writeEndElement();
// write metadata
writer.writeStartElement(metadataName.getNamespaceURI(), metadataName.getLocalPart());
// retrieve metadata element (if any)
Element metadataElement = getParameter(PARAM_SPATIAL_DATA_SET_METADATA_DOM).as(Element.class);
// metadata from file (if any)
if (metadataElement == null) {
String metadataFile = getParameter(PARAM_SPATIAL_DATA_SET_METADATA_FILE).as(String.class);
if (metadataFile != null && !metadataFile.isEmpty()) {
try (InputStream input = new BufferedInputStream(new FileInputStream(new File(metadataFile)))) {
metadataElement = findMetadata(input, reporter);
} catch (IOException e) {
reporter.warn(new IOMessageImpl("Could not load specified metadata file.", e));
}
}
}
if (metadataElement != null) {
try {
writeElement(metadataElement, writer);
} catch (TransformerException e) {
reporter.warn(new IOMessageImpl("Couldn't include specified metadata file.", e));
}
} else {
writer.writeAttribute(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "nil", "true");
}
writer.writeEndElement();
}
Aggregations