Skip to content

Commit

Permalink
Merge pull request #54 from lat-lon/deegree-3.4-pre12-xplan-geometryE…
Browse files Browse the repository at this point in the history
…rror-1007

Deegree 3.4 pre12 xplan geometry error 1007
  • Loading branch information
lgoltz committed Aug 28, 2014
2 parents a12ac40 + ac1f922 commit 0f96a3e
Show file tree
Hide file tree
Showing 16 changed files with 391 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@
----------------------------------------------------------------------------*/
package org.deegree.gml;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.deegree.commons.tom.gml.GMLObject;
import org.deegree.commons.tom.gml.GMLReference;
import org.deegree.commons.tom.gml.GMLReferenceResolver;
Expand All @@ -62,6 +57,12 @@
import org.deegree.gml.geometry.GMLGeometryReader;
import org.deegree.gml.reference.GmlDocumentIdContext;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.util.List;

/**
* Stream-based reader for GML instance documents or GML document fragments. Currently supports GML 2/3.0/3.1/3.2.
*
Expand Down Expand Up @@ -282,8 +283,24 @@ public GMLObject read()
* @throws UnknownCRSException
*/
public Feature readFeature()
throws XMLStreamException, XMLParsingException, UnknownCRSException {
return getFeatureReader().parseFeature( xmlStream, defaultCRS );
throws XMLStreamException, XMLParsingException, UnknownCRSException {
return readFeature( false );
}

/**
* Returns the deegree model representation for the GML feature element event that the cursor of the underlying xml
* stream points to.
*
* @param skipBrokenGeometries
* @return deegree model representation for the current GML feature element, never <code>null</code>
* @throws XMLStreamException
* @throws XMLParsingException
* @throws UnknownCRSException
*/
public Feature readFeature( boolean skipBrokenGeometries )
throws XMLStreamException, XMLParsingException, UnknownCRSException {
Feature feature = getFeatureReader( skipBrokenGeometries ).parseFeature( xmlStream, defaultCRS );
return feature;
}

/**
Expand Down Expand Up @@ -408,12 +425,22 @@ public void close()
* @return a configured {@link GMLFeatureReader} instance, never <code>null</code>
*/
public GMLFeatureReader getFeatureReader() {
return getFeatureReader( false );
}

/**
* Returns a configured {@link GMLFeatureReader} instance for calling specific feature parsing methods.
*
* @param skipBrokenGeometries
* @return a configured {@link GMLFeatureReader} instance, never <code>null</code>
*/
public GMLFeatureReader getFeatureReader( boolean skipBrokenGeometries ) {
if ( featureReader == null ) {
featureReader = new GMLFeatureReader( this );
featureReader = new GMLFeatureReader( this, skipBrokenGeometries );
}
return featureReader;
}

/**
* Returns a configured {@link GMLGeometryReader} instance for calling specific geometry parsing methods.
*
Expand Down Expand Up @@ -448,4 +475,9 @@ public GMLDictionaryReader getDictionaryReader() {
}
return dictReader;
}
}

public List<String> getSkippedBrokenGeometryErrors() {
return featureReader.getSkippedBrokenGeometryErrors();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,6 @@
----------------------------------------------------------------------------*/
package org.deegree.gml.commons;

import static java.util.Collections.EMPTY_LIST;
import static javax.xml.stream.XMLStreamConstants.CDATA;
import static javax.xml.stream.XMLStreamConstants.CHARACTERS;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import static org.apache.xerces.xs.XSComplexTypeDefinition.CONTENTTYPE_ELEMENT;
import static org.apache.xerces.xs.XSComplexTypeDefinition.CONTENTTYPE_EMPTY;
import static org.apache.xerces.xs.XSComplexTypeDefinition.CONTENTTYPE_MIXED;
import static org.apache.xerces.xs.XSComplexTypeDefinition.CONTENTTYPE_SIMPLE;
import static org.apache.xerces.xs.XSTypeDefinition.SIMPLE_TYPE;
import static org.deegree.commons.tom.primitive.BaseType.BOOLEAN;
import static org.deegree.commons.xml.CommonNamespaces.XLNNS;
import static org.deegree.commons.xml.CommonNamespaces.XSINS;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.apache.xerces.xs.XSAttributeDeclaration;
import org.apache.xerces.xs.XSAttributeUse;
import org.apache.xerces.xs.XSComplexTypeDefinition;
Expand Down Expand Up @@ -117,6 +91,31 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

import static java.util.Collections.EMPTY_LIST;
import static javax.xml.stream.XMLStreamConstants.CDATA;
import static javax.xml.stream.XMLStreamConstants.CHARACTERS;
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import static org.apache.xerces.xs.XSComplexTypeDefinition.CONTENTTYPE_ELEMENT;
import static org.apache.xerces.xs.XSComplexTypeDefinition.CONTENTTYPE_EMPTY;
import static org.apache.xerces.xs.XSComplexTypeDefinition.CONTENTTYPE_MIXED;
import static org.apache.xerces.xs.XSComplexTypeDefinition.CONTENTTYPE_SIMPLE;
import static org.apache.xerces.xs.XSTypeDefinition.SIMPLE_TYPE;
import static org.deegree.commons.tom.primitive.BaseType.BOOLEAN;
import static org.deegree.commons.xml.CommonNamespaces.XLNNS;
import static org.deegree.commons.xml.CommonNamespaces.XSINS;

/**
* Concrete extensions are parsers for a specific category of GML objects.
*
Expand All @@ -141,6 +140,10 @@ public abstract class AbstractGMLObjectReader extends XMLAdapter {
protected final GMLReferenceResolver specialResolver;

protected final GmlDocumentIdContext idContext;

private final boolean skipBrokenGeometries;

private final List<String> skippedBrokenGeometryErrors = new ArrayList<String>();

protected static final QName XSI_NIL = new QName( XSINS, "nil", "xsi" );

Expand All @@ -149,23 +152,35 @@ public abstract class AbstractGMLObjectReader extends XMLAdapter {

/**
* Creates a new {@link AbstractGMLObjectReader} instance.
*
*
* @param gmlStreamReader
* GML stream reader, must not be <code>null</code>
*/
protected AbstractGMLObjectReader( GMLStreamReader gmlStreamReader ) {
this( gmlStreamReader, false );
}

/**
* Creates a new {@link AbstractGMLObjectReader} instance.
*
* @param gmlStreamReader
* GML stream reader, must not be <code>null</code>
* @param skipBrokenGeometries
*/
protected AbstractGMLObjectReader( GMLStreamReader gmlStreamReader, boolean skipBrokenGeometries ) {
this.gmlStreamReader = gmlStreamReader;
this.specialResolver = gmlStreamReader.getResolver();
this.idContext = gmlStreamReader.getIdContext();
// TODO
this.schema = gmlStreamReader.getAppSchema();
this.gmlNs = gmlStreamReader.getVersion().getNamespace();
this.version = gmlStreamReader.getVersion();
this.skipBrokenGeometries = skipBrokenGeometries;
}

/**
* Returns the object representation for the given property element.
*
*
* @param xmlStream
* cursor must point at the <code>START_ELEMENT</code> event of the property, afterwards points at the
* corresponding <code>END_ELEMENT</code> event
Expand All @@ -190,7 +205,18 @@ public Property parseProperty( XMLStreamReaderWrapper xmlStream, PropertyType pr
if ( propDecl instanceof SimplePropertyType ) {
property = parseSimpleProperty( xmlStream, (SimplePropertyType) propDecl );
} else if ( propDecl instanceof GeometryPropertyType ) {
property = parseGeometryProperty( xmlStream, (GeometryPropertyType) propDecl, crs );
QName elementName = xmlStream.getName();
try {
property = parseGeometryProperty( xmlStream, (GeometryPropertyType) propDecl, crs );
} catch ( XMLParsingException e ) {
if ( skipBrokenGeometries ) {
LOG.warn( "Broken geometry was detected: " + e.getMessage() );
skippedBrokenGeometryErrors.add( e.getMessage() );
property = new GenericProperty( propDecl, elementName, null, true );
XMLStreamUtils.skipToEndElement( xmlStream, elementName );
} else
throw e;
}
} else if ( propDecl instanceof FeaturePropertyType ) {
property = parseFeatureProperty( xmlStream, (FeaturePropertyType) propDecl, crs );
} else if ( propDecl instanceof CustomPropertyType ) {
Expand Down Expand Up @@ -230,6 +256,10 @@ public final PropertyType findConcretePropertyType( final QName elemName, final
return null;
}

public List<String> getSkippedBrokenGeometryErrors() {
return skippedBrokenGeometryErrors;
}

private Property parseSimpleProperty( XMLStreamReaderWrapper xmlStream, SimplePropertyType propDecl )
throws NoSuchElementException, XMLStreamException, XMLParsingException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,6 @@
----------------------------------------------------------------------------*/
package org.deegree.gml.feature;

import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import static org.deegree.commons.tom.primitive.BaseType.STRING;
import static org.deegree.commons.xml.CommonNamespaces.GML3_2_NS;
import static org.deegree.commons.xml.CommonNamespaces.GMLNS;
import static org.deegree.commons.xml.CommonNamespaces.XLNNS;
import static org.deegree.commons.xml.CommonNamespaces.XSINS;
import static org.deegree.commons.xml.stax.XMLStreamUtils.nextElement;
import static org.deegree.feature.property.ExtraProps.EXTRA_PROP_NS;
import static org.deegree.feature.property.ExtraProps.EXTRA_PROP_NS_GEOMETRY;
import static org.deegree.feature.types.property.GeometryPropertyType.CoordinateDimension.DIM_2_OR_3;
import static org.deegree.feature.types.property.GeometryPropertyType.GeometryType.GEOMETRY;
import static org.deegree.feature.types.property.ValueRepresentation.INLINE;

import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;

import org.deegree.commons.tom.TypedObjectNode;
import org.deegree.commons.tom.gml.property.Property;
import org.deegree.commons.tom.gml.property.PropertyType;
Expand Down Expand Up @@ -88,6 +66,27 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import static org.deegree.commons.tom.primitive.BaseType.STRING;
import static org.deegree.commons.xml.CommonNamespaces.GML3_2_NS;
import static org.deegree.commons.xml.CommonNamespaces.GMLNS;
import static org.deegree.commons.xml.CommonNamespaces.XLNNS;
import static org.deegree.commons.xml.CommonNamespaces.XSINS;
import static org.deegree.commons.xml.stax.XMLStreamUtils.nextElement;
import static org.deegree.feature.property.ExtraProps.EXTRA_PROP_NS;
import static org.deegree.feature.property.ExtraProps.EXTRA_PROP_NS_GEOMETRY;
import static org.deegree.feature.types.property.GeometryPropertyType.CoordinateDimension.DIM_2_OR_3;
import static org.deegree.feature.types.property.GeometryPropertyType.GeometryType.GEOMETRY;
import static org.deegree.feature.types.property.ValueRepresentation.INLINE;

/**
* {@link AbstractGMLObjectReader} for features and feature collections.
*
Expand Down Expand Up @@ -118,6 +117,17 @@ public GMLFeatureReader( GMLStreamReader gmlStreamReader ) {
super( gmlStreamReader );
}

/**
* Creates a new {@link GMLFeatureReader} instance that is configured from the given {@link GMLStreamReader}.
*
* @param gmlStreamReader
* provides the configuration, must not be <code>null</code>
* @param skipBrokenGeometries
*/
public GMLFeatureReader( GMLStreamReader gmlStreamReader, boolean skipBrokenGeometries ) {
super( gmlStreamReader, skipBrokenGeometries );
}

/**
* Returns the object representation for the feature (or feature collection) element event that the cursor of the
* given <code>XMLStreamReader</code> points at.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,6 @@
----------------------------------------------------------------------------*/
package org.deegree.gml.geometry;

import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import static org.deegree.commons.xml.stax.XMLStreamUtils.nextElement;
import static org.deegree.commons.xml.stax.XMLStreamUtils.skipElement;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.deegree.commons.tom.gml.GMLObjectType;
import org.deegree.commons.tom.gml.property.Property;
import org.deegree.commons.tom.gml.property.PropertyType;
Expand All @@ -69,7 +53,6 @@
import org.deegree.geometry.composite.CompositeGeometry;
import org.deegree.geometry.composite.CompositeSolid;
import org.deegree.geometry.composite.CompositeSurface;
import org.deegree.geometry.i18n.Messages;
import org.deegree.geometry.multi.MultiCurve;
import org.deegree.geometry.multi.MultiGeometry;
import org.deegree.geometry.multi.MultiLineString;
Expand Down Expand Up @@ -110,9 +93,25 @@
import org.deegree.geometry.refs.SolidReference;
import org.deegree.geometry.refs.SurfaceReference;
import org.deegree.gml.GMLStreamReader;
import org.deegree.gml.i18n.Messages;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
import static org.deegree.commons.xml.stax.XMLStreamUtils.nextElement;
import static org.deegree.commons.xml.stax.XMLStreamUtils.skipElement;

/**
* Parser for geometry and geometry-related constructs from the GML 3 specification series (3.0/3.1/3.2).
* <p>
Expand Down Expand Up @@ -1311,7 +1310,7 @@ public LinearRing parseLinearRing( XMLStreamReaderWrapper xmlStream, ICRS defaul

Points points = curveSegmentParser.parseControlPoints( xmlStream, crs );
if ( points.size() < 4 ) {
String msg = "Error in 'gml:LinearRing' element. Must specify at least four points.";
String msg = Messages.get( "GML_LINEAR_RING_LESS_THAN_FOUR_POINTS_ERROR" );
throw new XMLParsingException( xmlStream, msg );
}

Expand Down
Loading

0 comments on commit 0f96a3e

Please sign in to comment.