Allow filter collection element inside route
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 27 Dec 2011 12:39:28 +0000 (13:39 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 27 Dec 2011 12:39:28 +0000 (13:39 +0100)
This makes it possible to include multiple filters at once.

src/router_flexml.cpp
xml/schema/metaproxy.rnc

index a904d6e..dd08976 100644 (file)
@@ -69,6 +69,9 @@ namespace metaproxy_1 {
 
         void parse_xml_filters(xmlDocPtr doc, const xmlNode *node,
                                bool test_only, const char *file_include_path);
+        void parse_xml_filters1(xmlDocPtr doc, const xmlNode *node,
+                                bool test_only, const char *file_include_path,
+                                Route &route);
         void parse_xml_routes(xmlDocPtr doc, const xmlNode *node,
                               bool test_only, const char *file_include_path);
         void check_routes_in_filters(const xmlNode *n);
@@ -141,74 +144,51 @@ void mp::RouterFleXML::Rep::parse_xml_filters(xmlDocPtr doc,
     }
 }
 
-void mp::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc,
-                                             const xmlNode *node,
-                                             bool test_only,
-                                             const char *file_include_path)
+void mp::RouterFleXML::Rep::parse_xml_filters1(xmlDocPtr doc,
+                                              const xmlNode *node,
+                                              bool test_only,
+                                              const char *file_include_path,
+                                              Route &route)
 {
-    mp::xml::check_element_mp(node, "route");
-
-    unsigned int route_nr = 0;
-    while (mp::xml::is_element_mp(node, "route"))
+    while (node)
     {
-        route_nr++;
-
-        const struct _xmlAttr *attr;
-        std::string id_value;
-        for (attr = node->properties; attr; attr = attr->next)
+        if (mp::xml::is_element_mp(node, "filters"))
         {
-            std::string name = std::string((const char *) attr->name);
-            std::string value;
-            
-            if (attr->children && attr->children->type == XML_TEXT_NODE)
-                value = std::string((const char *)attr->children->content);
-            
-            if (name == "id")
-                id_value = value;
-            else
-                throw mp::XMLError("Only attribute 'id' allowed for"
-                                    " element 'route'."
-                                    " Got " + name);
-        }
-
-        Route route;
-
-        // process <filter> nodes in third level
-        const xmlNode* node3 = mp::xml::jump_to_children(node, XML_ELEMENT_NODE);
+            const xmlNode* node1 =
+                mp::xml::jump_to_children(node, XML_ELEMENT_NODE);
 
-        unsigned int filter3_nr = 0;
-        while (node3 && mp::xml::check_element_mp(node3, "filter"))
+            parse_xml_filters1(doc, node1, test_only, file_include_path, route);
+        }
+        else if (mp::xml::check_element_mp(node, "filter"))
         {
-            filter3_nr++;
-            
             const struct _xmlAttr *attr;
             std::string refid_value;
             std::string type_value;
-            for (attr = node3->properties; attr; attr = attr->next)
+            for (attr = node->properties; attr; attr = attr->next)
             {
                 std::string name = std::string((const char *) attr->name);
                 std::string value;
-                
+            
                 if (attr->children && attr->children->type == XML_TEXT_NODE)
                     value = std::string((const char *)attr->children->content);
-                
+            
                 if (name == "refid")
                     refid_value = value;
                 else if (name == "type")
                     type_value = value;
                 else
                     throw mp::XMLError("Only attribute 'refid' or 'type'"
-                                        " allowed for element 'filter'."
-                                        " Got " + name);
+                                       " allowed for element 'filter'."
+                                       " Got " + name);
             }
             if (refid_value.length())
             {
                 std::map<std::string,
-                    boost::shared_ptr<const mp::filter::Base > >::iterator it;
+                         boost::shared_ptr<const mp::filter::Base > >::iterator it;
                 it = m_id_filter_map.find(refid_value);
                 if (it == m_id_filter_map.end())
                     throw mp::XMLError("Unknown filter refid "
-                                        + refid_value);
+                                       + refid_value);
                 else
                     route.m_list.push_back(it->second);
             }
@@ -221,15 +201,55 @@ void mp::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc,
                     m_factory->add_creator_dl(type_value, m_dl_path);
                 }
                 mp::filter::Base* filter_base = m_factory->create(type_value);
-
-                filter_base->configure(node3, test_only, file_include_path);
-                
+            
+                filter_base->configure(node, test_only, file_include_path);
+            
                 route.m_list.push_back(
                     boost::shared_ptr<mp::filter::Base>(filter_base));
             }
-            node3 = mp::xml::jump_to_next(node3, XML_ELEMENT_NODE);
+        
+        }
+        node = mp::xml::jump_to_next(node, XML_ELEMENT_NODE);
+    }
+}
+
+
+void mp::RouterFleXML::Rep::parse_xml_routes(xmlDocPtr doc,
+                                             const xmlNode *node,
+                                             bool test_only,
+                                             const char *file_include_path)
+{
+    mp::xml::check_element_mp(node, "route");
+
+    unsigned int route_nr = 0;
+    while (mp::xml::is_element_mp(node, "route"))
+    {
+        route_nr++;
+
+        const struct _xmlAttr *attr;
+        std::string id_value;
+        for (attr = node->properties; attr; attr = attr->next)
+        {
+            std::string name = std::string((const char *) attr->name);
+            std::string value;
+            
+            if (attr->children && attr->children->type == XML_TEXT_NODE)
+                value = std::string((const char *)attr->children->content);
             
+            if (name == "id")
+                id_value = value;
+            else
+                throw mp::XMLError("Only attribute 'id' allowed for"
+                                    " element 'route'."
+                                    " Got " + name);
         }
+
+        Route route;
+
+        // process <filter> / <filters> nodes in third level
+        const xmlNode* node3 = mp::xml::jump_to_children(node, XML_ELEMENT_NODE);
+        parse_xml_filters1(doc, node3, test_only, file_include_path, route);
+
         std::map<std::string,RouterFleXML::Route>::iterator it;
         it = m_routes.find(id_value);
         if (it != m_routes.end())
@@ -245,7 +265,13 @@ void mp::RouterFleXML::Rep::check_routes_in_filters(const xmlNode *node)
 {
     while (node)
     {
-        if (mp::xml::is_element_mp(node, "filter"))
+        if (mp::xml::is_element_mp(node, "filters"))
+        {
+            const xmlNode *n =
+                mp::xml::jump_to_children(node, XML_ELEMENT_NODE);
+            check_routes_in_filters(n);
+        }
+        else if (mp::xml::is_element_mp(node, "filter"))
         {
             const xmlNode *n =
                 mp::xml::jump_to_children(node, XML_ELEMENT_NODE);
index f128ed5..8b2262e 100644 (file)
@@ -57,7 +57,13 @@ metaproxy =
 route =
   element mp:route {
     attribute id { xsd:NCName },
-    filter+
+    filters+
+  }
+
+filters =
+  filter |
+  element mp:filters {
+    filters+
   }
 
 filter =