def passing_XMLtree(node, oldlayers_Server, newlayers_Server, cur, conn, name_xmlfile): # Will store the number of Server and URL where store .DTD file global Nwms, URL_dtd # If the node not the text (is not between opening and closing tags) if node.nodeType != node.TEXT_NODE: if(node.nodeName == "Service"): # Handler is called subtree tag <Service> and defined number of Server Nwms = 0 Nwms = parse_subtreeService(node, cur, conn, name_xmlfile) # Get all the layers of this server already exists in the database # SELECT Nlayer, Name From KnownLayers WHERE Nwms = Nwms; condition = {} condition["Nwms"] = Nwms oldlayers_Server = BD.ifselect_table(cur, "KnownLayers", "Nlayer", condition, "Name") # access to the following brother of the node that not to handle the # node some times node = node.nextSibling if(node.nodeName == "Layer"): # Handler is called subtree tag <Service> and defined number of Server parse_subtreeLayer(node, newlayers_Server, cur, conn, -1) # access to the following brother of the node node = node.nextSibling if(node.nodeName == "Capability"): # Update table WMSresources. Find record with primary key = Nwms # SELECT Nwms, Name FROM WMSresources WHERE Nwms = Nwms; condition = {} condition["Nwms"] = Nwms res = BD.ifselect_table(cur, "WMSresources", "Nwms", condition, "Name") if res: # If this Server already exists in the database # UPDATE WMSresources SET # Capabilites = 'node.toxml('utf-8').replace("\", "\'\'")' # WHERE Nwms = Nwms; BD.updatebd_xmlfield(cur, conn, "WMSresources", "Capabilites", node,\ "Nwms", Nwms) if(node.nodeType != node.TEXT_NODE): if node.nodeType == node.DOCUMENT_TYPE_NODE: # If the node is tag <!DOCTYPE> global URL_dtd # URL where store .DTD file URL_dtd = node.systemId # Recursively goes through all subnodes for child in node.childNodes: oldlayers_Server = passing_XMLtree(child, oldlayers_Server, newlayers_Server,\ cur, conn, name_xmlfile) # Returns a list of server layers, that were already in the database return oldlayers_Server
def form_layerInfo(cur, layer_id, capabilities): # Requested by the parent layer "parent_id" values = {} values["Nlayer"] = layer_id res = BD.ifselect_table(cur, "KnownLayers", "Nlayer", values, "Nl_group") for Nlayer, parent_id in res: # Requested tag SRS from "Capabilities" # SELECT xpath_nodeset(LayerCapabilites, '/Layer/SRS') WHERE Nlayer = Nlayer; result = BD.interset_request(cur, "KnownLayers", "LayerCapabilites", "/Layer/SRS", "Nlayer", Nlayer) if result: capabilities = insert_tag(result[0][0], capabilities, "<SRS>", "</SRS>", 1) # Requested tag LatLonBoundingBox from "Capabilities" # SELECT xpath_nodeset(LayerCapabilites, '/Layer/LatLonBoundingBox') WHERE Nlayer = Nlayer; result = BD.interset_request(cur, "KnownLayers", "LayerCapabilites", "/Layer/LatLonBoundingBox", "Nlayer", Nlayer) if result: capabilities = insert_tag(result[0][0], capabilities, "<LatLonBoundingBox", "</LatLonBoundingBox>", 0) # Requested tag BoundingBox from "Capabilities" # SELECT xpath_nodeset(LayerCapabilites, '/Layer/BoundingBox') WHERE Nlayer = Nlayer; result = BD.interset_request(cur, "KnownLayers", "LayerCapabilites", "/Layer/BoundingBox", "Nlayer", Nlayer) if result: capabilities = insert_tag(result[0][0], capabilities, "<BoundingBox", "</BoundingBox>", 0) # Requested tag Style from "Capabilities" # SELECT xpath_nodeset(LayerCapabilites, '/Layer/Style') WHERE Nlayer = Nlayer; result = BD.interset_request(cur, "KnownLayers", "LayerCapabilites", "/Layer/Style", "Nlayer", Nlayer) if result: capabilities = insert_tag(result[0][0], capabilities, "<Style>", "</Style>", 1) if parent_id != -1: capabilities = form_layerInfo(cur, parent_id, capabilities) return capabilities
def form_subxml(cur, Nlayer, capabilities, server_URL, flnogroup): # Requested to number the server layers, the parent layer and Capabilities. values = {} values["Nlayer"] = Nlayer res = BD.ifselect_table(cur, "KnownLayers", "Nlayer", values, "Nwms", "Nl_group", "LayerCapabilites") for Nlayer, Nwms, parent_id, sub_capabilities in res: if flnogroup: # If the layer is not a group if parent_id != -1: sub_capabilities = form_layerInfo(cur, parent_id, sub_capabilities) capabilities = capabilities + form_layer(sub_capabilities, Nlayer, server_URL) else: # If the layer is a group capabilities = capabilities + form_layerGroup(cur, Nlayer) return capabilities