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

deegree-layers-feature: Fix rendering behaviour for feature layer configs with multiple layers/filters #195

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 @@ -68,21 +68,21 @@ Occam Labs UG (haftungsbeschränkt)

/**
* Builds feature layers that are manually configured.
*
*
* @author <a href="mailto:schmitz@occamlabs.de">Andreas Schmitz</a>
* @author last edited by: $Author: stranger $
*
*
* @version $Revision: $, $Date: $
*/
class ManualFeatureLayerBuilder {

private FeatureLayers lays;
private final FeatureLayers lays;

private URL configUrl;
private final URL configUrl;

private FeatureStore store;
private final FeatureStore store;

private DeegreeWorkspace workspace;
private final DeegreeWorkspace workspace;

ManualFeatureLayerBuilder( FeatureLayers lays, URL configUrl, FeatureStore store, DeegreeWorkspace workspace ) {
this.lays = lays;
Expand All @@ -94,13 +94,14 @@ class ManualFeatureLayerBuilder {
MultipleLayerStore buildFeatureLayers()
throws XMLStreamException, URISyntaxException, FeatureStoreException {
Map<String, Layer> map = new LinkedHashMap<String, Layer>();
int index = 0;
for ( FeatureLayerType lay : lays.getFeatureLayer() ) {
QName featureType = lay.getFeatureType();

// these methods do not use the dom elements but reparse the configuration file using StAX due to bugs
// in jaxb/woodstox when using multiple jaxb:dom bindings and DOMSources for XMLStreamReaders
OperatorFilter filter = QueryOptionsParser.parseFilter( configUrl );
List<SortProperty> sortBy = QueryOptionsParser.parseSortBy( configUrl );
OperatorFilter filter = QueryOptionsParser.parseFilter( index, configUrl );
List<SortProperty> sortBy = QueryOptionsParser.parseSortBy( index, configUrl );
List<SortProperty> sortByFeatureInfo = sortBy;
if ( sortBy != null && lay.getSortBy().isReverseFeatureInfo() ) {
sortByFeatureInfo = new ArrayList<SortProperty>();
Expand All @@ -116,6 +117,7 @@ MultipleLayerStore buildFeatureLayers()
md.setLegendStyles( p.second );
Layer l = new FeatureLayer( md, store, featureType, filter, sortBy, sortByFeatureInfo );
map.put( lay.getName(), l );
index++;
}
return new MultipleLayerStore( map );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Occam Labs UG (haftungsbeschränkt)
Germany

e-mail: info@deegree.org
----------------------------------------------------------------------------*/
----------------------------------------------------------------------------*/
package org.deegree.layer.persistence.feature;

import static java.util.Collections.singleton;
Expand Down Expand Up @@ -70,78 +70,99 @@ Occam Labs UG (haftungsbeschränkt)

/**
* Parses sortby and filter sections of feature layer configurations.
*
*
* @author <a href="mailto:schmitz@occamlabs.de">Andreas Schmitz</a>
* @author last edited by: $Author: stranger $
*
*
* @version $Revision: $, $Date: $
*/
class QueryOptionsParser {

static OperatorFilter parseFilter( URL configUrl )
throws XMLStreamException, URISyntaxException {

File file = new File( configUrl.toURI() );
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader( new StreamSource( file ) );

if ( !moveReaderToFirstMatch( reader, new QName( OGCNS, "Filter" ) ) ) {
return null;
}

OperatorFilter filter = null;
filter = (OperatorFilter) Filter110XMLDecoder.parse( reader );
reader.close();
return filter;
}

static List<SortProperty> parseSortBy( URL configUrl )
throws XMLStreamException, URISyntaxException {

File file = new File( configUrl.toURI() );
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader( new StreamSource( file ) );

if ( !moveReaderToFirstMatch( reader, new QName( OGCNS, "SortBy" ) ) ) {
return null;
}

// ogc:SortBy
requireStartElement( reader, singleton( new QName( OGCNS, "SortBy" ) ) );

nextElement( reader );
List<SortProperty> sortCrits = new ArrayList<SortProperty>();
while ( reader.isStartElement() ) {
SortProperty prop = parseSortProperty( reader );
sortCrits.add( prop );
nextElement( reader );
}
reader.close();
return sortCrits;
}

private static SortProperty parseSortProperty( XMLStreamReader reader )
throws XMLStreamException {

requireStartElement( reader, singleton( new QName( OGCNS, "SortProperty" ) ) );
nextElement( reader );

requireStartElement( reader, singleton( new QName( OGCNS, "PropertyName" ) ) );

String xpath = reader.getElementText().trim();
Set<String> prefixes = XPathUtils.extractPrefixes( xpath );
NamespaceBindings nsContext = new NamespaceBindings( reader.getNamespaceContext(), prefixes );
ValueReference propName = new ValueReference( xpath, nsContext );
nextElement( reader );

boolean sortAscending = true;
if ( reader.isStartElement() ) {
requireStartElement( reader, singleton( new QName( OGCNS, "SortOrder" ) ) );
String s = reader.getElementText().trim();
sortAscending = "ASC".equals( s );
nextElement( reader );
}

reader.require( END_ELEMENT, OGCNS, "SortProperty" );
return new SortProperty( propName, sortAscending );
}
class QueryOptionsParser {

static OperatorFilter parseFilter( int layerIndex, URL configUrl )
throws XMLStreamException, URISyntaxException {

File file = new File( configUrl.toURI() );
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader( new StreamSource( file ) );

int idx = -1;
while ( idx != layerIndex ) {
moveReaderToFirstMatch( reader, new QName( "http://www.deegree.org/layers/feature", "FeatureLayer" ) );
reader.next();
++idx;
}

while ( !( reader.isEndElement() && reader.getLocalName().equals( "FeatureLayer" ) ) ) {
reader.next();
if ( reader.isStartElement() && reader.getLocalName().equals( "Filter" )
&& reader.getNamespaceURI().equals( OGCNS ) ) {
OperatorFilter filter = null;
filter = (OperatorFilter) Filter110XMLDecoder.parse( reader );
reader.close();
return filter;
}
}

reader.close();
return null;
}

static List<SortProperty> parseSortBy( int layerIndex, URL configUrl )
throws XMLStreamException, URISyntaxException {

File file = new File( configUrl.toURI() );
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader( new StreamSource( file ) );

int idx = -1;
while ( idx != layerIndex ) {
moveReaderToFirstMatch( reader, new QName( "http://www.deegree.org/layers/feature", "FeatureLayer" ) );
reader.next();
++idx;
}

while ( !( reader.isEndElement() && reader.getLocalName().equals( "FeatureLayer" ) ) ) {
reader.next();
if ( reader.isStartElement() && reader.getLocalName().equals( "SortBy" )
&& reader.getNamespaceURI().equals( OGCNS ) ) {
nextElement( reader );
List<SortProperty> sortCrits = new ArrayList<SortProperty>();
while ( reader.isStartElement() ) {
SortProperty prop = parseSortProperty( reader );
sortCrits.add( prop );
nextElement( reader );
}
reader.close();
return sortCrits;
}
}

reader.close();
return null;
}

private static SortProperty parseSortProperty( XMLStreamReader reader )
throws XMLStreamException {

requireStartElement( reader, singleton( new QName( OGCNS, "SortProperty" ) ) );
nextElement( reader );

requireStartElement( reader, singleton( new QName( OGCNS, "PropertyName" ) ) );

String xpath = reader.getElementText().trim();
Set<String> prefixes = XPathUtils.extractPrefixes( xpath );
NamespaceBindings nsContext = new NamespaceBindings( reader.getNamespaceContext(), prefixes );
ValueReference propName = new ValueReference( xpath, nsContext );
nextElement( reader );

boolean sortAscending = true;
if ( reader.isStartElement() ) {
requireStartElement( reader, singleton( new QName( OGCNS, "SortOrder" ) ) );
String s = reader.getElementText().trim();
sortAscending = "ASC".equals( s );
nextElement( reader );
}

reader.require( END_ELEMENT, OGCNS, "SortProperty" );
return new SortProperty( propName, sortAscending );
}

}