allow versioned profiled parsers to fallback to the non-profiled parser, this will help deal with situations in which a WMSC parser is created, the server is requested for WMS 1.1.1, but returns 1.1.0

This commit is contained in:
Bart van den Eijnden
2012-10-08 16:28:19 +02:00
parent e3a5091ebd
commit fd6e7ebe03
2 changed files with 158 additions and 2 deletions

View File

@@ -36,6 +36,17 @@ OpenLayers.Format.XML.VersionedOGC = OpenLayers.Class(OpenLayers.Format.XML, {
*/
profile: null,
/**
* APIProperty: allowFallback
* {Boolean} If a profiled parser cannot be found for the returned version,
* use a non-profiled parser as the fallback. Application code using this
* should take into account that the return object structure might be
* missing the specifics of the profile. Defaults to false Application code using this
* should take into account that the return object structure might be
* missing the specifics of the profile. Defaults to false.
*/
allowFallback: false,
/**
* APIProperty: errorProperty
* {String} Which property of the returned object to check for in order to
@@ -128,8 +139,17 @@ OpenLayers.Format.XML.VersionedOGC = OpenLayers.Class(OpenLayers.Format.XML, {
"v" + version.replace(/\./g, "_") + profile
];
if(!format) {
throw "Can't find a " + this.name + " parser for version " +
version + profile;
if (profile !== "" && this.allowFallback) {
// fallback to the non-profiled version of the parser
profile = "";
format = OpenLayers.Format[this.name][
"v" + version.replace(/\./g, "_")
];
}
if (!format) {
throw "Can't find a " + this.name + " parser for version " +
version + profile;
}
}
this.parser = new format(this.options);
}

View File

@@ -24,10 +24,146 @@
t.eq(tileset.styles, "", "Styles correctly parsed");
}
function test_read_fallback(t) {
t.plan(1);
var xml = document.getElementById("fallback").firstChild.nodeValue;
var doc = new OpenLayers.Format.XML().read(xml);
var format = new OpenLayers.Format.WMSCapabilities({profile: "WMSC", allowFallback: true});
var obj = format.read(doc);
t.eq(obj.capability.layers.length, 2, "2 layers parsed with allowFallback true");
}
</script>
</head>
<body>
<div id="fallback"><!--
<?xml version='1.0' encoding="ISO-8859-1" standalone="no" ?>
<!DOCTYPE WMT_MS_Capabilities SYSTEM "http://schemas.opengis.net/wms/1.1.0/capabilities_1_1_0.dtd"
[
<!ELEMENT VendorSpecificCapabilities EMPTY>
]>
<WMT_MS_Capabilities version="1.1.0">
<Service>
<Name>OGC:WMS</Name>
<Title>i3Geo - i3geo</Title>
<Abstract>Web services gerados da base de dados do i3Geo. Para chamar um tema especificamente, veja o sistema de ajuda, digitando no navegador web ogc.php?ajuda=, para uma lista compacta de todos os servicos, digite ogc.php?lista=temas</Abstract>
<KeywordList>
<Keyword>i3Geo</Keyword>
</KeywordList>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://mapas.mma.gov.br/i3geo/ogc.php?"/>
<ContactInformation>
<ContactPersonPrimary>
<ContactPerson>Web Master</ContactPerson>
<ContactOrganization>Coordena??o Geral de TI</ContactOrganization>
</ContactPersonPrimary>
<ContactPosition>Administrador do s?tio web</ContactPosition>
<ContactAddress>
<AddressType>uri</AddressType>
<Address>http://www.mma.gov.br</Address>
<City>Brasilia</City>
<StateOrProvince>DF</StateOrProvince>
<PostCode></PostCode>
<Country>Brasil</Country>
</ContactAddress>
<ContactElectronicMailAddress>geoprocessamento@mma.gov.br</ContactElectronicMailAddress>
</ContactInformation>
<Fees>none</Fees>
<AccessConstraints>vedado o uso comercial</AccessConstraints>
</Service>
<Capability>
<Request>
<GetCapabilities>
<Format>application/vnd.ogc.wms_xml</Format>
<DCPType>
<HTTP>
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://mapas.mma.gov.br/i3geo/ogc.php?"/></Get>
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://mapas.mma.gov.br/i3geo/ogc.php?"/></Post>
</HTTP>
</DCPType>
</GetCapabilities>
<GetMap>
<Format>image/png</Format>
<Format>image/jpeg</Format>
<Format>image/gif</Format>
<Format>image/png; mode=8bit</Format>
<Format>application/x-pdf</Format>
<Format>image/svg+xml</Format>
<Format>image/tiff</Format>
<Format>application/vnd.google-earth.kml+xml</Format>
<Format>application/vnd.google-earth.kmz</Format>
<DCPType>
<HTTP>
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://mapas.mma.gov.br/i3geo/ogc.php?"/></Get>
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://mapas.mma.gov.br/i3geo/ogc.php?"/></Post>
</HTTP>
</DCPType>
</GetMap>
<GetFeatureInfo>
<Format>text/plain</Format>
<Format>application/vnd.ogc.gml</Format>
<DCPType>
<HTTP>
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://mapas.mma.gov.br/i3geo/ogc.php?"/></Get>
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://mapas.mma.gov.br/i3geo/ogc.php?"/></Post>
</HTTP>
</DCPType>
</GetFeatureInfo>
<DescribeLayer>
<Format>text/xml</Format>
<DCPType>
<HTTP>
<Get><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://mapas.mma.gov.br/i3geo/ogc.php?"/></Get>
<Post><OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://mapas.mma.gov.br/i3geo/ogc.php?"/></Post>
</HTTP>
</DCPType>
</DescribeLayer>
</Request>
<Exception>
<Format>application/vnd.ogc.se_xml</Format>
<Format>application/vnd.ogc.se_inimage</Format>
<Format>application/vnd.ogc.se_blank</Format>
</Exception>
<VendorSpecificCapabilities />
<UserDefinedSymbolization SupportSLD="1" UserLayer="0" UserStyle="1" RemoteWFS="0"/>
<Layer>
<Name>i3geoogc</Name>
<Title>i3Geo - i3geo</Title>
<Abstract>Web services gerados da base de dados do i3Geo. Para chamar um tema especificamente, veja o sistema de ajuda, digitando no navegador web ogc.php?ajuda=, para uma lista compacta de todos os servicos, digite ogc.php?lista=temas</Abstract>
<KeywordList>
<Keyword>i3Geo</Keyword>
</KeywordList>
<SRS></SRS>
<LatLonBoundingBox minx="-76.5126" miny="-36.9484" maxx="-29.5852" maxy="7.04601" />
<BoundingBox SRS=""
minx="-76.5126" miny="-36.9484" maxx="-29.5852" maxy="7.04601" />
<Attribution>
<Title>i3Geo</Title>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://mapas.mma.gov.br/i3geo"/>
<LogoURL width="85" height="56">
<Format>image/png</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://mapas.mma.gov.br/i3geo/imagens/i3geo.png"/>
</LogoURL>
</Attribution>
<Layer queryable="1" opaque="0" cascaded="0">
<Name>antigo_caminantes</Name>
<Title>Guia de Caminantes - 1817</Title>
<SRS> EPSG:4618 EPSG:4291 EPSG:4326 EPSG:22521 EPSG:22522 EPSG:22523 EPSG:22524 EPSG:22525 EPSG:29101 EPSG:29119 EPSG:29120 EPSG:29121 EPSG:29122 EPSG:29177 EPSG:29178 EPSG:29179 EPSG:29180 EPSG:29181 EPSG:29182 EPSG:29183 EPSG:29184 EPSG:29185</SRS>
<LatLonBoundingBox minx="-75.2336" miny="-33.7516" maxx="-27.593" maxy="5.27216" />
<BoundingBox SRS=""
minx="-75.2336" miny="-33.7516" maxx="-27.593" maxy="5.27216" />
<MetadataURL type="TC211">
<Format>text/html</Format>
<OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://consorcio.bn.br"/>
</MetadataURL>
</Layer>
</Layer>
</Capability>
</WMT_MS_Capabilities>
--></div>
<div id="wmsc"><!--
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE WMT_MS_Capabilities SYSTEM "http://schemas.opengis.net/wms/1.1.1/capabilities_1_1_1.dtd"[