/**
* XidDemo
*/
import fr.devinsy.xidyn.Data;
import fr.devinsy.xidyn.IdData;
import fr.devinsy.xidyn.StringPresenter;
/**
*
*/
class XidDemo
{
static
{
// Initialize logger.
org.apache.log4j.BasicConfigurator.configure();
org.apache.log4j.Logger log = null;
log = org.apache.log4j.Logger.getRootLogger();
log = org.apache.log4j.Logger.getLogger(XidDemo.class);
}
/**
*
*/
public static void main(final String[] args)
{
System.out.println("Hello World!");
// test ();
//
Data datas;
// Step #01.
{
System.out.println("----------------------------");
// Populate attributes.
datas = new Data();
datas.setContent("name", "Superman");
String htmlSource = "
a name
";
StringBuffer htmlTarget;
try
{
htmlTarget = StringPresenter.dynamize(htmlSource, datas);
}
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("a name
");
System.out.println("=>");
System.out.println(htmlTarget);
System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]");
}
// Step #02.
{
System.out.println("----------------------------");
// Populate attributes.
datas = new Data();
datas.setContent("lastname", "Spiderman");
datas.appendAttribute("lastname", "style", "background: blue;");
datas.appendAttribute("lastname", "style", "foreground: red;");
datas.setAttribute("lastname", "class", "nameClass");
String htmlSource = "a last name
";
StringBuffer htmlTarget;
try
{
htmlTarget = StringPresenter.dynamize(htmlSource, datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
htmlTarget = null;
}
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("a last name
");
System.out.println("=>");
System.out.println(htmlTarget);
System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]");
}
// Step #03.
{
System.out.println("----------------------------");
// Populate attributes.
datas = new Data();
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");
String htmlSource = "";
StringBuffer htmlTarget;
try
{
htmlTarget = StringPresenter.dynamize(htmlSource, datas);
}
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("");
System.out.println(" - a word
");
System.out.println("
");
System.out.println("=>");
System.out.println(htmlTarget);
System.out.println("[" + htmlSource.length() + "] => [" + htmlTarget.length() + "]");
}
// Step #04.
{
System.out.println("----------------------------");
// Populate attributes.
datas = new Data();
datas.setContent("identity", 0, "last_name", "Jemba");
datas.setContent("identity", 0, "first_name", "Epo");
datas.setContent("identity", 1, "last_name", "Momon");
datas.setContent("identity", 1, "first_name", "Christian");
datas.setContent("identity", 2, "last_name", "Tronche");
datas.setContent("identity", 2, "first_name", "Christophe");
StringBuffer source = new StringBuffer();
source.append("\n");
source.append(" noid | Jean | Reve |
\n");
source.append("
");
String htmlSource = source.toString();
StringBuffer htmlTarget;
try
{
htmlTarget = StringPresenter.dynamize(htmlSource, datas);
}
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.
datas = new Data();
datas.setContent("identity", 0, "last_name", "Jemba");
datas.setContent("identity", 0, "first_name", "Epo");
datas.setContent("identity", 1, "last_name", "Momon");
datas.setContent("identity", 1, "first_name", "Christian");
datas.setContent("identity", 2, "last_name", "Tronche");
datas.setContent("identity", 2, "first_name", "Christophe");
// 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("\n");
source.append(" noid | First Name | Last Name |
\n");
source.append(" noid | Jean | Reve |
\n");
source.append(" noid | a first name | a last name |
\n");
source.append(" noid | a first name more | a last name more |
\n");
source.append("
\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
datas.setIterationStrategy("identities", IdData.IterationStrategy.ONLY_FIRST_ROW);
System.out.println("ONLY_FIRST_ROW:");
StringBuffer html;
try
{
html = StringPresenter.dynamize(htmlSource, datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
html = null;
}
System.out.println(html);
System.out.println("");
// #05.2
datas.setIterationStrategy("identities", IdData.IterationStrategy.ONLY_FIRST_TWO_ROWS);
System.out.println("ONLY_FIRST_TWO_ROWS:");
try
{
html = StringPresenter.dynamize(htmlSource, datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
html = null;
}
System.out.println(html);
System.out.println("");
// #05.3
datas.setIterationStrategy("identities", IdData.IterationStrategy.ONLY_ROWS_WITH_ID);
System.out.println("ONLY_ROWS_WITH_ID:");
try
{
html = StringPresenter.dynamize(htmlSource, datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
html = null;
}
System.out.println(html);
System.out.println("");
// #05.4
datas.setIterationStrategy("identities", IdData.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
System.out.println("ONLY_ROWS_WITHOUT_ID:");
try
{
html = StringPresenter.dynamize(htmlSource, datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
html = null;
}
System.out.println(html);
System.out.println("");
// #05.5
datas.setIterationStrategy("identities", IdData.IterationStrategy.ALL_ROWS);
System.out.println("ALL_ROWS:");
try
{
html = StringPresenter.dynamize(htmlSource, datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
html = null;
}
System.out.println(html);
}
}
}