Index: branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c
===================================================================
--- branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 854)
+++ branches/prototype-v0/zoo-project/zoo-kernel/service_internal_ms.c	(revision 860)
@@ -76,4 +76,16 @@
 
 /**
+ * Return the current publish_id value
+ * @param elem and maps pointer on which the search occur
+ * @return the integer value of the publish_id field, if any, 0 otherwise
+ */ 
+int getPublishedId(maps* elem){
+  map* myIndex=getMap(elem->content,"published_id");
+  if(myIndex!=NULL){
+    return atoi(myIndex->value);
+  }
+  return 0;
+}
+/**
  * Add width and height keys to an output maps containing the maximum width
  * and height for displaying the full data extent.
@@ -87,4 +99,5 @@
  */
 void setMapSize(maps* output,double minx,double miny,double maxx,double maxy){
+  int imyIndex=getPublishedId(output);
   double maxWidth=640;
   double maxHeight=480;
@@ -118,6 +131,6 @@
 #endif
   if(output!=NULL){
-    addToMap(output->content,"width",sWidth);
-    addToMap(output->content,"height",sHeight);
+    setMapArray(output->content,"width",imyIndex,sWidth);
+    setMapArray(output->content,"height",imyIndex,sHeight);
   }
 }
@@ -131,5 +144,4 @@
  */
 void setReferenceUrl(maps* m,maps* tmpI){
-  outputMapfile(m,tmpI);
   map *msUrl=getMapFromMaps(m,"main","mapserverAddress");
   if(msUrl==NULL){
@@ -138,14 +150,19 @@
     exit(-1);
   }
+  int imyIndex=getPublishedId(tmpI);
+  if(getMapArray(tmpI->content,"ref_wms_link",imyIndex)!=NULL)
+    return;
+  outputMapfile(m,tmpI);
   int finalProto=-1;
   map *msOgcVersion=getMapFromMaps(m,"main","msOgcVersion");
   map *dataPath=getMapFromMaps(m,"main","dataPath");
   map *sid=getMapFromMaps(m,"lenv","usid");
-  map* format=getMap(tmpI->content,"mimeType");
-  map* rformat=getMap(tmpI->content,"requestedMimeType");
-  map* width=getMap(tmpI->content,"width");
-  map* height=getMap(tmpI->content,"height");
-  map* protoMap=getMap(tmpI->content,"msOgc");
-  map* versionMap=getMap(tmpI->content,"msOgcVersion");
+  map* format=getMapArray(tmpI->content,"mimeType",imyIndex);
+  map* rformat=getMapArray(tmpI->content,"requestedMimeType",imyIndex);
+  map* width=getMapArray(tmpI->content,"width",imyIndex);
+  map* height=getMapArray(tmpI->content,"height",imyIndex);
+  map* protoMap=getMapArray(tmpI->content,"msOgc",imyIndex);
+  map* versionMap=getMapArray(tmpI->content,"msOgcVersion",imyIndex);
+  map* datatype=getMapArray(tmpI->content,"geodatatype",imyIndex);
   char options[4][5][25]={
     {"WMS","1.3.0","GetMap","layers=%s","wms_extent"},
@@ -154,16 +171,18 @@
     {"WCS","1.1.0","GetCoverage","coverage=%s","wcs_extent"}
   };
-  map* datatype=getMap(tmpI->content,"geodatatype");
   if(datatype==NULL || strncmp(datatype->value,"other",5)==0){
-    setMapInMaps(m,"lenv","mapError","true");
-    setMapInMaps(m,"lenv","locator",tmpI->name);
-    setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data."));
-    if(getMapFromMaps(m,"lenv","state")==NULL)
-      errorException (m, _("Unable to find any geographic data"), "WrongInputData", tmpI->name);
+    map* minNb=getMap(tmpI->content,"minoccurs");
+    if(minNb==NULL || atoi(minNb->value)>=1){
+      setMapInMaps(m,"lenv","mapError","true");
+      setMapInMaps(m,"lenv","locator",tmpI->name);
+      setMapInMaps(m,"lenv","message",_("The ZOO-Kernel was able to retrieve the data but could not read it as geographic data."));
+      if(getMapFromMaps(m,"lenv","state")==NULL)
+	errorException (m, _("Unable to find any geographic data"), "WrongInputData", tmpI->name);
+    }
     return;
   }
   int proto=0;
   if(rformat==NULL){
-    rformat=getMap(tmpI->content,"mimeType");
+    rformat=getMapArray(tmpI->content,"mimeType",imyIndex);
   }
   if(strncasecmp(rformat->value,"text/xml",8)==0)
@@ -172,12 +191,20 @@
      strncasecmp(rformat->value,"image/geotiff",10)==0)
     proto=2;
+  int hasFormat=-1;
   if(protoMap!=NULL){
-    if(strncasecmp(protoMap->value,"WMS",3)==0)
+    hasFormat=1;
+    if(strncasecmp(protoMap->value,"WMS",3)==0){
       proto=0;
+      rformat=createMap("value","image/png");
+    }
     else{
-      if(strncasecmp(protoMap->value,"WFS",3)==0)
+      if(strncasecmp(protoMap->value,"WFS",3)==0){
 	proto=1;
-      else 
+	rformat=createMap("value","text/xml");
+      }
+      else {
 	proto=2;
+	rformat=createMap("value","image/tiff");
+      }
     }
   }
@@ -190,6 +217,7 @@
   }
 
-  map* extent=getMap(tmpI->content,options[proto][4]);
-  map* crs=getMap(tmpI->content,"crs");
+
+  map* extent=getMapArray(tmpI->content,options[proto][4],imyIndex);
+  map* crs=getMapArray(tmpI->content,"crs",imyIndex);
   int hasCRS=1;
   if(crs==NULL){
@@ -203,14 +231,41 @@
   sprintf(layers,options[proto][3],tmpI->name);
 
-  char* webService_url=(char*)malloc((strlen(msUrl->value)+strlen(format->value)+strlen(tmpI->name)+strlen(width->value)+strlen(height->value)+strlen(extent->value)+256)*sizeof(char));
+  if(format==NULL || width==NULL || height==NULL || extent==NULL){
+    char tmpStr[1024];
+    sprintf(tmpStr,_("Unable to create the mapfile for %s because of missing values."),tmpI->name);
+    errorException (m, tmpStr,
+		    "InternalError", NULL);
+    exit(-1);
+    return;
+  }
+
+  if(proto==0){
+    hasFormat=1;
+    rformat=createMap("mimeType","image/png");
+  }else{
+    if(proto==1){
+      rformat=createMap("mimeType","text/xml");
+      hasFormat=1;
+    }
+    else
+      if(proto==2){
+        rformat=createMap("mimeType","image/tiff");
+	hasFormat=1;
+	finalProto=1;
+      }
+  }
   
+  char* webService_url=(char*)malloc((strlen(msUrl->value)+strlen(rformat->value)+strlen(tmpI->name)+strlen(width->value)+strlen(height->value)+strlen(extent->value)+256)*sizeof(char));
+
+
   if(proto>0){
     if(proto==2)
       finalProto=1;
     sprintf(webService_url,
-	    "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
+	    "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
 	    msUrl->value,
 	    dataPath->value,
 	    tmpI->name,
+	    imyIndex,
 	    sid->value,
 	    options[proto][2],
@@ -223,18 +278,21 @@
 	    );
     if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){
-      addToMap(tmpI->content,"ref_wcs_link",webService_url);
+      setMapArray(tmpI->content,"ref_wcs_link",imyIndex,webService_url);
     }
     else{
-      addToMap(tmpI->content,"ref_wfs_link",webService_url);
+      setMapArray(tmpI->content,"ref_wfs_link",imyIndex,webService_url);
     }
     proto=0;
+    freeMap(&rformat);
+    free(rformat);
     rformat=createMap("mimeType","image/png");
   }
   else{
     sprintf(webService_url,
-	    "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",
+	    "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",
 	    msUrl->value,
 	    dataPath->value,
 	    tmpI->name,
+	    imyIndex,
 	    sid->value,
 	    options[proto][2],
@@ -248,19 +306,23 @@
 	    crs->value
 	    );
-    addToMap(tmpI->content,"ref_wms_link",webService_url);
+    setMapArray(tmpI->content,"ref_wms_link",imyIndex,webService_url);
     if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){
       proto=2;
+      freeMap(&rformat);
+      free(rformat);
       rformat=createMap("mimeType","image/tiff");
     }
     else{
       proto=1;
+      freeMap(&rformat);
+      free(rformat);
       rformat=createMap("mimeType","text/xml");
     }
   }
-  addToMap(tmpI->content,"Reference",webService_url);
+  setMapArray(tmpI->content,"Reference",imyIndex,webService_url);
   memset(layers,0,128);
   sprintf(layers,options[proto][3],tmpI->name);
   protoVersion=options[proto][1];
-  extent=getMap(tmpI->content,options[proto][4]);
+  extent=getMapArray(tmpI->content,options[proto][4],imyIndex);
   memset(webService_url,0,strlen(webService_url));
   if(proto>0){
@@ -268,8 +330,9 @@
       finalProto=1;
     sprintf(webService_url,
-	    "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
+	    "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
 	    msUrl->value,
 	    dataPath->value,
 	    tmpI->name,
+	    imyIndex,
 	    sid->value,
 	    options[proto][2],
@@ -282,15 +345,16 @@
 	    );
     if(datatype!=NULL && strncasecmp(datatype->value,"raster",6)==0){
-      addToMap(tmpI->content,"ref_wcs_link",webService_url);
+      setMapArray(tmpI->content,"ref_wcs_link",imyIndex,webService_url);
     }
     else{
-      addToMap(tmpI->content,"ref_wfs_link",webService_url);
+      setMapArray(tmpI->content,"ref_wfs_link",imyIndex,webService_url);
     }
   }else{
     sprintf(webService_url,
-	    "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",
+	    "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&width=%s&height=%s&format=%s&bbox=%s&crs=%s",
 	    msUrl->value,
 	    dataPath->value,
 	    tmpI->name,
+	    imyIndex,
 	    sid->value,
 	    options[proto][2],
@@ -304,5 +368,5 @@
 	    crs->value
 	    );
-    addToMap(tmpI->content,"ref_wms_link",webService_url);
+    setMapArray(tmpI->content,"ref_wms_link",imyIndex,webService_url);
   }
   if(finalProto>0){
@@ -311,11 +375,15 @@
     sprintf(layers,options[proto][3],tmpI->name);
     protoVersion=options[proto][1];
-    extent=getMap(tmpI->content,options[proto][4]);
+    extent=getMapArray(tmpI->content,options[proto][4],imyIndex);
     memset(webService_url,0,strlen(webService_url));
+    freeMap(&rformat);
+    free(rformat);
+    rformat=createMap("value","image/tiff");
     sprintf(webService_url,
-	    "%s?map=%s/%s_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
+	    "%s?map=%s/%s_%d_%s.map&request=%s&service=%s&version=%s&%s&format=%s&bbox=%s&crs=%s",
 	    msUrl->value,
 	    dataPath->value,
 	    tmpI->name,
+	    imyIndex,
 	    sid->value,
 	    options[proto][2],
@@ -327,5 +395,5 @@
 	    crs->value
 	    );
-    addToMap(tmpI->content,"ref_wcs_preview_link",webService_url);
+    setMapArray(tmpI->content,"ref_wcs_preview_link",imyIndex,webService_url);
   }
   if(hasCRS==0){
@@ -352,4 +420,5 @@
   OGRSpatialReferenceH  hSRS;
   map* msSrs=NULL;
+  int imyIndex=getPublishedId(output);
   hSRS = OSRNewSpatialReference(NULL);
   if( pszProjection!=NULL && strlen(pszProjection)>1){
@@ -375,8 +444,8 @@
 	if(output!=NULL){
 	  if(OSRIsGeographic(hSRS)==TRUE)
-	    addToMap(output->content,"crs_isGeographic","true");
+	    setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
 	  else
-	    addToMap(output->content,"crs_isGeographic","false");
-	  addToMap(output->content,"crs",tmpSrs);
+	    setMapArray(output->content,"crs_isGeographic",imyIndex,"false");
+	  setMapArray(output->content,"crs",imyIndex,tmpSrs);
 	}
       }
@@ -391,7 +460,7 @@
 	  if(output!=NULL){ 
 	    if(OSRIsGeographic(hSRS)==TRUE)
-	      addToMap(output->content,"crs_isGeographic","true");
+	      setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
 	    else
-	      addToMap(output->content,"crs_isGeographic","false");
+	      setMapArray(output->content,"crs_isGeographic",imyIndex,"false");
 	  }
 	  free(proj4Str);
@@ -401,10 +470,10 @@
 	  msLoadProjectionStringEPSG(&myLayer->projection,"EPSG:4326");
 	  if(output!=NULL){
-	    addToMap(output->content,"crs_isGeographic","true");
+	    setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
 	  }
 	}
 	if(output!=NULL){
-	  addToMap(output->content,"crs","EPSG:4326");
-	  addToMap(output->content,"real_extent","true");
+	  setMapArray(output->content,"crs",imyIndex,"EPSG:4326");
+	  setMapArray(output->content,"real_extent",imyIndex,"true");
 	}
 	msInsertHashTable(&(m->web.metadata),"ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857");
@@ -415,5 +484,5 @@
   else{
     if(output!=NULL){
-      msSrs=getMap(output->content,"msSrs");
+      msSrs=getMapArray(output->content,"msSrs",imyIndex);
     }
     if(msSrs!=NULL){
@@ -431,6 +500,6 @@
     }
     if(output!=NULL){
-      addToMap(output->content,"crs",msSrs->value);
-      addToMap(output->content,"crs_isGeographic","true");
+      setMapArray(output->content,"crs",imyIndex,msSrs->value);
+      setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
     }
   }
@@ -454,4 +523,5 @@
 void setMsExtent(maps* output,mapObj* m,layerObj* myLayer,
 		 double minX,double minY,double maxX,double maxY){
+  int imyIndex=getPublishedId(output);
   msMapSetExtent(m,minX,minY,maxX,maxY);
 #ifdef DEBUGMS
@@ -466,32 +536,40 @@
   
   if(output!=NULL){
-    map* test=getMap(output->content,"real_extent");
+    map* test=getMapArray(output->content,"real_extent",imyIndex);
+    pointObj min, max;
+    projectionObj tempSrs;
+    min.x = m->extent.minx;
+    min.y = m->extent.miny;
+    max.x = m->extent.maxx;
+    max.y = m->extent.maxy;
+    char tmpSrsStr[1024];
+    msInitProjection(&tempSrs);
+    msLoadProjectionStringEPSG(&tempSrs,"EPSG:4326");
+
+    msProjectPoint(&(myLayer->projection),&tempSrs,&min);
+    msProjectPoint(&myLayer->projection,&tempSrs,&max);
+  
     if(test!=NULL){
-      pointObj min, max;
-      projectionObj tempSrs;
-      min.x = m->extent.minx;
-      min.y = m->extent.miny;
-      max.x = m->extent.maxx;
-      max.y = m->extent.maxy;
-      char tmpSrsStr[1024];
-      msInitProjection(&tempSrs);
-      msLoadProjectionStringEPSG(&tempSrs,"EPSG:4326");
-
-      msProjectPoint(&(m->projection),&tempSrs,&min);
-      msProjectPoint(&m->projection,&tempSrs,&max);
-      
       sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",min.y,min.x,max.y,max.x);
-      map* isGeo=getMap(output->content,"crs_isGeographic");
+      map* isGeo=getMapArray(output->content,"crs_isGeographic",imyIndex);
 #ifdef DEBUGMS
       fprintf(stderr,"isGeo = %s\n",isGeo->value);
 #endif
-      if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0)
+      if(isGeo!=NULL && strcasecmp("true",isGeo->value)==0){
+	sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",min.y,min.x,max.y,max.x);
+	setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent);
         sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX);
-      addToMap(output->content,"wms_extent",tmpExtent);
+      }else{
+	sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",min.x,min.y,max.x,max.y);
+	setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent);
+      }
+      setMapArray(output->content,"wms_extent",imyIndex,tmpExtent);
       sprintf(tmpSrsStr,"%.3f,%.3f,%.3f,%.3f",min.x,min.y,max.x,max.y);
-      addToMap(output->content,"wcs_extent",tmpExtent);
+      setMapArray(output->content,"wcs_extent",imyIndex,tmpExtent);
     }else{
+      sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",min.x,min.y,max.x,max.y);
+      setMapArray(output->content,"wgs84_extent",imyIndex,tmpExtent);
       sprintf(tmpExtent,"%f,%f,%f,%f",minX, minY, maxX, maxY);
-      map* isGeo=getMap(output->content,"crs_isGeographic");
+      map* isGeo=getMapArray(output->content,"crs_isGeographic",imyIndex);
       if(isGeo!=NULL){
 #ifdef DEBUGMS
@@ -501,7 +579,7 @@
 	  sprintf(tmpExtent,"%f,%f,%f,%f", minY,minX, maxY, maxX);
       }
-      addToMap(output->content,"wms_extent",tmpExtent); 
+      setMapArray(output->content,"wms_extent",imyIndex,tmpExtent); 
       sprintf(tmpExtent,"%.3f,%.3f,%.3f,%.3f",minX,minY,maxX,maxY);
-      addToMap(output->content,"wcs_extent",tmpExtent);
+      setMapArray(output->content,"wcs_extent",imyIndex,tmpExtent);
     }
   }
@@ -518,6 +596,6 @@
  */
 int tryOgr(maps* conf,maps* output,mapObj* m){
-
-  map* tmpMap=getMap(output->content,"storage");
+  int imyIndex=getPublishedId(output);
+  map* tmpMap=getMapArray(output->content,"storage",imyIndex);
   char *pszDataSource=tmpMap->value;
 
@@ -643,6 +721,4 @@
 #endif
     setMapInMaps(conf,"lenv","message","Unable to open datasource in read only mode");
-    //OGR_DS_Destroy(poDS);
-    //OGRCleanupAll();
 #ifdef DEBUGMS
     fprintf(stderr,"Unable to access the DataSource, exit! \n"); 
@@ -651,5 +727,5 @@
   }
 
-  addToMap(output->content,"geodatatype","vector");
+  setMapArray(output->content,"geodatatype",imyIndex,"vector");
   int iLayer = 0;
   for( iLayer=0; iLayer < OGR_DS_GetLayerCount(poDS); iLayer++ ){
@@ -687,5 +763,5 @@
     msConnectLayer(myLayer,MS_OGR,pszDataSource);
 
-    addIntToMap(output->content,"nb_features",OGR_L_GetFeatureCount(poLayer,1));
+    addIntToMapArray(output->content,"nb_features",imyIndex,OGR_L_GetFeatureCount(poLayer,1));
 
     /**
@@ -739,6 +815,6 @@
     }
     else{
-      addToMap(output->content,"crs","EPSG:4326");
-      addToMap(output->content,"crs_isGeographic","true");
+      setMapArray(output->content,"crs",imyIndex,"EPSG:4326");
+      setMapArray(output->content,"crs_isGeographic",imyIndex,"true");
       msLoadProjectionStringEPSG(&m->projection,"EPSG:4326");
       msInsertHashTable(&(m->web.metadata), "ows_srs", "EPSG:4326 EPSG:900913 EPSG:3857");
@@ -752,5 +828,5 @@
       memset(&extent,0,1024);
       sprintf(extent,"%d,%d,%d,%d",oExt.MinX, oExt.MinY, oExt.MaxX, oExt.MaxY);
-      addToMap(output->content,"boundingbox",extent);
+      setMapArray(output->content,"boundingbox",imyIndex,extent);
     }
   
@@ -771,5 +847,5 @@
     msInsertHashTable(&(myLayer->metadata), "gml_include_items", "all");
     msInsertHashTable(&(myLayer->metadata), "ows_name", output->name);
-    map* tmpMap=getMap(output->content,"title");
+    map* tmpMap=getMapArray(output->content,"title",imyIndex);
     if(tmpMap!=NULL)
       msInsertHashTable(&(myLayer->metadata), "ows_title", tmpMap->value);
@@ -839,5 +915,6 @@
  */
 int tryGdal(maps* conf,maps* output,mapObj* m){
-  map* tmpMap=getMap(output->content,"storage");
+  int imyIndex=getPublishedId(output);
+  map* tmpMap=getMapArray(output->content,"storage",imyIndex);
   char *pszFilename=tmpMap->value;
   GDALDatasetH hDataset;
@@ -855,5 +932,5 @@
     fprintf(stderr,"Unable to access the DataSource %s \n",pszFilename);
 #endif
-    addToMap(output->content,"geodatatype","other");
+    setMapArray(output->content,"geodatatype",imyIndex,"other");
     setMapInMaps(conf,"lenv","message","gdalinfo failed - unable to open");
     GDALDestroyDriverManager();
@@ -864,5 +941,5 @@
 #endif
 
-  addToMap(output->content,"geodatatype","raster");
+  setMapArray(output->content,"geodatatype",imyIndex,"raster");
   /**
    * Add a new layer set name, data
@@ -886,9 +963,9 @@
 
   char *title=output->name;
-  tmpMap=getMap(output->content,"title");
+  tmpMap=getMapArray(output->content,"title",imyIndex);
   if(tmpMap!=NULL)
     title=tmpMap->value;
   char *abstract=output->name;
-  tmpMap=getMap(output->content,"abstract");
+  tmpMap=getMapArray(output->content,"abstract",imyIndex);
   if(tmpMap!=NULL)
     abstract=tmpMap->value;
@@ -905,5 +982,5 @@
   m->width=GDALGetRasterXSize( hDataset );
   m->height=GDALGetRasterYSize( hDataset );
-  addIntToMap(output->content,"nb_pixels",GDALGetRasterXSize( hDataset )*GDALGetRasterYSize( hDataset ));
+  addIntToMapArray(output->content,"nb_pixels",imyIndex,GDALGetRasterXSize( hDataset )*GDALGetRasterYSize( hDataset ));
   
   /**
@@ -947,14 +1024,14 @@
       memset(&extent,0,1024);
       sprintf(extent,"%d,%d,%d,%d",minX,minY,maxX,maxY);
-      addToMap(output->content,"boundingbox",extent);
+      setMapArray(output->content,"boundingbox",imyIndex,extent);
     }
   }else{
     int scale=1;
     if(m->width>2048){
-      addIntToMap(output->content,"width",2048);
+      addIntToMapArray(output->content,"width",imyIndex,2048);
       scale=2048/m->width;
     }else
-      addIntToMap(output->content,"width",m->width);
-    addIntToMap(output->content,"height",m->height*scale);
+      addIntToMapArray(output->content,"width",imyIndex,m->width);
+    addIntToMapArray(output->content,"height",imyIndex,m->height*scale);
   }
 
@@ -1130,5 +1207,6 @@
    * First store the value on disk
    */
-  map* mime=getMap(outputs->content,"mimeType");
+  int imyIndex=getPublishedId(outputs);
+  map* mime=getMapArray(outputs->content,"mimeType",imyIndex);
   char *ext="data";
   if(mime!=NULL)
@@ -1136,17 +1214,17 @@
       ext="json";
 
-  map* storage=getMap(outputs->content,"storage");
+  map* storage=getMapArray(outputs->content,"storage",imyIndex);
   if(storage==NULL){
     map* tmpMap=getMapFromMaps(conf,"main","dataPath");
     map* sidMap=getMapFromMaps(conf,"lenv","usid");
     char *pszDataSource=(char*)malloc((strlen(tmpMap->value)+strlen(sidMap->value)+strlen(outputs->name)+17)*sizeof(char));
-    sprintf(pszDataSource,"%s/ZOO_DATA_%s_%s.%s",tmpMap->value,outputs->name,sidMap->value,ext);
+    sprintf(pszDataSource,"%s/ZOO_DATA_%d_%s_%s.%s",tmpMap->value,imyIndex,outputs->name,sidMap->value,ext);
     int f=zOpen(pszDataSource,O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
-    map *gfile=getMap(outputs->content,"generated_file");
+    map *gfile=getMapArray(outputs->content,"generated_file",imyIndex);
     if(gfile!=NULL){
       readGeneratedFile(conf,outputs->content,gfile->value);	    
     }
-    map* sizeMap=getMap(outputs->content,"size");
-    map* vData=getMap(outputs->content,"value");
+    map* sizeMap=getMapArray(outputs->content,"size",imyIndex);
+    map* vData=getMapArray(outputs->content,"value",imyIndex);
     if(sizeMap!=NULL){
       zWrite(f,vData->value,atoi(sizeMap->value)*sizeof(char));
@@ -1156,5 +1234,5 @@
     }
     close(f);
-    addToMap(outputs->content,"storage",pszDataSource);
+    setMapArray(outputs->content,"storage",imyIndex,pszDataSource);
     free(pszDataSource);
   }
@@ -1327,6 +1405,6 @@
   map* sid=getMapFromMaps(conf,"lenv","usid");
   char *mapPath=
-    (char*)malloc((7+strlen(sid->value)+strlen(outputs->name)+strlen(tmp1->value))*sizeof(char));
-  sprintf(mapPath,"%s/%s_%s.map",tmp1->value,outputs->name,sid->value);
+    (char*)malloc((14+strlen(sid->value)+strlen(outputs->name)+strlen(tmp1->value))*sizeof(char));
+  sprintf(mapPath,"%s/%s_%d_%s.map",tmp1->value,outputs->name,imyIndex,sid->value);
   msSaveMap(myMap,mapPath);
   free(mapPath);
