IterationStrategy implementation.

This commit is contained in:
administrateur 2007-01-26 07:05:50 +01:00
parent e65faec673
commit 2d6e8b1639
10 changed files with 213 additions and 75 deletions

Binary file not shown.

Binary file not shown.

BIN
dist/test.jar vendored

Binary file not shown.

BIN
dist/xid.jar vendored

Binary file not shown.

View file

@ -283,77 +283,152 @@ public class Presenter
static protected StringBuffer processChildren (Node node, TagsDataById datas, String webappPath, String prefix, StringBuffer errorOutput) static protected StringBuffer processChildren (Node node, TagsDataById datas, String webappPath, String prefix, StringBuffer errorOutput)
{ {
StringBuffer result; StringBuffer result;
result = new StringBuffer (); result = new StringBuffer ();
NodeList children = node.getChildNodes(); NodeList children = node.getChildNodes();
int childrenCount = children.getLength ();
if (children == null) if ((children == null) || (childrenCount == 0))
{ {
result.append (" "); result.append (" ");
} }
else else
{ {
int childrenCount = children.getLength (); //
// Is there a TagsDataByIndex associated with the first ELEMENT_NODE child?
//
TagsDataByIndex tagsData;
// TODO Analyze IterationStragy if datas is a TagsData. // Find the first ELEMENT_NODE child.
int childIndex = 0;
// Determine Node child = null;
NamedNodeMap attrs = node.getAttributes (); boolean ended = false;
Node idAttr = attrs.getNamedItem ("id"); while (!ended)
String tag = node.getNodeName();
String idValue = idAttr.getNodeValue();
TagDataCore tagDataCore = datas.getId (idValue);
if (tagDataCore instanceof TagsDataByIndex)
{ {
TagsDataByIndex tagsData = (TagsDataByIndex) tagDataCore; if (childIndex >= childrenCount)
switch (tagsData.getIterationStrategy ())
{ {
case TagsDataByIndex.ONLY_FIRST_ROW: ended = true;
result.append (process (children.item (0), datas, webappPath, prefix, errorOutput)); child = null;
break; }
else if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE)
case TagsDataByIndex.ONLY_ROWS_WITH_ID:
for (int i = 0; i < childrenCount; i++)
{ {
NamedNodeMap attrs2 = children.item (i); ended = true;
Node idAttr2 = attrs2.getNamedItem ("id"); child = children.item (childIndex);
}
if (idAttr2 != null) else
{ {
result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); childIndex += 1;
} }
} }
break;
case TagsDataByIndex.ONLY_ROWS_WITHOUT_ID: System.out.println ("childIndex=" + childIndex);
for (int i = 0; i < childrenCount; i++) if (child == null)
{ {
NamedNodeMap attrs2 = children.item (i); tagsData = null;
Node idAttr2 = attrs2.getNamedItem ("id"); }
else
{
// Searching for the ID value of the child.
String childId;
if (idAttr2 == null) System.out.println ("child" + child);
NamedNodeMap attrsChild = child.getAttributes ();
System.out.println ("attrsChild=" + attrsChild);
if (attrsChild == null)
{ {
result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); childId = null;
}
else
{
Node idAttrChild;
idAttrChild = attrsChild.getNamedItem ("id");
if (idAttrChild == null)
{
childId = null;
}
else
{
childId = idAttrChild.getNodeValue ();
} }
} }
break;
case TagsDataByIndex.ALL_ROWS:
// 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++) for (int i = 0; i < childrenCount; i++)
{ {
result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); result.append (process (children.item(i), datas, webappPath, prefix, errorOutput));
} }
break;
}
} }
else else
{ {
System.out.println ("TagsDataByIndex detected.");
switch (tagsData.getIterationStrategy ())
{
case ONLY_FIRST_ROW:
System.out.println ("ONLY FIRST ROW");
result.append (process (child, datas, webappPath, prefix, errorOutput));
break;
case ONLY_ROWS_WITH_ID:
System.out.println ("ONLY ROWS WITH ID");
for (int i = 0; i < childrenCount; i++)
{
NamedNodeMap attrs2 = children.item (i).getAttributes ();
if ((attrs2 != null) &&
(attrs2.getNamedItem ("id") != null))
{
result.append (process (children.item(i), datas, webappPath, prefix, errorOutput));
}
}
break;
case ONLY_ROWS_WITHOUT_ID:
for (int i = 0; i < childrenCount; i++)
{
// Process row?
boolean processRow;
NamedNodeMap attrs2 = children.item (i).getAttributes ();
if ((attrs2 == null) ||
(attrs2.getNamedItem ("id") == null))
{
result.append (process (children.item(i), datas, webappPath, prefix, errorOutput));
}
}
break;
case ALL_ROWS:
for (int i = 0; i < childrenCount; i++) for (int i = 0; i < childrenCount; i++)
{ {
result.append (process (children.item(i), datas, webappPath, prefix, errorOutput)); result.append (process (children.item(i), datas, webappPath, prefix, errorOutput));
} }
break;
}
} }
} }
@ -726,12 +801,13 @@ public class Presenter
NamedNodeMap attrs = node.getAttributes (); NamedNodeMap attrs = node.getAttributes ();
Node idAttr = attrs.getNamedItem ("id"); Node idAttr = attrs.getNamedItem ("id");
System.out.println ("process=" + node);
if (idAttr != null) if (idAttr != null)
{ {
result.append (Presenter.processElementWithId (node, attrs, idAttr, datas, webappPath, prefix, errorOutput)); result.append (Presenter.processElementWithId (node, attrs, idAttr, datas, webappPath, prefix, errorOutput));
} }
else else
{ {System.out.println ("basically");
result.append (Presenter.processElementBasically (node, datas, webappPath, prefix, errorOutput)); result.append (Presenter.processElementBasically (node, datas, webappPath, prefix, errorOutput));
} }
@ -846,16 +922,7 @@ public class Presenter
// //
NodeList children = node.getChildNodes(); if (node.getChildNodes () == null)
if (children == null)
{
result.append(" />");
}
else
{
int childrenCount = children.getLength ();
if (childrenCount == 0)
{ {
result.append(" />"); result.append(" />");
} }
@ -863,17 +930,13 @@ public class Presenter
{ {
result.append('>'); result.append('>');
for (int i = 0; i < childrenCount; i++) result.append (processChildren (node, datas, webappPath, prefix, errorOutput));
{
result.append (process (children.item(i), datas, webappPath, prefix, errorOutput));
}
result.append("</"); result.append("</");
result.append(node.getNodeName()); result.append(node.getNodeName());
result.append('>'); result.append('>');
} }
} }
}
// //

View file

@ -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); TagsDataByIndex tags = (TagsDataByIndex) this.get (id);

View file

@ -8,7 +8,7 @@ import java.io.*;
*/ */
public class TagsDataByIndex extends Vector<TagDataCore> implements TagDataCore public class TagsDataByIndex extends Vector<TagDataCore> 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; protected IterationStrategy iterationStrategy;

View file

@ -52,7 +52,7 @@ class Test
String htmlSource;
StringBuffer html; StringBuffer html;
StringBuffer errorMessage; StringBuffer errorMessage;
@ -192,11 +192,53 @@ class Test
System.out.println ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");"); 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, \"nom\", \"Tronche\");");
System.out.println ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");"); System.out.println ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");");
System.out.println ("+"); System.out.println ("+");
System.out.println ("<table>"); System.out.println ("<table>");
System.out.println (" <tr id='identity'><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>"); System.out.println (" <tr id='identity'><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>");
System.out.println (" <tr id='identity2'><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>");
System.out.println (" <tr id='identity3'><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>");
System.out.println ("</table>"); System.out.println ("</table>");
System.out.println ("=>"); System.out.println ("=>");
System.out.println (html); 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 ("<table>\n");
source.append (" <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>\n");
source.append (" <tr id='identity2'><td>noid</td><td id='nom2'>un nom</td><td id='prenom2'>un prenom</td></tr>\n");
source.append (" <tr><td>noid</td><td id='nom3'>un nom</td><td id='prenom3'>un prenom</td></tr>\n");
source.append ("</table>");
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);
} }
} }

View file

@ -47,17 +47,17 @@ class Test
//test (); //test ();
// //
TagsDataById datas; TagsData datas;
TagData tag; TagData tag;
String htmlSource;
StringBuffer html; StringBuffer html;
StringBuffer errorMessage; StringBuffer errorMessage;
// Populate attributes of Test 03. // Populate attributes of Test 03.
datas = new TagsDataById (); datas = new TagsData ();
tag = new TagData (); tag = new TagData ();
tag.setContent ("Superman"); tag.setContent ("Superman");
datas.put ("name", tag); datas.put ("name", tag);
@ -66,7 +66,7 @@ class Test
html = Presenter.doXid ("<div id='name'>a name</div >", datas, "", errorMessage); html = Presenter.doXid ("<div id='name'>a name</div >", datas, "", errorMessage);
System.out.println ("----------------------------"); 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 = new TagData ();");
System.out.println ("tag.setContent (\"Superman\");"); System.out.println ("tag.setContent (\"Superman\");");
System.out.println ("datas.put (\"name\", tag););"); System.out.println ("datas.put (\"name\", tag););");
@ -77,14 +77,14 @@ class Test
// Populate attributes of Test 03. // Populate attributes of Test 03.
datas = new TagsDataById (); datas = new TagsData ();
datas.setContent ("name", "Superman"); datas.setContent ("name", "Superman");
errorMessage = new StringBuffer (); errorMessage = new StringBuffer ();
html = Presenter.doXid ("<div id='name'>a name</div >", datas, "", errorMessage); html = Presenter.doXid ("<div id='name'>a name</div >", datas, "", errorMessage);
System.out.println ("----------------------------"); 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 ("datas.setContent (\"name\", \"Superman\");");
System.out.println ("+"); System.out.println ("+");
System.out.println ("<div id='name'>a name</div >"); System.out.println ("<div id='name'>a name</div >");
@ -93,7 +93,7 @@ class Test
// Populate attributes of Test 03. // Populate attributes of Test 03.
datas = new TagsDataById (); datas = new TagsData ();
tag = new TagData (); tag = new TagData ();
tag.setContent ("Spiderman"); tag.setContent ("Spiderman");
tag.getAttributes ().appendAttribute ("style", "background: blue;"); tag.getAttributes ().appendAttribute ("style", "background: blue;");
@ -106,7 +106,7 @@ class Test
html = Presenter.doXid ("<div id='lastname'>a last name</div >", datas, "", errorMessage); html = Presenter.doXid ("<div id='lastname'>a last name</div >", datas, "", errorMessage);
System.out.println ("----------------------------"); 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 = new TagData ();");
System.out.println ("tag.getAttributes ().setAttribute (\"class\", \"lastnameClass\");"); System.out.println ("tag.getAttributes ().setAttribute (\"class\", \"lastnameClass\");");
System.out.println ("tag.getAttributes ().appendAttribute (\"style\", \"background: blue;\");"); System.out.println ("tag.getAttributes ().appendAttribute (\"style\", \"background: blue;\");");
@ -120,7 +120,7 @@ class Test
// Populate attributes of Test 03. // Populate attributes of Test 03.
datas = new TagsDataById (); datas = new TagsData ();
datas.setContent ("lastname", "Spiderman"); datas.setContent ("lastname", "Spiderman");
datas.appendAttribute ("lastname", "style", "background: blue;"); datas.appendAttribute ("lastname", "style", "background: blue;");
datas.appendAttribute ("lastname", "style", "foreground: red;"); datas.appendAttribute ("lastname", "style", "foreground: red;");
@ -131,7 +131,7 @@ class Test
html = Presenter.doXid ("<div id='lastname'>a last name</div >", datas, "", errorMessage); html = Presenter.doXid ("<div id='lastname'>a last name</div >", datas, "", errorMessage);
System.out.println ("----------------------------"); 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.setContent (\"lastname\", \"Spiderman\");");
System.out.println ("datas.appendAttribute (\"lastname\", \"style\", \"background: blue;\");"); 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;\"");
@ -143,7 +143,7 @@ class Test
// Populate attributes of Test 03. // Populate attributes of Test 03.
datas = new TagsDataById (); datas = new TagsData ();
datas.setContent ("words", 0, "alpha"); datas.setContent ("words", 0, "alpha");
datas.setContent ("words", 1, "bravo"); datas.setContent ("words", 1, "bravo");
datas.setContent ("words", 2, "charlie"); datas.setContent ("words", 2, "charlie");
@ -156,7 +156,7 @@ class Test
html = Presenter.doXid ("<ul>\n <li id='words'>a word</li>\n</ul>", datas, "", errorMessage); html = Presenter.doXid ("<ul>\n <li id='words'>a word</li>\n</ul>", datas, "", errorMessage);
System.out.println ("----------------------------"); 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\", 0, \"alpha\");");
System.out.println ("datas.setContent (\"words\", 1, \"bravo\");"); System.out.println ("datas.setContent (\"words\", 1, \"bravo\");");
System.out.println ("datas.setContent (\"words\", 2, \"charlie\");"); System.out.println ("datas.setContent (\"words\", 2, \"charlie\");");
@ -172,7 +172,7 @@ class Test
// Populate attributes of Test 03. // Populate attributes of Test 03.
datas = new TagsDataById (); datas = new TagsData ();
datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent ("identity", 0, "nom", "Jemba");
datas.setContent ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 0, "prenom", "Epo");
datas.setContent ("identity", 1, "nom", "Momon"); datas.setContent ("identity", 1, "nom", "Momon");
@ -182,21 +182,54 @@ class Test
errorMessage = new StringBuffer (); errorMessage = new StringBuffer ();
html = Presenter.doXid ("<table>\n <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>\n</table>", datas, "", errorMessage); html = Presenter.doXid ("<table>\n <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td>\n</table>", datas, "", errorMessage);
System.out.println ("----------------------------"); 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, \"nom\", \"Jemba\");");
System.out.println ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");"); 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, \"nom\", \"Momon\");");
System.out.println ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");"); 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, \"nom\", \"Tronche\");");
System.out.println ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");"); System.out.println ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");");
System.out.println ("+"); System.out.println ("+");
System.out.println ("<table>"); System.out.println ("<table>");
System.out.println (" <tr id='identity'><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>"); System.out.println (" <tr id='identity'><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>");
System.out.println (" <tr id='identity2'><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>");
System.out.println (" <tr id='identity3'><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>");
System.out.println ("</table>"); System.out.println ("</table>");
System.out.println ("=>"); System.out.println ("=>");
System.out.println (html); 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 = "<table id='table'>\n <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td>\n<tr id='identity2'><td>noid</td><td id='nom2'>un nom</td><td id='prenom2'>un prenom</td>\n<tr><td>noid</td><td id='nom3'>un nom</td><td id='prenom3'>un prenom</td>\n</table>";
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);
} }
} }