[mapserver-commits] r9279 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Fri Aug 28 04:56:28 EDT 2009
Author: tbonfort
Date: 2009-08-28 04:56:27 -0400 (Fri, 28 Aug 2009)
New Revision: 9279
Modified:
trunk/mapserver/HISTORY.TXT
trunk/mapserver/mapfile.c
trunk/mapserver/mapserv.c
trunk/mapserver/mapserver.h
trunk/mapserver/shp2img.c
Log:
add default values for CGI %key% substitutions (#3108)
Modified: trunk/mapserver/HISTORY.TXT
===================================================================
--- trunk/mapserver/HISTORY.TXT 2009-08-28 08:40:04 UTC (rev 9278)
+++ trunk/mapserver/HISTORY.TXT 2009-08-28 08:56:27 UTC (rev 9279)
@@ -13,6 +13,7 @@
Current Version (SVN trunk):
----------------------------
+- add default values for CGI %key% substitutions (#3108)
- fix clipping of polygon shapes in line layers (#3059)
Modified: trunk/mapserver/mapfile.c
===================================================================
--- trunk/mapserver/mapfile.c 2009-08-28 08:40:04 UTC (rev 9278)
+++ trunk/mapserver/mapfile.c 2009-08-28 08:56:27 UTC (rev 9279)
@@ -5382,6 +5382,45 @@
return(MS_SUCCESS);
}
+/* look in places authorized for url substitution and replace "from" by "to" */
+void msLayerSubstituteString(layerObj *layer, const char *from, const char *to) {
+ int k;
+ if(layer->data && (strstr(layer->data, from) != NULL))
+ layer->data = msReplaceSubstring(layer->data, from, to);
+ if(layer->tileindex && (strstr(layer->tileindex, from) != NULL))
+ layer->tileindex = msReplaceSubstring(layer->tileindex, from, to);
+ if(layer->connection && (strstr(layer->connection, from) != NULL))
+ layer->connection = msReplaceSubstring(layer->connection, from, to);
+ if(layer->filter.string && (strstr(layer->filter.string, from) != NULL))
+ layer->filter.string = msReplaceSubstring(layer->filter.string, from, to);
+ for(k=0; k<layer->numclasses; k++) {
+ if(layer->class[k]->expression.string && (strstr(layer->class[k]->expression.string, from) != NULL))
+ layer->class[k]->expression.string = msReplaceSubstring(layer->class[k]->expression.string, from, to);
+ }
+}
+
+
+/* loop through layer metadata for keys that have a default_%key% pattern to replace
+* remaining %key% entries by their default value */
+void msApplyDefaultSubstitutions(mapObj *map) {
+ int i;
+ for(i=0;i<map->numlayers;i++) {
+ layerObj *layer = GET_LAYER(map, i);
+ const char *defaultkey = msFirstKeyFromHashTable(&(layer->metadata));
+ while(defaultkey) {
+ if(!strncmp(defaultkey,"default_",8)){
+ char *tmpstr = (char *)malloc(sizeof(char)*(strlen(defaultkey)-8));
+ sprintf(tmpstr,"%%%s%%", &(defaultkey[8]));
+
+ msLayerSubstituteString(layer,tmpstr,msLookupHashTable(&(layer->metadata),defaultkey));
+ defaultkey = msNextKeyFromHashTable(&(layer->metadata),defaultkey);
+ free(tmpstr);
+ }
+ }
+ }
+
+}
+
/*
** Returns an array with one entry per mapfile token. Useful to manipulate
** mapfiles in MapScript.
Modified: trunk/mapserver/mapserv.c
===================================================================
--- trunk/mapserver/mapserv.c 2009-08-28 08:40:04 UTC (rev 9278)
+++ trunk/mapserver/mapserv.c 2009-08-28 08:56:27 UTC (rev 9279)
@@ -176,13 +176,15 @@
return rv;
}
+
+
/*
** Extract Map File name from params and load it.
** Returns map object or NULL on error.
*/
mapObj *loadMap(void)
{
- int i,j,k;
+ int i,j;
mapObj *map = NULL;
char *tmpstr, *key, *value=NULL;
@@ -243,32 +245,23 @@
sprintf(key,"%s_validation_pattern", mapserv->request->ParamNames[i]);
for(j=0; j<map->numlayers; j++) {
- value = msLookupHashTable(&(GET_LAYER(map, j)->metadata), key);
+ layerObj *layer = GET_LAYER(map, j);
+ value = msLookupHashTable(&(layer->metadata), key);
if(value) { /* validate parameter value */
if(msEvalRegex(value, mapserv->request->ParamValues[i]) == MS_FALSE) {
msSetError(MS_WEBERR, "Parameter '%s' value fails to validate.", "loadMap()", mapserv->request->ParamNames[i]);
writeError();
}
}
-
- if(GET_LAYER(map, j)->data && (strstr(GET_LAYER(map, j)->data, tmpstr) != NULL))
- GET_LAYER(map, j)->data = msReplaceSubstring(GET_LAYER(map, j)->data, tmpstr, mapserv->request->ParamValues[i]);
- if(GET_LAYER(map, j)->tileindex && (strstr(GET_LAYER(map, j)->tileindex, tmpstr) != NULL))
- GET_LAYER(map, j)->tileindex = msReplaceSubstring(GET_LAYER(map, j)->tileindex, tmpstr, mapserv->request->ParamValues[i]);
- if(GET_LAYER(map, j)->connection && (strstr(GET_LAYER(map, j)->connection, tmpstr) != NULL))
- GET_LAYER(map, j)->connection = msReplaceSubstring(GET_LAYER(map, j)->connection, tmpstr, mapserv->request->ParamValues[i]);
- if(GET_LAYER(map, j)->filter.string && (strstr(GET_LAYER(map, j)->filter.string, tmpstr) != NULL))
- GET_LAYER(map, j)->filter.string = msReplaceSubstring(GET_LAYER(map, j)->filter.string, tmpstr, mapserv->request->ParamValues[i]);
- for(k=0; k<GET_LAYER(map, j)->numclasses; k++) {
- if(GET_LAYER(map, j)->class[k]->expression.string && (strstr(GET_LAYER(map, j)->class[k]->expression.string, tmpstr) != NULL))
- GET_LAYER(map, j)->class[k]->expression.string = msReplaceSubstring(GET_LAYER(map, j)->class[k]->expression.string, tmpstr, mapserv->request->ParamValues[i]);
- }
+ msLayerSubstituteString(layer, key, mapserv->request->ParamValues[i]);
}
free(tmpstr);
free(key);
}
+ msApplyDefaultSubstitutions(map);
+
/* check to see if a ogc map context is passed as argument. if there */
/* is one load it */
@@ -287,6 +280,7 @@
return map;
}
+
/*
** Set operation mode. First look in MS_MODE env. var. as a
** default value that can be overridden by the mode=... CGI param.
Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h 2009-08-28 08:40:04 UTC (rev 9278)
+++ trunk/mapserver/mapserver.h 2009-08-28 08:56:27 UTC (rev 9279)
@@ -1574,6 +1574,9 @@
MS_DLL_EXPORT void freeExpression(expressionObj *exp);
MS_DLL_EXPORT char *msGetExpressionString(expressionObj *exp);
+MS_DLL_EXPORT void msLayerSubstituteString(layerObj *layer, const char *from, const char *to);
+MS_DLL_EXPORT void msApplyDefaultSubstitutions(mapObj *map);
+
MS_DLL_EXPORT int getClassIndex(layerObj *layer, char *str);
/* For maplabel and mappdf */
Modified: trunk/mapserver/shp2img.c
===================================================================
--- trunk/mapserver/shp2img.c 2009-08-28 08:40:04 UTC (rev 9278)
+++ trunk/mapserver/shp2img.c 2009-08-28 08:56:27 UTC (rev 9279)
@@ -128,6 +128,7 @@
if(strcmp(argv[i],"-m") == 0) {
map = msLoadMap(argv[i+1], NULL);
+ msApplyDefaultSubstitutions(map);
if(!map) {
msWriteError(stderr);
msCleanup();
More information about the mapserver-commits
mailing list