bool QgsWcsCapabilities::parseCapabilitiesDom( QByteArray const &xml, QgsWcsCapabilitiesProperty &capabilities ) { QgsDebugMsg( "Entered." ); #ifdef QGISDEBUG QFile file( QDir::tempPath() + "/qgis-wcs-capabilities.xml" ); if ( file.open( QIODevice::WriteOnly ) ) { file.write( xml ); file.close(); } #endif if ( ! convertToDom( xml ) ) return false; QDomElement docElem = mCapabilitiesDom.documentElement(); // Assert that the DTD is what we expected (i.e. a WCS Capabilities document) QgsDebugMsg( "testing tagName " + docElem.tagName() ); QString tagName = stripNS( docElem.tagName() ); if ( // We don't support 1.0, but try WCS_Capabilities tag to get version tagName != "WCS_Capabilities" && // 1.0 tagName != "Capabilities" // 1.1, tags seen: Capabilities, wcs:Capabilities ) { if ( tagName == "ExceptionReport" ) { mErrorTitle = tr( "Exception" ); mErrorFormat = "text/plain"; mError = tr( "Could not get WCS capabilities: %1" ).arg( domElementText( docElem, "Exception.ExceptionText" ) ); } else { mErrorTitle = tr( "Dom Exception" ); mErrorFormat = "text/plain"; mError = tr( "Could not get WCS capabilities in the expected format (DTD): no %1 found.\nThis might be due to an incorrect WCS Server URL.\nTag:%3\nResponse was:\n%4" ) .arg( "Capabilities" ) .arg( docElem.tagName() ) .arg( QString( xml ) ); } QgsLogger::debug( "Dom Exception: " + mError ); return false; } capabilities.version = docElem.attribute( "version" ); mVersion = capabilities.version; if ( !mVersion.startsWith( "1.0" ) && !mVersion.startsWith( "1.1" ) ) { mErrorTitle = tr( "Version not supported" ); mErrorFormat = "text/plain"; mError = tr( "WCS server version %1 is not supported by QGIS (supported versions: 1.0.0, 1.1.0, 1.1.2)" ) .arg( mVersion ); QgsLogger::debug( "WCS version: " + mError ); return false; } if ( mVersion.startsWith( "1.0" ) ) { capabilities.title = domElementText( docElem, "Service.name" ); capabilities.abstract = domElementText( docElem, "Service.description" ); // There is also "label" in 1.0 capabilities.getCoverageGetUrl = domElement( docElem, "Capability.Request.GetCoverage.DCPType.HTTP.Get.OnlineResource" ).attribute( "xlink:href" ); parseContentMetadata( domElement( docElem, "ContentMetadata" ), capabilities.contents ); } else if ( mVersion.startsWith( "1.1" ) ) { capabilities.title = domElementText( docElem, "ServiceIdentification.Title" ); capabilities.abstract = domElementText( docElem, "ServiceIdentification.Abstract" ); QList<QDomElement> operationElements = domElements( docElem, "OperationsMetadata.Operation" ); foreach ( QDomElement el, operationElements ) { if ( el.attribute( "name" ) == "GetCoverage" ) { capabilities.getCoverageGetUrl = domElement( el, "DCP.HTTP.Get" ).attribute( "xlink:href" ); } } parseCoverageSummary( domElement( docElem, "Contents" ), capabilities.contents ); }
void QgsWcsCapabilities::parseCoverageSummary( QDomElement const &e, QgsWcsCoverageSummary &coverageSummary, QgsWcsCoverageSummary *parent ) { coverageSummary.orderId = ++mCoverageCount; coverageSummary.identifier = firstChildText( e, QStringLiteral( "Identifier" ) ); coverageSummary.title = firstChildText( e, QStringLiteral( "Title" ) ); coverageSummary.abstract = firstChildText( e, QStringLiteral( "Abstract" ) ); QDomNode n1 = e.firstChild(); while ( !n1.isNull() ) { QDomElement el = n1.toElement(); if ( !el.isNull() ) { QString tagName = stripNS( el.tagName() ); QgsDebugMsg( tagName + " : " + el.text() ); if ( tagName == QLatin1String( "SupportedFormat" ) ) { // image/tiff, ... // Formats may be here (UMN Mapserver) or may not (GeoServer) coverageSummary.supportedFormat << el.text(); } else if ( tagName == QLatin1String( "SupportedCRS" ) ) { // TODO: SupportedCRS may be URL referencing a document coverageSummary.supportedCrs << crsUrnToAuthId( el.text() ); } else if ( tagName == QLatin1String( "WGS84BoundingBox" ) ) { QList<double> low = parseDoubles( domElementText( el, QStringLiteral( "LowerCorner" ) ) ); QList<double> high = parseDoubles( domElementText( el, QStringLiteral( "UpperCorner" ) ) ); if ( low.size() == 2 && high.size() == 2 ) { coverageSummary.wgs84BoundingBox = QgsRectangle( low[0], low[1], high[0], high[1] ); } } } n1 = n1.nextSibling(); } //QgsDebugMsg( "supportedFormat = " + coverageSummary.supportedFormat.join( "," ) ); // We collected params to be inherited, do children n1 = e.firstChild(); while ( !n1.isNull() ) { QDomElement el = n1.toElement(); if ( !el.isNull() ) { QString tagName = stripNS( el.tagName() ); if ( tagName == QLatin1String( "CoverageSummary" ) ) { QgsDebugMsg( QStringLiteral( " Nested coverage." ) ); QgsWcsCoverageSummary subCoverageSummary; initCoverageSummary( subCoverageSummary ); // Inherit subCoverageSummary.supportedCrs = coverageSummary.supportedCrs; subCoverageSummary.supportedFormat = coverageSummary.supportedFormat; parseCoverageSummary( el, subCoverageSummary, &coverageSummary ); subCoverageSummary.valid = true; coverageSummary.coverageSummary.push_back( subCoverageSummary ); } } n1 = n1.nextSibling(); } if ( parent && parent->orderId > 1 ) // ignore Contents to put them on top level { QgsDebugMsg( QStringLiteral( "coverage orderId = %1 identifier = %2 has parent %3" ).arg( coverageSummary.orderId ).arg( coverageSummary.identifier ).arg( parent->orderId ) ); mCoverageParents[ coverageSummary.orderId ] = parent->orderId; } if ( !coverageSummary.identifier.isEmpty() ) { QgsDebugMsg( "add coverage " + coverageSummary.identifier + " to supported" ); mCoveragesSupported.push_back( coverageSummary ); } if ( !coverageSummary.coverageSummary.empty() ) { mCoverageParentIdentifiers[ coverageSummary.orderId ] = QStringList() << coverageSummary.identifier << coverageSummary.title << coverageSummary.abstract; } QgsDebugMsg( QStringLiteral( "coverage orderId = %1 identifier = %2" ).arg( coverageSummary.orderId ).arg( coverageSummary.identifier ) ); }