[mapserver-users] Template for No Records?
Frank Koormann
frank.koormann at intevation.de
Thu Oct 24 02:27:25 PDT 2002
Matthew, David, all,
* Matthew Hatcher <MJHatcher at space.qinetiq.com> [021022 10:16]:
>
> Unfortunately, these URLs are simply forwarded to and are not treated as
> templates, so you can't include the usual template tags, but it's still
> possible to make things look much better than the old error messages.
>
I'd once implemented an enhancement for mapserver version 3.5, introducing
a EMPTY_TEMPLATE tag for the mapfile. This does what you are asking for.
You may find the attached patch usefull although it is an untested port
from the 3.5 to 3.6 series.
Regards,
Frank
--
Frank Koormann <frank.koormann at intevation.de>
Professional Service around Free Software (http://intevation.net/)
FreeGIS Project (http://freegis.org/)
-------------- next part --------------
diff -uNr mapserver-3.6.3.orig/map.h mapserver-3.6.3/map.h
--- mapserver-3.6.3.orig/map.h Tue Oct 8 05:50:17 2002
+++ mapserver-3.6.3/map.h Thu Oct 24 11:14:37 2002
@@ -326,6 +326,8 @@
char *header, *footer;
char *empty, *error; /* error handling */
+ char *empty_template; /* show error message with a template */
+
rectObj extent; /* clipping extent */
double minscale, maxscale;
char *mintemplate, *maxtemplate;
diff -uNr mapserver-3.6.3.orig/mapfile.c mapserver-3.6.3/mapfile.c
--- mapserver-3.6.3.orig/mapfile.c Fri Oct 4 23:44:19 2002
+++ mapserver-3.6.3/mapfile.c Thu Oct 24 11:14:37 2002
@@ -2788,7 +2788,7 @@
web->extent.minx = web->extent.miny = web->extent.maxx = web->extent.maxy = -1.0;
web->template = NULL;
web->header = web->footer = NULL;
- web->error = web->empty = NULL;
+ web->error = web->empty = web->empty_template = NULL;
web->mintemplate = web->maxtemplate = NULL;
web->minscale = web->maxscale = -1;
web->log = NULL;
@@ -2804,6 +2804,7 @@
msFree(web->footer);
msFree(web->error);
msFree(web->empty);
+ msFree(web->empty_template);
msFree(web->maxtemplate);
msFree(web->mintemplate);
msFree(web->log);
@@ -2816,6 +2817,8 @@
{
fprintf(stream, " WEB\n");
if(web->empty) fprintf(stream, " EMPTY \"%s\"\n", web->empty);
+ if(web->empty_template) fprintf(stream, " EMPTY_TEMPLATE \"%s\"\n",
+ web->empty);
if(web->error) fprintf(stream, " ERROR \"%s\"\n", web->error);
if(web->footer) fprintf(stream, " FOOTER \"%s\"\n", web->footer);
if(web->header) fprintf(stream, " HEADER \"%s\"\n", web->header);
@@ -2838,6 +2841,9 @@
case(EMPTY):
if((web->empty = getString()) == NULL) return(-1);
break;
+ case(EMPTY_TEMPLATE):
+ if((web->empty_template = getString()) == NULL) return(-1);
+ break;
case(EOF):
msSetError(MS_EOFERR, NULL, "loadWeb()");
return(-1);
@@ -2901,6 +2907,10 @@
case(EMPTY):
msFree(web->empty);
web->empty = strdup(value);
+ break;
+ case(EMPTY_TEMPLATE):
+ if(web->empty_template) msFree(web->empty);
+ web->empty_template = strdup(value);
break;
case(ERROR):
msFree(web->error);
diff -uNr mapserver-3.6.3.orig/mapfile.h mapserver-3.6.3/mapfile.h
--- mapserver-3.6.3.orig/mapfile.h Mon Apr 29 20:04:21 2002
+++ mapserver-3.6.3/mapfile.h Thu Oct 24 11:14:37 2002
@@ -158,4 +158,6 @@
#define MINBOXSIZE 1133
#define MAXBOXSIZE 1134
+#define EMPTY_TEMPLATE 1140
+
#endif /* MAPFILE_H */
diff -uNr mapserver-3.6.3.orig/maplexer.l mapserver-3.6.3/maplexer.l
--- mapserver-3.6.3.orig/maplexer.l Wed Sep 18 17:14:17 2002
+++ mapserver-3.6.3/maplexer.l Thu Oct 24 11:14:37 2002
@@ -111,6 +111,7 @@
<INITIAL,OBJECT_STRING>data { return(DATA); }
<INITIAL,OBJECT_STRING>dump { return(DUMP); }
<INITIAL,OBJECT_STRING>empty { return(EMPTY); }
+<INITIAL,OBJECT_STRING>empty_template { return(EMPTY_TEMPLATE); }
<INITIAL>end { return(END); }
<INITIAL,OBJECT_STRING>error { return(ERROR); }
<INITIAL,OBJECT_STRING>expression { return(EXPRESSION); }
diff -uNr mapserver-3.6.3.orig/mapserv.c mapserver-3.6.3/mapserv.c
--- mapserver-3.6.3.orig/mapserv.c Thu Jun 27 21:10:39 2002
+++ mapserver-3.6.3/mapserv.c Thu Oct 24 11:17:57 2002
@@ -83,8 +83,17 @@
exit(0);
}
- if((ms_error->code == MS_NOTFOUND) && (msObj->Map->web.empty)) {
- msRedirect(msObj->Map->web.empty);
+ if((ms_error.code == MS_NOTFOUND)
+ && (Map->web.empty || Map->web.empty_template)) {
+ if (Map->web.empty_template) {
+ /* set to mode to something other than QUERY so that writeError
+ * is not called recursively. */
+ Mode = BROWSE;
+ printf("Content-type: text/html%c%c", 10, 10);
+ returnPage(Map->web.empty_template, BROWSE);
+ } else {
+ redirect(Map->web.empty);
+ }
} else {
if(msObj->Map->web.error) {
msRedirect(msObj->Map->web.error);
More information about the MapServer-users
mailing list