Search in sources :

Example 16 with IOMessageImpl

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));
}
Also used : UnionValidationConstraint(eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionValidationConstraint) UnionBinding(eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionBinding) QName(javax.xml.namespace.QName) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) UnionValidationConstraint(eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionValidationConstraint) TypeConstraint(eu.esdihumboldt.hale.common.schema.model.TypeConstraint) ValidationConstraint(eu.esdihumboldt.hale.common.schema.model.constraint.type.ValidationConstraint) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) UnionEnumeration(eu.esdihumboldt.hale.io.xsd.reader.internal.constraint.UnionEnumeration) XmlSchemaObject(org.apache.ws.commons.schema.XmlSchemaObject) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) XmlSchemaObjectCollection(org.apache.ws.commons.schema.XmlSchemaObjectCollection) HashSet(java.util.HashSet)

Example 17 with IOMessageImpl

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();
            }
        }
    });
}
Also used : IContentProvider(org.eclipse.jface.viewers.IContentProvider) GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) CellGraphContentProvider(eu.esdihumboldt.hale.ui.common.graph.content.CellGraphContentProvider) Dimension(java.awt.Dimension) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) GraphViewer(org.eclipse.zest.core.viewers.GraphViewer) OffscreenGraph(eu.esdihumboldt.hale.ui.util.graph.OffscreenGraph) Graph(org.eclipse.zest.core.widgets.Graph) FileOutputStream(java.io.FileOutputStream) OffscreenGraph(eu.esdihumboldt.hale.ui.util.graph.OffscreenGraph) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Display(org.eclipse.swt.widgets.Display)

Example 18 with IOMessageImpl

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;
}
Also used : IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)

Example 19 with IOMessageImpl

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;
}
Also used : WfsBackedGmlInstanceCollection(eu.esdihumboldt.hale.io.gml.reader.internal.wfs.WfsBackedGmlInstanceCollection) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) WfsBackedGmlInstanceCollection(eu.esdihumboldt.hale.io.gml.reader.internal.wfs.WfsBackedGmlInstanceCollection)

Example 20 with IOMessageImpl

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();
}
Also used : QName(javax.xml.namespace.QName) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) Element(org.w3c.dom.Element) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) DefinitionAccessor(eu.esdihumboldt.hale.common.schema.groovy.DefinitionAccessor) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Aggregations

IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)85 IOException (java.io.IOException)43 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)33 QName (javax.xml.namespace.QName)20 URI (java.net.URI)15 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)14 InputStream (java.io.InputStream)13 File (java.io.File)12 HashMap (java.util.HashMap)11 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)9 FileOutputStream (java.io.FileOutputStream)9 ArrayList (java.util.ArrayList)9 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)8 OutputStream (java.io.OutputStream)8 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)7 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)7 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)6 MutableCell (eu.esdihumboldt.hale.common.align.model.MutableCell)5 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)4 Value (eu.esdihumboldt.hale.common.core.io.Value)4