Ejemplo n.º 1
0
    def _buildMetadata(self, parse_remote_metadata=False):
        """set up capabilities metadata objects: """

        self.updateSequence = self._capabilities.attrib.get("updateSequence")

        # serviceIdentification metadata
        serviceidentelem = self._capabilities.find(
            nspath("ServiceIdentification"))
        if serviceidentelem is not None:
            self.identification = ServiceIdentification(serviceidentelem)
        # need to add to keywords list from featuretypelist information:
        featuretypelistelem = self._capabilities.find(
            nspath("FeatureTypeList", ns=WFS_NAMESPACE))
        featuretypeelems = featuretypelistelem.findall(
            nspath("FeatureType", ns=WFS_NAMESPACE))
        if serviceidentelem is not None:
            for f in featuretypeelems:
                kwds = f.findall(nspath("Keywords/Keyword", ns=OWS_NAMESPACE))
                if kwds is not None:
                    for kwd in kwds[:]:
                        if kwd.text not in self.identification.keywords:
                            self.identification.keywords.append(kwd.text)

        # TODO: update serviceProvider metadata, miss it out for now
        serviceproviderelem = self._capabilities.find(
            nspath("ServiceProvider"))
        if serviceproviderelem:
            self.provider = ServiceProvider(serviceproviderelem)

        # serviceOperations metadata
        self.operations = []

        for elem in self._capabilities.find(nspath("OperationsMetadata"))[:]:
            if elem.tag != nspath("ExtendedCapabilities"):
                self.operations.append(OperationsMetadata(elem))
        self.constraints = {}
        for elem in self._capabilities.findall(
                nspath("OperationsMetadata/Constraint", ns=WFS_NAMESPACE)):
            self.constraints[elem.attrib["name"]] = Constraint(
                elem, self.owscommon.namespace)
        self.parameters = {}
        for elem in self._capabilities.findall(
                nspath("OperationsMetadata/Parameter", ns=WFS_NAMESPACE)):
            self.parameters[elem.attrib["name"]] = Parameter(
                elem, self.owscommon.namespace)

        # serviceContents metadata: our assumption is that services use a top-level
        # layer as a metadata organizer, nothing more.

        self.contents = {}
        featuretypelist = self._capabilities.find(
            nspath("FeatureTypeList", ns=WFS_NAMESPACE))
        features = self._capabilities.findall(
            nspath("FeatureTypeList/FeatureType", ns=WFS_NAMESPACE))
        for feature in features:
            cm = ContentMetadata(feature,
                                 featuretypelist,
                                 parse_remote_metadata,
                                 auth=self.auth)
            self.contents[cm.id] = cm

        # exceptions
        self.exceptions = [
            f.text
            for f in self._capabilities.findall("Capability/Exception/Format")
        ]