Skip to content

Commit

Permalink
Editor / Polygon / Fix validation error on srsName and id attributes. (
Browse files Browse the repository at this point in the history
…#4791)

* Editor / Polygon / Fix validation error on srsName and id attributes.

When adding bounding polygon, issues are reported on validation.

![image](https://user-images.githubusercontent.com/1701393/85522811-6d6adb80-b606-11ea-8c02-726e4d61f55e.png)

Since OL6 update, an srsName is added to LinearRing in GML3.2.0.

![image](https://user-images.githubusercontent.com/1701393/85522835-722f8f80-b606-11ea-87c6-a8056e1ae5b9.png)

GML2 OL format was not. See
 https://github.com/openlayers/openlayers/blame/v6.3.1/src/ol/format/GML2.js#L228
.
GML3 does https://github.com/openlayers/openlayers/blob/v6.3.1/src/ol/format/GML3.js#L503

From the XSD, this attribute should probably not be added https://schemas.wmo.int/wmdr/1.0RC6/documentation/schemadoc/schemas/geometryBasic2d_xsd/elements/LinearRing.html.

Workaround that issue by updating `LinearRing` in `update-fixed-info.xsl`.

* Editor / Polygon / Fix validation error on srsName and id attributes / Preserve existing.

* Editor / Polygon / Fix validation error on srsName and id attributes / Avoid xmlns attribute.

* Editor / Polygon / Fix validation error on srsName and id attributes. Avoid empty xmlns by cleaning gml namespaces of all elements.

* Editor / Polygon / Fix validation error on srsName and id attributes.

* Editor / Polygon / Fix validation error on srsName and id attributes / Avoid xmlns='' attribute and keep GML namesapce declaration at the root document level only. Thanks josegar74 for helping on that.

* Editor / Polygon / Fix validation error on srsName and id attributes.
  • Loading branch information
fxprunayre authored and josegar74 committed Jul 8, 2020
1 parent ffa577f commit a83b132
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
</xsl:choose>
</xsl:template>


<xsl:template match="gml:LinearRing/@srsName"/>

<xsl:template name="correct_ns_prefix">
<xsl:param name="element"/>
Expand Down
129 changes: 84 additions & 45 deletions schemas/iso19139/src/main/plugin/iso19139/update-fixed-info.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@

<!-- The default language is also added as gmd:locale
for multilingual metadata records. -->
<xsl:variable name="mainLanguage">
<xsl:call-template name="langId_from_gmdlanguage19139">
<xsl:with-param name="gmdlanguage" select="/root/*/gmd:language"/>
</xsl:call-template>
<xsl:variable name="mainLanguage">
<xsl:call-template name="langId_from_gmdlanguage19139">
<xsl:with-param name="gmdlanguage" select="/root/*/gmd:language"/>
</xsl:call-template>
</xsl:variable>

<xsl:variable name="isMultilingual"
Expand Down Expand Up @@ -259,8 +259,10 @@
<xsl:template match="@gml:id|@gml320:id">
<xsl:choose>
<xsl:when test="normalize-space(.)=''">
<xsl:attribute name="{if ($isUsing2005Schema and not($isUsing2007Schema))
then 'gml320' else 'gml'}:id">
<xsl:attribute name="gml:id"
namespace="{if($isUsing2005Schema)
then 'http://www.opengis.net/gml'
else 'http://www.opengis.net/gml/3.2'}">
<xsl:value-of select="generate-id(.)"/>
</xsl:attribute>
</xsl:when>
Expand All @@ -274,6 +276,8 @@
<!-- Fix srsName attribute generate CRS:84 (EPSG:4326 with long/lat
ordering) by default -->

<xsl:template match="gml:LinearRing/@srsName|gml320:LinearRing/@srsName"/>

<xsl:template match="@srsName">
<xsl:choose>
<xsl:when test="normalize-space(.)=''">
Expand All @@ -287,30 +291,44 @@
</xsl:choose>
</xsl:template>


<!-- Add required gml attributes if missing -->
<xsl:template match="gml:Polygon[not(@gml:id) and not(@srsName)]|
gml:MultiSurface[not(@gml:id) and not(@srsName)]|
gml:LineString[not(@gml:id) and not(@srsName)]|
gml320:Polygon[not(@gml320:id) and not(@srsName)]">
<xsl:copy copy-namespaces="no">
<xsl:choose>
<xsl:when test="$isUsing2005Schema and not($isUsing2007Schema)">
<xsl:namespace name="gml320" select="'http://www.opengis.net/gml'"/>
</xsl:when>
<xsl:otherwise>
<xsl:namespace name="gml" select="'http://www.opengis.net/gml/3.2'"/>
</xsl:otherwise>
</xsl:choose>
<xsl:attribute name="{if ($isUsing2005Schema and not($isUsing2007Schema))
then 'gml320' else 'gml'}:id">
<xsl:value-of select="generate-id(.)"/>
<xsl:template match="gml:Polygon[not(@gml:id) or not(@srsName)]|
gml:MultiSurface[not(@gml:id) or not(@srsName)]|
gml:LineString[not(@gml:id) or not(@srsName)]|
gml320:Polygon[not(@gml320:id) or not(@srsName)]|
gml320:MultiSurface[not(@gml:id) or not(@srsName)]|
gml320:LineString[not(@gml:id) or not(@srsName)]">
<xsl:element name="gml:{local-name()}"
namespace="{if($isUsing2005Schema)
then 'http://www.opengis.net/gml'
else 'http://www.opengis.net/gml/3.2'}">

<xsl:attribute name="gml:id"
namespace="{if($isUsing2005Schema)
then 'http://www.opengis.net/gml'
else 'http://www.opengis.net/gml/3.2'}">
<xsl:value-of select="if (@gml:id != '')
then @gml:id
else if (@gml320:id != '')
then @gml320:id
else generate-id(.)"/>
</xsl:attribute>
<xsl:attribute name="srsName">
<xsl:text>urn:ogc:def:crs:EPSG:6.6:4326</xsl:text>
<xsl:value-of select="if (@srsName != '') then @srsName else 'urn:ogc:def:crs:EPSG:6.6:4326'"/>
</xsl:attribute>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="@*[name() != 'srsName' and local-name() != 'id']"/>
<xsl:apply-templates select="*"/>
</xsl:copy>
</xsl:element>
</xsl:template>

<xsl:template match="gml:*|gml320:*">
<xsl:element name="gml:{local-name()}"
namespace="{if($isUsing2005Schema)
then 'http://www.opengis.net/gml'
else 'http://www.opengis.net/gml/3.2'}">
<xsl:apply-templates select="@*|*"/>
</xsl:element>
</xsl:template>

<!-- INSPIRE / TG2 / Require nilReason attribute to be
Expand Down Expand Up @@ -425,19 +443,19 @@

<!-- Populate PT_FreeText for default language if not existing and it is not null. -->
<xsl:apply-templates select="gco:CharacterString|gmx:Anchor"/>
<!-- only put this in if there's stuff to put in, otherwise we get a <gmd:PT_FreeText/> in output -->
<xsl:if test="(normalize-space(gco:CharacterString|gmx:Anchor) != '') or gmd:PT_FreeText">
<gmd:PT_FreeText>
<xsl:if test="normalize-space(gco:CharacterString|gmx:Anchor) != ''"> <!-- default lang-->
<gmd:textGroup>
<gmd:LocalisedCharacterString locale="#{$mainLanguageId}">
<xsl:value-of select="gco:CharacterString|gmx:Anchor"/>
</gmd:LocalisedCharacterString>
</gmd:textGroup>
</xsl:if>
<xsl:call-template name="populate-free-text"/> <!-- other langs -->
</gmd:PT_FreeText>
</xsl:if>
<!-- only put this in if there's stuff to put in, otherwise we get a <gmd:PT_FreeText/> in output -->
<xsl:if test="(normalize-space(gco:CharacterString|gmx:Anchor) != '') or gmd:PT_FreeText">
<gmd:PT_FreeText>
<xsl:if test="normalize-space(gco:CharacterString|gmx:Anchor) != ''"> <!-- default lang-->
<gmd:textGroup>
<gmd:LocalisedCharacterString locale="#{$mainLanguageId}">
<xsl:value-of select="gco:CharacterString|gmx:Anchor"/>
</gmd:LocalisedCharacterString>
</gmd:textGroup>
</xsl:if>
<xsl:call-template name="populate-free-text"/> <!-- other langs -->
</gmd:PT_FreeText>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
Expand Down Expand Up @@ -479,10 +497,10 @@

<xsl:if test="normalize-space(./text()) != '' and string(@codeListValue)">
<xsl:value-of select="java:getIsoLanguageLabel(@codeListValue, $mainLanguage)" />
<!--
<!--
If wanting to get strings from codelists then add gmd:LanguageCode codelist in loc/{lang}/codelists.xml
and use getCodelistTranslation instead of getIsoLanguageLabel. This will allow for custom values such as "eng; USA"
i.e.
i.e.
<xsl:value-of select="java:getCodelistTranslation(name(), string(@codeListValue), string($mainLanguage))"/>
-->
</xsl:if>
Expand Down Expand Up @@ -645,6 +663,26 @@
</xsl:choose>
</xsl:template>

<xsl:template name="correct_ns_prefix_with_namespace">
<xsl:param name="element"/>
<xsl:param name="prefix"/>
<xsl:param name="namespace"/>

<xsl:choose>
<xsl:when test="local-name($element)=name($element) and $prefix != '' ">
<xsl:element name="{$prefix}:{local-name($element)}" namespace="{$namespace}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template match="gmd:*">
<xsl:call-template name="correct_ns_prefix">
<xsl:with-param name="element" select="."/>
Expand All @@ -661,20 +699,21 @@

<!-- Move to GML 3.2.1 when using 2007 version. -->
<xsl:template match="gml320:*[$isUsing2007Schema]">
<xsl:element name="gml:{local-name()}">
<xsl:element name="gml:{local-name()}" namespace="http://www.opengis.net/gml/3.2">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@gml320:*[$isUsing2007Schema]">
<xsl:attribute name="gml:{local-name()}" select="."/>
<xsl:attribute name="gml:{local-name()}" namespace="http://www.opengis.net/gml/3.2" select="."/>
</xsl:template>

<xsl:template match="gml:*|gml320:*">
<xsl:call-template name="correct_ns_prefix">
<xsl:call-template name="correct_ns_prefix_with_namespace">
<xsl:with-param name="element" select="."/>
<xsl:with-param name="prefix"
select="if ($isUsing2005Schema and not($isUsing2007Schema))
then 'gml320' else 'gml'"/>
select="'gml'"/>
<xsl:with-param name="namespace"
select="if($isUsing2005Schema) then 'http://www.opengis.net/gml' else 'http://www.opengis.net/gml/3.2'"/>
</xsl:call-template>
</xsl:template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ Object getRecordAsXML(
isJson ? "json" : "xml"
));
return isJson ? Xml.getJSON(xml) : xml;
//return xml;
}

@ApiOperation(
Expand Down

0 comments on commit a83b132

Please sign in to comment.