[QGIS Commit] r15067 - trunk/qgis/src/mapserver

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Jan 24 05:50:58 EST 2011


Author: mhugent
Date: 2011-01-24 02:50:58 -0800 (Mon, 24 Jan 2011)
New Revision: 15067

Modified:
   trunk/qgis/src/mapserver/qgsconfigparser.cpp
   trunk/qgis/src/mapserver/qgsconfigparser.h
   trunk/qgis/src/mapserver/qgsprojectparser.cpp
   trunk/qgis/src/mapserver/qgsprojectparser.h
   trunk/qgis/src/mapserver/qgswmsserver.cpp
Log:
[FEATURE]: Optionally specify wms service capabilities in the properties section of the project file (instead of wms_metadata.xml file)

Modified: trunk/qgis/src/mapserver/qgsconfigparser.cpp
===================================================================
--- trunk/qgis/src/mapserver/qgsconfigparser.cpp	2011-01-22 16:00:28 UTC (rev 15066)
+++ trunk/qgis/src/mapserver/qgsconfigparser.cpp	2011-01-24 10:50:58 UTC (rev 15067)
@@ -23,6 +23,7 @@
 #include "qgsrasterlayer.h"
 #include "qgsvectorlayer.h"
 #include <sqlite3.h>
+#include <QFile>
 
 
 QgsConfigParser::QgsConfigParser()
@@ -401,3 +402,20 @@
 
   return c;
 }
+
+void QgsConfigParser::serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
+{
+  QFile wmsService( "wms_metadata.xml" );
+  if ( wmsService.open( QIODevice::ReadOnly ) )
+  {
+    QDomDocument externServiceDoc;
+    QString parseError;
+    int errorLineNo;
+    if ( externServiceDoc.setContent( &wmsService, false, &parseError, &errorLineNo ) )
+    {
+      wmsService.close();
+      QDomElement service = externServiceDoc.firstChildElement();
+      parentElement.appendChild( service );
+    }
+  }
+}

Modified: trunk/qgis/src/mapserver/qgsconfigparser.h
===================================================================
--- trunk/qgis/src/mapserver/qgsconfigparser.h	2011-01-22 16:00:28 UTC (rev 15066)
+++ trunk/qgis/src/mapserver/qgsconfigparser.h	2011-01-24 10:50:58 UTC (rev 15067)
@@ -101,6 +101,9 @@
     /**Adds print capabilities to xml document. ParentElem usually is the <Capabilities> element*/
     virtual void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const = 0;
 
+    /**Appends service metadata to the capabilities document*/
+    virtual void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;
+
   protected:
     /**Parser to forward not resolved requests (e.g. SLD parser based on user request might have a fallback parser with admin configuration)*/
     QgsConfigParser* mFallbackParser;

Modified: trunk/qgis/src/mapserver/qgsprojectparser.cpp
===================================================================
--- trunk/qgis/src/mapserver/qgsprojectparser.cpp	2011-01-22 16:00:28 UTC (rev 15066)
+++ trunk/qgis/src/mapserver/qgsprojectparser.cpp	2011-01-24 10:50:58 UTC (rev 15067)
@@ -422,7 +422,7 @@
   {
     return epsgSet;
   }
-  QDomNodeList valueList = propertiesElem.elementsByTagName( "value" );
+  QDomNodeList valueList = wmsEpsgElem.elementsByTagName( "value" );
   bool conversionOk;
   for ( int i = 0; i < valueList.size(); ++i )
   {
@@ -1009,3 +1009,20 @@
   return composerElem;
 }
 
+void QgsProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
+{
+  QDomElement qgisElem = mXMLDoc->documentElement();
+  QDomNodeList serviceCapabilitiesList = qgisElem.elementsByTagName( "WMSServiceCapabilities" );
+  if ( serviceCapabilitiesList.size() < 1 ) //service capabilities not embedded in the project file. Use wms_metadata.xml as fallback
+  {
+    QgsConfigParser::serviceCapabilities( parentElement, doc );
+    return;
+  }
+
+  QDomElement serviceElem = serviceCapabilitiesList.at( 0 ).firstChildElement( "Service" );
+  if ( !serviceElem.isNull() )
+  {
+    parentElement.appendChild( doc.importNode( serviceElem, true ) );
+  }
+}
+

Modified: trunk/qgis/src/mapserver/qgsprojectparser.h
===================================================================
--- trunk/qgis/src/mapserver/qgsprojectparser.h	2011-01-22 16:00:28 UTC (rev 15066)
+++ trunk/qgis/src/mapserver/qgsprojectparser.h	2011-01-24 10:50:58 UTC (rev 15067)
@@ -93,6 +93,9 @@
     /**Adds print capabilities to xml document. ParentElem usually is the <Capabilities> element*/
     void printCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;
 
+    /**Reads service metadata from projectfile or falls back to parent class method if not there*/
+    void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;
+
   private:
     /**Content of project file*/
     QDomDocument* mXMLDoc;

Modified: trunk/qgis/src/mapserver/qgswmsserver.cpp
===================================================================
--- trunk/qgis/src/mapserver/qgswmsserver.cpp	2011-01-22 16:00:28 UTC (rev 15066)
+++ trunk/qgis/src/mapserver/qgswmsserver.cpp	2011-01-24 10:50:58 UTC (rev 15067)
@@ -78,29 +78,11 @@
   wmsCapabilitiesElement.setAttribute( "version", "1.3.0" );
   doc.appendChild( wmsCapabilitiesElement );
 
-  QFile wmsService( "wms_metadata.xml" );
-  if ( !wmsService.open( QIODevice::ReadOnly ) )
+  if ( mConfigParser )
   {
-    //throw an exception...
-    QgsMSDebugMsg( "external wms service capabilities not found" )
+    mConfigParser->serviceCapabilities( wmsCapabilitiesElement, doc );
   }
-  else
-  {
-    QDomDocument externServiceDoc;
-    QString parseError;
-    int errorLineNo;
-    if ( !externServiceDoc.setContent( &wmsService, false, &parseError, &errorLineNo ) )
-    {
-      QgsMSDebugMsg( "parse error at setting content of external wms service capabilities: "
-                     + parseError + " at line " + QString::number( errorLineNo ) )
-      wmsService.close();
-    }
-    wmsService.close();
 
-    QDomElement service = externServiceDoc.firstChildElement();
-    wmsCapabilitiesElement.appendChild( service );
-  }
-
   //wms:Capability element
   QDomElement capabilityElement = doc.createElement( "Capability"/*wms:Capability*/ );
   wmsCapabilitiesElement.appendChild( capabilityElement );



More information about the QGIS-commit mailing list