Exemplo n.º 1
0
    def buildNode(self, element):
        if not isinstance(element.tag, str) or not element.tag.startswith("{%(map)s}" % ns):
            return None

        suffix = element.tag[len("{%(map)s}" % ns):]
        if suffix == "parameter":
            return None        
        try:
            node = self.nodeClasses[suffix]()
        except KeyError:
            raise Exception("Unknown sitemap element tag: %s" % suffix)
        
        node.build(element)
        
        if isinstance(node, SelectNode):
            node.whenElements = []

            for when in element.findall("{%(map)s}when" % ns):
                test = variables.getResolver(when.get("test"))
                nodes = [self.buildNode(c) for c in when]
                actualNodes = [n for n in nodes if n is not None]
                node.whenElements.append((test, actualNodes))
            
            otherwise = element.find("{%(map)s}otherwise" % ns)
            if otherwise is not None:
                nodes = [self.buildNode(c) for c in otherwise]
                node.otherwiseNodes = [n for n in nodes if n is not None]
            
            return node
        
        if isinstance(node, ResourceCall):
            element = None
            for r in self.root.findall("{%(map)s}resources/{%(map)s}resource" % ns):
                if r.get("name") == node.name:
                    element = r
                    break
            if element is None:
                raise Exception('<map:resource name="%s"> not found' % node.name)
        
        if isinstance(node, ContainerNode):
            children = [self.buildNode(c) for c in element]
            def isRegularNode(c):
                return isinstance(c, Node) and not isinstance(c, HandleErrorsNode)
            node.children = [c for c in children if isRegularNode(c)]
            handleNodes = [c for c in children if isinstance(c, HandleErrorsNode)]
            if len(handleNodes) > 0:
                node.handleErrorsNode = handleNodes.pop()
                
        if isinstance(node, PipelinesNode):
            if len(node.children) > 0:
                node.children[-1].isLast = True

        if isinstance(node, ComponentConfigurations):
            self.processor.componentConfigurations = node.element

        return node
Exemplo n.º 2
0
 def build(self, element):
     Node.build(self, element)
     self.src = variables.getResolver(element.get("src"))
     self.prefix = variables.getResolver(element.get("uri-prefix"))
Exemplo n.º 3
0
 def build(self, element):
     Node.build(self, element)
     self.uri = variables.getResolver(element.get("uri"))
     self.permanent = (element.get("permanent", "no") == "yes")
Exemplo n.º 4
0
 def build(self, element):
     Node.build(self, element)
     self.when = variables.getResolver(element.get("when", "external"))
Exemplo n.º 5
0
 def build(self, element):
     Node.build(self, element)
     self._buildParams(element)
     self.src = variables.getResolver(element.get("src"))
     self.mimeType = element.get("mime-type")
Exemplo n.º 6
0
 def build(self, element):
     Node.build(self, element)
     self.element = variables.getResolver(element.get("element"))
     self.ns = variables.getResolver(element.get("ns"))
     self.parts = [variables.getResolver(c.get("src")) for c in element.findall("{%(map)s}part" % ns)]
Exemplo n.º 7
0
 def build(self, element):
     Node.build(self, element)
     self._buildParams(element)
     self.src = variables.getResolver(element.get("src"))
Exemplo n.º 8
0
 def _buildParams(self, element):
     for c in element.findall("{%(map)s}parameter" % ns):
         name = variables.getResolver(c.get("name"))
         value = variables.getResolver(c.get("value"))
         self.params[name] = value
Exemplo n.º 9
0
    def buildNode(self, element):
        if not isinstance(element.tag, str) or not element.tag.startswith(
                "{%(map)s}" % ns):
            return None

        suffix = element.tag[len("{%(map)s}" % ns):]
        if suffix == "parameter":
            return None
        try:
            node = self.nodeClasses[suffix]()
        except KeyError:
            raise Exception("Unknown sitemap element tag: %s" % suffix)

        node.build(element)

        if isinstance(node, SelectNode):
            node.whenElements = []

            for when in element.findall("{%(map)s}when" % ns):
                test = variables.getResolver(when.get("test"))
                nodes = [self.buildNode(c) for c in when]
                actualNodes = [n for n in nodes if n is not None]
                node.whenElements.append((test, actualNodes))

            otherwise = element.find("{%(map)s}otherwise" % ns)
            if otherwise is not None:
                nodes = [self.buildNode(c) for c in otherwise]
                node.otherwiseNodes = [n for n in nodes if n is not None]

            return node

        if isinstance(node, ResourceCall):
            element = None
            for r in self.root.findall("{%(map)s}resources/{%(map)s}resource" %
                                       ns):
                if r.get("name") == node.name:
                    element = r
                    break
            if element is None:
                raise Exception('<map:resource name="%s"> not found' %
                                node.name)

        if isinstance(node, ContainerNode):
            children = [self.buildNode(c) for c in element]

            def isRegularNode(c):
                return isinstance(
                    c, Node) and not isinstance(c, HandleErrorsNode)

            node.children = [c for c in children if isRegularNode(c)]
            handleNodes = [
                c for c in children if isinstance(c, HandleErrorsNode)
            ]
            if len(handleNodes) > 0:
                node.handleErrorsNode = handleNodes.pop()

        if isinstance(node, PipelinesNode):
            if len(node.children) > 0:
                node.children[-1].isLast = True

        if isinstance(node, ComponentConfigurations):
            self.processor.componentConfigurations = node.element

        return node