source: cows/trunk/cows/xml/iso19115_subset.py @ 4912

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/cows/trunk/cows/xml/iso19115_subset.py@5424
Revision 4912, 3.2 KB checked in by spascoe, 13 years ago (diff)

Added LICENSE file and a short banner at the top of each python file.
Use add_license.py to add a license to new files.

NOTE: also contains a couple of files missed at last commit.

Line 
1# BSD Licence
2# Copyright (c) 2009, Science & Technology Facilities Council (STFC)
3# All rights reserved.
4#
5# See the LICENSE file in the source distribution of this software for
6# the full license text.
7
8# Copyright (C) 2007 STFC & NERC (Science and Technology Facilities Council).
9# This software may be distributed under the terms of the
10# Q Public License, version 1.0 or later.
11# http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
12"""
13Reads XML fragments from the OWS ISO19115 subset package v1.1.0 and
14creates cows objects.
15
16Each function expects an ElementTree node as it's first argument and returns
17an cows object.
18
19@author: Stephen Pascoe
20"""
21
22from cows.xml import ns
23from cows.xml.util import *
24from cows.model.iso19115_subset import *
25
26
27def language_string(node):
28    try:
29        lang = node.attrib['{%s}lang' % ns.xml]
30    except KeyError:
31        return node.text
32
33    return LanguageString(node.text, lang)
34
35def keywords(node):
36    type_n = node.find('./{%s}Type' % ns.ows)
37    if type_n is None:
38        kl = []
39    else:
40        kl = Keywords([], code(type_n))
41
42    for k_n in node.findall('./{%s}Keyword' % ns.ows):
43        kl.append(language_string(k_n))
44
45    return kl
46
47def code(node):
48    try:
49        codeSpace = node.attrib['{%s}codeSpace' % ns.ows]
50    except KeyError:
51        return node.text
52
53    return Code(node.text, codeSpace)
54   
55def xlink(node):
56    xl = Xlink(node.attrib['{%s}href'%ns.xlink])
57
58    for a in ['role', 'show', 'title', 'actuate', 'arcrole']:
59        setattr(xl, a, node.attrib.get('{%s}%s' % (ns.xlink, a)))
60
61    return xl
62
63def online_resource(node):
64    return xlink(node)
65
66def responsible_party(node):
67    rp = ResponsibleParty(
68        individualName=find_text(node, './{%s}IndividualName' % ns.ows),
69        positionName=find_text(node, './{%s}PositionName' % ns.ows),
70        role=find_with(node, './{%s}Role' % ns.ows, code),
71        contactInfo=find_with(node, './{%s}ContactInfo' % ns.ows, contact)
72        )
73    return rp
74
75def contact(node):
76    ci = Contact(
77        hoursOfService=find_text(node, './{%s}HoursOfService' % ns.ows),
78        contactInstructions=find_text(node, './{%s}ContactInstructions'
79                                       % ns.ows),
80        address=find_with(node, './{%s}Address' % ns.ows, address),
81        phone=find_with(node, './{%s}Phone' % ns.ows, telephone),
82        onlineResource=find_with(node, './{%s}OnlineResource' % ns.ows,
83                                  online_resource)
84        )
85    return ci
86
87def address(node):
88    a = Address(
89        deliveryPoints=findall_text(node, './{%s}DeliveryPoint' % ns.ows),
90        city=find_text(node, './{%s}City' % ns.ows),
91        administrativeArea=find_text(node, './{%s}AdministrativeArea'
92                                      % ns.ows),
93        postalCode=find_text(node, './{%s}PostalCode' % ns.ows),
94        country=find_text(node, './{%s}Country' % ns.ows),
95        electronicMailAddress=find_text(node, './{%s}ElectronicMailAddress'
96                                         % ns.ows)
97        )
98    return a
99
100def telephone(node):
101    t = Telephone(
102        voice=find_text(node, './{%s}Voice' % ns.ows),
103        facsimile=find_text(node, './{%s}Facsimile' % ns.ows)
104        )
105    return t
Note: See TracBrowser for help on using the repository browser.