Changeset 2435

Show
Ignore:
Timestamp:
10/06/03 09:03:19 (5 years ago)
Author:
assefa
Message:

Use of namespace. Correct execption return.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/mapserver/mapgml.c

    r2410 r2435  
    429429*/ 
    430430 
    431 int msGMLWriteWFSQuery(mapObj *map, FILE *stream, int maxfeatures) 
     431int msGMLWriteWFSQuery(mapObj *map, FILE *stream, int maxfeatures,  
     432                       char *namespace) 
    432433{ 
    433434  int status; 
     
    463464      if(status != MS_SUCCESS) return(status); 
    464465 
    465       // retrieve all the item names 
    466       status = msLayerGetItems(lp); 
    467       if(status != MS_SUCCESS) return(status); 
     466      // retrieve all the item names. (Note : there might be no attributs) 
     467      //status = msLayerGetItems(lp); 
     468      //if(status != MS_SUCCESS) return(status); 
    468469 
    469470      for(j=0; j<lp->resultcache->numresults; j++)  
     
    482483        // start this feature 
    483484        fprintf(stream, "    <gml:featureMember>\n"); 
    484         fprintf(stream, "      <%s>\n", lp->name); 
     485        if (namespace) 
     486          fprintf(stream, "      <%s:%s>\n", namespace,lp->name); 
     487 
     488        else 
     489           fprintf(stream, "      <%s>\n", lp->name); 
    485490 
    486491        // write the bounding box 
     
    494499#endif 
    495500 
    496         fprintf(stream, "        <%s>\n", geom_name);  
     501        fprintf(stream, "        <gml:%s>\n", geom_name);  
    497502 
    498503        // write the feature geometry 
     
    506511#endif 
    507512 
    508         fprintf(stream, "        </%s>\n", geom_name);  
     513        fprintf(stream, "        </gml:%s>\n", geom_name);  
    509514 
    510515        // write the item/values 
     
    513518          char *encoded_val; 
    514519          encoded_val = msEncodeHTMLEntities(shape.values[k]); 
    515           fprintf(stream, "        <%s>%s</%s>\n",  
    516                   lp->items[k], encoded_val, lp->items[k]); 
     520          
     521          if (namespace) 
     522            fprintf(stream, "        <%s:%s>%s</%s:%s>\n",  
     523                    namespace, lp->items[k], encoded_val, namespace, lp->items[k]); 
     524          else       
     525            fprintf(stream, "        <%s>%s</%s>\n",  
     526                    lp->items[k], encoded_val, lp->items[k]); 
    517527          free(encoded_val); 
    518528        } 
    519529 
    520530        // end this feature 
    521         fprintf(stream, "      </%s>\n", lp->name); 
     531         if (namespace) 
     532           fprintf(stream, "      </%s:%s>\n", namespace, lp->name); 
     533         else 
     534           fprintf(stream, "      </%s>\n", lp->name); 
     535 
    522536        fprintf(stream, "    </gml:featureMember>\n"); 
    523537 
  • trunk/mapserver/mapows.h

    r2386 r2435  
    66 ********************************************************************** 
    77 * $Log$ 
     8 * Revision 1.18  2003/10/06 13:03:19  assefa 
     9 * Use of namespace. Correct execption return. 
     10 * 
    811 * Revision 1.17  2003/09/19 21:54:19  assefa 
    912 * Add support fot the Post request. 
     
    177180 
    178181#ifdef USE_WFS_SVR 
    179 int msGMLWriteWFSQuery(mapObj *map, FILE *stream, int maxfeatures); 
     182int msGMLWriteWFSQuery(mapObj *map, FILE *stream, int maxfeatures, char *); 
    180183#endif 
    181184 
  • trunk/mapserver/mapwfs.c

    r2424 r2435  
    3030 ********************************************************************** 
    3131 * $Log$ 
     32 * Revision 1.24  2003/10/06 13:03:19  assefa 
     33 * Use of namespace. Correct execption return. 
     34 * 
    3235 * Revision 1.23  2003/09/30 15:56:40  assefa 
    3336 * Typenames may have namespaces. 
     
    125128    printf("Content-type: text/xml%c%c",10,10); 
    126129 
    127     printf("<WFS_Exception>\n"); 
    128     printf("  <Exception>\n"); 
     130    printf("<ServiceExceptionReport\n"); 
     131    printf("xmlns=\"http://www.opengis.net/ogc\" "); 
     132    printf("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "); 
     133    printf("xsi:schemaLocation=\"http://www.opengis.net/ogc http://ogc.dmsolutions.ca/wfs/1.0/OGC-exception.xsd\">\n"); 
     134    printf("  <ServiceException>\n"); 
    129135    /* Optional <Locator> element currently unused. */ 
    130     printf("    <Message>\n"); 
    131     msWriteError(stdout); 
    132     printf("    </Message>\n"); 
    133     printf("  </Exception>\n"); 
    134     printf("</WFS_Exception>\n"); 
     136    //printf("    <Message>\n"); 
     137    msWriteErrorXML(stdout); 
     138    //printf("    </Message>\n"); 
     139    printf("  </ServiceException>\n"); 
     140    printf("</ServiceExceptionReport>\n"); 
    135141 
    136142    return MS_FAILURE; // so we can call 'return msWFSException();' anywhere 
     
    213219const char *msWFSGetGeomElementName(mapObj *map, layerObj *lp) 
    214220{ 
    215     const char *name; 
    216  
    217     if ((name = msLookupHashTable(lp->metadata,  
    218                                   "wfs_geometry_element_name")) == NULL && 
    219         (name = msLookupHashTable(map->web.metadata,  
    220                                   "wfs_geometry_element_name")) == NULL ) 
    221     { 
    222         name = "MS_GEOMETRY"; 
    223     } 
    224  
    225     return name; 
     221    switch(lp->type) 
     222    { 
     223        case MS_LAYER_POINT: 
     224          return "pointProperty"; 
     225        case MS_LAYER_LINE: 
     226          return "lineStringProperty"; 
     227        case MS_LAYER_POLYGON: 
     228          return "polygonProperty"; 
     229        default: 
     230          break; 
     231    } 
     232 
     233    return "???unknown???"; 
    226234 
    227235} 
     
    475483    char **layers = NULL; 
    476484    const char *myns_uri = NULL; 
    477  
     485    char **tokens; 
     486    int n=0; 
     487    char *pszNameSpace = strdup("myns"); 
    478488 
    479489    if(paramsObj->pszTypeName && numlayers == 0)  
     
    484494        // 
    485495        layers = split(paramsObj->pszTypeName, ',', &numlayers); 
     496        if (numlayers > 0) 
     497        { 
     498            //strip namespace if there is one :ex TYPENAME=cdf:Other 
     499            tokens = split(layers[0], ':', &n); 
     500            if (tokens && n==2 && msGetLayerIndex(map, layers[0]) < 0) 
     501            { 
     502                pszNameSpace = strdup(tokens[0]); 
     503                msFreeCharArray(tokens, n); 
     504                for (i=0; i<numlayers; i++) 
     505                { 
     506                    tokens = split(layers[i], ':', &n); 
     507                    if (tokens && n==2) 
     508                    { 
     509                        free(layers[i]); 
     510                        layers[i] = strdup(tokens[1]); 
     511                    } 
     512                    if (tokens) 
     513                      msFreeCharArray(tokens, n); 
     514                } 
     515            } 
     516        } 
    486517    }  
    487518    if (paramsObj->pszOutputFormat) 
     
    498529    } 
    499530 
    500      
    501  
     531    //Validate layers 
     532    if (numlayers > 0) 
     533    { 
     534        for (i=0; i<numlayers; i++) 
     535        { 
     536            if (msGetLayerIndex(map, layers[i]) < 0) 
     537            { 
     538                msSetError(MS_WFSERR,  
     539                       "Invalid typename (%s).",  
     540                       "msWFSDescribeFeatureType()", paramsObj->pszTypeName); 
     541                return msWFSException(map, paramsObj->pszVersion); 
     542            } 
     543        } 
     544    } 
     545             
    502546    /* 
    503547    ** DescribeFeatureType response 
     
    515559    printf("<schema\n" 
    516560           "   targetNamespace=\"%s\" \n" 
    517            "   xmlns:myns=\"%s\" \n" 
     561           "   xmlns:%s=\"%s\" \n" 
     562           "   xmlns:ogc=\"http://www.opengis.net/ogc\"\n" 
    518563           "   xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" 
    519564           "   xmlns=\"http://www.w3.org/2001/XMLSchema\"\n" 
    520565           "   xmlns:gml=\"http://www.opengis.net/gml\"\n" 
    521566           "   elementFormDefault=\"qualified\" version=\"0.1\" >\n",  
    522            myns_uri, myns_uri ); 
     567           myns_uri, pszNameSpace, myns_uri ); 
    523568 
    524569    printf("\n" 
    525570           "  <import namespace=\"http://www.opengis.net/gml\" \n" 
    526            "          schemaLocation=\"%s/gml/2.1/feature.xsd\" />\n", 
     571           "          schemaLocation=\"%s/gml/2.1.1/feature.xsd\" />\n", 
    527572           msOWSGetSchemasLocation(map)); 
    528573 
     
    553598            printf("\n" 
    554599                   "  <element name=\"%s\" \n" 
    555                    "           type=\"myns:%s_Type\" \n" 
     600                   "           type=\"%s:%s_Type\" \n" 
    556601                   "           substitutionGroup=\"gml:_Feature\" />\n\n", 
    557                    lp->name, lp->name); 
     602                   lp->name, pszNameSpace, lp->name); 
    558603 
    559604            printf("  <complexType name=\"%s_Type\">\n", lp->name); 
     
    562607            printf("        <sequence>\n"); 
    563608 
    564             printf("          <element name=\"%s\" \n" 
    565                    "                   type=\"gml:%s\" \n" 
    566                    "                   nillable=\"false\" />\n", 
    567                    msWFSGetGeomElementName(map, lp), 
    568                    msWFSGetGeomType(lp) ); 
     609            printf("          <element ref=\"gml:%s\" minOccurs=\"0\" />\n", 
     610                   msWFSGetGeomElementName(map, lp)); 
     611 
    569612 
    570613            if (msLayerOpen(lp) == MS_SUCCESS) 
     
    601644    if (layers) 
    602645        msFreeCharArray(layers, numlayers); 
     646 
     647    if (pszNameSpace) 
     648      free(pszNameSpace); 
    603649 
    604650    return MS_SUCCESS; 
     
    624670    int bFilterSet = 0; 
    625671    int bBBOXSet = 0; 
    626     
     672    char *pszNameSpace = strdup("myns"); 
    627673     
    628674    // Default filter is map extents 
     
    650696        layers = split(typename, ',', &numlayers); 
    651697/* ==================================================================== */ 
    652 /*      check if the typename contains name spaces (ex cdf:Other),      */ 
     698/*      check if the typename contains namespaces (ex cdf:Other),       */ 
    653699/*      If that is the case extarct only the layer name.                */ 
    654700/* ==================================================================== */ 
     
    662708        } 
    663709        tokens = split(layers[0], ':', &n); 
    664         if (tokens && n==2) 
    665         { 
     710        if (tokens && n==2 && msGetLayerIndex(map, layers[0]) < 0) 
     711        { 
     712            pszNameSpace = strdup(tokens[0]); 
    666713            msFreeCharArray(tokens, n); 
    667714            for (i=0; i<numlayers; i++) 
     
    741788        } 
    742789    } 
    743      
     790    //Validate outputformat 
     791    if (paramsObj->pszOutputFormat) 
     792    { 
     793        /* We support only GML2 for now. 
     794         */ 
     795        if (strcasecmp(paramsObj->pszOutputFormat, "GML2") != 0) 
     796        { 
     797            msSetError(MS_WFSERR,  
     798                       "Unsupported GetFeature outputFormat (%s). Only GML2 is supported.",  
     799                       "msWFSDescribeFeatureType()", paramsObj->pszOutputFormat); 
     800            return msWFSException(map, paramsObj->pszVersion); 
     801        } 
     802    } 
    744803    //else if (strcasecmp(names[i], "PROPERTYNAME") == 0) 
    745804    //{ 
     
    10421101    printf("<wfs:FeatureCollection\n" 
    10431102           "   xmlns=\"%s\"\n" 
    1044            "   xmlns:myns=\"%s\"\n" 
     1103           "   xmlns:%s=\"%s\"\n" 
    10451104           "   xmlns:wfs=\"http://www.opengis.net/wfs\"\n" 
    10461105           "   xmlns:gml=\"http://www.opengis.net/gml\"\n" 
     1106           "   xmlns:ogc=\"http://www.opengis.net/ogc\"\n" 
    10471107           "   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" 
    10481108           "   xsi:schemaLocation=\"http://www.opengis.net/wfs %s/wfs/%s/WFS-basic.xsd \n" 
    1049            "                       %s %sSERVICE=WFS&amp;VERSION=%s&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=%s\">\n",  
    1050            myns_uri, myns_uri, 
    1051            msOWSGetSchemasLocation(map), paramsObj->pszVersion,  
     1109           "                       %s %sSERVICE=WFS&amp;VERSION=%s&amp;REQUEST=DescribeFeatureType&amp;TYP\ 
     1110ENAME=%s\">\n", 
     1111           myns_uri, pszNameSpace, myns_uri, 
     1112           msOWSGetSchemasLocation(map), paramsObj->pszVersion, 
    10521113           myns_uri, script_url_encoded, paramsObj->pszVersion, typename); 
    10531114 
     
    10561117    **          contain mixed geometry types... how to deal with that??? 
    10571118    */ 
    1058     msGMLWriteWFSQuery(map, stdout, maxfeatures); 
     1119    msGMLWriteWFSQuery(map, stdout, maxfeatures, pszNameSpace); 
     1120     
    10591121 
    10601122    /* 
     
    10651127    free(script_url); 
    10661128    free(script_url_encoded); 
     1129    if (pszNameSpace) 
     1130      free(pszNameSpace); 
    10671131 
    10681132    return MS_SUCCESS; 
     
    12631327                else if (strcasecmp(request->ParamNames[i], "FILTER") == 0) 
    12641328                  wfsparams->pszFilter = strdup(request->ParamValues[i]); 
     1329                 
     1330                else if (strcasecmp(request->ParamNames[i], "OUTPUTFORMAT") == 0) 
     1331                  wfsparams->pszOutputFormat = strdup(request->ParamValues[i]); 
    12651332            } 
    12661333        } 
     
    14751542                wfsparams->pszRequest = strdup("DescribeFeatureType"); 
    14761543 
    1477                 pszValue = (char*)CPLGetXMLValue(psGetFeature, "version", NULL); 
     1544                pszValue = (char*)CPLGetXMLValue(psDescribeFeature, "version",  
     1545                                                 NULL); 
    14781546                if (pszValue) 
    14791547                  wfsparams->pszVersion = strdup(pszValue); 
    14801548 
    1481                 pszValue = (char*)CPLGetXMLValue(psGetFeature, "service", NULL); 
     1549                pszValue = (char*)CPLGetXMLValue(psDescribeFeature, "service",  
     1550                                                 NULL); 
    14821551                if (pszValue) 
    14831552                  wfsparams->pszService = strdup(pszValue); 
    14841553 
    1485                 pszValue = (char*)CPLGetXMLValue(psGetFeature, "outputFormat",  
     1554                pszValue = (char*)CPLGetXMLValue(psDescribeFeature,  
     1555                                                 "outputFormat",  
    14861556                                                 NULL); 
    14871557                if (pszValue) 
    14881558                  wfsparams->pszOutputFormat = strdup(pszValue); 
    14891559 
    1490                 psTypeName = CPLGetXMLNode(psGetFeature, "TypeName"); 
     1560                psTypeName = CPLGetXMLNode(psDescribeFeature, "TypeName"); 
    14911561                if (psTypeName) 
    14921562                {