Manage namedTagData ('<div>').

This commit is contained in:
administrateur 2007-01-31 05:24:46 +01:00
parent 1b32ee50f7
commit 00e729af30
9 changed files with 293 additions and 103 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

@ -21,6 +21,15 @@ public class Attributes extends HashMap<String, String>
}
/*
* Useful for the merge attributes.
*/
public Attributes (Attributes attributes)
{
super (attributes);
}
/*
*
*/

View file

@ -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<String, String> attribute = (Map.Entry<String, String>) 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(node.getNodeName());
result.append('>');
}
result.append (processChildren (node, datas, webappPath, prefix, errorOutput));
result.append("</");
result.append(node.getNodeName());
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<String, String> attribute = (Map.Entry<String, String>) iterator.next();
while (iterator.hasNext())
if (mergedAttributes.containsKey (attribute.getKey ()))
{
Map.Entry<String, String> attribute = (Map.Entry<String, String>) 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();

View file

@ -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 ("<div id='name'>a name</div >", 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 ("<div id='name'>a name</div >", 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 ("<div id='lastname'>a last name</div >", 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 ("<div id='lastname'>a last name</div >", 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 ("<div id='lastname'>a last name</div>");
@ -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 ("<ul>\n <li id='words'>a word</li>\n</ul>", 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 = "<table>\n <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>\n</table>";
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 ("</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\");");
@ -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 ("<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");
@ -223,7 +228,6 @@ class Test
source.append ("</table>");
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 ("<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");
source.append (" <h1>one</h1>\n");
source.append ("</div>\n");
source.append ("<div id=\"number\">\n");
source.append (" <h1>three</h1>\n");
source.append ("</div>");
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 (\"<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

@ -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 ("<div id='lastname'>a last name</div>");
@ -182,40 +182,7 @@ 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>\n</table>", 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 ("<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>";
htmlSource = "<table>\n <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>\n</table>";
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 ("<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 ();
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 ("<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");
source.append (" <h1>one</h1>\n");
source.append ("</div>\n");
source.append ("<div id=\"number\">\n");
source.append (" <h1>three</h1>\n");
source.append ("</div>");
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 (\"<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);
}
}