Manage de hashtable list tag.
This commit is contained in:
parent
cbfbfc71d5
commit
c667a7e4ba
7 changed files with 288 additions and 45 deletions
Binary file not shown.
Binary file not shown.
BIN
dist/test.jar
vendored
BIN
dist/test.jar
vendored
Binary file not shown.
BIN
dist/xid.jar
vendored
BIN
dist/xid.jar
vendored
Binary file not shown.
|
@ -269,6 +269,20 @@ public class Presenter
|
|||
{
|
||||
StringBuffer result;
|
||||
|
||||
result = processChildren (node, datas, webappPath, "", errorOutput);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
static protected StringBuffer processChildren (Node node, TagsDataById datas, String webappPath, String prefix, StringBuffer errorOutput)
|
||||
{
|
||||
StringBuffer result;
|
||||
|
||||
result = new StringBuffer ();
|
||||
|
||||
NodeList children = node.getChildNodes();
|
||||
|
@ -283,7 +297,7 @@ public class Presenter
|
|||
|
||||
for (int i = 0; i < childrenCount; i++)
|
||||
{
|
||||
result.append (process (children.item(i), datas, webappPath, errorOutput));
|
||||
result.append (process (children.item(i), datas, webappPath, prefix, errorOutput));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -413,6 +427,35 @@ public class Presenter
|
|||
TagsDataById datas,
|
||||
String webappPath,
|
||||
StringBuffer errorOutput)
|
||||
|
||||
{
|
||||
StringBuffer result;
|
||||
|
||||
result = processElementWithId (node, attrs, idAttr, datas, "", webappPath, errorOutput);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes a node that has dynamic content. Calls the appropriate code
|
||||
* generator method, depending on the tag.
|
||||
*
|
||||
* @param node
|
||||
* Current node.
|
||||
* @param attrs
|
||||
* The tag attributes.
|
||||
* @param idAttr
|
||||
* The ID.
|
||||
*/
|
||||
static protected StringBuffer processElementWithId (Node node,
|
||||
NamedNodeMap attrs,
|
||||
Node idAttr,
|
||||
TagsDataById datas,
|
||||
String webappPath,
|
||||
String prefix,
|
||||
StringBuffer errorOutput)
|
||||
{
|
||||
StringBuffer result;
|
||||
result = new StringBuffer ();
|
||||
|
@ -427,7 +470,7 @@ public class Presenter
|
|||
|
||||
if (dataCore == null)
|
||||
{
|
||||
result.append (Presenter.processElementBasically (node, datas, webappPath, errorOutput));
|
||||
result.append (Presenter.processElementBasically (node, datas, webappPath, prefix, errorOutput));
|
||||
}
|
||||
else if (dataCore instanceof TagData)
|
||||
{
|
||||
|
@ -451,7 +494,7 @@ public class Presenter
|
|||
result.append (node.getNodeName());
|
||||
|
||||
// Build attributes.
|
||||
result.append (processAttributes (attrs, data));
|
||||
result.append (processAttributes (attrs, data, prefix));
|
||||
|
||||
if ((node.getChildNodes () == null) &&
|
||||
((data == null) || data.display ().equals ("")))
|
||||
|
@ -467,7 +510,7 @@ public class Presenter
|
|||
if ((data == null) ||
|
||||
(data.display ().equals ("")))
|
||||
{
|
||||
result.append (processChildren (node, datas, webappPath, errorOutput));
|
||||
result.append (processChildren (node, datas, webappPath, prefix, errorOutput));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -488,40 +531,51 @@ public class Presenter
|
|||
int nbLines = tags.size ();
|
||||
for (int nLine = 0; nLine < nbLines; nLine++)
|
||||
{
|
||||
TagData data = (TagData) tags.elementAt (nLine);
|
||||
|
||||
// Open the tag.
|
||||
result.append ("<");
|
||||
result.append (node.getNodeName());
|
||||
|
||||
// Build attributes.
|
||||
result.append (processAttributes (attrs, data, Integer.toString (nLine)));
|
||||
|
||||
if ((node.getChildNodes () == null) &&
|
||||
((data == null) || data.display ().equals ("")))
|
||||
if (tags.elementAt (nLine) instanceof TagData)
|
||||
{
|
||||
// Close the tag.
|
||||
result.append (" />\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
result.append ('>');
|
||||
TagData data = (TagData) tags.elementAt (nLine);
|
||||
|
||||
// Insert data.
|
||||
if ((data == null) ||
|
||||
(data.display ().equals ("")))
|
||||
// Open the tag.
|
||||
result.append ("<");
|
||||
result.append (node.getNodeName());
|
||||
|
||||
// Build attributes.
|
||||
result.append (processAttributes (attrs, data, Integer.toString (nLine)));
|
||||
|
||||
if ((node.getChildNodes () == null) &&
|
||||
((data == null) || data.display ().equals ("")))
|
||||
{
|
||||
result.append (processChildren (node, datas, webappPath, errorOutput));
|
||||
// Close the tag.
|
||||
result.append (" />\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
result.append (data.display ());
|
||||
result.append ('>');
|
||||
|
||||
// Insert data.
|
||||
if ((data == null) ||
|
||||
(data.display ().equals ("")))
|
||||
{
|
||||
result.append (processChildren (node, datas, webappPath, prefix, errorOutput));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.append (data.display ());
|
||||
}
|
||||
|
||||
// Close the tag.
|
||||
result.append ("</");
|
||||
result.append (node.getNodeName());
|
||||
result.append (">\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Manage a Hashmap.
|
||||
TagsDataById data = (TagsDataById) tags.elementAt (nLine);
|
||||
|
||||
// Close the tag.
|
||||
result.append ("</");
|
||||
result.append (node.getNodeName());
|
||||
result.append (">\n");
|
||||
result.append (Presenter.processElementWithId (node, attrs, idAttr, data, webappPath, Integer.toString (nLine), errorOutput));
|
||||
result.append ('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -542,10 +596,24 @@ public class Presenter
|
|||
|
||||
|
||||
/**
|
||||
* Recursive method that processes a node and any child nodes.
|
||||
*
|
||||
*/
|
||||
static protected StringBuffer process (Node node, TagsDataById datas, String webappPath, StringBuffer errorOutput)
|
||||
{
|
||||
StringBuffer result;
|
||||
|
||||
result = Presenter.process (node, datas, webappPath, "", errorOutput);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Recursive method that processes a node and any child nodes.
|
||||
*
|
||||
*/
|
||||
static protected StringBuffer process (Node node, TagsDataById datas, String webappPath, String prefix, StringBuffer errorOutput)
|
||||
{
|
||||
log.debug ("Enter");
|
||||
String TRANSITIONAL_DTD = "xhtml1-transitional.dtd";
|
||||
|
@ -590,7 +658,7 @@ public class Presenter
|
|||
// Log.write(Log.TRACE,"systemId = " + systemId);
|
||||
}
|
||||
|
||||
result.append (Presenter.process (((Document) node).getDocumentElement(), datas, webappPath, errorOutput));
|
||||
result.append (Presenter.process (((Document) node).getDocumentElement(), datas, webappPath, prefix, errorOutput));
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -604,11 +672,11 @@ public class Presenter
|
|||
|
||||
if (idAttr != null)
|
||||
{
|
||||
result.append (Presenter.processElementWithId (node, attrs, idAttr, datas, webappPath, errorOutput));
|
||||
result.append (Presenter.processElementWithId (node, attrs, idAttr, datas, webappPath, prefix, errorOutput));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.append (Presenter.processElementBasically (node, datas, webappPath, errorOutput));
|
||||
result.append (Presenter.processElementBasically (node, datas, webappPath, prefix, errorOutput));
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -673,8 +741,23 @@ public class Presenter
|
|||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
static StringBuffer processElementBasically (Node node, TagsDataById datas, String webappPath, StringBuffer errorOutput)
|
||||
{
|
||||
StringBuffer result;
|
||||
|
||||
result = processElementBasically (node, datas, webappPath, "", errorOutput);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
static StringBuffer processElementBasically (Node node, TagsDataById datas, String webappPath, String prefix, StringBuffer errorOutput)
|
||||
{
|
||||
StringBuffer result;
|
||||
result = new StringBuffer ();
|
||||
|
@ -694,6 +777,14 @@ public class Presenter
|
|||
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 ('_');
|
||||
result.append (prefix);
|
||||
}
|
||||
|
||||
result.append ("\"");
|
||||
}
|
||||
|
||||
|
@ -718,7 +809,7 @@ public class Presenter
|
|||
|
||||
for (int i = 0; i < childrenCount; i++)
|
||||
{
|
||||
result.append (process (children.item(i), datas, webappPath, errorOutput));
|
||||
result.append (process (children.item(i), datas, webappPath, prefix, errorOutput));
|
||||
}
|
||||
|
||||
result.append("</");
|
||||
|
@ -1104,7 +1195,7 @@ public class Presenter
|
|||
{
|
||||
Map.Entry<String, String> attribute = (Map.Entry<String, String>) iterator.next();
|
||||
|
||||
if (attribute.getKey ().equals ("id"))
|
||||
if ((attribute.getKey ().equals ("id")) && (prefix.length () != 0))
|
||||
{
|
||||
result.append(" " + attribute.getKey () + "=\"" + attribute.getValue () + '_' + prefix + "\"");
|
||||
}
|
||||
|
|
|
@ -251,6 +251,34 @@ class Test
|
|||
System.out.println ("</ul>");
|
||||
System.out.println ("=>");
|
||||
System.out.println (html);
|
||||
|
||||
|
||||
// Populate attributes of Test 03.
|
||||
datas = new TagsDataById ();
|
||||
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");
|
||||
|
||||
|
||||
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);
|
||||
|
||||
System.out.println ("----------------------------");
|
||||
System.out.println ("datas = new TagsDataId ();");
|
||||
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 ("</table>");
|
||||
System.out.println ("=>");
|
||||
System.out.println (html);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,10 +90,31 @@ class Test
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static private org.apache.log4j.Logger log;
|
||||
|
||||
static
|
||||
{
|
||||
// Initialize log.
|
||||
org.apache.log4j.Logger log = null;
|
||||
|
||||
org.apache.log4j.BasicConfigurator.configure ();
|
||||
|
||||
|
||||
log = org.apache.log4j.Logger.getRootLogger ();
|
||||
//log.setLevel (org.apache.log4j.Level.INFO);
|
||||
log.setLevel (org.apache.log4j.Level.INFO);
|
||||
|
||||
log.info ("Enter");
|
||||
|
||||
//
|
||||
log.info ("Set the log file format...");
|
||||
|
||||
|
||||
// log = org.apache.log4j.Category.getInstance(Application.class.getName());
|
||||
log.info ("... done.");
|
||||
|
||||
log.debug ("Exit");
|
||||
log = org.apache.log4j.Logger.getLogger (Test.class.getName ());
|
||||
}
|
||||
|
||||
|
@ -108,24 +129,127 @@ class Test
|
|||
//test ();
|
||||
|
||||
//
|
||||
TagsDataById datas = new TagsDataById ();
|
||||
TagsDataById datas;
|
||||
TagData tag;
|
||||
|
||||
// Populate attributes of Test 03.
|
||||
tag = new TagData ();
|
||||
tag.setContent ("hello");
|
||||
tag.getAttributes ().appendAttribute ("style", "background: blue;");
|
||||
tag.getAttributes ().appendAttribute ("style", "foreground: red;");
|
||||
tag.getAttributes ().setAttribute ("class", "totoClass");
|
||||
datas.put ("test03", tag);
|
||||
|
||||
|
||||
|
||||
StringBuffer html;
|
||||
StringBuffer errorMessage;
|
||||
|
||||
// Populate attributes of Test 03.
|
||||
datas = new TagsDataById ();
|
||||
tag = new TagData ();
|
||||
tag.setContent ("Superman");
|
||||
datas.put ("name", tag);
|
||||
|
||||
errorMessage = new StringBuffer ();
|
||||
html = Presenter.doXid ("<X id='test03'>bla</X>", datas, "", errorMessage);
|
||||
html = Presenter.doXid ("<div id='name'>a name</div >", datas, "", errorMessage);
|
||||
|
||||
System.out.println ("----------------------------");
|
||||
System.out.println ("datas = new TagsDataId ();");
|
||||
System.out.println ("tag = new TagData ();");
|
||||
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.
|
||||
datas = new TagsDataById ();
|
||||
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 TagsDataId ();");
|
||||
System.out.println ("datas.setContent (\"name\", \"Superman\");");
|
||||
System.out.println ("+");
|
||||
System.out.println ("<div id='name'>a name</div >");
|
||||
System.out.println ("=>");
|
||||
System.out.println (html);
|
||||
|
||||
|
||||
// Populate attributes of Test 03.
|
||||
datas = new TagsDataById ();
|
||||
tag = new TagData ();
|
||||
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 ("----------------------------");
|
||||
System.out.println ("datas = new TagsDataId ();");
|
||||
System.out.println ("tag = new TagData ();");
|
||||
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.
|
||||
datas = new TagsDataById ();
|
||||
datas.setContent ("lastname", "Spiderman");
|
||||
datas.appendAttribute ("lastname", "style", "background: blue;");
|
||||
datas.appendAttribute ("lastname", "style", "foreground: red;");
|
||||
datas.setAttribute ("lastname", "class", "nameClass");
|
||||
|
||||
|
||||
errorMessage = new StringBuffer ();
|
||||
html = Presenter.doXid ("<div id='lastname'>a last name</div >", datas, "", errorMessage);
|
||||
|
||||
System.out.println ("----------------------------");
|
||||
System.out.println ("datas = new TagsDataId ();");
|
||||
System.out.println ("datas.setContent (\"lastname\", \"Spiderman\");");
|
||||
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>");
|
||||
System.out.println ("=>");
|
||||
System.out.println (html);
|
||||
|
||||
|
||||
// Populate attributes of Test 03.
|
||||
datas = new TagsDataById ();
|
||||
datas.setContent ("words", 0, "alpha");
|
||||
datas.setContent ("words", 1, "bravo");
|
||||
datas.setContent ("words", 2, "charlie");
|
||||
datas.setContent ("words", 3, "delta");
|
||||
datas.setContent ("words", 4, "echo");
|
||||
datas.setContent ("words", 5, "fox");
|
||||
|
||||
|
||||
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 TagsDataId ();");
|
||||
System.out.println ("datas.setContent (\"words\", 0, \"alpha\");");
|
||||
System.out.println ("datas.setContent (\"words\", 1, \"bravo\");");
|
||||
System.out.println ("datas.setContent (\"words\", 2, \"charlie\");");
|
||||
System.out.println ("datas.setContent (\"words\", 3, \"delta\");");
|
||||
System.out.println ("datas.setContent (\"words\", 4, \"echo\");");
|
||||
System.out.println ("datas.setContent (\"words\", 5, \"fox\");");
|
||||
System.out.println ("+");
|
||||
System.out.println ("<ul>");
|
||||
System.out.println (" <li id='words'>a word</li>");
|
||||
System.out.println ("</ul>");
|
||||
System.out.println ("=>");
|
||||
System.out.println (html);
|
||||
System.out.println ("----------------------------");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue