void parseDimensions(mapcache_context *ctx, ezxml_t node, mapcache_tileset *tileset) {
   ezxml_t dimension_node;
   apr_array_header_t *dimensions = apr_array_make(ctx->pool,1,sizeof(mapcache_dimension*));
   for(dimension_node = ezxml_child(node,"dimension"); dimension_node; dimension_node = dimension_node->next) {
      char *name = (char*)ezxml_attr(dimension_node,"name");
      char *type = (char*)ezxml_attr(dimension_node,"type");
      char *unit = (char*)ezxml_attr(dimension_node,"unit");
      char *default_value = (char*)ezxml_attr(dimension_node,"default");
      
      mapcache_dimension *dimension = NULL;
      
      if(!name || !strlen(name)) {
         ctx->set_error(ctx, 400, "mandatory attribute \"name\" not found in <dimension>");
         return;
      }

      if(type && *type) {
         if(!strcmp(type,"values")) {
            dimension = mapcache_dimension_values_create(ctx->pool);
         } else if(!strcmp(type,"regex")) {
            dimension = mapcache_dimension_regex_create(ctx->pool);
         } else if(!strcmp(type,"intervals")) {
            dimension = mapcache_dimension_intervals_create(ctx->pool);
         } else if(!strcmp(type,"time")) {
            ctx->set_error(ctx,501,"time dimension type not implemented yet");
            return;
            dimension = mapcache_dimension_time_create(ctx->pool);
         } else {
            ctx->set_error(ctx,400,"unknown dimension type \"%s\"",type);
            return;
         }
      } else {
         ctx->set_error(ctx,400, "mandatory attribute \"type\" not found in <dimensions>");
         return;
      }

      dimension->name = apr_pstrdup(ctx->pool,name);

      if(unit && *unit) {
         dimension->unit = apr_pstrdup(ctx->pool,unit);
      }

      if(default_value && *default_value) {
         dimension->default_value = apr_pstrdup(ctx->pool,default_value);
      } else {
         ctx->set_error(ctx,400,"dimension \"%s\" has no \"default\" attribute",dimension->name);
         return;
      }

      dimension->configuration_parse_xml(ctx,dimension,dimension_node);
      GC_CHECK_ERROR(ctx);

      APR_ARRAY_PUSH(dimensions,mapcache_dimension*) = dimension;
   }
   if(apr_is_empty_array(dimensions)) {
      ctx->set_error(ctx, 400, "<dimensions> for tileset \"%s\" has no dimensions defined (expecting <dimension> children)",tileset->name);
      return;
   }
   tileset->dimensions = dimensions;
}
예제 #2
0
void parseDimensions(mapcache_context *ctx, ezxml_t node, mapcache_tileset *tileset)
{
  ezxml_t dimension_node;
  apr_array_header_t *dimensions = apr_array_make(ctx->pool,1,sizeof(mapcache_dimension*));
  for(dimension_node = ezxml_child(node,"dimension"); dimension_node; dimension_node = dimension_node->next) {
    char *name = (char*)ezxml_attr(dimension_node,"name");
    char *type = (char*)ezxml_attr(dimension_node,"type");
    char *unit = (char*)ezxml_attr(dimension_node,"unit");
    char *default_value = (char*)ezxml_attr(dimension_node,"default");

    mapcache_dimension *dimension = NULL;

    if(!name || !strlen(name)) {
      ctx->set_error(ctx, 400, "mandatory attribute \"name\" not found in <dimension>");
      return;
    }

    if(type && *type) {
      if(!strcmp(type,"values")) {
        dimension = mapcache_dimension_values_create(ctx,ctx->pool);
      } else if(!strcmp(type,"regex")) {
        dimension = mapcache_dimension_regex_create(ctx,ctx->pool);
      } else if(!strcmp(type,"sqlite")) {
        dimension = mapcache_dimension_sqlite_create(ctx,ctx->pool);
      } else if(!strcmp(type,"time")) {
        dimension = mapcache_dimension_time_create(ctx,ctx->pool);
      } else {
        ctx->set_error(ctx,400,"unknown dimension type \"%s\"",type);
        return;
      }
    } else {
      ctx->set_error(ctx,400, "mandatory attribute \"type\" not found in <dimensions>");
      return;
    }
    GC_CHECK_ERROR(ctx);

    dimension->name = apr_pstrdup(ctx->pool,name);

    if(unit && *unit) {
      dimension->unit = apr_pstrdup(ctx->pool,unit);
    }
    
    if(default_value && *default_value) {
      dimension->default_value = apr_pstrdup(ctx->pool,default_value);
    } else {
      ctx->set_error(ctx,400,"dimension \"%s\" has no \"default\" attribute",dimension->name);
      return;
    }
    

    dimension->configuration_parse_xml(ctx,dimension,dimension_node);
    GC_CHECK_ERROR(ctx);

    APR_ARRAY_PUSH(dimensions,mapcache_dimension*) = dimension;
  }
  if(apr_is_empty_array(dimensions)) {
    ctx->set_error(ctx, 400, "<dimensions> for tileset \"%s\" has no dimensions defined (expecting <dimension> children)",tileset->name);
    return;
  }
  
  tileset->dimensions = dimensions;
  dimension_node = ezxml_child(node,"store_assemblies");
  if(dimension_node && dimension_node->txt) {
    if(!strcmp(dimension_node->txt,"false")) {
      tileset->store_dimension_assemblies = 0;
    } else if(strcmp(dimension_node->txt,"true")) {
      ctx->set_error(ctx,400,"failed to parse <store_assemblies> (%s), expecting \"true\" or \"false\"",dimension_node->txt);
      return;
    }
  }
  
  dimension_node = ezxml_child(node,"assembly_type");
  if(dimension_node) {
    if(!strcmp(dimension_node->txt,"stack")) {
      tileset->dimension_assembly_type = MAPCACHE_DIMENSION_ASSEMBLY_STACK;
    } else if(!strcmp(dimension_node->txt,"animate")) {
      tileset->dimension_assembly_type = MAPCACHE_DIMENSION_ASSEMBLY_ANIMATE;
      ctx->set_error(ctx,400,"animate dimension assembly mode not implemented");
      return;
    } else if(strcmp(dimension_node->txt,"none")) {
      ctx->set_error(ctx,400,"unknown dimension assembly mode (%s). Can be one of \"stack\" or \"none\"",dimension_node->txt);
      return;
    } else {
      tileset->dimension_assembly_type = MAPCACHE_DIMENSION_ASSEMBLY_NONE;
    }
  }
  
  /* should we create subdimensions from source if not found in cache.
  e.g. if dimension=mosaic returns dimension=val1,val2,val3 should we 
  query the wms source with dimension=val1 , dimension=val2 and/or
  dimension=val3 if they are not found in cache */
  dimension_node = ezxml_child(node,"subdimensions_read_only");
  if(dimension_node) {
    if(tileset->dimension_assembly_type == MAPCACHE_DIMENSION_ASSEMBLY_NONE) {
      ctx->set_error(ctx,400,"<subdimensions_read_only> used on a tileset with no <assembly_type> set, which makes no sense");
      return;
    }
    if(dimension_node && dimension_node->txt && !strcmp(dimension_node->txt,"true")) {
      tileset->subdimension_read_only = 1;
    } else if(strcmp(dimension_node->txt,"false")) {
      ctx->set_error(ctx,400,"failed to parse <subdimensions_read_only> (%s), expecting \"true\" or \"false\"",dimension_node->txt);
      return;
    }
  }
}