Search in sources :

Example 21 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.

the class XmlSchemaReaderTest method testRead_definitive_annotated.

/**
 * Test reading a simple XML schema with an annotated element.
 *
 * @throws Exception if reading the schema fails
 */
@Test
public void testRead_definitive_annotated() throws Exception {
    URI location = getClass().getResource("/testdata/definitive/documentation_ex.xsd").toURI();
    LocatableInputSupplier<? extends InputStream> input = new DefaultInputSupplier(location);
    XmlIndex schema = (XmlIndex) readSchema(input);
    // product element
    XmlElement product = schema.getElements().get(new QName("product"));
    assertNotNull(product);
    assertTrue(product.getDescription().contains("This element represents a product."));
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) QName(javax.xml.namespace.QName) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) URI(java.net.URI) Test(org.junit.Test)

Example 22 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.

the class OmlReader method findElementType.

private QName findElementType(TypeIndex schema, QName elementName) {
    if (schema instanceof SchemaSpace) {
        SchemaSpace ss = (SchemaSpace) schema;
        for (Schema schem : ss.getSchemas()) {
            if (schem instanceof XmlIndex) {
                XmlElement xmlelem = ((XmlIndex) schem).getElements().get(elementName);
                if (xmlelem != null) {
                    return xmlelem.getType().getName();
                }
                // if there is no element try to find one with an extra "/"
                // sign in the namespace because in earlier version this
                // case can occur
                xmlelem = ((XmlIndex) schem).getElements().get(new QName(elementName.getNamespaceURI() + "/", elementName.getLocalPart()));
                if (xmlelem != null) {
                    return xmlelem.getType().getName();
                }
            }
        }
    } else {
        for (TypeDefinition typedef : schema.getTypes()) {
            XmlElements xmlelem = typedef.getConstraint(XmlElements.class);
            for (XmlElement elem : xmlelem.getElements()) {
                if (elem.getName().equals(elementName) || elem.getName().equals(new QName(elementName.getNamespaceURI() + "/", elementName.getLocalPart()))) {
                    return typedef.getName();
                }
            }
        }
    }
    return elementName;
}
Also used : XmlElements(eu.esdihumboldt.hale.io.xsd.constraint.XmlElements) SchemaSpace(eu.esdihumboldt.hale.common.schema.model.SchemaSpace) QName(javax.xml.namespace.QName) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition)

Example 23 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.

the class PatternTest method createCurveType.

private TypeDefinition createCurveType() {
    // create the curve type
    DefaultTypeDefinition curve = new DefaultTypeDefinition(new QName(GML_NS, "CurveType"));
    XmlElement curveElement = new XmlElement(CURVE_ELEMENT, curve, null);
    curve.getConstraint(XmlElements.class).addElement(curveElement);
    // create the segments property for curve
    TypeDefinition segArray = new DefaultTypeDefinition(new QName(GML_NS, // $NON-NLS-1$
    "CurveSegmentArrayPropertyType"));
    new DefaultPropertyDefinition(new QName("segments"), curve, segArray);
    // create the AbstractCurveSegement property for segArray
    DefaultTypeDefinition absSeg = new DefaultTypeDefinition(new QName(GML_NS, // $NON-NLS-1$
    "AbstractCurveSegementType"));
    absSeg.setConstraint(AbstractFlag.ENABLED);
    new DefaultPropertyDefinition(new QName("AbstractCurveSegment"), segArray, absSeg);
    // add dummy sub-type
    DefaultTypeDefinition subtype = new DefaultTypeDefinition(new QName("somespace", // $NON-NLS-1$ //$NON-NLS-2$
    "SomeSegmentType"));
    subtype.setSuperType(absSeg);
    // create the LineStringSegmentType sub-type
    DefaultTypeDefinition lineSeg = new DefaultTypeDefinition(new QName(GML_NS, // $NON-NLS-1$
    "LineStringSegmentType"));
    lineSeg.setSuperType(absSeg);
    XmlElement lineSegElement = new XmlElement(new QName(GML_NS, "LineStringSegment"), lineSeg, new QName(GML_NS, "AbstractCurveSegment"));
    lineSeg.getConstraint(XmlElements.class).addElement(lineSegElement);
    return curve;
}
Also used : DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition) DefaultPropertyDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition) XmlElements(eu.esdihumboldt.hale.io.xsd.constraint.XmlElements) QName(javax.xml.namespace.QName) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) DefaultTypeDefinition(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)

Example 24 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement in project hale by halestudio.

the class SpatialDataSetConfigurationPage method createContent.

/**
 * @see HaleWizardPage#createContent(Composite)
 */
@Override
protected void createContent(Composite page) {
    GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false).spacing(6, 12).applyTo(page);
    // Get the property definitions of localId and namespace.
    String action = getWizard().getActionId();
    SchemaService ss = PlatformUI.getWorkbench().getService(SchemaService.class);
    SchemaSpaceID ssid = SchemaSpaceID.TARGET;
    if (InstanceIO.ACTION_SAVE_SOURCE_DATA.equals(action)) {
        ssid = SchemaSpaceID.SOURCE;
    }
    SchemaSpace target = ss.getSchemas(ssid);
    XmlIndex index = StreamGmlWriter.getXMLIndex(target);
    XmlElement sdsElement = InspireUtil.findSpatialDataSet(index);
    TypeDefinition sdsType = null;
    if (sdsElement != null) {
        sdsType = sdsElement.getType();
    }
    // applicable.
    if (sdsType == null)
        return;
    // find localId and namespace definitions
    Path<Definition<?>> localIdPath = new DefinitionAccessor(sdsType).findChildren("identifier").findChildren("Identifier").findChildren("localId").eval(false);
    List<Definition<?>> localIdDefs = localIdPath.getElements();
    PropertyDefinition localIdDef = (PropertyDefinition) localIdDefs.get(localIdDefs.size() - 1);
    Path<Definition<?>> namespacePath = new DefinitionAccessor(sdsType).findChildren("identifier").findChildren("Identifier").findChildren("namespace").eval(false);
    List<Definition<?>> namespaceDefs = namespacePath.getElements();
    PropertyDefinition nsDef = (PropertyDefinition) namespaceDefs.get(namespaceDefs.size() - 1);
    IPropertyChangeListener changeListener = new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(AttributeEditor.IS_VALID) || event.getProperty().equals(FileFieldEditor.IS_VALID))
                updateState();
        }
    };
    // inspire identifier
    Label inspireId = new Label(page, SWT.NONE);
    inspireId.setText("Please specify the local ID and the namespace as part of the INSPIRE identifier of the Spatial Data Set:");
    GridDataFactory.fillDefaults().span(2, 1).applyTo(inspireId);
    AttributeEditorFactory aef = PlatformUI.getWorkbench().getService(AttributeEditorFactory.class);
    Composite localIdtitle = new Composite(page, SWT.NONE);
    localIdtitle.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).create());
    DefinitionLabelFactory dlf = PlatformUI.getWorkbench().getService(DefinitionLabelFactory.class);
    dlf.createLabel(localIdtitle, localIdDef, false);
    Label label = new Label(localIdtitle, SWT.NONE);
    label.setText(" = ");
    localIdEditor = aef.createEditor(page, localIdDef, null, false);
    localIdEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    localIdEditor.setPropertyChangeListener(changeListener);
    Composite namespacetitle = new Composite(page, SWT.NONE);
    namespacetitle.setLayout(GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).create());
    dlf.createLabel(namespacetitle, nsDef, false);
    label = new Label(namespacetitle, SWT.NONE);
    label.setText(" = ");
    namespaceEditor = aef.createEditor(page, nsDef, null, false);
    namespaceEditor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
    namespaceEditor.setPropertyChangeListener(changeListener);
    // spacer
    Composite spacer = new Composite(page, SWT.NONE);
    GridDataFactory.fillDefaults().hint(0, 8).applyTo(spacer);
    // metadata file
    Label metadataLabel = new Label(page, SWT.NONE);
    metadataLabel.setText("You can include metadata in the Spatial Data Set from a XML file with a MD_Metadata element:");
    GridDataFactory.fillDefaults().span(2, 1).applyTo(metadataLabel);
    // source file
    Composite fileFieldComposite = new Composite(page, SWT.NONE);
    fileFieldComposite.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
    metadataFile = new OpenFileFieldEditor("metadataFile", "ISO Geographic MetaData XML", true, FileFieldEditor.VALIDATE_ON_KEY_STROKE, fileFieldComposite);
    metadataFile.setPage(this);
    metadataFile.setEmptyStringAllowed(true);
    metadataFile.setFileExtensions(new String[] { "*.xml" });
    metadataFile.setPropertyChangeListener(changeListener);
    // isValid starts with false even if emptyStringAllowed is true.
    // -> force validation hack
    metadataFile.setStringValue(" ");
    metadataFile.setStringValue("");
    updateState();
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) DefinitionLabelFactory(eu.esdihumboldt.hale.ui.common.definition.DefinitionLabelFactory) Composite(org.eclipse.swt.widgets.Composite) SchemaSpace(eu.esdihumboldt.hale.common.schema.model.SchemaSpace) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) Label(org.eclipse.swt.widgets.Label) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) AttributeEditorFactory(eu.esdihumboldt.hale.ui.common.definition.AttributeEditorFactory) PropertyDefinition(eu.esdihumboldt.hale.common.schema.model.PropertyDefinition) SchemaSpaceID(eu.esdihumboldt.hale.common.schema.SchemaSpaceID) TypeDefinition(eu.esdihumboldt.hale.common.schema.model.TypeDefinition) OpenFileFieldEditor(eu.esdihumboldt.hale.ui.util.io.OpenFileFieldEditor) SchemaService(eu.esdihumboldt.hale.ui.service.schema.SchemaService) DefinitionAccessor(eu.esdihumboldt.hale.common.schema.groovy.DefinitionAccessor) GridData(org.eclipse.swt.layout.GridData) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement)

Example 25 with XmlElement

use of eu.esdihumboldt.hale.io.xsd.model.XmlElement 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;
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) URI(java.net.URI) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) XMLStreamException(javax.xml.stream.XMLStreamException) MismatchedDimensionException(org.opengis.geometry.MismatchedDimensionException) IOException(java.io.IOException) FactoryException(org.opengis.referencing.FactoryException) URISyntaxException(java.net.URISyntaxException) TransformException(org.opengis.referencing.operation.TransformException) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) HashSet(java.util.HashSet)

Aggregations

XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)37 QName (javax.xml.namespace.QName)23 XmlIndex (eu.esdihumboldt.hale.io.xsd.model.XmlIndex)16 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)14 XmlElements (eu.esdihumboldt.hale.io.xsd.constraint.XmlElements)12 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)11 URI (java.net.URI)11 Test (org.junit.Test)9 HashSet (java.util.HashSet)7 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)6 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)4 SchemaSpace (eu.esdihumboldt.hale.common.schema.model.SchemaSpace)4 IOException (java.io.IOException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)3 PropertyDefinition (eu.esdihumboldt.hale.common.schema.model.PropertyDefinition)3 DefaultPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition)3 DefaultTypeDefinition (eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeDefinition)3 File (java.io.File)3 ValueList (eu.esdihumboldt.hale.common.core.io.ValueList)2