diff --git a/build/classes/xid/Presenter.class b/build/classes/xid/Presenter.class index 5eff7e2..e0e6d6f 100644 Binary files a/build/classes/xid/Presenter.class and b/build/classes/xid/Presenter.class differ diff --git a/build/classes/xid/TagsData.class b/build/classes/xid/TagsData.class index d065714..68212a5 100644 Binary files a/build/classes/xid/TagsData.class and b/build/classes/xid/TagsData.class differ diff --git a/build_test/classes/xid/test/Test.class b/build_test/classes/xid/test/Test.class index 1da341f..5a5533d 100644 Binary files a/build_test/classes/xid/test/Test.class and b/build_test/classes/xid/test/Test.class differ diff --git a/dist/test.jar b/dist/test.jar index 54295a7..cdf3f1a 100644 Binary files a/dist/test.jar and b/dist/test.jar differ diff --git a/dist/xid.jar b/dist/xid.jar index c759277..d121051 100644 Binary files a/dist/xid.jar and b/dist/xid.jar differ diff --git a/src/xid/Presenter.java b/src/xid/Presenter.java index 0828a56..bacbf79 100644 --- a/src/xid/Presenter.java +++ b/src/xid/Presenter.java @@ -283,64 +283,146 @@ public class Presenter static protected StringBuffer processChildren (Node node, TagsDataById datas, String webappPath, String prefix, StringBuffer errorOutput) { StringBuffer result; - result = new StringBuffer (); NodeList children = node.getChildNodes(); + int childrenCount = children.getLength (); - if (children == null) + if ((children == null) || (childrenCount == 0)) { result.append (" "); } else { - int childrenCount = children.getLength (); - - // TODO Analyze IterationStragy if datas is a TagsData. + // + // Is there a TagsDataByIndex associated with the first ELEMENT_NODE child? + // + TagsDataByIndex tagsData; - // Determine - NamedNodeMap attrs = node.getAttributes (); - Node idAttr = attrs.getNamedItem ("id"); - String tag = node.getNodeName(); - String idValue = idAttr.getNodeValue(); - - TagDataCore tagDataCore = datas.getId (idValue); - if (tagDataCore instanceof TagsDataByIndex) + // Find the first ELEMENT_NODE child. + int childIndex = 0; + Node child = null; + boolean ended = false; + while (!ended) { - TagsDataByIndex tagsData = (TagsDataByIndex) tagDataCore; + if (childIndex >= childrenCount) + { + ended = true; + child = null; + } + else if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE) + { + ended = true; + child = children.item (childIndex); + } + else + { + childIndex += 1; + } + } + + System.out.println ("childIndex=" + childIndex); + if (child == null) + { + tagsData = null; + } + else + { + // Searching for the ID value of the child. + String childId; + + System.out.println ("child" + child); + NamedNodeMap attrsChild = child.getAttributes (); + System.out.println ("attrsChild=" + attrsChild); + + if (attrsChild == null) + { + childId = null; + } + else + { + Node idAttrChild; + idAttrChild = attrsChild.getNamedItem ("id"); + + if (idAttrChild == null) + { + childId = null; + } + else + { + childId = idAttrChild.getNodeValue (); + } + } + + + // Searching for the datas associated to the childId. + if (childId == null) + { + tagsData = null; + } + else + { + // Check if the data is a TagsDataByIndex. + if (datas.getId (childId) instanceof TagsDataByIndex) + { + tagsData = (TagsDataByIndex) datas.getId (childId); + } + else + { + tagsData = null; + } + } + } + + + // So, is there? + if (tagsData == null) + { + for (int i = 0; i < childrenCount; i++) + { + result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); + } + } + else + { + System.out.println ("TagsDataByIndex detected."); switch (tagsData.getIterationStrategy ()) { - case TagsDataByIndex.ONLY_FIRST_ROW: - result.append (process (children.item (0), datas, webappPath, prefix, errorOutput)); + case ONLY_FIRST_ROW: + System.out.println ("ONLY FIRST ROW"); + result.append (process (child, datas, webappPath, prefix, errorOutput)); break; - case TagsDataByIndex.ONLY_ROWS_WITH_ID: + case ONLY_ROWS_WITH_ID: + System.out.println ("ONLY ROWS WITH ID"); for (int i = 0; i < childrenCount; i++) { - NamedNodeMap attrs2 = children.item (i); - Node idAttr2 = attrs2.getNamedItem ("id"); + NamedNodeMap attrs2 = children.item (i).getAttributes (); - if (idAttr2 != null) + if ((attrs2 != null) && + (attrs2.getNamedItem ("id") != null)) { - result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); + result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); } } break; - case TagsDataByIndex.ONLY_ROWS_WITHOUT_ID: + case ONLY_ROWS_WITHOUT_ID: for (int i = 0; i < childrenCount; i++) { - NamedNodeMap attrs2 = children.item (i); - Node idAttr2 = attrs2.getNamedItem ("id"); + // Process row? + boolean processRow; - if (idAttr2 == null) + NamedNodeMap attrs2 = children.item (i).getAttributes (); + if ((attrs2 == null) || + (attrs2.getNamedItem ("id") == null)) { - result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); + result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); } } break; - case TagsDataByIndex.ALL_ROWS: + case ALL_ROWS: for (int i = 0; i < childrenCount; i++) { result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); @@ -348,13 +430,6 @@ public class Presenter break; } } - else - { - for (int i = 0; i < childrenCount; i++) - { - result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); - } - } } // @@ -725,13 +800,14 @@ public class Presenter NamedNodeMap attrs = node.getAttributes (); Node idAttr = attrs.getNamedItem ("id"); - + + System.out.println ("process=" + node); if (idAttr != null) { result.append (Presenter.processElementWithId (node, attrs, idAttr, datas, webappPath, prefix, errorOutput)); } else - { + {System.out.println ("basically"); result.append (Presenter.processElementBasically (node, datas, webappPath, prefix, errorOutput)); } @@ -846,32 +922,19 @@ public class Presenter // - NodeList children = node.getChildNodes(); - if (children == null) + if (node.getChildNodes () == null) { result.append(" />"); } else { - int childrenCount = children.getLength (); - - if (childrenCount == 0) - { - result.append(" />"); - } - else - { - result.append('>'); - - for (int i = 0; i < childrenCount; i++) - { - result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); - } - - result.append("'); - } + result.append('>'); + + result.append (processChildren (node, datas, webappPath, prefix, errorOutput)); + + result.append("'); } } diff --git a/src/xid/TagsData.java b/src/xid/TagsData.java index 458523a..cfc7b9c 100644 --- a/src/xid/TagsData.java +++ b/src/xid/TagsData.java @@ -114,7 +114,7 @@ public class TagsData extends TagsDataById /** * */ - public void setIterationStragey (String id, TagsDataByIndex.IterationStrategy strategy) + public void setIterationStrategy (String id, TagsDataByIndex.IterationStrategy strategy) { TagsDataByIndex tags = (TagsDataByIndex) this.get (id); diff --git a/src/xid/TagsDataByIndex.java b/src/xid/TagsDataByIndex.java index 73a34f4..e8ee8d9 100644 --- a/src/xid/TagsDataByIndex.java +++ b/src/xid/TagsDataByIndex.java @@ -8,7 +8,7 @@ import java.io.*; */ public class TagsDataByIndex extends Vector implements TagDataCore { - public enum IterationStrategy {ONLY_FIRST_ROW, ONLY_ROWS_WITH_ID, ONLY_ROWS_WITHOU_ID, ALL_ROWS} + public enum IterationStrategy {ONLY_FIRST_ROW, ONLY_ROWS_WITH_ID, ONLY_ROWS_WITHOUT_ID, ALL_ROWS} protected IterationStrategy iterationStrategy; diff --git a/test/xid/test/Test.java b/test/xid/test/Test.java index 00fa03d..ee83ebc 100644 --- a/test/xid/test/Test.java +++ b/test/xid/test/Test.java @@ -52,7 +52,7 @@ class Test - + String htmlSource; StringBuffer html; StringBuffer errorMessage; @@ -192,11 +192,53 @@ class Test System.out.println ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");"); System.out.println ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");"); System.out.println ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");"); + System.out.println ("+"); System.out.println (""); System.out.println (" "); + System.out.println (" "); + System.out.println (" "); System.out.println ("
un nomun prenom
un nomun prenom
un nomun prenom
"); System.out.println ("=>"); System.out.println (html); + + + // Populate attributes of Test 03. + datas = new TagsData (); + datas.setContent ("identity", 0, "nom", "Jemba"); + datas.setContent ("identity", 0, "prenom", "Epo"); + datas.setContent ("identity", 1, "nom", "Momon"); + datas.setContent ("identity", 1, "prenom", "Christian"); + datas.setContent ("identity", 2, "nom", "Tronche"); + datas.setContent ("identity", 2, "prenom", "Christophe"); + datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); + //datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); + //datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); + //datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ALL_ROWS); + + + errorMessage = new StringBuffer (); + StringBuffer source = new StringBuffer (); + source.append ("\n"); + source.append (" \n"); + source.append (" \n"); + source.append (" \n"); + source.append ("
noidun nomun prenom
noidun nomun prenom
noidun nomun prenom
"); + htmlSource = source.toString (); + html = Presenter.doXid (htmlSource, datas, "", errorMessage); + + System.out.println ("----------------------------"); + System.out.println ("datas = new TagsData ();"); + System.out.println ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");"); + System.out.println ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");"); + System.out.println ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");"); + System.out.println ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");"); + System.out.println ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");"); + System.out.println ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");"); + + System.out.println ("+"); + System.out.println (htmlSource); + System.out.println ("=>"); + System.out.println (html); } } diff --git a/test/xid/test/Test.java~ b/test/xid/test/Test.java~ index 16aba38..75c0380 100644 --- a/test/xid/test/Test.java~ +++ b/test/xid/test/Test.java~ @@ -47,17 +47,17 @@ class Test //test (); // - TagsDataById datas; + TagsData datas; TagData tag; - + String htmlSource; StringBuffer html; StringBuffer errorMessage; // Populate attributes of Test 03. - datas = new TagsDataById (); + datas = new TagsData (); tag = new TagData (); tag.setContent ("Superman"); datas.put ("name", tag); @@ -66,7 +66,7 @@ class Test html = Presenter.doXid ("
a name
", datas, "", errorMessage); System.out.println ("----------------------------"); - System.out.println ("datas = new TagsDataById ();"); + System.out.println ("datas = new TagsData ();"); System.out.println ("tag = new TagData ();"); System.out.println ("tag.setContent (\"Superman\");"); System.out.println ("datas.put (\"name\", tag););"); @@ -77,14 +77,14 @@ class Test // Populate attributes of Test 03. - datas = new TagsDataById (); + datas = new TagsData (); datas.setContent ("name", "Superman"); errorMessage = new StringBuffer (); html = Presenter.doXid ("
a name
", datas, "", errorMessage); System.out.println ("----------------------------"); - System.out.println ("datas = new TagsDataById ();"); + System.out.println ("datas = new TagsData ();"); System.out.println ("datas.setContent (\"name\", \"Superman\");"); System.out.println ("+"); System.out.println ("
a name
"); @@ -93,7 +93,7 @@ class Test // Populate attributes of Test 03. - datas = new TagsDataById (); + datas = new TagsData (); tag = new TagData (); tag.setContent ("Spiderman"); tag.getAttributes ().appendAttribute ("style", "background: blue;"); @@ -106,7 +106,7 @@ class Test html = Presenter.doXid ("
a last name
", datas, "", errorMessage); System.out.println ("----------------------------"); - System.out.println ("datas = new TagsDataById ();"); + System.out.println ("datas = new TagsData ();"); System.out.println ("tag = new TagData ();"); System.out.println ("tag.getAttributes ().setAttribute (\"class\", \"lastnameClass\");"); System.out.println ("tag.getAttributes ().appendAttribute (\"style\", \"background: blue;\");"); @@ -120,7 +120,7 @@ class Test // Populate attributes of Test 03. - datas = new TagsDataById (); + datas = new TagsData (); datas.setContent ("lastname", "Spiderman"); datas.appendAttribute ("lastname", "style", "background: blue;"); datas.appendAttribute ("lastname", "style", "foreground: red;"); @@ -131,7 +131,7 @@ class Test html = Presenter.doXid ("
a last name
", datas, "", errorMessage); System.out.println ("----------------------------"); - System.out.println ("datas = new TagsDataById ();"); + System.out.println ("datas = new TagsData ();"); System.out.println ("datas.setContent (\"lastname\", \"Spiderman\");"); System.out.println ("datas.appendAttribute (\"lastname\", \"style\", \"background: blue;\");"); System.out.println ("datas.appendAttribute (\"lastname\", \"style\", \"foreground: red;\""); @@ -143,7 +143,7 @@ class Test // Populate attributes of Test 03. - datas = new TagsDataById (); + datas = new TagsData (); datas.setContent ("words", 0, "alpha"); datas.setContent ("words", 1, "bravo"); datas.setContent ("words", 2, "charlie"); @@ -156,7 +156,7 @@ class Test html = Presenter.doXid ("", datas, "", errorMessage); System.out.println ("----------------------------"); - System.out.println ("datas = new TagsDataById ();"); + System.out.println ("datas = new TagsData ();"); System.out.println ("datas.setContent (\"words\", 0, \"alpha\");"); System.out.println ("datas.setContent (\"words\", 1, \"bravo\");"); System.out.println ("datas.setContent (\"words\", 2, \"charlie\");"); @@ -172,7 +172,7 @@ class Test // Populate attributes of Test 03. - datas = new TagsDataById (); + datas = new TagsData (); datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 1, "nom", "Momon"); @@ -182,21 +182,54 @@ class Test errorMessage = new StringBuffer (); - html = Presenter.doXid ("\n \n
noidun nomun prenom
", datas, "", errorMessage); + html = Presenter.doXid ("\n \n
noidun nomun prenom
", datas, "", errorMessage); System.out.println ("----------------------------"); - System.out.println ("datas = new TagsDataById ();"); + System.out.println ("datas = new TagsData ();"); System.out.println ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");"); System.out.println ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");"); System.out.println ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");"); System.out.println ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");"); System.out.println ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");"); System.out.println ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");"); + System.out.println ("+"); System.out.println (""); System.out.println (" "); + System.out.println (" "); + System.out.println (" "); System.out.println ("
un nomun prenom
un nomun prenom
un nomun prenom
"); System.out.println ("=>"); System.out.println (html); + + + // Populate attributes of Test 03. + datas = new TagsData (); + datas.setContent ("identity", 0, "nom", "Jemba"); + datas.setContent ("identity", 0, "prenom", "Epo"); + datas.setContent ("identity", 1, "nom", "Momon"); + datas.setContent ("identity", 1, "prenom", "Christian"); + datas.setContent ("identity", 2, "nom", "Tronche"); + datas.setContent ("identity", 2, "prenom", "Christophe"); + //datas.setIterationStrategy ("table" + + + errorMessage = new StringBuffer (); + htmlSource = "\n \n\n\n
noidun nomun prenom
noidun nomun prenom
noidun nomun prenom
"; + html = Presenter.doXid (htmlSource, datas, "", errorMessage); + + System.out.println ("----------------------------"); + System.out.println ("datas = new TagsData ();"); + System.out.println ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");"); + System.out.println ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");"); + System.out.println ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");"); + System.out.println ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");"); + System.out.println ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");"); + System.out.println ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");"); + + System.out.println ("+"); + System.out.println (htmlSource); + System.out.println ("=>"); + System.out.println (html); } }