diff --git a/build/classes/xid/Attributes.class b/build/classes/xid/Attributes.class index 7691c5e..a2cf8f1 100644 Binary files a/build/classes/xid/Attributes.class and b/build/classes/xid/Attributes.class differ diff --git a/build/classes/xid/Presenter.class b/build/classes/xid/Presenter.class index 2f5b08e..2dc6bc9 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 a2560f4..9785932 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 ffe9f01..4d6118d 100644 Binary files a/dist/test.jar and b/dist/test.jar differ diff --git a/dist/xid.jar b/dist/xid.jar index 433fd7c..532c1fc 100644 Binary files a/dist/xid.jar and b/dist/xid.jar differ diff --git a/src/xid/Attributes.java b/src/xid/Attributes.java index a283778..cad8b68 100644 --- a/src/xid/Attributes.java +++ b/src/xid/Attributes.java @@ -21,6 +21,15 @@ public class Attributes extends HashMap } + /* + * Useful for the merge attributes. + */ + public Attributes (Attributes attributes) + { + super (attributes); + } + + /* * */ diff --git a/src/xid/Presenter.java b/src/xid/Presenter.java index c9d2834..e812476 100644 --- a/src/xid/Presenter.java +++ b/src/xid/Presenter.java @@ -263,6 +263,89 @@ public class Presenter } + + /** + * + */ + static public Attributes getNamedTagAttributes (TagsDataById datas, String name) + { + Attributes result; + + if ((name == null) || (datas == null)) + { + result = null; + } + else + { + TagDataCore dataCore = datas.getId ("<" + name + ">"); + if (dataCore == null) + { + result = null; + } + else if (!(dataCore instanceof TagData)) + { + result = null; + } + else + { + TagData data = (TagData) dataCore; + + result = data.getAttributes (); + } + } + + // + return (result); + } + + + /** + * + */ + static public Attributes mergeAttributes (Attributes target, Attributes source) + { + Attributes result; + + // + if (target == null) + { + result = source; + } + else if (source == null) + { + result = target; + } + else + { + result = new Attributes (target); + + Iterator iterator = source.entrySet().iterator(); + + while (iterator.hasNext()) + { + Map.Entry attribute = (Map.Entry) iterator.next(); + + String currentValue = target.get (attribute.getKey ()); + + if (currentValue == null) + { + result.put (attribute.getKey (), attribute.getValue ()); + } + else if (attribute.getKey ().equals ("style")) + { + result.put (attribute.getKey (), currentValue + attribute.getValue ()); + } + else + { + result.put (attribute.getKey (), attribute.getValue ()); + } + } + } + + // + return (result); + } + /* * */ @@ -622,7 +705,7 @@ public class Presenter result.append (node.getNodeName()); // Build attributes. - result.append (processAttributes (attrs, data, prefix)); + result.append (processAttributes (attrs, data.getAttributes (), getNamedTagAttributes (datas, node.getNodeName ()), prefix)); if ((node.getChildNodes () == null) && ((data == null) || data.display ().equals (""))) @@ -668,7 +751,7 @@ public class Presenter result.append (node.getNodeName()); // Build attributes. - result.append (processAttributes (attrs, data, Integer.toString (nLine))); + result.append (processAttributes (attrs, data.getAttributes (), getNamedTagAttributes (datas, node.getNodeName ()), Integer.toString (nLine))); if ((node.getChildNodes () == null) && ((data == null) || data.display ().equals (""))) @@ -751,7 +834,6 @@ public class Presenter if (node != null) { log.debug ("nodeName=" + node.getNodeName ()); - // Find the name attribute value. String name; name = getClassAttributeValue (node); @@ -891,43 +973,25 @@ public class Presenter result.append (node.getNodeName()); // Build the tag attributes. - NamedNodeMap attrs = node.getAttributes (); - if (attrs != null) + result.append (processAttributes (node.getAttributes (), + getNamedTagAttributes (datas, node.getNodeName ()), + null, + prefix)); + + // + if (node.getChildNodes () == null) { - for (int i = 0; i < attrs.getLength(); i++) - { - Attr attr = (Attr) attrs.item(i); - result.append (' '); - 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 (Presenter.INDEX_SEPARATOR); - result.append (prefix); - } - - result.append ("\""); - } + result.append(" />"); + } + else + { + result.append('>'); - - // - if (node.getChildNodes () == null) - { - result.append(" />"); - } - else - { - result.append('>'); - - result.append (processChildren (node, datas, webappPath, prefix, errorOutput)); - - result.append("'); - } + result.append (processChildren (node, datas, webappPath, prefix, errorOutput)); + + result.append("'); } @@ -1237,11 +1301,11 @@ public class Presenter /* * */ - static protected StringBuffer processAttributes (NamedNodeMap attrs, TagData model) + static protected StringBuffer processAttributes (NamedNodeMap attrs, Attributes dataAttributes, Attributes namedDataAttributes, String prefix) { StringBuffer result; - result = processAttributes (attrs, model, ""); + result = processAttributes (attrs, mergeAttributes (dataAttributes, namedDataAttributes), prefix); // return (result); @@ -1251,7 +1315,35 @@ public class Presenter /* * */ - static protected StringBuffer processAttributes (NamedNodeMap attrs, TagData model, String prefix) + static protected StringBuffer processAttributes (NamedNodeMap attrs, Attributes dataAttributes) + { + StringBuffer result; + + result = processAttributes (attrs, dataAttributes, ""); + + // + return (result); + } + + + /* + * + */ + static protected StringBuffer processAttributes (NamedNodeMap attrs) + { + StringBuffer result; + + result = processAttributes (attrs, null, null, ""); + + // + return (result); + } + + + /* + * + */ + static protected StringBuffer processAttributes (NamedNodeMap attrs, Attributes dataAttributes, String prefix) { StringBuffer result; @@ -1268,37 +1360,31 @@ public class Presenter // Put model attributes in the merged attributes list. - if (model != null) + if (dataAttributes != null) { - Attributes modelAttributes = model.getAttributes(); + Iterator iterator = dataAttributes.entrySet().iterator(); - if (modelAttributes != null) + while (iterator.hasNext()) { - Iterator iterator = modelAttributes.entrySet().iterator(); + Map.Entry attribute = (Map.Entry) iterator.next(); - while (iterator.hasNext()) + if (mergedAttributes.containsKey (attribute.getKey ())) { - Map.Entry attribute = (Map.Entry) iterator.next(); - - if (mergedAttributes.containsKey (attribute.getKey ())) + if (attribute.getKey ().equalsIgnoreCase ("style")) { - if (attribute.getKey ().equalsIgnoreCase ("style")) - { - mergedAttributes.put (attribute.getKey (), mergedAttributes.get (attribute.getKey ()) + attribute.getValue ()); - } - else - { - mergedAttributes.put (attribute.getKey (), attribute.getValue ()); - } + mergedAttributes.put (attribute.getKey (), mergedAttributes.get (attribute.getKey ()) + attribute.getValue ()); } else { mergedAttributes.put (attribute.getKey (), attribute.getValue ()); } } + else + { + mergedAttributes.put (attribute.getKey (), attribute.getValue ()); + } } } - // Display the attributes Iterator iterator = mergedAttributes.entrySet().iterator(); diff --git a/test/xid/test/Test.java b/test/xid/test/Test.java index f827eb9..816f07b 100644 --- a/test/xid/test/Test.java +++ b/test/xid/test/Test.java @@ -57,6 +57,7 @@ class Test StringBuffer errorMessage; // Populate attributes of Test 03. + System.out.println ("----------------------------"); datas = new TagsData (); tag = new TagData (); tag.setContent ("Superman"); @@ -65,7 +66,6 @@ class Test errorMessage = new StringBuffer (); html = Presenter.doXid ("
a name
", datas, "", errorMessage); - System.out.println ("----------------------------"); System.out.println ("datas = new TagsData ();"); System.out.println ("tag = new TagData ();"); System.out.println ("tag.setContent (\"Superman\");"); @@ -77,13 +77,13 @@ class Test // Populate attributes of Test 03. + System.out.println ("----------------------------"); 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 TagsData ();"); System.out.println ("datas.setContent (\"name\", \"Superman\");"); System.out.println ("+"); @@ -93,6 +93,7 @@ class Test // Populate attributes of Test 03. + System.out.println ("----------------------------"); datas = new TagsData (); tag = new TagData (); tag.setContent ("Spiderman"); @@ -105,7 +106,6 @@ class Test errorMessage = new StringBuffer (); html = Presenter.doXid ("
a last name
", datas, "", errorMessage); - System.out.println ("----------------------------"); System.out.println ("datas = new TagsData ();"); System.out.println ("tag = new TagData ();"); System.out.println ("tag.getAttributes ().setAttribute (\"class\", \"lastnameClass\");"); @@ -120,6 +120,7 @@ class Test // Populate attributes of Test 03. + System.out.println ("----------------------------"); datas = new TagsData (); datas.setContent ("lastname", "Spiderman"); datas.appendAttribute ("lastname", "style", "background: blue;"); @@ -130,11 +131,10 @@ class Test errorMessage = new StringBuffer (); html = Presenter.doXid ("
a last name
", datas, "", errorMessage); - System.out.println ("----------------------------"); 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;\""); + 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
"); @@ -143,6 +143,7 @@ class Test // Populate attributes of Test 03. + System.out.println ("----------------------------"); datas = new TagsData (); datas.setContent ("words", 0, "alpha"); datas.setContent ("words", 1, "bravo"); @@ -155,7 +156,6 @@ class Test errorMessage = new StringBuffer (); html = Presenter.doXid ("
    \n
  • a word
  • \n
", datas, "", errorMessage); - System.out.println ("----------------------------"); System.out.println ("datas = new TagsData ();"); System.out.println ("datas.setContent (\"words\", 0, \"alpha\");"); System.out.println ("datas.setContent (\"words\", 1, \"bravo\");"); @@ -172,6 +172,7 @@ class Test // Populate attributes of Test 03. + System.out.println ("----------------------------"); datas = new TagsData (); datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent ("identity", 0, "prenom", "Epo"); @@ -182,10 +183,13 @@ class Test errorMessage = new StringBuffer (); - htmlSource = "\n \n
noidun nomun prenom
"; + StringBuffer source = new StringBuffer (); + source.append ("\n"); + source.append (" \n"); + source.append ("
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\");"); @@ -201,6 +205,7 @@ class Test // Populate attributes of Test 03. + System.out.println ("----------------------------"); datas = new TagsData (); datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent ("identity", 0, "prenom", "Epo"); @@ -215,7 +220,7 @@ class Test errorMessage = new StringBuffer (); - StringBuffer source = new StringBuffer (); + source = new StringBuffer (); source.append ("\n"); source.append (" \n"); source.append (" \n"); @@ -223,7 +228,6 @@ class Test source.append ("
noidun nomun prenom
noidun nomun prenom
"); htmlSource = source.toString (); - 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\");"); @@ -256,5 +260,38 @@ class Test System.out.println ("ALL_ROWS:"); html = Presenter.doXid (htmlSource, datas, "", errorMessage); System.out.println (html); + + + + // Populate attributes of Test 03. + System.out.println ("----------------------------"); + datas = new TagsData (); + datas.setAttribute ("
", "class", "aDivClass"); + datas.setAttribute ("
", "style", "background-color: #000000;"); + datas.setAttribute ("number", "style", "background-color: #0000FF;"); + + + errorMessage = new StringBuffer (); + source = new StringBuffer (); + source.append ("
\n"); + source.append ("

one

\n"); + source.append ("
\n"); + source.append ("
\n"); + source.append ("

three

\n"); + source.append ("
"); + htmlSource = source.toString (); + html = Presenter.doXid (htmlSource, datas, "", errorMessage); + + System.out.println (htmlSource); + System.out.println ("+"); + System.out.println ("datas = new TagsData ();"); + System.out.println ("datas.setAttribute (\"
\", \"class\", \"aDivClass\");"); + System.out.println ("datas.setAttribute (\"
\", \"style\", \"background-color: #000000;\");"); + System.out.println ("datas.setAttribute (\"number\", \"style\", \"background-color: #0000FF;\");"); + + System.out.println ("=>"); + System.out.println (html); + + } } diff --git a/test/xid/test/Test.java~ b/test/xid/test/Test.java~ index 75c0380..7b4873c 100644 --- a/test/xid/test/Test.java~ +++ b/test/xid/test/Test.java~ @@ -134,7 +134,7 @@ class Test 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;\""); + 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
"); @@ -182,40 +182,7 @@ class Test errorMessage = new StringBuffer (); - html = Presenter.doXid ("\n \n
noidun nomun prenom
", 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 (""); - 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
"; + htmlSource = "\n \n
noidun nomun prenom
"; html = Presenter.doXid (htmlSource, datas, "", errorMessage); System.out.println ("----------------------------"); @@ -231,5 +198,96 @@ class Test System.out.println (htmlSource); 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 (); + + 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 ("=>"); + + + datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); + System.out.println ("ONLY_FIRST_ROW:"); + html = Presenter.doXid (htmlSource, datas, "", errorMessage); + System.out.println (html); + + datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); + System.out.println ("ONLY_ROWS_WITH_ID:"); + html = Presenter.doXid (htmlSource, datas, "", errorMessage); + System.out.println (html); + + datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); + System.out.println ("ONLY_ROWS_WITHOUT_ID:"); + html = Presenter.doXid (htmlSource, datas, "", errorMessage); + System.out.println (html); + + datas.setIterationStrategy ("identity", TagsDataByIndex.IterationStrategy.ALL_ROWS); + System.out.println ("ALL_ROWS:"); + html = Presenter.doXid (htmlSource, datas, "", errorMessage); + System.out.println (html); + + + + // Populate attributes of Test 03. + System.out.println ("----------------------------"); + datas = new TagsData (); + datas.setAttribute ("
", "class", "aDivClass"); + datas.setAttribute ("
", "style", "background-color: #000000;"); + datas.setAttribute ("number", "style", "background-color: #0000FF;"); + + + errorMessage = new StringBuffer (); + source = new StringBuffer (); + source.append ("
\n"); + source.append ("

one

\n"); + source.append ("
\n"); + source.append ("
\n"); + source.append ("

three

\n"); + source.append ("
"); + htmlSource = source.toString (); + html = Presenter.doXid (htmlSource, datas, "", errorMessage); + + System.out.println (htmlSource); + System.out.println ("+"); + System.out.println ("datas = new TagsData ();"); + System.out.println ("datas.setAttribute (\"
\", \"class\", \"aDivClass\");"); + System.out.println ("datas.setAttribute (\"
\", \"style\", \"background-color: #000000;\");"); + System.out.println ("datas.setAttribute (\"number\", \"style\", \"background-color: #0000FF;\");"); + + System.out.println ("=>"); + System.out.println (html); + + } }