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 a642b5d commit 1766269
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
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
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
Expand Up @@ -524,10 +524,12 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QStringList::const_iterator alstIt;
QList<int> idxList;
// 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 @@ -542,6 +544,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 @@ -953,16 +959,22 @@ int QgsWFSServer::getFeature( QgsRequestHandler& request, const QString& format
QStringList::const_iterator alstIt;
QList<int> idxList;
// 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 @@ -2110,7 +2122,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 @@ -2194,7 +2206,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 1766269

Please sign in to comment.