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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Jan 14 08:58:06 EST 2011


Author: mhugent
Date: 2011-01-14 05:58:06 -0800 (Fri, 14 Jan 2011)
New Revision: 15044

Modified:
   trunk/qgis/src/mapserver/qgis_map_serv.cpp
   trunk/qgis/src/mapserver/qgsgetrequesthandler.cpp
   trunk/qgis/src/mapserver/qgsgetrequesthandler.h
   trunk/qgis/src/mapserver/qgshttprequesthandler.cpp
   trunk/qgis/src/mapserver/qgshttprequesthandler.h
   trunk/qgis/src/mapserver/qgsrequesthandler.h
   trunk/qgis/src/mapserver/qgssoaprequesthandler.cpp
   trunk/qgis/src/mapserver/qgssoaprequesthandler.h
   trunk/qgis/src/mapserver/qgswmsserver.cpp
   trunk/qgis/src/mapserver/qgswmsserver.h
Log:
Consistent handling of outputformat in mapserver and better error handling

Modified: trunk/qgis/src/mapserver/qgis_map_serv.cpp
===================================================================
--- trunk/qgis/src/mapserver/qgis_map_serv.cpp	2011-01-14 12:07:30 UTC (rev 15043)
+++ trunk/qgis/src/mapserver/qgis_map_serv.cpp	2011-01-14 13:58:06 UTC (rev 15044)
@@ -385,10 +385,9 @@
     else if ( requestIt->second == "GetPrint" )
     {
       QByteArray* printOutput = 0;
-      QString formatString;
       try
       {
-        printOutput = theServer->getPrint( formatString );
+        printOutput = theServer->getPrint( theRequestHandler->format() );
       }
       catch ( QgsMapServiceException& ex )
       {
@@ -397,7 +396,7 @@
 
       if ( printOutput )
       {
-        theRequestHandler->sendGetPrintResponse( printOutput, formatString );
+        theRequestHandler->sendGetPrintResponse( printOutput );
       }
       delete printOutput;
       delete theRequestHandler;

Modified: trunk/qgis/src/mapserver/qgsgetrequesthandler.cpp
===================================================================
--- trunk/qgis/src/mapserver/qgsgetrequesthandler.cpp	2011-01-14 12:07:30 UTC (rev 15043)
+++ trunk/qgis/src/mapserver/qgsgetrequesthandler.cpp	2011-01-14 13:58:06 UTC (rev 15044)
@@ -99,14 +99,24 @@
       QgsMapServerLogger::instance()->printMessage( "formatString is: " + formatString );
 
       //remove the image/ in front of the format
-      if ( formatString == "image/jpeg" || formatString == "image/jpg" || formatString == "JPG" || formatString == "jpg" )
+      if ( formatString.compare( "image/png", Qt::CaseInsensitive ) == 0 || formatString.compare( "png", Qt::CaseInsensitive ) == 0 )
       {
+        formatString = "PNG";
+      }
+      else if ( formatString.compare( "image/jpeg", Qt::CaseInsensitive ) == 0 || formatString.compare( "image/jpg", Qt::CaseInsensitive ) == 0 \
+                || formatString.compare( "jpg", Qt::CaseInsensitive ) == 0 )
+      {
         formatString = "JPG";
       }
-      else if ( formatString == "image/png" || formatString == "PNG" || formatString == "png" )
+      else if ( formatString.compare( "svg", Qt::CaseInsensitive ) == 0 )
       {
-        formatString = "PNG";
+        formatString = "SVG";
       }
+      else if ( formatString.compare( "pdf", Qt::CaseInsensitive ) == 0 )
+      {
+        formatString = "PDF";
+      }
+
       mFormat = formatString;
     }
   }
@@ -119,25 +129,19 @@
 {
   if ( img )
   {
+    if ( mFormat != "PNG" && mFormat != "JPG" )
+    {
+      sendServiceException( QgsMapServiceException( "InvalidFormat", "Output format '" + mFormat + "' is not supported in the GetMap request" ) );
+      return;
+    }
+
     //store the image in a QByteArray and send it directly
     QByteArray ba;
     QBuffer buffer( &ba );
     buffer.open( QIODevice::WriteOnly );
     img->save( &buffer, mFormat.toLocal8Bit().data(), -1 );
-    QString mimetype; //official mime-type string differs sometimes
-    if ( mFormat == "PNG" )
-    {
-      mimetype = "image/png";
-    }
-    else if ( mFormat == "JPG" )
-    {
-      mimetype = "image/jpeg";
-    }
-    else
-    {
-      //we don't support other formats yet...
-    }
-    sendHttpResponse( &ba, mimetype );
+
+    sendHttpResponse( &ba, formatToMimeType( mFormat ) );
   }
 }
 
@@ -298,7 +302,7 @@
   sendHttpResponse( &ba, "text/xml" );
 }
 
-void QgsGetRequestHandler::sendGetPrintResponse( QByteArray* ba, const QString& formatString ) const
+void QgsGetRequestHandler::sendGetPrintResponse( QByteArray* ba ) const
 {
-  sendHttpResponse( ba, formatString );
+  sendHttpResponse( ba, formatToMimeType( mFormat ) );
 }

Modified: trunk/qgis/src/mapserver/qgsgetrequesthandler.h
===================================================================
--- trunk/qgis/src/mapserver/qgsgetrequesthandler.h	2011-01-14 12:07:30 UTC (rev 15043)
+++ trunk/qgis/src/mapserver/qgsgetrequesthandler.h	2011-01-14 13:58:06 UTC (rev 15044)
@@ -29,5 +29,5 @@
     void sendGetFeatureInfoResponse( const QDomDocument& infoDoc, const QString& infoFormat ) const;
     void sendServiceException( const QgsMapServiceException& ex ) const;
     void sendGetStyleResponse( const QDomDocument& doc ) const;
-    void sendGetPrintResponse( QByteArray* ba, const QString& formatString ) const;
+    void sendGetPrintResponse( QByteArray* ba ) const;
 };

Modified: trunk/qgis/src/mapserver/qgshttprequesthandler.cpp
===================================================================
--- trunk/qgis/src/mapserver/qgshttprequesthandler.cpp	2011-01-14 12:07:30 UTC (rev 15043)
+++ trunk/qgis/src/mapserver/qgshttprequesthandler.cpp	2011-01-14 13:58:06 UTC (rev 15044)
@@ -48,3 +48,24 @@
   printf( "\n" );
   fwrite( ba->data(), ba->size(), 1, FCGI_stdout );
 }
+
+QString QgsHttpRequestHandler::formatToMimeType( const QString& format ) const
+{
+  if ( format.compare( "png", Qt::CaseInsensitive ) )
+  {
+    return "image/png";
+  }
+  else if ( format.compare( "jpg", Qt::CaseInsensitive ) )
+  {
+    return "image/jpeg";
+  }
+  else if ( format.compare( "svg", Qt::CaseInsensitive ) )
+  {
+    return "image/svg+xml";
+  }
+  else if ( format.compare( "pdf", Qt::CaseInsensitive ) )
+  {
+    return "application/pdf";
+  }
+  return format;
+}

Modified: trunk/qgis/src/mapserver/qgshttprequesthandler.h
===================================================================
--- trunk/qgis/src/mapserver/qgshttprequesthandler.h	2011-01-14 12:07:30 UTC (rev 15043)
+++ trunk/qgis/src/mapserver/qgshttprequesthandler.h	2011-01-14 13:58:06 UTC (rev 15044)
@@ -30,6 +30,9 @@
 
   protected:
     void sendHttpResponse( QByteArray* ba, const QString& format ) const;
+    /**Converts format to official mimetype (e.g. 'jpg' to 'image/jpeg')
+      @return mime string (or the entered string if not found)*/
+    QString formatToMimeType( const QString& format ) const;
 };
 
 #endif

Modified: trunk/qgis/src/mapserver/qgsrequesthandler.h
===================================================================
--- trunk/qgis/src/mapserver/qgsrequesthandler.h	2011-01-14 12:07:30 UTC (rev 15043)
+++ trunk/qgis/src/mapserver/qgsrequesthandler.h	2011-01-14 13:58:06 UTC (rev 15044)
@@ -40,7 +40,8 @@
     virtual void sendGetFeatureInfoResponse( const QDomDocument& infoDoc, const QString& infoFormat ) const = 0;
     virtual void sendServiceException( const QgsMapServiceException& ex ) const = 0;
     virtual void sendGetStyleResponse( const QDomDocument& doc ) const = 0;
-    virtual void sendGetPrintResponse( QByteArray* ba, const QString& formatString ) const = 0;
+    virtual void sendGetPrintResponse( QByteArray* ba ) const = 0;
+    QString format() const { return mFormat; }
   protected:
     /**This is set by the parseInput methods of the subclasses (parameter FORMAT, e.g. 'FORMAT=PNG')*/
     QString mFormat;

Modified: trunk/qgis/src/mapserver/qgssoaprequesthandler.cpp
===================================================================
--- trunk/qgis/src/mapserver/qgssoaprequesthandler.cpp	2011-01-14 12:07:30 UTC (rev 15043)
+++ trunk/qgis/src/mapserver/qgssoaprequesthandler.cpp	2011-01-14 13:58:06 UTC (rev 15044)
@@ -469,7 +469,7 @@
   sendHttpResponse( &ba, "text/xml" );
 }
 
-void QgsSOAPRequestHandler::sendGetPrintResponse( QByteArray* ba, const QString& formatString ) const
+void QgsSOAPRequestHandler::sendGetPrintResponse( QByteArray* ba ) const
 {
   //soon...
 }

Modified: trunk/qgis/src/mapserver/qgssoaprequesthandler.h
===================================================================
--- trunk/qgis/src/mapserver/qgssoaprequesthandler.h	2011-01-14 12:07:30 UTC (rev 15043)
+++ trunk/qgis/src/mapserver/qgssoaprequesthandler.h	2011-01-14 13:58:06 UTC (rev 15044)
@@ -34,7 +34,7 @@
     void sendGetFeatureInfoResponse( const QDomDocument& infoDoc, const QString& infoFormat ) const;
     void sendServiceException( const QgsMapServiceException& ex ) const;
     void sendGetStyleResponse( const QDomDocument& doc ) const;
-    void sendGetPrintResponse( QByteArray* ba, const QString& formatString ) const;
+    void sendGetPrintResponse( QByteArray* ba ) const;
   private:
     /**Parses the xml of a getMap request and fills the parameters into the map. Returns 0 in case of success*/
     int parseGetMapElement( std::map<QString, QString>& parameterMap, const QDomElement& getMapElement ) const;

Modified: trunk/qgis/src/mapserver/qgswmsserver.cpp
===================================================================
--- trunk/qgis/src/mapserver/qgswmsserver.cpp	2011-01-14 12:07:30 UTC (rev 15043)
+++ trunk/qgis/src/mapserver/qgswmsserver.cpp	2011-01-14 13:58:06 UTC (rev 15044)
@@ -355,10 +355,11 @@
   return mConfigParser->getStyle( styleName, layerName );
 }
 
-QByteArray* QgsWMSServer::getPrint( QString& formatString )
+QByteArray* QgsWMSServer::getPrint( const QString& formatString )
 {
   QStringList layersList, stylesList, layerIdList;
-  QImage* theImage = initializeRendering( layersList, stylesList, layerIdList, formatString );
+  QString dummyFormat;
+  QImage* theImage = initializeRendering( layersList, stylesList, layerIdList );
   if ( !theImage )
   {
     return 0;
@@ -455,8 +456,7 @@
 QImage* QgsWMSServer::getMap()
 {
   QStringList layersList, stylesList, layerIdList;
-  QString outputFormat;
-  QImage* theImage = initializeRendering( layersList, stylesList, layerIdList, outputFormat );
+  QImage* theImage = initializeRendering( layersList, stylesList, layerIdList );
 
   QPainter thePainter( theImage );
   thePainter.setRenderHint( QPainter::Antialiasing ); //make it look nicer
@@ -652,7 +652,7 @@
   return 0;
 }
 
-QImage* QgsWMSServer::initializeRendering( QStringList& layersList, QStringList& stylesList, QStringList& layerIdList, QString& outputFormat )
+QImage* QgsWMSServer::initializeRendering( QStringList& layersList, QStringList& stylesList, QStringList& layerIdList )
 {
   if ( !mConfigParser )
   {
@@ -695,15 +695,6 @@
     }
   }
 
-  //get output format
-  std::map<QString, QString>::const_iterator outIt = mParameterMap.find( "FORMAT" );
-  if ( outIt == mParameterMap.end() )
-  {
-    QgsMSDebugMsg( "Error, no parameter FORMAT found" )
-    return 0; //output format parameter also mandatory
-  }
-  outputFormat = outIt->second;
-
   QImage* theImage = createImage();
   if ( !theImage )
   {

Modified: trunk/qgis/src/mapserver/qgswmsserver.h
===================================================================
--- trunk/qgis/src/mapserver/qgswmsserver.h	2011-01-14 12:07:30 UTC (rev 15043)
+++ trunk/qgis/src/mapserver/qgswmsserver.h	2011-01-14 13:58:06 UTC (rev 15044)
@@ -63,7 +63,7 @@
     /**Returns printed page as binary
       @param formatString out: format of the print output (e.g. pdf, svg, png, ...)
       @return printed page as binary or 0 in case of error*/
-    QByteArray* getPrint( QString& formatString );
+    QByteArray* getPrint( const QString& formatString );
 
     /**Creates an xml document that describes the result of the getFeatureInfo request.
        @return 0 in case of success*/
@@ -80,9 +80,8 @@
       @param layersList out: list with WMS layer names
       @param stylesList out: list with WMS style names
       @param layerIdList out: list with QGIS layer ids
-      @param outputFormat out: name of requested output format
       @return image configured together with mMapRenderer (or 0 in case of error). The calling function takes ownership of the image*/
-    QImage* initializeRendering( QStringList& layersList, QStringList& stylesList, QStringList& layerIdList, QString& outputFormat );
+    QImage* initializeRendering( QStringList& layersList, QStringList& stylesList, QStringList& layerIdList );
 
     /**Creates a QImage from the HEIGHT and WIDTH parameters
      @param width image width (or -1 if width should be taken from WIDTH wms parameter)



More information about the QGIS-commit mailing list