Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for retrieving exception formats from WMS capabilities #67

Merged
merged 5 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/shared/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ export type GenericEndpointInfo = {
* or the list of 'Formats' from a WMS GetCapabilities
*/
outputFormats?: MimeType[];
/**
* Contains a list of formats that can be used for WMS GetFeatureInfo,
* 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
10 changes: 10 additions & 0 deletions src/wms/capabilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ describe('WMS capabilities', () => {
'application/x-pdf',
'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 @@ -310,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
43 changes: 41 additions & 2 deletions src/wms/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,40 @@ export function readOutputFormatsFromCapabilities(
return outputFormats;
}

export function readInfoFormatsFromCapabilities(capabilitiesDoc: XmlDocument) {
const capability = findChildElement(
getRootElement(capabilitiesDoc),
'Capability'
);
const getFeatureInfo = findChildElement(
findChildElement(capability, 'Request'),
'GetFeatureInfo'
);
const outputFormats = findChildrenElement(getFeatureInfo, 'Format').map(
getElementText
);
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 @@ -66,7 +100,10 @@ export function readInfoFromCapabilities(
capabilitiesDoc: XmlDocument
): GenericEndpointInfo {
const service = findChildElement(getRootElement(capabilitiesDoc), 'Service');
const formats = readOutputFormatsFromCapabilities(capabilitiesDoc);
const outputFormats = readOutputFormatsFromCapabilities(capabilitiesDoc);
const infoFormats = readInfoFormatsFromCapabilities(capabilitiesDoc);
const exceptionFormats =
readExceptionFormatsFromCapabilities(capabilitiesDoc);
const keywords = findChildrenElement(
findChildElement(service, 'KeywordList'),
'Keyword'
Expand All @@ -78,7 +115,9 @@ export function readInfoFromCapabilities(
title: getElementText(findChildElement(service, 'Title')),
name: getElementText(findChildElement(service, 'Name')),
abstract: getElementText(findChildElement(service, 'Abstract')),
outputFormats: formats,
outputFormats: outputFormats,
infoFormats: infoFormats,
exceptionFormats: exceptionFormats,
fees: getElementText(findChildElement(service, 'Fees')),
constraints: getElementText(findChildElement(service, 'AccessConstraints')),
keywords,
Expand Down
2 changes: 2 additions & 0 deletions src/wms/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ describe('WmsEndpoint', () => {
'application/x-pdf',
'image/svg+xml',
],
infoFormats: ['text/plain', 'application/vnd.ogc.gml'],
exceptionFormats: ['XML', 'INIMAGE', 'BLANK'],
keywords: [
'Géologie',
'BRGM',
Expand Down