handle infinite recursion in markup keys
authorAndreas Müller <a.mueller@bgbm.org>
Wed, 9 Oct 2013 16:45:05 +0000 (16:45 +0000)
committerAndreas Müller <a.mueller@bgbm.org>
Wed, 9 Oct 2013 16:45:05 +0000 (16:45 +0000)
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/markup/MarkupKeyImport.java

index edbeb24bb988751ca42eaccb090824f6e9ba2615..4cfe234fc7c32791881286180574206090b34dc0 100644 (file)
@@ -171,9 +171,14 @@ public class MarkupKeyImport  extends MarkupImportBase  {
                        Set<PolytomousKeyNode> nodes = state.getUnmatchedLeads().getNodes(unmatchedKey);\r
                        for(PolytomousKeyNode nodeToMatch: nodes){\r
                                for (PolytomousKeyNode childNode : childList){\r
-                                       nodeToMatch.addChild(childNode);\r
-                                       //just to be on the save side\r
-                                       nodeToMatch.refreshNodeNumbering();\r
+                                       try {\r
+                                               nodeToMatch.addChild(childNode);\r
+                                               //just to be on the save side\r
+                                               nodeToMatch.refreshNodeNumbering();\r
+                                       } catch (Exception e) {\r
+                                               String message = "An exception occurred when trying to add a key node child or to referesh the node numbering: " + e.getMessage();\r
+                                               fireWarningEvent(message, parentEvent, 6);\r
+                                       }\r
                                }\r
                                state.getUnmatchedLeads().removeNode(unmatchedKey, nodeToMatch);\r
                        }\r
@@ -374,11 +379,11 @@ public class MarkupKeyImport  extends MarkupImportBase  {
                \r
                //try to find matching lead nodes \r
                UnmatchedLeadsKey leadsKey = UnmatchedLeadsKey.NewInstance(num, nameString);\r
-               Set<PolytomousKeyNode> matchingNodes = handleMatchingNodes(state, taxon, leadsKey);\r
+               Set<PolytomousKeyNode> matchingNodes = handleMatchingNodes(state, event, taxon, leadsKey);\r
                \r
                if (num != null){//same without using the num\r
                        UnmatchedLeadsKey noNumLeadsKey = UnmatchedLeadsKey.NewInstance("", nameString);\r
-                       Set<PolytomousKeyNode> noNumMatchingNodes = handleMatchingNodes(state, taxon, noNumLeadsKey);\r
+                       Set<PolytomousKeyNode> noNumMatchingNodes = handleMatchingNodes(state, event, taxon, noNumLeadsKey);\r
                        if(noNumMatchingNodes.size() > 0){\r
                                String message ="Taxon matches additional key node when not considering <num> attribute in taxontitle. This may be correct but may also indicate an error.";\r
                                fireWarningEvent(message, event, 1);\r
@@ -393,13 +398,18 @@ public class MarkupKeyImport  extends MarkupImportBase  {
                \r
        }\r
        \r
-       private Set<PolytomousKeyNode> handleMatchingNodes(MarkupImportState state, Taxon taxon, UnmatchedLeadsKey leadsKey) {\r
+       private Set<PolytomousKeyNode> handleMatchingNodes(MarkupImportState state, XMLEvent event, Taxon taxon, UnmatchedLeadsKey leadsKey) {\r
                Set<PolytomousKeyNode> matchingNodes = state.getUnmatchedLeads().getNodes(leadsKey);\r
                for (PolytomousKeyNode matchingNode : matchingNodes){\r
                        state.getUnmatchedLeads().removeNode(leadsKey, matchingNode);\r
                        matchingNode.setTaxon(taxon);\r
                        //just to be on the save side\r
-                       matchingNode.refreshNodeNumbering();\r
+                       try{    \r
+                               matchingNode.refreshNodeNumbering();\r
+                       } catch (Exception e) {\r
+                               String message = "An exception occurred when trying to referesh the node numbering: " + e.getMessage();\r
+                               fireWarningEvent(message, event, 6);\r
+                       }\r
                        state.getPolytomousKeyNodesToSave().add(matchingNode);\r
                }\r
                return matchingNodes;\r