Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make gml:id attribute optional as defined in updated GML 3.2.1 schemas #1092

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
import static org.deegree.commons.xml.stax.XMLStreamUtils.nextElement;
import static org.deegree.commons.xml.stax.XMLStreamUtils.require;
import static org.deegree.commons.xml.stax.XMLStreamUtils.skipElement;
import static org.deegree.gml.GMLVersion.GML_2;
import static org.deegree.gml.GMLVersion.GML_30;
import static org.deegree.gml.GMLVersion.GML_31;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -181,32 +178,17 @@ protected AbstractGMLObjectReader( GMLStreamReader gmlStreamReader ) {
* Parses the gml:id attribute of a GML object element.
*
* @param xmlStream
* must not be <code>null</code> and point to the start element of a GML object
* must not be <code>null</code> and point to the start element of a GML object
* @return value of the GML id, can be <code>null</code>
* @throws XMLStreamException
* if the GML version requires a gml:id attribute and none is present (or invalid)
*/
public String parseGmlId( final XMLStreamReader xmlStream )
throws XMLStreamException {
public String parseGmlId( final XMLStreamReader xmlStream ) {
final String gmlId = xmlStream.getAttributeValue( gmlNs, "id" );
if ( gmlId == null && isGmlIdRequired() ) {
final String msg = "Required attribute gml:id is missing.";
throw new XMLStreamException( msg, xmlStream.getLocation() );
}
if ( gmlId != null ) {
checkValidNcName( gmlId );
}
return gmlId;
}

// required since GML 3.2
private boolean isGmlIdRequired() {
if ( gmlStreamReader.getLaxMode() ) {
return false;
}
return version != GML_2 && version != GML_30 || version != GML_31;
}

private void checkValidNcName( final String gmlId ) {
if ( gmlId.length() > 0 && !gmlId.matches( "[^\\d][^:]+" ) ) {
final String msg = gmlId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import static org.deegree.commons.tom.gml.GMLObjectCategory.TIME_SLICE;
import static org.deegree.commons.xml.CommonNamespaces.GML3_2_NS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
Expand All @@ -48,7 +49,12 @@

import javax.xml.namespace.QName;

import org.apache.xerces.impl.xs.XSAttributeDecl;
import org.apache.xerces.xs.XSAttributeDeclaration;
import org.apache.xerces.xs.XSAttributeUse;
import org.apache.xerces.xs.XSComplexTypeDefinition;
import org.apache.xerces.xs.XSElementDeclaration;
import org.apache.xerces.xs.XSTypeDefinition;
import org.deegree.commons.tom.gml.GMLObjectType;
import org.deegree.commons.tom.gml.property.PropertyType;
import org.deegree.commons.utils.test.TestProperties;
Expand Down Expand Up @@ -466,6 +472,29 @@ public void testAIXMTimeSlicePropertyDeclarations()
assertNull( propertySemantics );
}

@Test
public void testIncludedGml321BaseSchemaIncludesGmlIdCorrigendum()
throws ClassCastException,
ClassNotFoundException,
InstantiationException,
IllegalAccessException {
// schemaUrl is internally redirected to copy of the schema in the deegree-ogcschemas.jar
String schemaUrl = "http://schemas.opengis.net/gml/3.2.1/gmlBase.xsd";
GMLAppSchemaReader adapter = new GMLAppSchemaReader( null, null, schemaUrl );
AppSchema schema = adapter.extractAppSchema();
XSElementDeclaration abstractGmlElementDecl = schema.getGMLSchema().getAbstractGMLElementDeclaration();
XSComplexTypeDefinition typeDefinition = (XSComplexTypeDefinition) abstractGmlElementDecl.getTypeDefinition();
XSAttributeUse attrUse = null;
for ( Object object : typeDefinition.getAttributeUses() ) {
XSAttributeDecl attrDecl = (XSAttributeDecl) ( (XSAttributeUse) object ).getAttrDeclaration();
if ( attrDecl.getNamespace().equals( "http://www.opengis.net/gml/3.2" )
&& attrDecl.getName().equals( "id" ) ) {
attrUse = (XSAttributeUse) object;
}
}
assertFalse( attrUse.getRequired() );
}

private void assertPropertyType( GMLObjectType geometryDecl, int propDeclIdx, QName propName, int minOccurs,
int maxOccurs ) {
PropertyType pt = geometryDecl.getPropertyDeclarations().get( propDeclIdx );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public void test200Example01()
throws Exception {

DescribeFeatureTypeXMLAdapter parser = new DescribeFeatureTypeXMLAdapter();
parser.load( get200ExampleUrl( "DescribeFeatureType_Example01_Request.xml" ) );
parser.load( DescribeFeatureTypeXMLAdapterTest.class.getResource(
"wfs200/DescribeFeatureType_Example01_Request.xml" ) );
DescribeFeatureType request = parser.parse();
assertEquals( VERSION_200, request.getVersion() );
assertEquals( null, request.getHandle() );
Expand All @@ -83,14 +84,20 @@ public void test200Example02()
throws Exception {

DescribeFeatureTypeXMLAdapter parser = new DescribeFeatureTypeXMLAdapter();
parser.load( get200ExampleUrl( "DescribeFeatureType_Example02_Request.xml" ) );
parser.load( DescribeFeatureTypeXMLAdapterTest.class.getResource(
"wfs200/DescribeFeatureType_Example02_Request.xml" ) );
DescribeFeatureType request = parser.parse();
assertEquals( VERSION_200, request.getVersion() );
assertEquals( null, request.getHandle() );
assertEquals( "text/xml; subtype=gml/3.2", request.getOutputFormat() );
assertEquals( 1, request.getTypeNames().length );
}

/**
* TODO: Unused until https://github.com/deegree/deegree3/issues/1091 is implemented.
* @param name
* @return
*/
private URL get200ExampleUrl( String name ) {
try {
String url = new RedirectingEntityResolver().redirect( WFS200_EXAMPLES_BASE_URL + name );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" ?>
<DescribeFeatureType
service="WFS"
version="2.0.0"
xmlns="http://www.opengis.net/wfs/2.0"
xmlns:myns="http://www.myserver.com/myns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs/2.0
http://schemas.opengis.net/wfs/2.0/wfs.xsd">
<TypeName>myns:TreesA_1M</TypeName>
<TypeName>myns:RoadL_1M</TypeName>
</DescribeFeatureType>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" ?>
<DescribeFeatureType
service="WFS"
version="2.0.0"
outputFormat="text/xml; subtype=gml/3.2"
xmlns="http://www.opengis.net/wfs/2.0"
xmlns:myns="http://www.someserver.com/myns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs/2.0
http://schemas.opengis.net/wfs/2.0/wfs.xsd">
<TypeName>myns:Person</TypeName>
</DescribeFeatureType>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@
<dependency>
<groupId>org.deegree</groupId>
<artifactId>deegree-ogcschemas</artifactId>
<version>20120804</version>
<version>20191108</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
Expand Down