2010-02-23 15:03:14 +01:00
|
|
|
/**
|
|
|
|
* XidDemo
|
|
|
|
*/
|
|
|
|
|
2013-06-26 14:00:04 +02:00
|
|
|
import org.apache.log4j.Level;
|
|
|
|
|
2013-06-23 18:03:53 +02:00
|
|
|
import fr.devinsy.xidyn.SimpleTagData;
|
2013-06-23 01:38:08 +02:00
|
|
|
import fr.devinsy.xidyn.StringPresenter;
|
2013-06-26 14:00:04 +02:00
|
|
|
import fr.devinsy.xidyn.TagDataManager;
|
2007-02-05 06:10:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2013-06-26 02:21:03 +02:00
|
|
|
class XidynDemo
|
2007-02-05 06:10:27 +01:00
|
|
|
{
|
2010-02-23 16:22:50 +01:00
|
|
|
static
|
2013-06-23 01:28:40 +02:00
|
|
|
{
|
|
|
|
// Initialize logger.
|
|
|
|
org.apache.log4j.BasicConfigurator.configure();
|
2007-02-05 06:10:27 +01:00
|
|
|
|
2013-06-26 14:00:04 +02:00
|
|
|
org.apache.log4j.Logger logger = null;
|
|
|
|
logger = org.apache.log4j.Logger.getRootLogger();
|
|
|
|
logger.setLevel(Level.INFO);
|
|
|
|
logger = org.apache.log4j.Logger.getLogger(XidynDemo.class);
|
2013-06-23 01:28:40 +02:00
|
|
|
}
|
2007-02-05 06:10:27 +01:00
|
|
|
|
2013-06-23 01:28:40 +02:00
|
|
|
/**
|
2007-02-05 06:10:27 +01:00
|
|
|
*
|
|
|
|
*/
|
2013-06-23 01:28:40 +02:00
|
|
|
public static void main(final String[] args)
|
2010-02-25 01:22:06 +01:00
|
|
|
{
|
2013-06-23 01:28:40 +02:00
|
|
|
System.out.println("Hello World!");
|
|
|
|
|
|
|
|
// test ();
|
|
|
|
|
|
|
|
//
|
2013-06-23 02:17:42 +02:00
|
|
|
TagDataManager data;
|
2013-06-23 01:28:40 +02:00
|
|
|
|
|
|
|
// Step #01.
|
|
|
|
{
|
|
|
|
System.out.println("----------------------------");
|
|
|
|
|
|
|
|
// Populate attributes.
|
2013-06-23 02:17:42 +02:00
|
|
|
data = new TagDataManager();
|
|
|
|
data.setContent("name", "Superman");
|
2013-06-23 01:28:40 +02:00
|
|
|
|
|
|
|
String htmlSource = "<div id='name'>a name</div >";
|
|
|
|
StringBuffer htmlTarget;
|
|
|
|
try
|
|
|
|
{
|
2013-06-23 02:17:42 +02:00
|
|
|
htmlTarget = StringPresenter.dynamize(htmlSource, data);
|
2013-06-23 01:28:40 +02:00
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println(exception.getMessage());
|
|
|
|
htmlTarget = null;
|
|
|
|
}
|
|
|
|
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 >");
|
|
|
|
System.out.println("=>");
|
|
|
|
System.out.println(htmlTarget);
|
|
|
|
System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step #02.
|
|
|
|
{
|
|
|
|
System.out.println("----------------------------");
|
|
|
|
// Populate attributes.
|
2013-06-23 02:17:42 +02:00
|
|
|
data = new TagDataManager();
|
|
|
|
data.setContent("lastname", "Spiderman");
|
|
|
|
data.appendAttribute("lastname", "style", "background: blue;");
|
|
|
|
data.appendAttribute("lastname", "style", "foreground: red;");
|
|
|
|
data.setAttribute("lastname", "class", "nameClass");
|
2013-06-23 01:28:40 +02:00
|
|
|
|
|
|
|
String htmlSource = "<div id='lastname'>a last name</div >";
|
|
|
|
StringBuffer htmlTarget;
|
|
|
|
try
|
|
|
|
{
|
2013-06-23 02:17:42 +02:00
|
|
|
htmlTarget = StringPresenter.dynamize(htmlSource, data);
|
2013-06-23 01:28:40 +02:00
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println(exception.getMessage());
|
|
|
|
htmlTarget = null;
|
|
|
|
}
|
2010-02-25 01:22:06 +01:00
|
|
|
|
2013-06-23 01:28:40 +02:00
|
|
|
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;\");");
|
|
|
|
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(htmlTarget);
|
|
|
|
System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]");
|
|
|
|
}
|
2010-02-25 01:22:06 +01:00
|
|
|
|
2013-06-23 01:28:40 +02:00
|
|
|
// Step #03.
|
|
|
|
{
|
|
|
|
System.out.println("----------------------------");
|
|
|
|
// Populate attributes.
|
2013-06-23 02:17:42 +02:00
|
|
|
data = new TagDataManager();
|
|
|
|
data.setContent("words", 0, "alpha");
|
|
|
|
data.setContent("words", 1, "bravo");
|
|
|
|
data.setContent("words", 2, "charlie");
|
|
|
|
data.setContent("words", 3, "delta");
|
|
|
|
data.setContent("words", 4, "echo");
|
|
|
|
data.setContent("words", 5, "fox");
|
2013-06-23 01:28:40 +02:00
|
|
|
|
|
|
|
String htmlSource = "<ul>\n <li id='words'>a word</li>\n</ul>";
|
|
|
|
StringBuffer htmlTarget;
|
|
|
|
try
|
|
|
|
{
|
2013-06-23 02:17:42 +02:00
|
|
|
htmlTarget = StringPresenter.dynamize(htmlSource, data);
|
2013-06-23 01:28:40 +02:00
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println(exception.getMessage());
|
|
|
|
htmlTarget = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
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\");");
|
|
|
|
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(htmlTarget);
|
|
|
|
System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step #04.
|
|
|
|
{
|
|
|
|
System.out.println("----------------------------");
|
|
|
|
// Populate attributes.
|
2013-06-23 02:17:42 +02:00
|
|
|
data = new TagDataManager();
|
|
|
|
data.setContent("identity", 0, "last_name", "Jemba");
|
|
|
|
data.setContent("identity", 0, "first_name", "Epo");
|
|
|
|
data.setContent("identity", 1, "last_name", "Momon");
|
|
|
|
data.setContent("identity", 1, "first_name", "Christian");
|
|
|
|
data.setContent("identity", 2, "last_name", "Tronche");
|
|
|
|
data.setContent("identity", 2, "first_name", "Christophe");
|
2013-06-23 01:28:40 +02:00
|
|
|
|
|
|
|
StringBuffer source = new StringBuffer();
|
|
|
|
source.append("<table>\n");
|
|
|
|
source.append(" <tr id='identity'><td>noid</td><td id='first_name'>Jean</td><td id='last_name'>Reve</td></tr>\n");
|
|
|
|
source.append("</table>");
|
|
|
|
|
|
|
|
String htmlSource = source.toString();
|
|
|
|
StringBuffer htmlTarget;
|
|
|
|
try
|
|
|
|
{
|
2013-06-23 02:17:42 +02:00
|
|
|
htmlTarget = StringPresenter.dynamize(htmlSource, data);
|
2013-06-23 01:28:40 +02:00
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println(exception.getMessage());
|
|
|
|
htmlTarget = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("datas = new Data ();");
|
|
|
|
System.out.println("datas.setContent (\"identity\", 0, \"last_name\", \"Jemba\");");
|
|
|
|
System.out.println("datas.setContent (\"identity\", 0, \"first_name\", \"Epo\");");
|
|
|
|
System.out.println("datas.setContent (\"identity\", 1, \"last_name\", \"Momon\");");
|
|
|
|
System.out.println("datas.setContent (\"identity\", 1, \"first_name\", \"Christian\");");
|
|
|
|
System.out.println("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");");
|
|
|
|
System.out.println("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");");
|
|
|
|
|
|
|
|
System.out.println("+");
|
|
|
|
System.out.println(htmlSource);
|
|
|
|
System.out.println("=>");
|
|
|
|
System.out.println(htmlTarget);
|
|
|
|
System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step #05.
|
|
|
|
{
|
|
|
|
System.out.println("----------------------------");
|
|
|
|
// Populate attributes.
|
2013-06-23 02:17:42 +02:00
|
|
|
data = new TagDataManager();
|
|
|
|
data.setContent("identity", 0, "last_name", "Jemba");
|
|
|
|
data.setContent("identity", 0, "first_name", "Epo");
|
|
|
|
data.setContent("identity", 1, "last_name", "Momon");
|
|
|
|
data.setContent("identity", 1, "first_name", "Christian");
|
|
|
|
data.setContent("identity", 2, "last_name", "Tronche");
|
|
|
|
data.setContent("identity", 2, "first_name", "Christophe");
|
2013-06-23 01:28:40 +02:00
|
|
|
// datas.setIterationStrategy ("identity",
|
|
|
|
// IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID);
|
|
|
|
// datas.setIterationStrategy ("identity",
|
|
|
|
// IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
|
|
|
|
// datas.setIterationStrategy ("identity",
|
|
|
|
// IdsDataByIndex.IterationStrategy.ALL_ROWS);
|
|
|
|
|
|
|
|
//
|
|
|
|
StringBuffer source = new StringBuffer();
|
|
|
|
source.append("<table id=\"identities\">\n");
|
|
|
|
source.append(" <tr id='the_head'><th>noid</th><th>First Name</th><th>Last Name</th></tr>\n");
|
|
|
|
source.append(" <tr id='identity'><td>noid</td><td id='first_name'>Jean</td><td id='last_name'>Reve</td></tr>\n");
|
|
|
|
source.append(" <tr id='identity_bis'><td>noid</td><td id='first_name_bis'>a first name</td><td id='last_name_bis'>a last name</td></tr>\n");
|
|
|
|
source.append(" <tr><td>noid</td><td id='first_name_ter'>a first name more</td><td id='last_name_ter'>a last name more</td></tr>\n");
|
|
|
|
source.append("</table>\n");
|
|
|
|
String htmlSource = source.toString();
|
|
|
|
|
|
|
|
System.out.println("datas = new Data ();");
|
|
|
|
System.out.println("datas.setContent (\"identity\", 0, \"first_name\", \"Epo\");");
|
|
|
|
System.out.println("datas.setContent (\"identity\", 0, \"last_name\", \"Jemba\");");
|
|
|
|
System.out.println("datas.setContent (\"identity\", 1, \"first_name\", \"Christian\");");
|
|
|
|
System.out.println("datas.setContent (\"identity\", 1, \"last_name\", \"Momon\");");
|
|
|
|
System.out.println("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");");
|
|
|
|
System.out.println("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");");
|
|
|
|
|
|
|
|
System.out.println("+");
|
|
|
|
System.out.println(htmlSource);
|
|
|
|
System.out.println("=>");
|
|
|
|
|
|
|
|
// #05.1
|
2013-06-23 18:03:53 +02:00
|
|
|
data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_FIRST_ROW);
|
2013-06-23 01:28:40 +02:00
|
|
|
System.out.println("ONLY_FIRST_ROW:");
|
|
|
|
StringBuffer html;
|
|
|
|
try
|
|
|
|
{
|
2013-06-23 02:17:42 +02:00
|
|
|
html = StringPresenter.dynamize(htmlSource, data);
|
2013-06-23 01:28:40 +02:00
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println(exception.getMessage());
|
|
|
|
html = null;
|
|
|
|
}
|
|
|
|
System.out.println(html);
|
|
|
|
System.out.println("");
|
|
|
|
|
|
|
|
// #05.2
|
2013-06-23 18:03:53 +02:00
|
|
|
data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_FIRST_TWO_ROWS);
|
2013-06-23 01:28:40 +02:00
|
|
|
System.out.println("ONLY_FIRST_TWO_ROWS:");
|
|
|
|
try
|
|
|
|
{
|
2013-06-23 02:17:42 +02:00
|
|
|
html = StringPresenter.dynamize(htmlSource, data);
|
2013-06-23 01:28:40 +02:00
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println(exception.getMessage());
|
|
|
|
html = null;
|
|
|
|
}
|
|
|
|
System.out.println(html);
|
|
|
|
System.out.println("");
|
|
|
|
|
|
|
|
// #05.3
|
2013-06-23 18:03:53 +02:00
|
|
|
data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_ROWS_WITH_ID);
|
2013-06-23 01:28:40 +02:00
|
|
|
System.out.println("ONLY_ROWS_WITH_ID:");
|
|
|
|
try
|
|
|
|
{
|
2013-06-23 02:17:42 +02:00
|
|
|
html = StringPresenter.dynamize(htmlSource, data);
|
2013-06-23 01:28:40 +02:00
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println(exception.getMessage());
|
|
|
|
html = null;
|
|
|
|
}
|
|
|
|
System.out.println(html);
|
|
|
|
System.out.println("");
|
|
|
|
|
|
|
|
// #05.4
|
2013-06-23 18:03:53 +02:00
|
|
|
data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
|
2013-06-23 01:28:40 +02:00
|
|
|
System.out.println("ONLY_ROWS_WITHOUT_ID:");
|
|
|
|
try
|
|
|
|
{
|
2013-06-23 02:17:42 +02:00
|
|
|
html = StringPresenter.dynamize(htmlSource, data);
|
2013-06-23 01:28:40 +02:00
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println(exception.getMessage());
|
|
|
|
html = null;
|
|
|
|
}
|
|
|
|
System.out.println(html);
|
|
|
|
System.out.println("");
|
|
|
|
|
|
|
|
// #05.5
|
2013-06-23 18:03:53 +02:00
|
|
|
data.setIterationStrategy("identities", SimpleTagData.IterationStrategy.ALL_ROWS);
|
2013-06-23 01:28:40 +02:00
|
|
|
System.out.println("ALL_ROWS:");
|
|
|
|
try
|
|
|
|
{
|
2013-06-23 02:17:42 +02:00
|
|
|
html = StringPresenter.dynamize(htmlSource, data);
|
2013-06-23 01:28:40 +02:00
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println(exception.getMessage());
|
|
|
|
html = null;
|
|
|
|
}
|
|
|
|
System.out.println(html);
|
|
|
|
}
|
|
|
|
}
|
2007-02-05 06:10:27 +01:00
|
|
|
}
|