Changeset 2435
- Timestamp:
- 10/06/03 09:03:19 (5 years ago)
- Files:
-
- trunk/mapserver/mapgml.c (modified) (6 diffs)
- trunk/mapserver/mapows.h (modified) (2 diffs)
- trunk/mapserver/mapwfs.c (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/mapserver/mapgml.c
r2410 r2435 429 429 */ 430 430 431 int msGMLWriteWFSQuery(mapObj *map, FILE *stream, int maxfeatures) 431 int msGMLWriteWFSQuery(mapObj *map, FILE *stream, int maxfeatures, 432 char *namespace) 432 433 { 433 434 int status; … … 463 464 if(status != MS_SUCCESS) return(status); 464 465 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); 468 469 469 470 for(j=0; j<lp->resultcache->numresults; j++) … … 482 483 // start this feature 483 484 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); 485 490 486 491 // write the bounding box … … 494 499 #endif 495 500 496 fprintf(stream, " < %s>\n", geom_name);501 fprintf(stream, " <gml:%s>\n", geom_name); 497 502 498 503 // write the feature geometry … … 506 511 #endif 507 512 508 fprintf(stream, " </ %s>\n", geom_name);513 fprintf(stream, " </gml:%s>\n", geom_name); 509 514 510 515 // write the item/values … … 513 518 char *encoded_val; 514 519 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]); 517 527 free(encoded_val); 518 528 } 519 529 520 530 // 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 522 536 fprintf(stream, " </gml:featureMember>\n"); 523 537 trunk/mapserver/mapows.h
r2386 r2435 6 6 ********************************************************************** 7 7 * $Log$ 8 * Revision 1.18 2003/10/06 13:03:19 assefa 9 * Use of namespace. Correct execption return. 10 * 8 11 * Revision 1.17 2003/09/19 21:54:19 assefa 9 12 * Add support fot the Post request. … … 177 180 178 181 #ifdef USE_WFS_SVR 179 int msGMLWriteWFSQuery(mapObj *map, FILE *stream, int maxfeatures );182 int msGMLWriteWFSQuery(mapObj *map, FILE *stream, int maxfeatures, char *); 180 183 #endif 181 184 trunk/mapserver/mapwfs.c
r2424 r2435 30 30 ********************************************************************** 31 31 * $Log$ 32 * Revision 1.24 2003/10/06 13:03:19 assefa 33 * Use of namespace. Correct execption return. 34 * 32 35 * Revision 1.23 2003/09/30 15:56:40 assefa 33 36 * Typenames may have namespaces. … … 125 128 printf("Content-type: text/xml%c%c",10,10); 126 129 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"); 129 135 /* 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"); 135 141 136 142 return MS_FAILURE; // so we can call 'return msWFSException();' anywhere … … 213 219 const char *msWFSGetGeomElementName(mapObj *map, layerObj *lp) 214 220 { 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???"; 226 234 227 235 } … … 475 483 char **layers = NULL; 476 484 const char *myns_uri = NULL; 477 485 char **tokens; 486 int n=0; 487 char *pszNameSpace = strdup("myns"); 478 488 479 489 if(paramsObj->pszTypeName && numlayers == 0) … … 484 494 // 485 495 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 } 486 517 } 487 518 if (paramsObj->pszOutputFormat) … … 498 529 } 499 530 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 502 546 /* 503 547 ** DescribeFeatureType response … … 515 559 printf("<schema\n" 516 560 " targetNamespace=\"%s\" \n" 517 " xmlns:myns=\"%s\" \n" 561 " xmlns:%s=\"%s\" \n" 562 " xmlns:ogc=\"http://www.opengis.net/ogc\"\n" 518 563 " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" 519 564 " xmlns=\"http://www.w3.org/2001/XMLSchema\"\n" 520 565 " xmlns:gml=\"http://www.opengis.net/gml\"\n" 521 566 " elementFormDefault=\"qualified\" version=\"0.1\" >\n", 522 myns_uri, myns_uri );567 myns_uri, pszNameSpace, myns_uri ); 523 568 524 569 printf("\n" 525 570 " <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", 527 572 msOWSGetSchemasLocation(map)); 528 573 … … 553 598 printf("\n" 554 599 " <element name=\"%s\" \n" 555 " type=\" myns:%s_Type\" \n"600 " type=\"%s:%s_Type\" \n" 556 601 " substitutionGroup=\"gml:_Feature\" />\n\n", 557 lp->name, lp->name);602 lp->name, pszNameSpace, lp->name); 558 603 559 604 printf(" <complexType name=\"%s_Type\">\n", lp->name); … … 562 607 printf(" <sequence>\n"); 563 608 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 569 612 570 613 if (msLayerOpen(lp) == MS_SUCCESS) … … 601 644 if (layers) 602 645 msFreeCharArray(layers, numlayers); 646 647 if (pszNameSpace) 648 free(pszNameSpace); 603 649 604 650 return MS_SUCCESS; … … 624 670 int bFilterSet = 0; 625 671 int bBBOXSet = 0; 626 672 char *pszNameSpace = strdup("myns"); 627 673 628 674 // Default filter is map extents … … 650 696 layers = split(typename, ',', &numlayers); 651 697 /* ==================================================================== */ 652 /* check if the typename contains name spaces (ex cdf:Other),*/698 /* check if the typename contains namespaces (ex cdf:Other), */ 653 699 /* If that is the case extarct only the layer name. */ 654 700 /* ==================================================================== */ … … 662 708 } 663 709 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]); 666 713 msFreeCharArray(tokens, n); 667 714 for (i=0; i<numlayers; i++) … … 741 788 } 742 789 } 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 } 744 803 //else if (strcasecmp(names[i], "PROPERTYNAME") == 0) 745 804 //{ … … 1042 1101 printf("<wfs:FeatureCollection\n" 1043 1102 " xmlns=\"%s\"\n" 1044 " xmlns: myns=\"%s\"\n"1103 " xmlns:%s=\"%s\"\n" 1045 1104 " xmlns:wfs=\"http://www.opengis.net/wfs\"\n" 1046 1105 " xmlns:gml=\"http://www.opengis.net/gml\"\n" 1106 " xmlns:ogc=\"http://www.opengis.net/ogc\"\n" 1047 1107 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" 1048 1108 " xsi:schemaLocation=\"http://www.opengis.net/wfs %s/wfs/%s/WFS-basic.xsd \n" 1049 " %s %sSERVICE=WFS&VERSION=%s&REQUEST=DescribeFeatureType&TYPENAME=%s\">\n", 1050 myns_uri, myns_uri, 1051 msOWSGetSchemasLocation(map), paramsObj->pszVersion, 1109 " %s %sSERVICE=WFS&VERSION=%s&REQUEST=DescribeFeatureType&TYP\ 1110 ENAME=%s\">\n", 1111 myns_uri, pszNameSpace, myns_uri, 1112 msOWSGetSchemasLocation(map), paramsObj->pszVersion, 1052 1113 myns_uri, script_url_encoded, paramsObj->pszVersion, typename); 1053 1114 … … 1056 1117 ** contain mixed geometry types... how to deal with that??? 1057 1118 */ 1058 msGMLWriteWFSQuery(map, stdout, maxfeatures); 1119 msGMLWriteWFSQuery(map, stdout, maxfeatures, pszNameSpace); 1120 1059 1121 1060 1122 /* … … 1065 1127 free(script_url); 1066 1128 free(script_url_encoded); 1129 if (pszNameSpace) 1130 free(pszNameSpace); 1067 1131 1068 1132 return MS_SUCCESS; … … 1263 1327 else if (strcasecmp(request->ParamNames[i], "FILTER") == 0) 1264 1328 wfsparams->pszFilter = strdup(request->ParamValues[i]); 1329 1330 else if (strcasecmp(request->ParamNames[i], "OUTPUTFORMAT") == 0) 1331 wfsparams->pszOutputFormat = strdup(request->ParamValues[i]); 1265 1332 } 1266 1333 } … … 1475 1542 wfsparams->pszRequest = strdup("DescribeFeatureType"); 1476 1543 1477 pszValue = (char*)CPLGetXMLValue(psGetFeature, "version", NULL); 1544 pszValue = (char*)CPLGetXMLValue(psDescribeFeature, "version", 1545 NULL); 1478 1546 if (pszValue) 1479 1547 wfsparams->pszVersion = strdup(pszValue); 1480 1548 1481 pszValue = (char*)CPLGetXMLValue(psGetFeature, "service", NULL); 1549 pszValue = (char*)CPLGetXMLValue(psDescribeFeature, "service", 1550 NULL); 1482 1551 if (pszValue) 1483 1552 wfsparams->pszService = strdup(pszValue); 1484 1553 1485 pszValue = (char*)CPLGetXMLValue(psGetFeature, "outputFormat", 1554 pszValue = (char*)CPLGetXMLValue(psDescribeFeature, 1555 "outputFormat", 1486 1556 NULL); 1487 1557 if (pszValue) 1488 1558 wfsparams->pszOutputFormat = strdup(pszValue); 1489 1559 1490 psTypeName = CPLGetXMLNode(ps GetFeature, "TypeName");1560 psTypeName = CPLGetXMLNode(psDescribeFeature, "TypeName"); 1491 1561 if (psTypeName) 1492 1562 {
