diff --git a/build/classes/xid/Presenter.class b/build/classes/xid/Presenter.class index 473dcc8..f962186 100644 Binary files a/build/classes/xid/Presenter.class and b/build/classes/xid/Presenter.class differ diff --git a/build_test/classes/xid/test/Test.class b/build_test/classes/xid/test/Test.class index 17cec62..fa0764f 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 5fbd7ba..5f1b4d3 100644 Binary files a/dist/test.jar and b/dist/test.jar differ diff --git a/dist/xid.jar b/dist/xid.jar index a30bc79..10790f7 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 0e8f29d..e3d965e 100644 --- a/src/xid/Presenter.java +++ b/src/xid/Presenter.java @@ -269,6 +269,20 @@ public class Presenter { StringBuffer result; + result = processChildren (node, datas, webappPath, "", errorOutput); + + // + return (result); + } + + + /* + * + */ + static protected StringBuffer processChildren (Node node, TagsDataById datas, String webappPath, String prefix, StringBuffer errorOutput) + { + StringBuffer result; + result = new StringBuffer (); NodeList children = node.getChildNodes(); @@ -283,7 +297,7 @@ public class Presenter for (int i = 0; i < childrenCount; i++) { - result.append (process (children.item(i), datas, webappPath, errorOutput)); + result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); } } @@ -413,6 +427,35 @@ public class Presenter TagsDataById datas, String webappPath, StringBuffer errorOutput) + + { + StringBuffer result; + + result = processElementWithId (node, attrs, idAttr, datas, "", webappPath, errorOutput); + + // + return (result); + } + + + /** + * Processes a node that has dynamic content. Calls the appropriate code + * generator method, depending on the tag. + * + * @param node + * Current node. + * @param attrs + * The tag attributes. + * @param idAttr + * The ID. + */ + static protected StringBuffer processElementWithId (Node node, + NamedNodeMap attrs, + Node idAttr, + TagsDataById datas, + String webappPath, + String prefix, + StringBuffer errorOutput) { StringBuffer result; result = new StringBuffer (); @@ -427,7 +470,7 @@ public class Presenter if (dataCore == null) { - result.append (Presenter.processElementBasically (node, datas, webappPath, errorOutput)); + result.append (Presenter.processElementBasically (node, datas, webappPath, prefix, errorOutput)); } else if (dataCore instanceof TagData) { @@ -451,7 +494,7 @@ public class Presenter result.append (node.getNodeName()); // Build attributes. - result.append (processAttributes (attrs, data)); + result.append (processAttributes (attrs, data, prefix)); if ((node.getChildNodes () == null) && ((data == null) || data.display ().equals (""))) @@ -467,7 +510,7 @@ public class Presenter if ((data == null) || (data.display ().equals (""))) { - result.append (processChildren (node, datas, webappPath, errorOutput)); + result.append (processChildren (node, datas, webappPath, prefix, errorOutput)); } else { @@ -488,40 +531,51 @@ public class Presenter int nbLines = tags.size (); for (int nLine = 0; nLine < nbLines; nLine++) { - TagData data = (TagData) tags.elementAt (nLine); - - // Open the tag. - result.append ("<"); - result.append (node.getNodeName()); - - // Build attributes. - result.append (processAttributes (attrs, data, Integer.toString (nLine))); - - if ((node.getChildNodes () == null) && - ((data == null) || data.display ().equals (""))) + if (tags.elementAt (nLine) instanceof TagData) { - // Close the tag. - result.append (" />\n"); - } - else - { - result.append ('>'); + TagData data = (TagData) tags.elementAt (nLine); - // Insert data. - if ((data == null) || - (data.display ().equals (""))) + // Open the tag. + result.append ("<"); + result.append (node.getNodeName()); + + // Build attributes. + result.append (processAttributes (attrs, data, Integer.toString (nLine))); + + if ((node.getChildNodes () == null) && + ((data == null) || data.display ().equals (""))) { - result.append (processChildren (node, datas, webappPath, errorOutput)); + // Close the tag. + result.append (" />\n"); } else { - result.append (data.display ()); + result.append ('>'); + + // Insert data. + if ((data == null) || + (data.display ().equals (""))) + { + result.append (processChildren (node, datas, webappPath, prefix, errorOutput)); + } + else + { + result.append (data.display ()); + } + + // Close the tag. + result.append ("\n"); } + } + else + { + // Manage a Hashmap. + TagsDataById data = (TagsDataById) tags.elementAt (nLine); - // Close the tag. - result.append ("\n"); + result.append (Presenter.processElementWithId (node, attrs, idAttr, data, webappPath, Integer.toString (nLine), errorOutput)); + result.append ('\n'); } } } @@ -542,10 +596,24 @@ public class Presenter /** - * Recursive method that processes a node and any child nodes. * */ static protected StringBuffer process (Node node, TagsDataById datas, String webappPath, StringBuffer errorOutput) + { + StringBuffer result; + + result = Presenter.process (node, datas, webappPath, "", errorOutput); + + // + return (result); + } + + + /** + * Recursive method that processes a node and any child nodes. + * + */ + static protected StringBuffer process (Node node, TagsDataById datas, String webappPath, String prefix, StringBuffer errorOutput) { log.debug ("Enter"); String TRANSITIONAL_DTD = "xhtml1-transitional.dtd"; @@ -590,7 +658,7 @@ public class Presenter // Log.write(Log.TRACE,"systemId = " + systemId); } - result.append (Presenter.process (((Document) node).getDocumentElement(), datas, webappPath, errorOutput)); + result.append (Presenter.process (((Document) node).getDocumentElement(), datas, webappPath, prefix, errorOutput)); break; } @@ -604,11 +672,11 @@ public class Presenter if (idAttr != null) { - result.append (Presenter.processElementWithId (node, attrs, idAttr, datas, webappPath, errorOutput)); + result.append (Presenter.processElementWithId (node, attrs, idAttr, datas, webappPath, prefix, errorOutput)); } else { - result.append (Presenter.processElementBasically (node, datas, webappPath, errorOutput)); + result.append (Presenter.processElementBasically (node, datas, webappPath, prefix, errorOutput)); } break; @@ -673,8 +741,23 @@ public class Presenter /* + * */ static StringBuffer processElementBasically (Node node, TagsDataById datas, String webappPath, StringBuffer errorOutput) + { + StringBuffer result; + + result = processElementBasically (node, datas, webappPath, "", errorOutput); + + // + return (result); + } + + + /* + * + */ + static StringBuffer processElementBasically (Node node, TagsDataById datas, String webappPath, String prefix, StringBuffer errorOutput) { StringBuffer result; result = new StringBuffer (); @@ -694,6 +777,14 @@ public class Presenter result.append (attr.getNodeName()); result.append ("=\""); result.append (restoreEntities(new StringBuffer(attr.getNodeValue()))); + + // Don't forget the list case. + if ((attr.getNodeName ().equals ("id")) && (prefix.length () != 0)) + { + result.append ('_'); + result.append (prefix); + } + result.append ("\""); } @@ -718,7 +809,7 @@ public class Presenter for (int i = 0; i < childrenCount; i++) { - result.append (process (children.item(i), datas, webappPath, errorOutput)); + result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); } result.append(" attribute = (Map.Entry) iterator.next(); - if (attribute.getKey ().equals ("id")) + if ((attribute.getKey ().equals ("id")) && (prefix.length () != 0)) { result.append(" " + attribute.getKey () + "=\"" + attribute.getValue () + '_' + prefix + "\""); } diff --git a/test/xid/test/Test.java b/test/xid/test/Test.java index 2d03921..fb7c0f7 100644 --- a/test/xid/test/Test.java +++ b/test/xid/test/Test.java @@ -251,6 +251,34 @@ class Test System.out.println (""); System.out.println ("=>"); System.out.println (html); + + + // Populate attributes of Test 03. + datas = new TagsDataById (); + 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"); + + + errorMessage = new StringBuffer (); + html = Presenter.doXid ("\n \n
noidun nomun prenom
", datas, "", errorMessage); + System.out.println ("----------------------------"); + System.out.println ("datas = new TagsDataId ();"); + 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 ("
un nomun prenom
"); + System.out.println ("=>"); + System.out.println (html); } } diff --git a/test/xid/test/Test.java~ b/test/xid/test/Test.java~ index 8d5d95c..2d03921 100644 --- a/test/xid/test/Test.java~ +++ b/test/xid/test/Test.java~ @@ -90,10 +90,31 @@ class Test } } + static private org.apache.log4j.Logger log; static { + // Initialize log. + org.apache.log4j.Logger log = null; + + org.apache.log4j.BasicConfigurator.configure (); + + + log = org.apache.log4j.Logger.getRootLogger (); + //log.setLevel (org.apache.log4j.Level.INFO); + log.setLevel (org.apache.log4j.Level.INFO); + + log.info ("Enter"); + + // + log.info ("Set the log file format..."); + + + // log = org.apache.log4j.Category.getInstance(Application.class.getName()); + log.info ("... done."); + + log.debug ("Exit"); log = org.apache.log4j.Logger.getLogger (Test.class.getName ()); } @@ -108,24 +129,127 @@ class Test //test (); // - TagsDataById datas = new TagsDataById (); + TagsDataById datas; TagData tag; - // Populate attributes of Test 03. - tag = new TagData (); - tag.setContent ("hello"); - tag.getAttributes ().appendAttribute ("style", "background: blue;"); - tag.getAttributes ().appendAttribute ("style", "foreground: red;"); - tag.getAttributes ().setAttribute ("class", "totoClass"); - datas.put ("test03", tag); + + StringBuffer html; StringBuffer errorMessage; + // Populate attributes of Test 03. + datas = new TagsDataById (); + tag = new TagData (); + tag.setContent ("Superman"); + datas.put ("name", tag); + errorMessage = new StringBuffer (); - html = Presenter.doXid ("bla", datas, "", errorMessage); + html = Presenter.doXid ("
a name
", datas, "", errorMessage); System.out.println ("----------------------------"); + System.out.println ("datas = new TagsDataId ();"); + System.out.println ("tag = new TagData ();"); + System.out.println ("tag.setContent (\"Superman\");"); + System.out.println ("datas.put (\"name\", tag););"); + System.out.println ("+"); + System.out.println ("
a name
"); + System.out.println ("=>"); + System.out.println (html); + + + // Populate attributes of Test 03. + datas = new TagsDataById (); + datas.setContent ("name", "Superman"); + + errorMessage = new StringBuffer (); + html = Presenter.doXid ("
a name
", datas, "", errorMessage); + + System.out.println ("----------------------------"); + System.out.println ("datas = new TagsDataId ();"); + System.out.println ("datas.setContent (\"name\", \"Superman\");"); + System.out.println ("+"); + System.out.println ("
a name
"); + System.out.println ("=>"); + System.out.println (html); + + + // Populate attributes of Test 03. + datas = new TagsDataById (); + tag = new TagData (); + tag.setContent ("Spiderman"); + tag.getAttributes ().appendAttribute ("style", "background: blue;"); + tag.getAttributes ().appendAttribute ("style", "foreground: red;"); + tag.getAttributes ().setAttribute ("class", "nameClass"); + datas.put ("lastname", tag); + + + errorMessage = new StringBuffer (); + html = Presenter.doXid ("
a last name
", datas, "", errorMessage); + + System.out.println ("----------------------------"); + System.out.println ("datas = new TagsDataId ();"); + System.out.println ("tag = new TagData ();"); + System.out.println ("tag.getAttributes ().setAttribute (\"class\", \"lastnameClass\");"); + System.out.println ("tag.getAttributes ().appendAttribute (\"style\", \"background: blue;\");"); + System.out.println ("tag.getAttributes ().appendAttribute (\"style\", \"foreground: red;\");"); + System.out.println ("tag.setContent (\"Spiderman\");"); + System.out.println ("datas.put (\"lastname\", tag););"); + System.out.println ("+"); + System.out.println ("
a last name
"); + System.out.println ("=>"); + System.out.println (html); + + + // Populate attributes of Test 03. + datas = new TagsDataById (); + datas.setContent ("lastname", "Spiderman"); + datas.appendAttribute ("lastname", "style", "background: blue;"); + datas.appendAttribute ("lastname", "style", "foreground: red;"); + datas.setAttribute ("lastname", "class", "nameClass"); + + + errorMessage = new StringBuffer (); + html = Presenter.doXid ("
a last name
", datas, "", errorMessage); + + System.out.println ("----------------------------"); + System.out.println ("datas = new TagsDataId ();"); + System.out.println ("datas.setContent (\"lastname\", \"Spiderman\");"); + System.out.println ("datas.appendAttribute (\"lastname\", \"style\", \"foreground: red;\");"); + System.out.println ("datas.appendAttribute (\"lastname\", \"style\", \"foreground: red;\""); + System.out.println ("datas.setAttribute (\"lastname\", \"class\", \"nameClass\");"); + System.out.println ("+"); + System.out.println ("
a last name
"); + System.out.println ("=>"); + System.out.println (html); + + + // Populate attributes of Test 03. + datas = new TagsDataById (); + datas.setContent ("words", 0, "alpha"); + datas.setContent ("words", 1, "bravo"); + datas.setContent ("words", 2, "charlie"); + datas.setContent ("words", 3, "delta"); + datas.setContent ("words", 4, "echo"); + datas.setContent ("words", 5, "fox"); + + + errorMessage = new StringBuffer (); + html = Presenter.doXid ("", datas, "", errorMessage); + + System.out.println ("----------------------------"); + System.out.println ("datas = new TagsDataId ();"); + System.out.println ("datas.setContent (\"words\", 0, \"alpha\");"); + System.out.println ("datas.setContent (\"words\", 1, \"bravo\");"); + System.out.println ("datas.setContent (\"words\", 2, \"charlie\");"); + System.out.println ("datas.setContent (\"words\", 3, \"delta\");"); + System.out.println ("datas.setContent (\"words\", 4, \"echo\");"); + System.out.println ("datas.setContent (\"words\", 5, \"fox\");"); + System.out.println ("+"); + System.out.println (""); + System.out.println ("=>"); System.out.println (html); System.out.println ("----------------------------"); }