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)
{
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 ();
//
// Is there a TagsDataByIndex associated with the first ELEMENT_NODE child?
//
TagsDataByIndex tagsData;
// TODO Analyze IterationStragy if datas is a 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;
switch (tagsData.getIterationStrategy ())
if (childIndex >= childrenCount)
{
case TagsDataByIndex.ONLY_FIRST_ROW:
result.append (process (children.item (0), datas, webappPath, prefix, errorOutput));
break;
case TagsDataByIndex.ONLY_ROWS_WITH_ID:
for (int i = 0; i < childrenCount; i++)
ended = true;
child = null;
}
else if (children.item (childIndex).getNodeType () == Node.ELEMENT_NODE)
{
NamedNodeMap attrs2 = children.item (i);
Node idAttr2 = attrs2.getNamedItem ("id");
if (idAttr2 != null)
ended = true;
child = children.item (childIndex);
}
else
{
result.append (process (children.item(i), datas, webappPath, prefix, errorOutput));
childIndex += 1;
}
}
break;
case TagsDataByIndex.ONLY_ROWS_WITHOUT_ID:
for (int i = 0; i < childrenCount; i++)
System.out.println ("childIndex=" + childIndex);
if (child == null)
{
NamedNodeMap attrs2 = children.item (i);
Node idAttr2 = attrs2.getNamedItem ("id");
tagsData = null;
}
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++)
{
result.append (process (children.item(i), datas, webappPath, prefix, errorOutput));
}
break;
}
}
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++)
{
result.append (process (children.item(i), datas, webappPath, prefix, errorOutput));
}
break;
}
}
}
@ -726,12 +801,13 @@ 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,16 +922,7 @@ public class Presenter
//
NodeList children = node.getChildNodes();
if (children == null)
{
result.append(" />");
}
else
{
int childrenCount = children.getLength ();
if (childrenCount == 0)
if (node.getChildNodes () == null)
{
result.append(" />");
}
@ -863,17 +930,13 @@ public class Presenter
{
result.append('>');
for (int i = 0; i < childrenCount; i++)
{
result.append (process (children.item(i), datas, webappPath, prefix, errorOutput));
}
result.append (processChildren (node, datas, webappPath, prefix, errorOutput));
result.append("</");
result.append(node.getNodeName());
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);

View file

@ -8,7 +8,7 @@ import java.io.*;
*/
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;

View file

@ -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 ("<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='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 ("=>");
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 ();
//
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 ("<div id='name'>a name</div >", 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 ("<div id='name'>a name</div >", 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 ("<div id='name'>a name</div >");
@ -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 ("<div id='lastname'>a last name</div >", 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 ("<div id='lastname'>a last name</div >", 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 ("<ul>\n <li id='words'>a word</li>\n</ul>", 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 ("<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 ("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 ("<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='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 ("=>");
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);
}
}