Esempio n. 1
0
def service_metadata(root_el: gws.XmlElement) -> gws.lib.metadata.Metadata:
    # wms
    #
    #   <Capabilities
    #       <Service...
    #           <Name>...
    #           <Title>...
    #           <ContactInformation>...
    #
    # ows
    #
    #   <Capabilities
    #       <ows:ServiceIdentification>
    #           <ows:Title>....
    #       <ows:ServiceProvider>
    #           <ows:ProviderName>...
    #           <ows:ServiceContact>...

    d = _metadata_dict(xml2.first(root_el, 'Service', 'ServiceIdentification'))
    d.update(_contact_dict(root_el))
    d['contactProviderName'] = xml2.text(root_el,
                                         'ServiceProvider ProviderName')
    d['contactProviderSite'] = xml2.text(root_el,
                                         'ServiceProvider ProviderSite')

    #   <Capabilities
    #       <ServiceMetadataURL

    link = _parse_link(xml2.first(root_el, 'ServiceMetadataURL'))
    if link:
        d['metaLinks'] = [link]

    return gws.lib.metadata.from_dict(gws.strip(d))
Esempio n. 2
0
def _metadata_dict(el: gws.XmlElement) -> dict:
    if not el:
        return {}

    d = {
        'abstract':
        xml2.text(el, 'Abstract'),
        'accessConstraints':
        xml2.text(el, 'AccessConstraints'),
        'attribution':
        xml2.text(el, 'Attribution Title'),
        'fees':
        xml2.text(el, 'Fees'),
        'keywords':
        xml2.text_list(el, 'Keywords', 'KeywordList', deep=True),
        'name':
        xml2.text(el, 'Name') or xml2.text(el, 'Identifier'),
        'title':
        xml2.text(el, 'Title'),
        'metaLinks':
        gws.compact(_parse_link(e) for e in xml2.all(el, 'MetadataURL')),
    }

    e = xml2.first(el, 'AuthorityURL')
    if e:
        d['authorityUrl'] = _parse_url(e)
        d['authorityName'] = xml2.attr(e, 'name')

    e = xml2.first(el, 'Identifier')
    if e:
        d['authorityIdentifier'] = e.text

    return gws.strip(d)
Esempio n. 3
0
def _project_meta_from_props(props):
    # @TODO should also read `properties.projectMetadata`

    d = gws.strip({
        'abstract': _pval(props, 'WMSServiceAbstract'),
        'attribution': _pval(props, 'CopyrightLabel.Label'),
        'keywords': _pval(props, 'WMSKeywordList'),
        'title': _pval(props, 'WMSServiceTitle'),
        'contactEmail': _pval(props, 'WMSContactMail'),
        'contactOrganization': _pval(props, 'WMSContactOrganization'),
        'contactPerson': _pval(props, 'WMSContactPerson'),
        'contactPhone': _pval(props, 'WMSContactPhone'),
        'contactPosition': _pval(props, 'WMSContactPosition'),
    })
    return gws.lib.metadata.from_dict(d)
Esempio n. 4
0
def _parse_link(el: gws.XmlElement) -> t.Optional[gws.MetadataLink]:
    # <MetadataURL type="...
    #       <Format...
    # 	    <OnlineResource...

    if not el:
        return None

    d = gws.strip({
        'url': _parse_url(el),
        'type': xml2.attr(el, 'type'),
        'formatName': xml2.text(el, 'Format'),
    })

    if d:
        return gws.MetadataLink(d)
Esempio n. 5
0
def _map_layer_metadata(layer_el: gws.XmlElement):
    def tx(s):
        return xml2.text(layer_el, s)

    d = gws.strip({
        'abstract': tx('resourceMetadata.abstract'),
        'contactEmail': tx('email'),
        'contactFax': tx('fax'),
        'contactOrganization': tx('organization'),
        'contactPerson': tx('name'),
        'contactPhone': tx('voice'),
        'contactPosition': tx('position'),
        'contactRole': tx('role'),
        'keywords': xml2.text_list(layer_el, 'keywordList value'),
        'name': tx('id'),
        'title': tx('layername'),
        'url': tx('metadataUrl'),
    })

    return gws.lib.metadata.from_dict(d) if d else None
Esempio n. 6
0
def _properties(el: gws.XmlElement):
    # parse the nested `properties` structure into a flat dict
    # the struct is like this:
    #
    # <properties>
    #       ...
    #       <PositionPrecision>
    #            <Automatic type="bool">true</Automatic>
    #            <DecimalPlaces type="int">2</DecimalPlaces>
    #            ...
    #

    # <WMSFees type="QString">conditions unknown</WMSFees>
    # <WMSImageQuality type="int">90</WMSImageQuality>
    # <WMSKeywordList type="QStringList">
    #   <value>one</value>
    #   <value>two</value>
    #   <value>three</value>
    # </WMSKeywordList>

    ty = xml2.attr(el, 'type')

    if not ty:
        return gws.strip({c.name.lower(): _properties(c) for c in el.children})

    # e.g.
    # <WMSKeywordList type="QStringList">
    #   <value>A</value>
    #   <value>B</value>
    #   <value>C</value>

    if ty == 'QStringList':
        return xml2.text_list(el)
    if ty == 'QString':
        return el.text
    if ty == 'bool':
        return el.text.lower() == 'true'
    if ty == 'int':
        return _parse_int(el.text)
    if ty == 'double':
        return _parse_float(el.text)