sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Improve compatibility with other modules that use legacy metadata, for example Feature Catalog. Add CI_ResponsibleParty even if not used by the SIS branch on GeoAPI 4.0 because some standards still depend on it. Also, be less aggressive in the namespace renaming performed by TransformingReader because some names (e.g. "Record") are used in other context than metadata.
Date Fri, 29 Jun 2018 14:48:02 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 12ba81b  Improve compatibility with other modules that use legacy metadata, for example
Feature Catalog. Add CI_ResponsibleParty even if not used by the SIS branch on GeoAPI 4.0
because some standards still depend on it. Also, be less aggressive in the namespace renaming
performed by TransformingReader because some names (e.g. "Record") are used in other context
than metadata.
12ba81b is described below

commit 12ba81b53588e75186dfb240f0ebd3fb60a7cabf
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Fri Jun 29 16:44:10 2018 +0200

    Improve compatibility with other modules that use legacy metadata, for example Feature
Catalog.
    Add CI_ResponsibleParty even if not used by the SIS branch on GeoAPI 4.0 because some
standards still depend on it.
    Also, be less aggressive in the namespace renaming performed by TransformingReader because
some names (e.g. "Record") are used in other context than metadata.
---
 .../jaxb/metadata/CI_ResponsibleParty.java         | 132 +++++++++++++++++++++
 .../main/java/org/apache/sis/xml/Namespaces.java   |   3 +-
 .../main/java/org/apache/sis/xml/Transformer.java  |  22 +++-
 .../org/apache/sis/xml/TransformingReader.java     |  23 +++-
 .../org/apache/sis/xml/TransformingWriter.java     |  15 ++-
 .../sis/xml/CharSequenceSubstitutionTest.java      |  12 +-
 6 files changed, 188 insertions(+), 19 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/CI_ResponsibleParty.java
b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/CI_ResponsibleParty.java
new file mode 100644
index 0000000..22306ac
--- /dev/null
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/CI_ResponsibleParty.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.jaxb.metadata;
+
+import javax.xml.bind.annotation.XmlElementRef;
+import org.opengis.util.InternationalString;
+import org.opengis.metadata.citation.Contact;
+import org.opengis.metadata.citation.ResponsibleParty;
+import org.apache.sis.metadata.iso.citation.AbstractParty;
+import org.apache.sis.metadata.iso.citation.DefaultIndividual;
+import org.apache.sis.metadata.iso.citation.DefaultOrganisation;
+import org.apache.sis.metadata.iso.citation.DefaultResponsibility;
+import org.apache.sis.metadata.iso.citation.DefaultResponsibleParty;
+import org.apache.sis.internal.jaxb.gco.PropertyType;
+import org.apache.sis.internal.jaxb.FilterByVersion;
+
+
+/**
+ * JAXB adapter mapping implementing class to a legacy GeoAPI interface.
+ * See package documentation for more information about JAXB and interface.
+ *
+ * @deprecated This adapter is not used anymore for ISO 19115-3:2014 metadata.
+ * However it is needed for branches that depend on GeoAPI 3.x, and is also needed
+ * for implementing web services that have not yet been upgraded to latest ISO standard.
+ *
+ * @author  Cédric Briançon (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.0
+ * @since   0.3
+ * @module
+ */
+@Deprecated
+public final class CI_ResponsibleParty extends PropertyType<CI_ResponsibleParty, ResponsibleParty>
{
+    /**
+     * Empty constructor for JAXB only.
+     */
+    public CI_ResponsibleParty() {
+    }
+
+    /**
+     * Returns the GeoAPI interface which is bound by this adapter.
+     * This method is indirectly invoked by the private constructor
+     * below, so it shall not depend on the state of this object.
+     *
+     * @return {@code ResponsibleParty.class}
+     */
+    @Override
+    protected Class<ResponsibleParty> getBoundType() {
+        return ResponsibleParty.class;
+    }
+
+    /**
+     * Constructor for the {@link #wrap} method only.
+     */
+    private CI_ResponsibleParty(final ResponsibleParty metadata) {
+        super(metadata);
+    }
+
+    /**
+     * Invoked by {@link PropertyType} at marshalling time for wrapping the given metadata
value
+     * in a {@code <gmd:CI_ResponsibleParty>} XML element.
+     *
+     * @param  metadata  the metadata element to marshall.
+     * @return a {@code PropertyType} wrapping the given the metadata element.
+     */
+    @Override
+    protected CI_ResponsibleParty wrap(final ResponsibleParty metadata) {
+        return new CI_ResponsibleParty(metadata);
+    }
+
+    /**
+     * Invoked by JAXB at marshalling time for getting the actual metadata to write
+     * inside the {@code <gmd:CI_ResponsibleParty>} XML element.
+     * This is the value or a copy of the value given in argument to the {@code wrap} method.
+     *
+     * @return the metadata to be marshalled.
+     */
+    @XmlElementRef
+    public DefaultResponsibility getElement() {
+        if (FilterByVersion.LEGACY_METADATA.accept()) {
+            return DefaultResponsibleParty.castOrCopy(metadata);
+        } else if (metadata != null) {
+            final DefaultIndividual individual;
+            final String name = metadata.getIndividualName();
+            Contact contact = metadata.getContactInfo();
+            AbstractParty party;
+            if (name != null) {
+                individual = new DefaultIndividual(name, metadata.getPositionName(), contact);
+                party      = individual;
+                contact    = null;
+            } else {
+                individual = null;
+                party      = null;
+            }
+            final InternationalString organisation = metadata.getOrganisationName();
+            if (organisation != null) {
+                party = new DefaultOrganisation(organisation, null, individual, contact);
+            }
+            if (party != null) {
+                return new DefaultResponsibility(metadata.getRole(), null, party);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Invoked by JAXB at unmarshalling time for storing the result temporarily.
+     *
+     * @param  md  the unmarshalled metadata.
+     */
+    public void setElement(final DefaultResponsibility md) {
+        if (md instanceof DefaultResponsibleParty) {
+            metadata = (DefaultResponsibleParty) md;
+        } else if (md != null) {
+            metadata = new DefaultResponsibleParty(md);
+        }
+    }
+}
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/Namespaces.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/Namespaces.java
index 5c6ef61..c3ceaee 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/xml/Namespaces.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/Namespaces.java
@@ -539,8 +539,7 @@ public final class Namespaces extends Static {
         "http://www.isotc211.org/2005/",
         "http://www.opengis.net/",
         "http://www.w3.org/1999/",
-        "http://www.cnig.gouv.fr/2005/",
-        "http://purl.org/"
+        "http://www.cnig.gouv.fr/2005/"
     };
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/Transformer.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/Transformer.java
index 8050636..705ccdb 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/xml/Transformer.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/Transformer.java
@@ -26,6 +26,7 @@ import java.util.InvalidPropertiesFormatException;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.LineNumberReader;
+import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.events.Attribute;
@@ -336,7 +337,7 @@ abstract class Transformer {
                         String localPart = value.substring(s+1).trim();
                         QName name = new QName(namespace, localPart, prefix);
                         final Map<String,String> currentMap = outerElementProperties;
-                        outerElementProperties = renamingMap().getOrDefault(localPart, Collections.emptyMap());
+                        outerElementProperties = renamingMap(namespace).getOrDefault(localPart,
Collections.emptyMap());
                         final boolean changed = (name != (name = convert(name)));
                         outerElementProperties = currentMap;
                         if (changed) {
@@ -400,7 +401,7 @@ abstract class Transformer {
         final String localPart = name.getLocalPart();
         if (isTypeElement(localPart)) {
             outerElements.add(name);
-            outerElementProperties = renamingMap().getOrDefault(localPart, Collections.emptyMap());
+            outerElementProperties = renamingMap(name.getNamespaceURI()).getOrDefault(localPart,
Collections.emptyMap());
         }
     }
 
@@ -417,8 +418,16 @@ abstract class Transformer {
             for (int i=outerElements.size(); --i >= 0;) {
                 if (name.equals(outerElements.get(i))) {
                     outerElements.remove(i);
-                    final String parent = (--i >= 0) ? outerElements.get(i).getLocalPart()
: null;
-                    outerElementProperties = renamingMap().getOrDefault(parent, Collections.emptyMap());
+                    final String namespace, localPart;
+                    if (--i >= 0) {
+                        final QName parent = outerElements.get(i);
+                        namespace = parent.getNamespaceURI();
+                        localPart = parent.getLocalPart();
+                    } else {
+                        namespace = XMLConstants.NULL_NS_URI;
+                        localPart = null;
+                    }
+                    outerElementProperties = renamingMap(namespace).getOrDefault(localPart,
Collections.emptyMap());
                     break;
                 }
             }
@@ -468,8 +477,11 @@ abstract class Transformer {
     /**
      * Returns the map loaded by {@link #load(String, int)}.
      * This is a static field in the {@link TransformingReader} or {@link TransformingWriter}
subclass.
+     *
+     * @param  namespace  the namespace URI for which to get the substitution map (never
null).
+     * @return the substitution map for the given namespace, or an empty map if none.
      */
-    abstract Map<String, Map<String,String>> renamingMap();
+    abstract Map<String, Map<String,String>> renamingMap(String namespace);
 
     /**
      * Returns the new namespace for elements (types and properties) in the given namespace.
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingReader.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingReader.java
index 24d516f..dfa270d 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingReader.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingReader.java
@@ -30,6 +30,7 @@ import javax.xml.stream.events.Attribute;
 import javax.xml.stream.events.Namespace;
 import javax.xml.stream.events.EndElement;
 import javax.xml.stream.events.StartElement;
+import org.apache.sis.internal.xml.LegacyNamespaces;
 import org.apache.sis.util.collection.BackingStoreException;
 
 import static javax.xml.stream.XMLStreamConstants.*;
@@ -82,7 +83,7 @@ final class TransformingReader extends Transformer implements XMLEventReader
{
      * Returns the namespace for the given ISO type, or {@code null} if unknown.
      * This is the namespace used in JAXB annotations.
      *
-     * @param  type  a class name defined by ISO 19115 or related standards (e.g. {@code
"CI_Citation"}.
+     * @param  type  a class name defined by ISO 19115 or related standards (e.g. {@code
"CI_Citation"}).
      * @return a namespace for the given type, or {@code null} if unknown.
      */
     static String namespace(final String type) {
@@ -280,11 +281,27 @@ final class TransformingReader extends Transformer implements XMLEventReader
{
 
     /**
      * Returns the map loaded by {@link #load(String, int)}.
+     *
+     * @param  namespace  the namespace URI for which to get the substitution map.
+     * @return the substitution map for the given namespace, or an empty map if none.
      */
     @Override
     @SuppressWarnings("ReturnOfCollectionOrArrayField")
-    final Map<String, Map<String,String>> renamingMap() {
-        return NAMESPACES;
+    final Map<String, Map<String,String>> renamingMap(final String namespace)
{
+        if (!namespace.isEmpty()) {
+            switch (removeTrailingSlash(namespace)) {
+                case LegacyNamespaces.GMI_ALIAS:
+                case LegacyNamespaces.GMI:
+                case LegacyNamespaces.GMD:
+                case LegacyNamespaces.SRV:
+                case LegacyNamespaces.GCO:
+                case LegacyNamespaces.GMX:
+                case LegacyNamespaces.GML: {
+                    return NAMESPACES;
+                }
+            }
+        }
+        return Collections.emptyMap();
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingWriter.java b/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingWriter.java
index 80e63a3..ca570d2 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingWriter.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/xml/TransformingWriter.java
@@ -215,10 +215,13 @@ final class TransformingWriter extends Transformer implements XMLEventWriter
{
 
     /**
      * Returns the map loaded by {@link #load(String, int)}.
+     *
+     * @param  namespace  the namespace URI for which to get the substitution map.
+     * @return the substitution map for the given namespace.
      */
     @Override
     @SuppressWarnings("ReturnOfCollectionOrArrayField")
-    final Map<String, Map<String,String>> renamingMap() {
+    final Map<String, Map<String,String>> renamingMap(final String namespace)
{
         return NAMESPACES;
     }
 
@@ -276,8 +279,14 @@ final class TransformingWriter extends Transformer implements XMLEventWriter
{
         notify(namespace);
         String uri = namespace.getNamespaceURI();
         if (uri != null && !uri.isEmpty()) {
-            final String exported = relocate(removeTrailingSlash(uri));
-            if (exported != uri) {
+            /*
+             * Ignore trailing slash when checking if there is a namespace change.
+             * But if we do not find a namespace change, keep the trailing slash as
+             * given in the Namespace since that slash may be intentional.
+             */
+            final String trimed = removeTrailingSlash(uri);
+            final String exported = relocate(trimed);
+            if (exported != trimed) {
                 return uniqueNamespaces.computeIfAbsent(exported, (k) -> {
                     return new TransformedEvent.NS(namespace, Namespaces.getPreferredPrefix(k,
namespace.getPrefix()), k);
                     /*
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/xml/CharSequenceSubstitutionTest.java
b/core/sis-metadata/src/test/java/org/apache/sis/xml/CharSequenceSubstitutionTest.java
index 136cdf2..025bad7 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/xml/CharSequenceSubstitutionTest.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/xml/CharSequenceSubstitutionTest.java
@@ -80,17 +80,17 @@ public final strictfp class CharSequenceSubstitutionTest extends XMLTestCase
{
     @DependsOnMethod("testAnchor")
     public void testAnchorForString() throws JAXBException {
         final String expected =
-                "<mdb:MD_Identifier xmlns:mdb=\""   + Namespaces.MDB + '"' +
+                "<mcc:MD_Identifier xmlns:mcc=\""   + Namespaces.MCC + '"' +
                                   " xmlns:gcx=\""   + Namespaces.GCX + '"' +
                                   " xmlns:gco=\""   + Namespaces.GCO + '"' +
                                   " xmlns:xlink=\"" + Namespaces.XLINK + "\">\n" +
-                "  <mdb:code>\n" +
+                "  <mcc:code>\n" +
                 "    <gcx:Anchor xlink:href=\"SDN:L101:2:4326\">EPSG:4326</gcx:Anchor>\n"
+
-                "  </mdb:code>\n" +
-                "  <mdb:codeSpace>\n" +
+                "  </mcc:code>\n" +
+                "  <mcc:codeSpace>\n" +
                 "    <gco:CharacterString>L101</gco:CharacterString>\n" +
-                "  </mdb:codeSpace>\n" +
-                "</mdb:MD_Identifier>";
+                "  </mcc:codeSpace>\n" +
+                "</mcc:MD_Identifier>";
 
         final Identifier id = unmarshal(Identifier.class, expected);
         assertEquals("codespace", "L101", id.getCodeSpace());


Mime
View raw message