- Added support for complete service metadata

- refactored some code for optimization
- cusomtized the config parser
This commit is contained in:
Jean-Francois Doyon 2006-07-22 18:54:53 +00:00
parent ad79c5a4fd
commit 1c8aca919f
7 changed files with 168 additions and 44 deletions

View file

@ -28,7 +28,7 @@ from jon import cgi
from exceptions import OGCException, ServerConfigurationError
from wms111 import ExceptionHandler as ExceptionHandler111
from wms130 import ExceptionHandler as ExceptionHandler130
from ConfigParser import SafeConfigParser
from configparser import SafeConfigParser
from common import Version
class Handler(cgi.DebugHandler):
@ -37,7 +37,7 @@ class Handler(cgi.DebugHandler):
conf = SafeConfigParser()
conf.readfp(open(self.configpath))
self.conf = conf
if not conf.has_option('server', 'module'):
if not conf.has_option_with_value('server', 'module'):
raise ServerConfigurationError('The factory module is not defined in the configuration file.')
try:
mapfactorymodule = __import__(conf.get('server', 'module'))

View file

@ -79,6 +79,26 @@ class ParameterDefinition:
class BaseServiceHandler:
CONF_CONTACT_PERSON_PRIMARY = [
['contactperson', 'ContactPerson', str],
['contactorganization', 'ContactOrganization', str]
]
CONF_CONTACT_ADDRESS = [
['addresstype', 'AddressType', str],
['address', 'Address', str],
['city', 'City', str],
['stateorprovince', 'StateOrProvince', str],
['postcode', 'PostCode', str],
['country', 'Country', str]
]
CONF_CONTACT = [
['contactposition', 'ContactPosition', str],
['contactvoicetelephone', 'ContactVoiceTelephone', str],
['contactelectronicmailaddress', 'ContactElectronicMailAddress', str]
]
def processParameters(self, requestname, params):
finalparams = {}
for paramname, paramdef in self.SERVICE_PARAMS[requestname].items():
@ -101,6 +121,65 @@ class BaseServiceHandler:
elif not paramdef.mandatory and paramdef.default:
finalparams[paramname] = paramdef.default
return finalparams
def processServiceCapabilities(self, capetree):
if len(self.conf.items('service')) > 0:
servicee = capetree.find('{http://www.opengis.net/wms}Service')
for item in self.CONF_SERVICE:
if self.conf.has_option_with_value('service', item[0]):
value = self.conf.get('service', item[0]).strip()
try:
item[2](value)
except:
raise ServerConfigurationError('Configuration parameter [%s]->%s has an invalid value: %s.' % ('service', item[0], value))
if item[0] == 'onlineresource':
element = ElementTree.Element('%s' % item[1])
servicee.append(element)
element.set('{http://www.w3.org/1999/xlink}href', value)
element.set('{http://www.w3.org/1999/xlink}type', 'simple')
elif item[0] == 'keywordlist':
element = ElementTree.Element('%s' % item[1])
servicee.append(element)
keywords = value.split(',')
keywords = map(str.strip, keywords)
for keyword in keywords:
kelement = ElementTree.Element('Keyword')
kelement.text = keyword
element.append(kelement)
else:
element = ElementTree.Element('%s' % item[1])
element.text = value
servicee.append(element)
if len(self.conf.items_with_value('contact')) > 0:
element = ElementTree.Element('ContactInformation')
servicee.append(element)
for item in self.CONF_CONTACT:
if self.conf.has_option_with_value('contact', item[0]):
value = self.conf.get('contact', item[0]).strip()
try:
item[2](value)
except:
raise ServerConfigurationError('Configuration parameter [%s]->%s has an invalid value: %s.' % ('service', item[0], value))
celement = ElementTree.Element('%s' % item[1])
celement.text = value
element.append(celement)
for item in self.CONF_CONTACT_PERSON_PRIMARY + self.CONF_CONTACT_ADDRESS:
if item in self.CONF_CONTACT_PERSON_PRIMARY:
tagname = 'ContactPersonPrimary'
else:
tagname = 'ContactAddress'
if self.conf.has_option_with_value('contact', item[0]):
if element.find(tagname) == None:
subelement = ElementTree.Element(tagname)
element.append(subelement)
value = self.conf.get('contact', item[0]).strip()
try:
item[2](value)
except:
raise ServerConfigurationError('Configuration parameter [%s]->%s has an invalid value: %s.' % ('service', item[0], value))
celement = ElementTree.Element('%s' % item[1])
celement.text = value
subelement.append(celement)
class Response:

View file

@ -0,0 +1,44 @@
#
# This file is part of Mapnik (c++ mapping toolkit)
#
# Copyright (C) 2006 Jean-Francois Doyon
#
# Mapnik is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# $Id$
""" Change SafeConfigParser behavior to treat options without values as
non-existent.
"""
from ConfigParser import SafeConfigParser as OrigSafeConfigParser
class SafeConfigParser(OrigSafeConfigParser):
def items_with_value(self, section):
finallist = []
items = self.items(section)
for item in items:
if item[1] != '':
finallist.append(item)
return finallist
def has_option_with_value(self, section, option):
if self.has_option(section, option):
if self.get(section, option) == '':
return False
else:
return False
return True

View file

@ -51,11 +51,12 @@ class ServiceHandler(WMSBaseServiceHandler):
['onlineresource', 'OnlineResource', str],
['fees', 'Fees', str],
['accessconstraints', 'AccessConstraints', str],
['keywordlist', 'KeywordList', str]
]
capabilitiesxmltemplate = """<?xml version='1.0' encoding="UTF-8" standalone="no"?>
<!DOCTYPE WMT_MS_Capabilities SYSTEM "http://www.digitalearth.gov/wmt/xml/capabilities_1_1_1.dtd">
<WMT_MS_Capabilities version="1.1.1" updateSequence="0" xmlns:xlink="http://www.w3.org/1999/xlink">
<WMT_MS_Capabilities version="1.1.1" updateSequence="0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.opengis.net/wms">
<Service>
<Name>WMS</Name>
</Service>
@ -117,28 +118,11 @@ class ServiceHandler(WMSBaseServiceHandler):
for element in elements:
element.set('{http://www.w3.org/1999/xlink}href', opsonlineresource)
if len(self.conf.items('service')) > 0:
servicee = capetree.find('Service')
for item in self.CONF_SERVICE:
if self.conf.has_option('service', item[0]):
value = self.conf.get('service', item[0])
try:
item[2](value)
except:
raise ServerConfigurationError('Configuration parameter [%s]->%s has an invalid value: %s.' % ('service', item[0], value))
if item[0] == 'onlineresource':
element = ElementTree.Element('%s' % item[1])
servicee.append(element)
element.set('{http://www.w3.org/1999/xlink}href', value)
element.set('{http://www.w3.org/1999/xlink}type', 'simple')
else:
element = ElementTree.Element('%s' % item[1])
element.text = value
servicee.append(element)
self.processServiceCapabilities(capetree)
rootlayerelem = capetree.find('Capability/Layer')
rootlayerelem = capetree.find('{http://www.opengis.net/wms}Capability/{http://www.opengis.net/wms}Layer')
rootlayersrs = rootlayerelem.find('SRS')
rootlayersrs = rootlayerelem.find('{http://www.opengis.net/wms}SRS')
rootlayersrs.text = str(self.crs)
for layer in self.mapfactory.layers.values():

View file

@ -54,7 +54,8 @@ class ServiceHandler(WMSBaseServiceHandler):
['accessconstraints', 'AccessConstraints', str],
['layerlimit', 'LayerLimit', int],
['maxwidth', 'MaxWidth', int],
['maxheight', 'MaxHeight', int]
['maxheight', 'MaxHeight', int],
['keywordlist', 'KeywordList', str]
]
capabilitiesxmltemplate = """<?xml version="1.0" encoding="UTF-8"?>
@ -123,24 +124,7 @@ class ServiceHandler(WMSBaseServiceHandler):
for element in elements:
element.set('{http://www.w3.org/1999/xlink}href', opsonlineresource)
if len(self.conf.items('service')) > 0:
servicee = capetree.find('{http://www.opengis.net/wms}Service')
for item in self.CONF_SERVICE:
if self.conf.has_option('service', item[0]):
value = self.conf.get('service', item[0]).strip()
try:
item[2](value)
except:
raise ServerConfigurationError('Configuration parameter [%s]->%s has an invalid value: %s.' % ('service', item[0], value))
if item[0] == 'onlineresource':
element = ElementTree.Element('%s' % item[1])
servicee.append(element)
element.set('{http://www.w3.org/1999/xlink}href', value)
element.set('{http://www.w3.org/1999/xlink}type', 'simple')
else:
element = ElementTree.Element('%s' % item[1])
element.text = value
servicee.append(element)
self.processServiceCapabilities(capetree)
rootlayerelem = capetree.find('{http://www.opengis.net/wms}Capability/{http://www.opengis.net/wms}Layer')

View file

@ -18,7 +18,7 @@ Features/Caveats
- WMS 1.1.1 and 1.3.0
- CGI/FastCGI
- GetCapabilities and GetMap support only (NO GetFeatureInfo)
- GetCapabilities and GetMap support only (NO GetFeatureInfo ... yet)
- JPEG/PNG output
- XML/INIMAGE/BLANK error handling
- No real layer metadata support yet
@ -128,7 +128,6 @@ To Do
-----
- Named style support.
- Improve configuration to allow for full server metadata.
- Investigate moving to cElementTree from lxml.
- Add some internal "caching" for performance improvements.
- Support GetFeatureInfo (Requires core changes).

View file

@ -37,3 +37,37 @@ epsg=4326
# resource pointing to the CGI.
onlineresource=http://www.mapnik.org/
# fees: An explanation of the fee structure for the usage of your service,
# if any. Use the reserved keyword "none" if not applicable.
fees=
# keywords: A comma seperated list of key words.
keywordlist=
# accessconstraints: Plain language description of any constraints that might
# apply to the usage of your service, such as hours of
# operation.
accessconstraints=
# contact: Contact information. Provides niformation to service users on who
# to contact for help on or details about the service.
[contact]
contactperson=
contactorganization=
contactposition=
addresstype=
address=
city=
stateorprovince=
postcode=
country=
contactvoicetelephone=
contactelectronicmailaddress=