[mapserver-commits] r9328 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Mon Sep 21 17:41:45 EDT 2009


Author: assefa
Date: 2009-09-21 17:41:43 -0400 (Mon, 21 Sep 2009)
New Revision: 9328

Modified:
   trunk/mapserver/HISTORY.TXT
   trunk/mapserver/mapoutput.c
   trunk/mapserver/mapserver.h
   trunk/mapserver/mapwms.c
Log:
Allow users to set wms getmap and getlegendgraphic image format list (#455)

Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT	2009-09-21 19:30:42 UTC (rev 9327)
+++ trunk/mapserver/HISTORY.TXT	2009-09-21 21:41:43 UTC (rev 9328)
@@ -14,6 +14,8 @@
 Current Version (SVN trunk):
 ----------------------------
 
+- Allow users to set wms getmap and getlegendgraphic image format list (#455)
+
 - Fixed MapScript shapeObj->toWkt() segfaults (#2763)
 
 - add vertical bar charts to dynamic charting (#3128)

Modified: trunk/mapserver/mapoutput.c
===================================================================
--- trunk/mapserver/mapoutput.c	2009-09-21 19:30:42 UTC (rev 9327)
+++ trunk/mapserver/mapoutput.c	2009-09-21 21:41:43 UTC (rev 9328)
@@ -872,12 +872,32 @@
 /************************************************************************/
 /*                     msGetOutputFormatMimeList()                      */
 /************************************************************************/
+void msGetOutputFormatMimeListImg( mapObj *map, char **mime_list, int max_mime )
 
-void msGetOutputFormatMimeListGD( mapObj *map, char **mime_list, int max_mime )
-
 {
-    int mime_count = 0, i;
+  int mime_count = 0, i,j;
+    const char *format_list = NULL;
+    char **tokens = NULL;
+    int numtokens = 0;
+    outputFormatObj *format;
 
+    format_list = msOWSLookupMetadata(&(map->web.metadata), "M","getlegendgraphic_formatlist");
+    if ( format_list && strlen(format_list) > 0)
+      tokens = msStringSplit(format_list,  ',', &numtokens);
+
+    if (tokens && numtokens > 0)
+    {
+        for(j = 0; j < numtokens; j++ )
+        {
+            format = msSelectOutputFormat(map, tokens[j]);
+            if (format != NULL)
+            {
+                mime_list[mime_count++] = format->mimetype;
+            }
+        }
+        msFreeCharArray(tokens, numtokens);
+    }
+    else
     for( i = 0; i < map->numoutputformats && mime_count < max_mime; i++ )
     {
         int  j;
@@ -893,7 +913,8 @@
         }
 
         if( j == mime_count && map->outputformatlist[i]->driver &&
-            strncasecmp(map->outputformatlist[i]->driver, "GD/", 3)==0)
+            (strncasecmp(map->outputformatlist[i]->driver, "GD/", 3)==0 ||
+             strncasecmp(map->outputformatlist[i]->driver, "AGG/", 4)==0))
             mime_list[mime_count++] = map->outputformatlist[i]->mimetype;
     }
 
@@ -901,41 +922,63 @@
         mime_list[mime_count] = NULL;
 }
 
-
 /************************************************************************/
-/*                  msGetOutputFormatMimeListRaster()                   */
+/*                  msGetOutputFormatMimeListWMS()                      */
 /************************************************************************/
 
 void msGetOutputFormatMimeListWMS( mapObj *map, char **mime_list, int max_mime )
-
 {
-    int mime_count = 0, i;
+    int mime_count = 0, i,j;
+    const char *format_list = NULL;
+    char **tokens = NULL;
+    int numtokens = 0;
+    outputFormatObj *format;
 
-    for( i = 0; i < map->numoutputformats && mime_count < max_mime; i++ )
+    format_list = msOWSLookupMetadata(&(map->web.metadata), "M","getmap_formatlist");
+    if ( format_list && strlen(format_list) > 0)
+      tokens = msStringSplit(format_list,  ',', &numtokens);
+
+    if (tokens && numtokens > 0)
     {
-        int  j;
+        for(j = 0; j < numtokens; j++ )
+        {
+            format = msSelectOutputFormat(map, tokens[j]);
+            if (format != NULL)
+            {
+                mime_list[mime_count++] = format->mimetype;
+            }
+        }
+        msFreeCharArray(tokens, numtokens);
+    }
+    else
+    {
+        for( i = 0; i < map->numoutputformats && mime_count < max_mime; i++ )
+        {
+            int  j;
         
-        if( map->outputformatlist[i]->mimetype == NULL )
-            continue;
+            if( map->outputformatlist[i]->mimetype == NULL )
+              continue;
 
-        for( j = 0; j < mime_count; j++ )
-        {
-            if( strcasecmp(mime_list[j],
-                           map->outputformatlist[i]->mimetype) == 0 )
-                break;
+            for( j = 0; j < mime_count; j++ )
+            {
+                if( strcasecmp(mime_list[j],
+                               map->outputformatlist[i]->mimetype) == 0 )
+                  break;
+            }
+
+            if( j == mime_count && map->outputformatlist[i]->driver &&
+               (strncasecmp(map->outputformatlist[i]->driver, "GD/", 3)==0 ||
+                 strncasecmp(map->outputformatlist[i]->driver, "GDAL/", 5)==0 ||
+                 strncasecmp(map->outputformatlist[i]->driver, "AGG/", 4)==0 ||
+                 strcasecmp(map->outputformatlist[i]->driver, "svg")==0)) 
+              mime_list[mime_count++] = map->outputformatlist[i]->mimetype;
         }
-
-        if( j == mime_count && map->outputformatlist[i]->driver &&
-            (strncasecmp(map->outputformatlist[i]->driver, "GD/", 3)==0 ||
-             strncasecmp(map->outputformatlist[i]->driver, "GDAL/", 5)==0 ||
-             strcasecmp(map->outputformatlist[i]->driver, "svg")==0)) 
-            mime_list[mime_count++] = map->outputformatlist[i]->mimetype;
     }
-
     if( mime_count < max_mime )
         mime_list[mime_count] = NULL;
 }
 
+
 /************************************************************************/
 /*                       msOutputFormatValidate()                       */
 /*                                                                      */

Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h	2009-09-21 19:30:42 UTC (rev 9327)
+++ trunk/mapserver/mapserver.h	2009-09-21 21:41:43 UTC (rev 9328)
@@ -2263,7 +2263,7 @@
 MS_DLL_EXPORT int msPostMapParseOutputFormatSetup( mapObj *map );
 MS_DLL_EXPORT void msSetOutputFormatOption( outputFormatObj *format, const char *key, const char *value );
 MS_DLL_EXPORT void msGetOutputFormatMimeList( mapObj *map, char **mime_list, int max_mime );
-MS_DLL_EXPORT void msGetOutputFormatMimeListGD( mapObj *map, char **mime_list, int max_mime );
+MS_DLL_EXPORT void msGetOutputFormatMimeListImg( mapObj *map, char **mime_list, int max_mime );
 MS_DLL_EXPORT void msGetOutputFormatMimeListWMS( mapObj *map, char **mime_list, int max_mime );
 MS_DLL_EXPORT outputFormatObj *msCloneOutputFormat( outputFormatObj *format );
 MS_DLL_EXPORT int msOutputFormatValidate( outputFormatObj *format );

Modified: trunk/mapserver/mapwms.c
===================================================================
--- trunk/mapserver/mapwms.c	2009-09-21 19:30:42 UTC (rev 9327)
+++ trunk/mapserver/mapwms.c	2009-09-21 21:41:43 UTC (rev 9328)
@@ -639,23 +639,48 @@
       map->height = atoi(values[i]);
     }
     else if (strcasecmp(names[i], "FORMAT") == 0) {
+      const char *format_list = NULL;
       formatfound = 1;
-      format = msSelectOutputFormat( map, values[i] );
 
-      if( format == NULL || 
-          (strncasecmp(format->driver, "GD/", 3) != 0 &&
-           strncasecmp(format->driver, "GDAL/", 5) != 0 && 
-           strncasecmp(format->driver, "AGG/", 4) != 0 &&
-           strncasecmp(format->driver, "CAIRO/", 6) != 0 &&
-           strncasecmp(format->driver, "SVG", 3) != 0))
-        {
-          msSetError(MS_IMGERR,
-                   "Unsupported output format (%s).",
-                   "msWMSLoadGetMapParams()",
-                   values[i] );
-        return msWMSException(map, nVersion, "InvalidFormat");
+      /*check to see if a predefined list is given*/
+      format_list = msOWSLookupMetadata(&(map->web.metadata), "M","getmap_formatlist");
+      n = 0;
+      if ( format_list)
+        tokens = msStringSplit(format_list,  ',', &n);
+      
+      if (tokens && n > 0)
+      {
+          for (j=0; j<n; j++)
+          {
+              if (strcasecmp(tokens[j], values[i]) == 0)
+                break;
+          }
+          msFreeCharArray(tokens, n);
+          if (j == n || (format = msSelectOutputFormat( map, values[i])) == NULL)
+          {
+            msSetError(MS_IMGERR,
+                       "Unsupported output format (%s).",
+                       "msWMSLoadGetMapParams()",
+                       values[i] );
+            return msWMSException(map, nVersion, "InvalidFormat");
+          }
       }
-
+      else
+      {
+          format = msSelectOutputFormat( map, values[i] );
+          if( format == NULL || 
+              (strncasecmp(format->driver, "GD/", 3) != 0 &&
+               strncasecmp(format->driver, "GDAL/", 5) != 0 && 
+               strncasecmp(format->driver, "AGG/", 4) != 0 &&
+               strncasecmp(format->driver, "SVG", 3) != 0))
+          {
+              msSetError(MS_IMGERR,
+                         "Unsupported output format (%s).",
+                         "msWMSLoadGetMapParams()",
+                         values[i] );
+              return msWMSException(map, nVersion, "InvalidFormat");
+          }
+      }
       msFree( map->imagetype );
       map->imagetype = strdup(values[i]);
     }
@@ -2159,7 +2184,7 @@
         else
            msWMSPrintRequestCap(nVersion, "DescribeLayer", script_url_encoded, "text/xml", NULL);
 
-        msGetOutputFormatMimeListGD(map,mime_list,sizeof(mime_list)/sizeof(char*));
+        msGetOutputFormatMimeListImg(map,mime_list,sizeof(mime_list)/sizeof(char*));
 
         if (nVersion >= OWS_1_1_1) {
            if (nVersion == OWS_1_3_0)
@@ -3149,7 +3174,9 @@
     char *pszStyle = NULL;
     char *sld_version = NULL;
     const char *sldenabled = NULL;
-
+    const char *format_list = NULL;
+    char **tokens;
+    int n,j = 0;
     sldenabled = msOWSLookupMetadata(&(map->web.metadata), "MO", "sld_enabled");
 
     if (sldenabled == NULL)
@@ -3204,15 +3231,15 @@
      }
 
      if (nVersion >= OWS_1_3_0 && sld_version == NULL)
-  {
-      msSetError(MS_WMSERR, "Missing required parameter SLD_VERSION", "GetLegendGraphic()");
-      return msWMSException(map, nVersion, "MissingParameterValue");
-  }
-  if (nVersion >= OWS_1_3_0 && strcasecmp(sld_version, "1.1.0") != 0)
-  {
-      msSetError(MS_WMSERR, "SLD_VERSION must be 1.1.0", "GetLegendGraphic()");
-      return msWMSException(map, nVersion, "InvalidParameterValue");
-  }
+     {
+         msSetError(MS_WMSERR, "Missing required parameter SLD_VERSION", "GetLegendGraphic()");
+         return msWMSException(map, nVersion, "MissingParameterValue");
+     }
+     if (nVersion >= OWS_1_3_0 && strcasecmp(sld_version, "1.1.0") != 0)
+     {
+         msSetError(MS_WMSERR, "SLD_VERSION must be 1.1.0", "GetLegendGraphic()");
+         return msWMSException(map, nVersion, "InvalidParameterValue");
+     }
      /* check if layer name is valid. We only test the layer name and not */
      /* the group name. */
      for (i=0; i<map->numlayers; i++)
@@ -3233,21 +3260,48 @@
      }
 
      /* validate format */
-     psFormat = msSelectOutputFormat( map, pszFormat);
-     if( psFormat == NULL || 
-         (psFormat->renderer != MS_RENDER_WITH_GD
-                 &&
-          psFormat->renderer != MS_RENDER_WITH_AGG)) 
-          /* msDrawLegend and msCreateLegendIcon both switch the alpha channel to gd
-          ** after creation, so they can be called here without going through
-          ** the msAlphaGD2AGG functions */
+     
+     /*check to see if a predefined list is given*/
+     format_list = msOWSLookupMetadata(&(map->web.metadata), "M","getlegendgraphic_formatlist");
+     n = 0;
+     if ( format_list)
+       tokens = msStringSplit(format_list,  ',', &n);
+      
+     if (tokens && n > 0)
      {
-         msSetError(MS_IMGERR,
-                    "Unsupported output format (%s).",
-                    "msWMSGetLegendGraphic()",
-                    pszFormat);
-         return msWMSException(map, nVersion, "InvalidFormat");
+         for (j=0; j<n; j++)
+         {
+             if (strcasecmp(tokens[j], pszFormat) == 0)
+               break;
+         }
+         msFreeCharArray(tokens, n);
+         if (j == n || (psFormat = msSelectOutputFormat( map, pszFormat)) == NULL)
+         {
+             msSetError(MS_IMGERR,
+                        "Unsupported output format (%s).",
+                        "msWMSGetLegendGraphic()",
+                        values[i] );
+             return msWMSException(map, nVersion, "InvalidFormat");
+         }
      }
+     else
+     {
+         psFormat = msSelectOutputFormat( map, pszFormat);
+         if( psFormat == NULL || 
+             (psFormat->renderer != MS_RENDER_WITH_GD
+              &&
+              psFormat->renderer != MS_RENDER_WITH_AGG)) 
+           /* msDrawLegend and msCreateLegendIcon both switch the alpha channel to gd
+           ** after creation, so they can be called here without going through
+           ** the msAlphaGD2AGG functions */
+         {
+             msSetError(MS_IMGERR,
+                        "Unsupported output format (%s).",
+                        "msWMSGetLegendGraphic()",
+                        pszFormat);
+             return msWMSException(map, nVersion, "InvalidFormat");
+         }
+     }
      msApplyOutputFormat(&(map->outputformat), psFormat, MS_NOOVERRIDE,
                           MS_NOOVERRIDE, MS_NOOVERRIDE );
 
@@ -3473,6 +3527,8 @@
     return(MS_SUCCESS);
 }
 
+
+
 #endif /* USE_WMS_SVR */
 
 



More information about the mapserver-commits mailing list