source: TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/wms_capabilities.py @ 2488

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/wms_capabilities.py@2488
Revision 2488, 1.7 KB checked in by spascoe, 12 years ago (diff)

Moved wms_capabilities test cases to the correct place. Implemented
several tests using an OGC example document.

Line 
1"""
2Utilities for extracting WMS 1.3.0 compatible metadata out of an
3OWS common 1.1.0 XML tree.
4
5@author: Stephen Pascoe
6
7"""
8
9from elementtree import ElementTree as ET
10
11# Namespaces
12ows_ns = 'http://www.opengis.net/ows/1.1'
13xlink_ns = 'http://www.w3.org/1999/xlink'
14
15# ElementTree utilities
16def qname(ns, tag):
17    return '{%s}%s' % (ns, tag)
18def path(items):
19    return '/'.join(items)
20
21def ows_path(items):
22    return path([qname(ows_ns, x) for x in items])
23
24class WmsOwsAdapter(object):
25    """
26    This class is a facade over an OWS common XML tree which gives
27    easy access to key WMS metadata.
28
29    """
30    def __init__(self, ows_tree):
31        self.ows_tree = ows_tree
32
33    def _getTitle(self):
34        e = self.ows_tree.find(ows_path(['ServiceIdentification', 'Title']))
35        if e is not None:
36            return e.text
37        else:
38            return None
39    title = property(_getTitle)
40
41    def _getAbstracts(self):
42        es = self.ows_tree.findall(ows_path(['ServiceIdentification', 'Abstract']))
43        return [x.text for x in es]
44    abstracts = property(_getAbstracts)
45
46    def _getKeywords(self):
47        es = self.ows_tree.findall(ows_path(['ServiceIdentification',
48                                             'Keywords',
49                                             'Keyword']))
50        return [x.text for x in es]
51    keywords = property(_getKeywords)
52
53    def _getOnlineResource(self):
54        e = self.ows_tree.find(ows_path(['ServiceProvider',
55                                         'ProviderSite']))
56        if e is not None:
57            return e.attrib[qname(xlink_ns, 'href')]
58        else:
59            return None
60    onlineResource = property(_getOnlineResource)
Note: See TracBrowser for help on using the repository browser.