Skip to content

Commit

Permalink
[BUGFIX][Server] Enhance cleaning propertyname and searching by prope…
Browse files Browse the repository at this point in the history
…rtyname
  • Loading branch information
rldhont committed Apr 1, 2018
1 parent c1b9706 commit b7c566b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/server/qgswfsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ QgsWFSProjectParser::QgsWFSProjectParser(
#endif
{
mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
mCleanTagNameRegExp = QRegExp( "(?![\\w\\d\\.-])." );
}

QgsWFSProjectParser::~QgsWFSProjectParser()
Expand Down Expand Up @@ -464,7 +465,7 @@ void QgsWFSProjectParser::describeFeatureType( const QString& aTypeName, QDomEle

//xsd:element
QDomElement attElem = doc.createElement( "element"/*xsd:element*/ );
attElem.setAttribute( "name", attributeName.replace( " ", "_" ) );
attElem.setAttribute( "name", attributeName.replace( " ", "_" ).replace( mCleanTagNameRegExp, "" ) );
QVariant::Type attributeType = fields[idx].type();
if ( attributeType == QVariant::Int )
attElem.setAttribute( "type", "integer" );
Expand Down
3 changes: 3 additions & 0 deletions src/server/qgswfsprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class SERVER_EXPORT QgsWFSProjectParser
);
~QgsWFSProjectParser();

QRegExp getCleanTagNameRegExp() const { return mCleanTagNameRegExp; }

void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;
QString serviceUrl() const;
QString wfsServiceUrl() const;
Expand All @@ -56,6 +58,7 @@ class SERVER_EXPORT QgsWFSProjectParser

private:
QgsServerProjectParser* mProjectParser;
QRegExp mCleanTagNameRegExp;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
const QgsAccessControl* mAccessControl;
#endif
Expand Down
20 changes: 16 additions & 4 deletions src/server/qgswfsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,12 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QList<int> idxList;
QgsFields fields = layer->pendingFields();
// build corresponding propertyname
QList<QString> fieldnames;
QList<QString> propertynames;
for ( int idx = 0; idx < fields.count(); ++idx )
{
propertynames.append( fields[idx].name().replace( " ", "_" ) );
fieldnames.append( fields[idx].name() );
propertynames.append( fields[idx].name().replace( " ", "_" ).replace( mConfigParser->getCleanTagNameRegExp(), "" ) );
}
QString fieldName;
QDomElement propertyElem;
Expand All @@ -541,6 +543,10 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
fieldName = fieldName.section( ":", 1, 1 );
}
int fieldNameIdx = propertynames.indexOf( fieldName );
if ( fieldNameIdx == -1 )
{
fieldNameIdx = fieldnames.indexOf( fieldName );
}
if ( fieldNameIdx > -1 )
{
idxList.append( fieldNameIdx );
Expand Down Expand Up @@ -941,16 +947,22 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QList<int> idxList;
QgsFields fields = layer->pendingFields();
// build corresponding propertyname
QList<QString> fieldnames;
QList<QString> propertynames;
for ( int idx = 0; idx < fields.count(); ++idx )
{
propertynames.append( fields[idx].name().replace( " ", "_" ) );
fieldnames.append( fields[idx].name() );
propertynames.append( fields[idx].name().replace( " ", "_" ).replace( mConfigParser->getCleanTagNameRegExp(), "" ) );
}
QString fieldName;
for ( alstIt = attrList.begin(); alstIt != attrList.end(); ++alstIt )
{
fieldName = *alstIt;
int fieldNameIdx = propertynames.indexOf( fieldName );
if ( fieldNameIdx == -1 )
{
fieldNameIdx = fieldnames.indexOf( fieldName );
}
if ( fieldNameIdx > -1 )
{
idxList.append( fieldNameIdx );
Expand Down Expand Up @@ -2059,7 +2071,7 @@ QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc
continue;
}

QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ) );
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ).replace( mConfigParser->getCleanTagNameRegExp(), "" ) );
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
fieldElem.appendChild( fieldText );
typeNameElement.appendChild( fieldElem );
Expand Down Expand Up @@ -2141,7 +2153,7 @@ QDomElement QgsWFSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc
continue;
}

QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ) );
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ).replace( mConfigParser->getCleanTagNameRegExp(), "" ) );
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
fieldElem.appendChild( fieldText );
typeNameElement.appendChild( fieldElem );
Expand Down

0 comments on commit b7c566b

Please sign in to comment.