@@ -49,6 +49,8 @@ static const QString TEXT_PROVIDER_DESCRIPTION = "WFS data provider";
49
49
50
50
static const QString WFS_NAMESPACE = " http://www.opengis.net/wfs" ;
51
51
static const QString GML_NAMESPACE = " http://www.opengis.net/gml" ;
52
+ static const QString OGC_NAMESPACE = " http://www.opengis.net/ogc" ;
53
+ static const QString OWS_NAMESPACE = " http://www.opengis.net/ows" ;
52
54
53
55
QgsWFSProvider::QgsWFSProvider ( const QString& uri )
54
56
: QgsVectorDataProvider( uri )
@@ -332,7 +334,7 @@ bool QgsWFSProvider::addFeatures( QgsFeatureList &flist )
332
334
for ( ; featureIt != flist.end (); ++featureIt )
333
335
{
334
336
// Insert element
335
- QDomElement insertElem = transactionDoc.createElementNS ( " http://www.opengis.net/wfs " , " Insert" );
337
+ QDomElement insertElem = transactionDoc.createElementNS ( WFS_NAMESPACE , " Insert" );
336
338
transactionElem.appendChild ( insertElem );
337
339
338
340
QDomElement featureElem = transactionDoc.createElementNS ( mWfsNamespace , tname );
@@ -424,9 +426,9 @@ bool QgsWFSProvider::deleteFeatures( const QgsFeatureIds &id )
424
426
QDomElement transactionElem = createTransactionElement ( transactionDoc );
425
427
transactionDoc.appendChild ( transactionElem );
426
428
// delete element
427
- QDomElement deleteElem = transactionDoc.createElementNS ( " http://www.opengis.net/wfs " , " Delete" );
429
+ QDomElement deleteElem = transactionDoc.createElementNS ( WFS_NAMESPACE , " Delete" );
428
430
deleteElem.setAttribute ( " typeName" , tname );
429
- QDomElement filterElem = transactionDoc.createElementNS ( " http://www.opengis.net/ogc " , " Filter" );
431
+ QDomElement filterElem = transactionDoc.createElementNS ( OGC_NAMESPACE , " Filter" );
430
432
431
433
432
434
QgsFeatureIds::const_iterator idIt = id.constBegin ();
@@ -438,7 +440,7 @@ bool QgsWFSProvider::deleteFeatures( const QgsFeatureIds &id )
438
440
{
439
441
continue ;
440
442
}
441
- QDomElement featureIdElem = transactionDoc.createElementNS ( " http://www.opengis.net/ogc " , " FeatureId" );
443
+ QDomElement featureIdElem = transactionDoc.createElementNS ( OGC_NAMESPACE , " FeatureId" );
442
444
featureIdElem.setAttribute ( " fid" , fidIt.value () );
443
445
filterElem.appendChild ( featureIdElem );
444
446
}
@@ -502,23 +504,23 @@ bool QgsWFSProvider::changeGeometryValues( QgsGeometryMap & geometry_map )
502
504
continue ;
503
505
}
504
506
505
- QDomElement updateElem = transactionDoc.createElementNS ( " http://www.opengis.net/wfs " , " Update" );
507
+ QDomElement updateElem = transactionDoc.createElementNS ( WFS_NAMESPACE , " Update" );
506
508
updateElem.setAttribute ( " typeName" , tname );
507
509
// Property
508
- QDomElement propertyElem = transactionDoc.createElementNS ( " http://www.opengis.net/wfs " , " Property" );
509
- QDomElement nameElem = transactionDoc.createElementNS ( " http://www.opengis.net/wfs " , " Name" );
510
+ QDomElement propertyElem = transactionDoc.createElementNS ( WFS_NAMESPACE , " Property" );
511
+ QDomElement nameElem = transactionDoc.createElementNS ( WFS_NAMESPACE , " Name" );
510
512
QDomText nameText = transactionDoc.createTextNode ( mGeometryAttribute );
511
513
nameElem.appendChild ( nameText );
512
514
propertyElem.appendChild ( nameElem );
513
- QDomElement valueElem = transactionDoc.createElementNS ( " http://www.opengis.net/wfs " , " Value" );
515
+ QDomElement valueElem = transactionDoc.createElementNS ( WFS_NAMESPACE , " Value" );
514
516
QDomElement gmlElem = QgsOgcUtils::geometryToGML ( &geomIt.value (), transactionDoc );
515
517
valueElem.appendChild ( gmlElem );
516
518
propertyElem.appendChild ( valueElem );
517
519
updateElem.appendChild ( propertyElem );
518
520
519
521
// filter
520
- QDomElement filterElem = transactionDoc.createElementNS ( " http://www.opengis.net/ogc " , " Filter" );
521
- QDomElement featureIdElem = transactionDoc.createElementNS ( " http://www.opengis.net/ogc " , " FeatureId" );
522
+ QDomElement filterElem = transactionDoc.createElementNS ( OGC_NAMESPACE , " Filter" );
523
+ QDomElement featureIdElem = transactionDoc.createElementNS ( OGC_NAMESPACE , " FeatureId" );
522
524
featureIdElem.setAttribute ( " fid" , fidIt.value () );
523
525
filterElem.appendChild ( featureIdElem );
524
526
updateElem.appendChild ( filterElem );
@@ -589,21 +591,21 @@ bool QgsWFSProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
589
591
continue ;
590
592
}
591
593
592
- QDomElement updateElem = transactionDoc.createElementNS ( " http://www.opengis.net/wfs " , " Update" );
594
+ QDomElement updateElem = transactionDoc.createElementNS ( WFS_NAMESPACE , " Update" );
593
595
updateElem.setAttribute ( " typeName" , tname );
594
596
595
597
QgsAttributeMap::const_iterator attMapIt = attIt.value ().constBegin ();
596
598
for ( ; attMapIt != attIt.value ().constEnd (); ++attMapIt )
597
599
{
598
600
QString fieldName = mFields .at ( attMapIt.key () ).name ();
599
- QDomElement propertyElem = transactionDoc.createElementNS ( " http://www.opengis.net/wfs " , " Property" );
601
+ QDomElement propertyElem = transactionDoc.createElementNS ( WFS_NAMESPACE , " Property" );
600
602
601
- QDomElement nameElem = transactionDoc.createElementNS ( " http://www.opengis.net/wfs " , " Name" );
603
+ QDomElement nameElem = transactionDoc.createElementNS ( WFS_NAMESPACE , " Name" );
602
604
QDomText nameText = transactionDoc.createTextNode ( fieldName );
603
605
nameElem.appendChild ( nameText );
604
606
propertyElem.appendChild ( nameElem );
605
607
606
- QDomElement valueElem = transactionDoc.createElementNS ( " http://www.opengis.net/wfs " , " Value" );
608
+ QDomElement valueElem = transactionDoc.createElementNS ( WFS_NAMESPACE , " Value" );
607
609
QDomText valueText = transactionDoc.createTextNode ( attMapIt.value ().toString () );
608
610
valueElem.appendChild ( valueText );
609
611
propertyElem.appendChild ( valueElem );
@@ -612,8 +614,8 @@ bool QgsWFSProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
612
614
}
613
615
614
616
// Filter
615
- QDomElement filterElem = transactionDoc.createElementNS ( " http://www.opengis.net/ogc " , " Filter" );
616
- QDomElement featureIdElem = transactionDoc.createElementNS ( " http://www.opengis.net/ogc " , " FeatureId" );
617
+ QDomElement filterElem = transactionDoc.createElementNS ( OGC_NAMESPACE , " Filter" );
618
+ QDomElement featureIdElem = transactionDoc.createElementNS ( OGC_NAMESPACE , " FeatureId" );
617
619
featureIdElem.setAttribute ( " fid" , fidIt.value () );
618
620
filterElem.appendChild ( featureIdElem );
619
621
updateElem.appendChild ( filterElem );
@@ -1407,7 +1409,7 @@ bool QgsWFSProvider::sendTransactionDocument( const QDomDocument& doc, QDomDocum
1407
1409
1408
1410
QDomElement QgsWFSProvider::createTransactionElement ( QDomDocument& doc ) const
1409
1411
{
1410
- QDomElement transactionElem = doc.createElementNS ( " http://www.opengis.net/wfs " , " Transaction" );
1412
+ QDomElement transactionElem = doc.createElementNS ( WFS_NAMESPACE , " Transaction" );
1411
1413
transactionElem.setAttribute ( " version" , " 1.0.0" );
1412
1414
transactionElem.setAttribute ( " service" , " WFS" );
1413
1415
transactionElem.setAttribute ( " xmlns:xsi" , " http://www.w3.org/2001/XMLSchema-instance" );
@@ -1437,13 +1439,13 @@ bool QgsWFSProvider::transactionSuccess( const QDomDocument& serverResponse ) co
1437
1439
return false ;
1438
1440
}
1439
1441
1440
- QDomNodeList transactionResultList = documentElem.elementsByTagNameNS ( " http://www.opengis.net/wfs " , " TransactionResult" );
1442
+ QDomNodeList transactionResultList = documentElem.elementsByTagNameNS ( WFS_NAMESPACE , " TransactionResult" );
1441
1443
if ( transactionResultList.size () < 1 )
1442
1444
{
1443
1445
return false ;
1444
1446
}
1445
1447
1446
- QDomNodeList statusList = transactionResultList.at ( 0 ).toElement ().elementsByTagNameNS ( " http://www.opengis.net/wfs " , " Status" );
1448
+ QDomNodeList statusList = transactionResultList.at ( 0 ).toElement ().elementsByTagNameNS ( WFS_NAMESPACE , " Status" );
1447
1449
if ( statusList.size () < 1 )
1448
1450
{
1449
1451
return false ;
@@ -1473,10 +1475,10 @@ QStringList QgsWFSProvider::insertedFeatureIds( const QDomDocument& serverRespon
1473
1475
return ids;
1474
1476
}
1475
1477
1476
- QDomNodeList insertResultList = rootElem.elementsByTagNameNS ( " http://www.opengis.net/wfs " , " InsertResult" );
1478
+ QDomNodeList insertResultList = rootElem.elementsByTagNameNS ( WFS_NAMESPACE , " InsertResult" );
1477
1479
for ( int i = 0 ; i < insertResultList.size (); ++i )
1478
1480
{
1479
- QDomNodeList featureIdList = insertResultList.at ( i ).toElement ().elementsByTagNameNS ( " http://www.opengis.net/ogc " , " FeatureId" );
1481
+ QDomNodeList featureIdList = insertResultList.at ( i ).toElement ().elementsByTagNameNS ( OGC_NAMESPACE , " FeatureId" );
1480
1482
for ( int j = 0 ; j < featureIdList.size (); ++j )
1481
1483
{
1482
1484
QString fidString = featureIdList.at ( j ).toElement ().attribute ( " fid" );
@@ -1640,21 +1642,40 @@ QGis::WkbType QgsWFSProvider::geomTypeFromPropertyType( QString attName, QString
1640
1642
return ( QGis::WkbType ) i;
1641
1643
}
1642
1644
1643
- void QgsWFSProvider::handleException ( const QDomDocument& serverResponse ) const
1645
+ void QgsWFSProvider::handleException ( const QDomDocument& serverResponse )
1644
1646
{
1647
+ QgsDebugMsg ( QString ( " server response: %1" ).arg ( serverResponse.toString () ) );
1648
+
1645
1649
QDomElement exceptionElem = serverResponse.documentElement ();
1646
- if ( exceptionElem.isNull () || exceptionElem.tagName () != " ServiceExceptionReport" )
1650
+ if ( exceptionElem.isNull () )
1651
+ {
1652
+ pushError ( QObject::tr ( " empty response" ).arg ( exceptionElem.tagName () ) );
1653
+ return ;
1654
+ }
1655
+
1656
+ if ( exceptionElem.tagName () == " ServiceExceptionReport" )
1647
1657
{
1658
+ pushError ( QObject::tr ( " WFS service exception:%1" ).arg ( exceptionElem.firstChildElement ( " ServiceException" ).text () ) );
1648
1659
return ;
1649
1660
}
1650
1661
1651
- // possibly this class is used not in a gui application
1652
- if ( QApplication::topLevelWidgets ().size () < 1 )
1662
+ if ( exceptionElem.tagName () == " WFS_TransactionResponse" )
1653
1663
{
1664
+ pushError ( QObject::tr ( " unsuccessful service response: %1" ).arg ( exceptionElem.firstChildElement ( " TransactionResult" ).firstChildElement ( " Message" ).text () ) );
1654
1665
return ;
1655
1666
}
1656
- QString message = exceptionElem.firstChildElement ( " ServiceException" ).text ();
1657
- QMessageBox::critical ( 0 , tr ( " Error" ), message );
1667
+
1668
+ if ( exceptionElem.tagName () == " ExceptionReport" )
1669
+ {
1670
+ QDomElement exception = exceptionElem.firstChildElement ( " Exception" );
1671
+ pushError ( QObject::tr ( " WFS exception report (code=%1 text=%2)" )
1672
+ .arg ( exception.attribute ( " exceptionCode" , QObject::tr ( " missing" ) ) )
1673
+ .arg ( exception.firstChildElement ( " ExceptionText" ).text () )
1674
+ );
1675
+ return ;
1676
+ }
1677
+
1678
+ pushError ( QObject::tr ( " unhandled response: %1" ).arg ( exceptionElem.tagName () ) );
1658
1679
}
1659
1680
1660
1681
QGISEXTERN QgsWFSProvider* classFactory ( const QString *uri )
0 commit comments