Skip to content

Commit

Permalink
Merge pull request #67 from dvzgeo/feature-wms-exception-formats
Browse files Browse the repository at this point in the history
Add support for retrieving exception formats from WMS capabilities
  • Loading branch information
jahow authored Oct 25, 2024
2 parents bf94a45 + 29a465e commit ecb3450
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/shared/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ export type GenericEndpointInfo = {
outputFormats?: MimeType[];
/**
* Contains a list of formats that can be used for WMS GetFeatureInfo,
* or null for other services such as WFS
* or undefined for other services such as WFS
*/
infoFormats?: MimeType[];
/**
* Contains a list of formats that can be used for Exceptions for WMS GetMap,
* or undefined for other services such as WFS
*/
exceptionFormats?: MimeType[] | string[];
};

export type MimeType = string;
Expand Down
9 changes: 9 additions & 0 deletions src/wms/capabilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ describe('WMS capabilities', () => {
'image/svg+xml',
],
infoFormats: ['text/plain', 'application/vnd.ogc.gml'],
exceptionFormats: [
/* these differ depending on the WMS version used */
],
keywords: [
'Géologie',
'BRGM',
Expand All @@ -311,11 +314,17 @@ describe('WMS capabilities', () => {

it('reads the service info (1.3.0)', () => {
const doc = parseXmlString(capabilities130);
expectedInfo.exceptionFormats = ['XML', 'INIMAGE', 'BLANK'];
expect(readInfoFromCapabilities(doc)).toEqual(expectedInfo);
});

it('reads the service info (1.1.1)', () => {
const doc = parseXmlString(capabilities111);
expectedInfo.exceptionFormats = [
'application/vnd.ogc.se_xml',
'application/vnd.ogc.se_inimage',
'application/vnd.ogc.se_blank',
];
expect(readInfoFromCapabilities(doc)).toEqual(expectedInfo);
});
});
Expand Down
22 changes: 22 additions & 0 deletions src/wms/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ export function readInfoFormatsFromCapabilities(capabilitiesDoc: XmlDocument) {
return outputFormats;
}

/**
* Will return all available exception formats
* @param capabilitiesDoc Capabiliites document
* @return Available exception formats
*/
export function readExceptionFormatsFromCapabilities(
capabilitiesDoc: XmlDocument
) {
const capability = findChildElement(
getRootElement(capabilitiesDoc),
'Capability'
);
const exception = findChildElement(capability, 'Exception');
const exceptionFormats = findChildrenElement(exception, 'Format').map(
getElementText
);
return exceptionFormats;
}

/**
* Will read service-related info from the capabilities doc
* @param capabilitiesDoc Capabilities document
Expand All @@ -83,6 +102,8 @@ export function readInfoFromCapabilities(
const service = findChildElement(getRootElement(capabilitiesDoc), 'Service');
const outputFormats = readOutputFormatsFromCapabilities(capabilitiesDoc);
const infoFormats = readInfoFormatsFromCapabilities(capabilitiesDoc);
const exceptionFormats =
readExceptionFormatsFromCapabilities(capabilitiesDoc);
const keywords = findChildrenElement(
findChildElement(service, 'KeywordList'),
'Keyword'
Expand All @@ -96,6 +117,7 @@ export function readInfoFromCapabilities(
abstract: getElementText(findChildElement(service, 'Abstract')),
outputFormats: outputFormats,
infoFormats: infoFormats,
exceptionFormats: exceptionFormats,
fees: getElementText(findChildElement(service, 'Fees')),
constraints: getElementText(findChildElement(service, 'AccessConstraints')),
keywords,
Expand Down
1 change: 1 addition & 0 deletions src/wms/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ describe('WmsEndpoint', () => {
'image/svg+xml',
],
infoFormats: ['text/plain', 'application/vnd.ogc.gml'],
exceptionFormats: ['XML', 'INIMAGE', 'BLANK'],
keywords: [
'Géologie',
'BRGM',
Expand Down

0 comments on commit ecb3450

Please sign in to comment.