small fix.

This commit is contained in:
administrateur 2007-02-07 07:30:24 +01:00
parent faf7fd7fb0
commit 5bc5964bd6
5 changed files with 173 additions and 186 deletions

Binary file not shown.

View file

@ -60,7 +60,7 @@ class Demo
datas.setContent ("name", "Superman");
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 ("datas = new Data ();");
System.out.println ("datas.setContent (\"name\", \"Superman\");");
@ -80,7 +80,7 @@ class Demo
errorMessage = new StringBuffer ();
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 ("datas = new Data ();");
System.out.println ("datas.setContent (\"lastname\", \"Spiderman\");");
@ -105,7 +105,7 @@ class Demo
errorMessage = new StringBuffer ();
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 ("datas = new Data ();");
System.out.println ("datas.setContent (\"words\", 0, \"alpha\");");
@ -139,7 +139,7 @@ class Demo
source.append (" <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>\n");
source.append ("</table>");
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 (" <h1>three</h1>\n");
source.append ("</div>");
htmlSource = source.toString ();
html = Presenter.doXid (htmlSource, datas, "", errorMessage);
html = Presenter.doXid (htmlSource, datas, errorMessage);
System.out.println (htmlSource);
System.out.println ("+");

View file

@ -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 ("<div id='name'>a name</div >", 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 ("<div id='name'>a name</div >");
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 ("<div id='name'>a name</div >", 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 ("<div id='name'>a name</div >");
@ -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 ("<div id='lastname'>a last name</div >", 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 ("<div id='lastname'>a last name</div>");
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 ("<div id='lastname'>a last name</div >", 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 ("<ul>\n <li id='words'>a word</li>\n</ul>", 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 ("</table>");
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 ("<div>", "class", "aDivClass");
datas.setAttribute ("<div>", "style", "background-color: #000000;");
datas.setAttribute ("number", "style", "background-color: #0000FF;");
errorMessage = new StringBuffer ();
source = new StringBuffer ();
source.append ("<div>\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 (\"<div>\", \"class\", \"aDivClass\");");
System.out.println ("datas.setAttribute (\"<div>\", \"style\", \"background-color: #000000;\");");
System.out.println ("datas.setAttribute (\"number\", \"style\", \"background-color: #0000FF;\");");
System.out.println ("=>");
System.out.println (html);
*/
}
}

View file

@ -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 ("</");
result.append (node.getNodeName());
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 ("</");
result.append (node.getNodeName());
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 ("</");
result.append (node.getNodeName());
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;

View file

@ -83,7 +83,7 @@ class Test
datas.setContent ("name", "Superman");
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 (check ("only content change", html, "<div id=\"name\">Superman</div>"));
@ -97,7 +97,7 @@ class Test
datas.setAttribute ("lastname", "class", "nameClass");
errorMessage = new StringBuffer ();
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 (check ("content and attributes", html, "<div class=\"nameClass\" style=\"background: blue;foreground: red;\" id=\"lastname\">Spiderman</div>"));
// Populate attributes of Test 03.
@ -112,7 +112,7 @@ class Test
errorMessage = new StringBuffer ();
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 (check ("list assertion 1", html, "<li id=\"words_0\">alpha</li>"));
System.out.println (check ("list assertion 2", html, "<li id=\"words_1\">bravo</li>"));
@ -138,7 +138,7 @@ class Test
source.append (" <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>\n");
source.append ("</table>");
htmlSource = source.toString ();
html = Presenter.doXid (htmlSource, datas, "", errorMessage);
html = Presenter.doXid (htmlSource, datas, errorMessage);
System.out.println (check ("table 1 assertion 1", html, "<tr id=\"identity_0\"><td>noid</td><td id=\"nom_0\">Jemba</td><td id=\"prenom_0\">Epo</td></tr>"));
System.out.println (check ("table 1 assertion 2", html, "<tr id=\"identity_1\"><td>noid</td><td id=\"nom_1\">Momon</td><td id=\"prenom_1\">Christian</td></tr>"));