Skip to content
Permalink
Browse files

[Server][WFS] Define encodeValueToText to correctly format field values

  • Loading branch information
rldhont committed Sep 14, 2018
1 parent 00d81e0 commit f427577a369d92c7b566aee3b49c7e704c2482d3
Showing with 53 additions and 2 deletions.
  1. +50 −2 src/server/qgswfsserver.cpp
  2. +3 −0 src/server/qgswfsserver.h
@@ -2129,7 +2129,7 @@ QDomElement QgsWFSServer::createFeatureGML2( QgsFeature* feat, QDomDocument& doc
}*/

QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( " ", "_" ).replace( mConfigParser->getCleanTagNameRegExp(), "" ) );
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
QDomText fieldText = doc.createTextNode( encodeValueToText( featureAttributes[idx] ) );
fieldElem.appendChild( fieldText );
typeNameElement.appendChild( fieldElem );
}
@@ -2213,14 +2213,62 @@ QDomElement QgsWFSServer::createFeatureGML3( QgsFeature* feat, QDomDocument& doc
}*/

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

return featureElement;
}

QString QgsWFSServer::encodeValueToText( const QVariant& value )
{
if ( value.isNull() )
return "null";

switch ( value.type() )
{
case QVariant::Int:
case QVariant::UInt:
case QVariant::LongLong:
case QVariant::ULongLong:
case QVariant::Double:
return value.toString();

case QVariant::Bool:
return value.toBool() ? "true" : "false";

case QVariant::StringList:
case QVariant::List:
case QVariant::Map:
{
QString v = QgsJSONUtils::encodeValue( value );

//do we need CDATA
if ( v.indexOf( '<' ) != -1 || v.indexOf( '&' ) != -1 )
{
v.prepend( "<![CDATA[" ).append( "]]>" );
}

return v;
}

default:
case QVariant::String:
{
QString v = value.toString();

//do we need CDATA
if ( v.indexOf( '<' ) != -1 || v.indexOf( '&' ) != -1 )
{
v.prepend( "<![CDATA[" ).append( "]]>" );
}

return v;
}
}
}

QString QgsWFSServer::serviceUrl() const
{
QUrl mapUrl( getenv( "REQUEST_URI" ) );
@@ -136,6 +136,9 @@ class QgsWFSServer: public QgsOWSServer
QDomElement createFeatureGML3( QgsFeature* feat, QDomDocument& doc, int prec, QgsCoordinateReferenceSystem& crs, const QgsAttributeList& attrIndexes,
const QgsAttributeList& pkAttributes = QgsAttributeList() ) /*const*/;

//methods to encode value to string for text node
QString encodeValueToText( const QVariant& value );

void addTransactionResult( QDomDocument& responseDoc, QDomElement& responseElem, const QString& status, const QString& locator, const QString& message );
};

0 comments on commit f427577

Please sign in to comment.
You can’t perform that action at this time.