diff --git a/build/classes/xid/Presenter.class b/build/classes/xid/Presenter.class index 04637d2..1ac5e3f 100644 Binary files a/build/classes/xid/Presenter.class and b/build/classes/xid/Presenter.class differ diff --git a/demo/Demo.java b/demo/Demo.java index de01306..4d43a2f 100644 --- a/demo/Demo.java +++ b/demo/Demo.java @@ -60,7 +60,7 @@ class Demo datas.setContent ("name", "Superman"); errorMessage = new StringBuffer (); - html = Presenter.doXid ("
a name
", datas, "", errorMessage); + html = Presenter.doXid ("
a name
", datas, errorMessage); System.out.println ("datas = new Data ();"); System.out.println ("datas.setContent (\"name\", \"Superman\");"); @@ -80,7 +80,7 @@ class Demo errorMessage = new StringBuffer (); - html = Presenter.doXid ("
a last name
", datas, "", errorMessage); + html = Presenter.doXid ("
a last name
", datas, errorMessage); System.out.println ("datas = new Data ();"); System.out.println ("datas.setContent (\"lastname\", \"Spiderman\");"); @@ -105,7 +105,7 @@ class Demo errorMessage = new StringBuffer (); - html = Presenter.doXid ("", datas, "", errorMessage); + html = Presenter.doXid ("", datas, errorMessage); System.out.println ("datas = new Data ();"); System.out.println ("datas.setContent (\"words\", 0, \"alpha\");"); @@ -139,7 +139,7 @@ class Demo source.append (" noidun nomun prenom\n"); source.append (""); htmlSource = source.toString (); - html = Presenter.doXid (htmlSource, datas, "", errorMessage); + html = Presenter.doXid (htmlSource, datas, errorMessage); System.out.println ("datas = new Data ();"); System.out.println ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");"); @@ -194,22 +194,22 @@ class Demo datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); System.out.println ("ONLY_FIRST_ROW:"); - html = Presenter.doXid (htmlSource, datas, "", errorMessage); + html = Presenter.doXid (htmlSource, datas, errorMessage); System.out.println (html); datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); System.out.println ("ONLY_ROWS_WITH_ID:"); - html = Presenter.doXid (htmlSource, datas, "", errorMessage); + html = Presenter.doXid (htmlSource, datas, errorMessage); System.out.println (html); datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); System.out.println ("ONLY_ROWS_WITHOUT_ID:"); - html = Presenter.doXid (htmlSource, datas, "", errorMessage); + html = Presenter.doXid (htmlSource, datas, errorMessage); System.out.println (html); datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ALL_ROWS); System.out.println ("ALL_ROWS:"); - html = Presenter.doXid (htmlSource, datas, "", errorMessage); + html = Presenter.doXid (htmlSource, datas, errorMessage); System.out.println (html); @@ -230,7 +230,7 @@ class Demo source.append ("

three

\n"); source.append (""); htmlSource = source.toString (); - html = Presenter.doXid (htmlSource, datas, "", errorMessage); + html = Presenter.doXid (htmlSource, datas, errorMessage); System.out.println (htmlSource); System.out.println ("+"); diff --git a/demo/Demo.java~ b/demo/Demo.java~ index 4b6e3bc..de01306 100644 --- a/demo/Demo.java~ +++ b/demo/Demo.java~ @@ -1,5 +1,3 @@ -package xid.test; - import java.util.*; import java.io.*; import xid.*; @@ -7,7 +5,7 @@ import xid.*; /** * */ -class Test +class Demo { static private org.apache.log4j.Logger log; @@ -33,21 +31,21 @@ class Test log.info ("... done."); log.debug ("Exit"); - log = org.apache.log4j.Logger.getLogger (Test.class.getName ()); + log = org.apache.log4j.Logger.getLogger (Demo.class.getName ()); } /** * */ - public static void main(String[] args) + public static void main (String[] args) { System.out.println("Hello World!"); //test (); // - IdsData datas; + Data datas; IdData tag; @@ -58,33 +56,13 @@ class Test // Populate attributes of Test 03. System.out.println ("----------------------------"); - datas = new IdsData (); - tag = new IdData (); - tag.setContent ("Superman"); - datas.put ("name", tag); - - errorMessage = new StringBuffer (); - html = Presenter.doXid ("
a name
", datas, "", errorMessage); - - System.out.println ("datas = new IdsData ();"); - System.out.println ("tag = new IdData ();"); - 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. - System.out.println ("----------------------------"); - datas = new IdsData (); + datas = new Data (); datas.setContent ("name", "Superman"); errorMessage = new StringBuffer (); html = Presenter.doXid ("
a name
", datas, "", errorMessage); - System.out.println ("datas = new IdsData ();"); + System.out.println ("datas = new Data ();"); System.out.println ("datas.setContent (\"name\", \"Superman\");"); System.out.println ("+"); System.out.println ("
a name
"); @@ -94,34 +72,7 @@ class Test // Populate attributes of Test 03. System.out.println ("----------------------------"); - datas = new IdsData (); - tag = new IdData (); - 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 ("datas = new IdsData ();"); - System.out.println ("tag = new IdData ();"); - 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. - System.out.println ("----------------------------"); - datas = new IdsData (); + datas = new Data (); datas.setContent ("lastname", "Spiderman"); datas.appendAttribute ("lastname", "style", "background: blue;"); datas.appendAttribute ("lastname", "style", "foreground: red;"); @@ -131,7 +82,7 @@ class Test errorMessage = new StringBuffer (); html = Presenter.doXid ("
a last name
", datas, "", errorMessage); - System.out.println ("datas = new IdsData ();"); + System.out.println ("datas = new Data ();"); 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;\");"); @@ -144,7 +95,7 @@ class Test // Populate attributes of Test 03. System.out.println ("----------------------------"); - datas = new IdsData (); + datas = new Data (); datas.setContent ("words", 0, "alpha"); datas.setContent ("words", 1, "bravo"); datas.setContent ("words", 2, "charlie"); @@ -156,7 +107,7 @@ class Test errorMessage = new StringBuffer (); html = Presenter.doXid ("", datas, "", errorMessage); - System.out.println ("datas = new IdsData ();"); + System.out.println ("datas = new Data ();"); System.out.println ("datas.setContent (\"words\", 0, \"alpha\");"); System.out.println ("datas.setContent (\"words\", 1, \"bravo\");"); System.out.println ("datas.setContent (\"words\", 2, \"charlie\");"); @@ -173,7 +124,7 @@ class Test // Populate attributes of Test 03. System.out.println ("----------------------------"); - datas = new IdsData (); + datas = new Data (); datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 1, "nom", "Momon"); @@ -190,7 +141,7 @@ class Test htmlSource = source.toString (); html = Presenter.doXid (htmlSource, datas, "", errorMessage); - System.out.println ("datas = new IdsData ();"); + System.out.println ("datas = new Data ();"); 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\");"); @@ -206,7 +157,7 @@ class Test // Populate attributes of Test 03. System.out.println ("----------------------------"); - datas = new IdsData (); + datas = new Data (); datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 1, "nom", "Momon"); @@ -228,7 +179,7 @@ class Test source.append (""); htmlSource = source.toString (); - System.out.println ("datas = new IdsData ();"); + System.out.println ("datas = new Data ();"); 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\");"); @@ -264,14 +215,12 @@ class Test // Populate attributes of Test 03. - /* System.out.println ("----------------------------"); - datas = new IdsData (); + datas = new Data (); 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"); @@ -285,13 +234,12 @@ class Test System.out.println (htmlSource); System.out.println ("+"); - System.out.println ("datas = new IdsData ();"); + System.out.println ("datas = new Data ();"); 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/src/xid/Presenter.java b/src/xid/Presenter.java index 941fcae..edbb1e8 100644 --- a/src/xid/Presenter.java +++ b/src/xid/Presenter.java @@ -91,9 +91,9 @@ public class Presenter /* * */ - public StringBuffer doXid (IdsDataById datas, StringBuffer errorOutput) + public StringBuffer doXid (Data datas, StringBuffer errorOutput) { - return (doXid (datas, null, errorOutput)); + return (doXid (datas.getIdsDataById (), datas.getTagsDataById (), errorOutput)); } /* @@ -168,6 +168,15 @@ public class Presenter + /* + * + */ + static public StringBuffer doXid (String html, Data datas, StringBuffer errorOutput) + { + return (doXid (html, datas.getIdsDataById (), datas.getTagsDataById (), "", errorOutput)); + } + + /* * */ @@ -529,7 +538,13 @@ public class Presenter * @param attrMap * @param idAttr */ - static protected StringBuffer processObjectTag (Node node, NamedNodeMap attrMap, Node idAttr, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput) + static protected StringBuffer processObjectTag (Node node, + NamedNodeMap attrMap, + Node idAttr, + IdsDataById datas, + TagsDataById tagsData, + String webappPath, + StringBuffer errorOutput) { StringBuffer result; @@ -550,7 +565,6 @@ public class Presenter codetype = attrMap.getNamedItem ("codetype").getNodeValue (); } - // Check tag requirements. if ((attrMap == null) || (codetype == null) || @@ -577,7 +591,7 @@ public class Presenter } catch (Exception ex) { - result.append ("unable to build the file tree"); + errorOutput.append ("unable to build the file tree"); log.debug ("unable to build the file tree"); } @@ -589,7 +603,7 @@ public class Presenter if (nodes.getLength () == 0) { - result.append ("no body tag in include html"); + errorOutput.append ("no body tag in include html"); log.debug ("no body tag in include html"); } else @@ -599,19 +613,26 @@ public class Presenter } catch (Exception e) { - result.append ("error getting child"); + errorOutput.append ("error getting child"); log.debug ("error getting child"); } // Process the body child as part of the primary tree. - NodeList bodyChildren = body.getChildNodes (); - - if (bodyChildren != null) + if (body == null) { - int childCount = bodyChildren.getLength (); - for (int childCounter = 0; childCounter < childCount; childCounter++) + errorOutput.append ("xid object body empty."); + } + else + { + NodeList bodyChildren = body.getChildNodes (); + + if (bodyChildren != null) { - result.append (process (bodyChildren.item (childCounter), datas, tagsData, webappPath, errorOutput)); + int childCount = bodyChildren.getLength (); + for (int childCounter = 0; childCounter < childCount; childCounter++) + { + result.append (process (bodyChildren.item (childCounter), datas, tagsData, webappPath, errorOutput)); + } } } @@ -677,98 +698,41 @@ public class Presenter result = new StringBuffer (); String tag = node.getNodeName(); - String idValue = idAttr.getNodeValue(); - log.debug ("tag=" + tag); - - // Get data of this id. - IdDataCore dataCore = datas.get (idAttr.getNodeValue ()); - - if (dataCore == null) + if (tag.equals ("object")) { - result.append (Presenter.processElementBasically (node, datas, tagsData, webappPath, suffix, errorOutput)); + result.append (processObjectTag (node, attrs, idAttr, datas, tagsData, webappPath, errorOutput)); } - else if (dataCore instanceof IdData) + else { - IdData data = (IdData) dataCore; + String idValue = idAttr.getNodeValue(); - String theClass; - if (data == null) - { - theClass = null; - } - else - { - theClass = data.getAttributes ().getAttribute ("class"); - } + log.debug ("tag=" + tag); - if ((theClass == null) || - (!theClass.equals ("xid:nodisplay"))) + // Get data of this id. + IdDataCore dataCore = datas.get (idAttr.getNodeValue ()); + + if (dataCore == null) { - // Open the tag. - result.append ("<"); - result.append (node.getNodeName()); + result.append (Presenter.processElementBasically (node, datas, tagsData, webappPath, suffix, errorOutput)); + } + else if (dataCore instanceof IdData) + { + IdData data = (IdData) dataCore; - // Build attributes. - Attributes tagAttributes; - if (tagsData == null) + String theClass; + if (data == null) { - tagAttributes = null; + theClass = null; } else { - TagData tagData = tagsData.getId (node.getNodeName ()); - if (tagData == null) - { - tagAttributes = null; - } - else - { - tagAttributes = tagData.getAttributes (); - } + theClass = data.getAttributes ().getAttribute ("class"); } - - result.append (processAttributes (attrs, data.getAttributes (), tagAttributes, suffix)); - if ((node.getChildNodes () == null) && - ((data == null) || data.display ().equals (""))) + if ((theClass == null) || + (!theClass.equals ("xid:nodisplay"))) { - // Close the tag. - result.append (" />"); - } - else - { - result.append ('>'); - - // Insert data. - if ((data == null) || - (data.display ().equals (""))) - { - result.append (processChildren (node, datas, tagsData, webappPath, suffix, errorOutput)); - } - else - { - result.append (data.display ()); - } - - // Close the tag. - result.append ("'); - } - } - } - else if (dataCore instanceof IdsDataByIndex) - { - IdsDataByIndex tags = (IdsDataByIndex) dataCore; - - int nbLines = tags.size (); - for (int nLine = 0; nLine < nbLines; nLine++) - { - if (tags.elementAt (nLine) instanceof IdData) - { - IdData data = (IdData) tags.elementAt (nLine); - // Open the tag. result.append ("<"); result.append (node.getNodeName()); @@ -791,14 +755,14 @@ public class Presenter tagAttributes = tagData.getAttributes (); } } - - result.append (processAttributes (attrs, data.getAttributes (), tagAttributes, Integer.toString (nLine))); + + result.append (processAttributes (attrs, data.getAttributes (), tagAttributes, suffix)); if ((node.getChildNodes () == null) && ((data == null) || data.display ().equals (""))) { // Close the tag. - result.append (" />\n"); + result.append (" />"); } else { @@ -818,22 +782,87 @@ public class Presenter // Close the tag. result.append ("\n"); + result.append ('>'); } } - else + } + else if (dataCore instanceof IdsDataByIndex) + { + IdsDataByIndex tags = (IdsDataByIndex) dataCore; + + int nbLines = tags.size (); + for (int nLine = 0; nLine < nbLines; nLine++) { - // Manage a Hashmap. - IdsDataById data = (IdsDataById) tags.elementAt (nLine); - - result.append (Presenter.processElementWithId (node, attrs, idAttr, data, tagsData, webappPath, Integer.toString (nLine), errorOutput)); - result.append ('\n'); + if (tags.elementAt (nLine) instanceof IdData) + { + IdData data = (IdData) tags.elementAt (nLine); + + // Open the tag. + result.append ("<"); + result.append (node.getNodeName()); + + // Build attributes. + Attributes tagAttributes; + if (tagsData == null) + { + tagAttributes = null; + } + else + { + TagData tagData = tagsData.getId (node.getNodeName ()); + if (tagData == null) + { + tagAttributes = null; + } + else + { + tagAttributes = tagData.getAttributes (); + } + } + + result.append (processAttributes (attrs, data.getAttributes (), tagAttributes, Integer.toString (nLine))); + + if ((node.getChildNodes () == null) && + ((data == null) || data.display ().equals (""))) + { + // Close the tag. + result.append (" />\n"); + } + else + { + result.append ('>'); + + // Insert data. + if ((data == null) || + (data.display ().equals (""))) + { + result.append (processChildren (node, datas, tagsData, webappPath, suffix, errorOutput)); + } + else + { + result.append (data.display ()); + } + + // Close the tag. + result.append ("\n"); + } + } + else + { + // Manage a Hashmap. + IdsDataById data = (IdsDataById) tags.elementAt (nLine); + + result.append (Presenter.processElementWithId (node, attrs, idAttr, data, tagsData, webappPath, Integer.toString (nLine), errorOutput)); + result.append ('\n'); + } } } - } - else - { - log.warn ("Unknow type of IdDataId"); + else + { + log.warn ("Unknow type of IdDataId"); + } } // @@ -930,7 +959,17 @@ public class Presenter } else { - result.append (Presenter.processElementBasically (node, datas, tagsData, webappPath, suffix, errorOutput)); + + String tag = node.getNodeName(); + + if (tag.equals ("object")) + { + result.append (processObjectTag (node, attrs, idAttr, datas, tagsData, webappPath, errorOutput)); + } + else + { + result.append (Presenter.processElementBasically (node, datas, tagsData, webappPath, suffix, errorOutput)); + } } break; diff --git a/test/xid/test/Test.java b/test/xid/test/Test.java index 7184856..5ec5b99 100644 --- a/test/xid/test/Test.java +++ b/test/xid/test/Test.java @@ -83,7 +83,7 @@ class Test datas.setContent ("name", "Superman"); errorMessage = new StringBuffer (); - html = Presenter.doXid ("
a name
", datas, "", errorMessage); + html = Presenter.doXid ("
a name
", datas, errorMessage); System.out.println (check ("only content change", html, "
Superman
")); @@ -97,7 +97,7 @@ class Test datas.setAttribute ("lastname", "class", "nameClass"); errorMessage = new StringBuffer (); - html = Presenter.doXid ("
a last name
", datas, "", errorMessage); + html = Presenter.doXid ("
a last name
", datas, errorMessage); System.out.println (check ("content and attributes", html, "
Spiderman
")); // Populate attributes of Test 03. @@ -112,7 +112,7 @@ class Test errorMessage = new StringBuffer (); - html = Presenter.doXid ("
    \n
  • a word
  • \n
", datas, "", errorMessage); + html = Presenter.doXid ("
    \n
  • a word
  • \n
", datas, errorMessage); System.out.println (check ("list assertion 1", html, "
  • alpha
  • ")); System.out.println (check ("list assertion 2", html, "
  • bravo
  • ")); @@ -138,7 +138,7 @@ class Test source.append (" noidun nomun prenom\n"); source.append (""); htmlSource = source.toString (); - html = Presenter.doXid (htmlSource, datas, "", errorMessage); + html = Presenter.doXid (htmlSource, datas, errorMessage); System.out.println (check ("table 1 assertion 1", html, "noidJembaEpo")); System.out.println (check ("table 1 assertion 2", html, "noidMomonChristian"));