Presenter splits in FilePresenter, StringPresenter, DomPresenter ; add int support in set method of Data.
This commit is contained in:
parent
3c5c440821
commit
5fe91bd7dc
6 changed files with 131 additions and 536 deletions
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE project>
|
||||
<!-- Builds the XID Framework jar filen. -->
|
||||
<!-- Builds the XID Framework. -->
|
||||
<project name="xid" default="all" basedir=".">
|
||||
<property name="targetjar" value="xid.jar"/>
|
||||
<property name="zip_file" value="xid.zip"/> <!-- Release zip file -->
|
||||
|
|
|
@ -31,7 +31,7 @@ class Demo
|
|||
log.info ("... done.");
|
||||
|
||||
log.debug ("Exit");
|
||||
log = org.apache.log4j.Logger.getLogger (Demo.class.getName ());
|
||||
log = org.apache.log4j.Logger.getLogger (Demo.class);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 = StringPresenter.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 = StringPresenter.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 = StringPresenter.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='first_name'>Jean</td><td id='last_name'>Reve</td></tr>\n");
|
||||
source.append ("</table>");
|
||||
htmlSource = source.toString ();
|
||||
html = Presenter.doXid (htmlSource, datas, errorMessage);
|
||||
html = StringPresenter.doXid (htmlSource, datas, errorMessage);
|
||||
|
||||
System.out.println ("datas = new Data ();");
|
||||
System.out.println ("datas.setContent (\"identity\", 0, \"last_name\", \"Jemba\");");
|
||||
|
@ -194,31 +194,31 @@ class Demo
|
|||
|
||||
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_FIRST_ROW);
|
||||
System.out.println ("ONLY_FIRST_ROW:");
|
||||
html = Presenter.doXid (htmlSource, datas, errorMessage);
|
||||
html = StringPresenter.doXid (htmlSource, datas, errorMessage);
|
||||
System.out.println (html);
|
||||
|
||||
System.out.println ("");
|
||||
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_FIRST_TWO_ROWS);
|
||||
System.out.println ("ONLY_FIRST_TWO_ROWS:");
|
||||
html = Presenter.doXid (htmlSource, datas, errorMessage);
|
||||
html = StringPresenter.doXid (htmlSource, datas, errorMessage);
|
||||
System.out.println (html);
|
||||
|
||||
System.out.println ("");
|
||||
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_ROWS_WITH_ID);
|
||||
System.out.println ("ONLY_ROWS_WITH_ID:");
|
||||
html = Presenter.doXid (htmlSource, datas, errorMessage);
|
||||
html = StringPresenter.doXid (htmlSource, datas, errorMessage);
|
||||
System.out.println (html);
|
||||
|
||||
System.out.println ("");
|
||||
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
|
||||
System.out.println ("ONLY_ROWS_WITHOUT_ID:");
|
||||
html = Presenter.doXid (htmlSource, datas, errorMessage);
|
||||
html = StringPresenter.doXid (htmlSource, datas, errorMessage);
|
||||
System.out.println (html);
|
||||
|
||||
System.out.println ("");
|
||||
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ALL_ROWS);
|
||||
System.out.println ("ALL_ROWS:");
|
||||
html = Presenter.doXid (htmlSource, datas, errorMessage);
|
||||
html = StringPresenter.doXid (htmlSource, datas, errorMessage);
|
||||
System.out.println (html);
|
||||
|
||||
|
||||
|
@ -239,7 +239,7 @@ class Demo
|
|||
source.append (" <h1>three</h1>\n");
|
||||
source.append ("</div>");
|
||||
htmlSource = source.toString ();
|
||||
html = Presenter.doXid (htmlSource, datas, errorMessage);
|
||||
html = StringPresenter.doXid (htmlSource, datas, errorMessage);
|
||||
|
||||
System.out.println (htmlSource);
|
||||
System.out.println ("+");
|
||||
|
|
245
demo/Demo.java~
245
demo/Demo.java~
|
@ -1,245 +0,0 @@
|
|||
import java.util.*;
|
||||
import java.io.*;
|
||||
import xid.*;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Demo
|
||||
{
|
||||
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 (Demo.class.getName ());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
System.out.println("Hello World!");
|
||||
|
||||
//test ();
|
||||
|
||||
//
|
||||
Data datas;
|
||||
IdData tag;
|
||||
|
||||
|
||||
|
||||
String htmlSource;
|
||||
StringBuffer html;
|
||||
StringBuffer errorMessage;
|
||||
|
||||
// Populate attributes of Test 03.
|
||||
System.out.println ("----------------------------");
|
||||
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 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 (html);
|
||||
|
||||
|
||||
// Populate attributes of Test 03.
|
||||
System.out.println ("----------------------------");
|
||||
datas = new Data ();
|
||||
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 ("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 (html);
|
||||
|
||||
|
||||
// Populate attributes of Test 03.
|
||||
System.out.println ("----------------------------");
|
||||
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");
|
||||
|
||||
|
||||
errorMessage = new StringBuffer ();
|
||||
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\");");
|
||||
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);
|
||||
|
||||
|
||||
// Populate attributes of Test 03.
|
||||
System.out.println ("----------------------------");
|
||||
datas = new Data ();
|
||||
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 ();
|
||||
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 ("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\");");
|
||||
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 ("=>");
|
||||
System.out.println (html);
|
||||
|
||||
|
||||
// Populate attributes of Test 03.
|
||||
System.out.println ("----------------------------");
|
||||
datas = new Data ();
|
||||
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", IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW);
|
||||
//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);
|
||||
|
||||
|
||||
errorMessage = 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");
|
||||
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 ("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\");");
|
||||
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", IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW);
|
||||
System.out.println ("ONLY_FIRST_ROW:");
|
||||
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);
|
||||
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);
|
||||
System.out.println (html);
|
||||
|
||||
datas.setIterationStrategy ("identity", IdsDataByIndex.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 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");
|
||||
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 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);
|
||||
}
|
||||
}
|
|
@ -183,6 +183,15 @@ public class Data
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setContent (String id, int content)
|
||||
{
|
||||
setContent (id, (new Integer (content)).toString ());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -194,6 +203,15 @@ public class Data
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setContent (String id, int line, int content)
|
||||
{
|
||||
setContent (id, line, (new Integer (content)).toString ());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -205,6 +223,15 @@ public class Data
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setContent (String id, int line, String column, int content)
|
||||
{
|
||||
setContent (id, line, column, (new Integer (content)).toString ());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -232,6 +259,15 @@ public class Data
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAttribute (String id, String label, int value)
|
||||
{
|
||||
setAttribute (id, label, (new Integer (value)).toString ());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -243,6 +279,15 @@ public class Data
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAttribute (String id, int line, String label, int value)
|
||||
{
|
||||
setAttribute (id, line, label, (new Integer (value)).toString ());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -254,6 +299,15 @@ public class Data
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void setAttribute (String id, int line, String column, String label, int value)
|
||||
{
|
||||
setAttribute (id, line, column, label, (new Integer (value)).toString ());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -265,6 +319,15 @@ public class Data
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void appendAttribute (String id, String label, int value)
|
||||
{
|
||||
appendAttribute (id, label, (new Integer (value)).toString ());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -276,6 +339,15 @@ public class Data
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void appendContent (String id, int line, String label, int value)
|
||||
{
|
||||
appendContent (id, line, label, (new Integer (value)).toString ());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -285,4 +357,13 @@ public class Data
|
|||
|
||||
tag.getAttributes ().appendAttribute (label, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void appendContent (String id, int line, String column, String label, int value)
|
||||
{
|
||||
appendContent (id, line, column, label, (new Integer (value)).toString ());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public class Presenter
|
|||
static protected org.apache.log4j.Logger log;
|
||||
static
|
||||
{
|
||||
log = org.apache.log4j.Logger.getLogger (Presenter.class.getName ());
|
||||
log = org.apache.log4j.Logger.getLogger (Presenter.class);
|
||||
}
|
||||
|
||||
static protected String staticRootPath;
|
||||
|
@ -27,74 +27,6 @@ public class Presenter
|
|||
}
|
||||
|
||||
|
||||
protected String webappPath;
|
||||
protected String sourceFileName;
|
||||
protected long sourceFileTime;
|
||||
protected Document doc;
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public Presenter ()
|
||||
{
|
||||
this.webappPath = Presenter.staticRootPath;
|
||||
this.sourceFileName = null;
|
||||
this.sourceFileTime = 0;
|
||||
this.doc = null;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public Presenter (String fileName)
|
||||
{
|
||||
this.webappPath = Presenter.staticRootPath;
|
||||
this.sourceFileName = fileName;
|
||||
this.sourceFileTime = 0;
|
||||
this.doc = null;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public Presenter (String webappPath, String fileName)
|
||||
{
|
||||
if ((webappPath == null) || (webappPath.equals ("")))
|
||||
{
|
||||
this.webappPath = Presenter.staticRootPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.webappPath = webappPath;
|
||||
}
|
||||
this.sourceFileName = fileName;
|
||||
this.sourceFileTime = 0;
|
||||
this.doc = null;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public String getWebappPath ()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.webappPath;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public void setWebappPath (String path)
|
||||
{
|
||||
this.webappPath = path;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
@ -107,194 +39,16 @@ public class Presenter
|
|||
/*
|
||||
*
|
||||
*/
|
||||
public void setSource (String fileName)
|
||||
{
|
||||
this.sourceFileName = fileName;
|
||||
this.sourceFileTime = 0;
|
||||
this.doc = null;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public String getSource ()
|
||||
static public String getStaticRootPath ()
|
||||
{
|
||||
String result;
|
||||
|
||||
result = this.sourceFileName;
|
||||
result = Presenter.staticRootPath;
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public StringBuffer doXid (Data datas, StringBuffer errorOutput)
|
||||
{
|
||||
return (doXid (datas.getIdsDataById (), datas.getTagsDataById (), errorOutput));
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public StringBuffer doXid (IdsDataById datas, TagsDataById tagsData, StringBuffer errorOutput)
|
||||
{
|
||||
StringBuffer result;
|
||||
|
||||
String sourceFilePath = this.webappPath + File.separator + this.sourceFileName;
|
||||
|
||||
// Get the good tree.
|
||||
File source = new File (sourceFilePath);
|
||||
|
||||
if (source == null)
|
||||
{
|
||||
String errorMessage = "source file not defined";
|
||||
errorOutput.append (errorMessage);
|
||||
log.error (errorMessage);
|
||||
result = null;
|
||||
}
|
||||
else if (!source.exists ())
|
||||
{
|
||||
String errorMessage = "source file defined but not found (" + sourceFilePath + ")";
|
||||
errorOutput.append (errorMessage);
|
||||
log.error (errorMessage);
|
||||
result = null;
|
||||
}
|
||||
else if ((this.doc == null) ||
|
||||
(this.sourceFileTime != source.lastModified ()))
|
||||
{
|
||||
this.sourceFileTime = source.lastModified ();
|
||||
this.doc = Presenter.fileToTree (sourceFilePath, errorOutput);
|
||||
|
||||
if (this.doc != null)
|
||||
{
|
||||
Presenter.addMetaTag (doc, "generator", "XID 0.0");
|
||||
}
|
||||
}
|
||||
|
||||
// Build the web page.
|
||||
result = Presenter.doXid (doc, datas, tagsData, this.webappPath, errorOutput);
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Xid a file without data.
|
||||
*/
|
||||
static public StringBuffer doXid (String fileName, String webappPath, StringBuffer errorOutput)
|
||||
{
|
||||
StringBuffer result;
|
||||
|
||||
Document doc = Presenter.fileToTree (fileName, errorOutput);
|
||||
|
||||
if (doc == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
Presenter.addMetaTag (doc, "generator", "XID 0.0");
|
||||
|
||||
result = Presenter.doXid (doc, null, null, webappPath, errorOutput);
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
static public StringBuffer doXid (String html, Data datas, StringBuffer errorOutput)
|
||||
{
|
||||
return (doXid (html, datas.getIdsDataById (), datas.getTagsDataById (), "", errorOutput));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
static public StringBuffer doXid (String html, Data datas, String webappPath, StringBuffer errorOutput)
|
||||
{
|
||||
return (doXid (html, datas.getIdsDataById (), datas.getTagsDataById (), webappPath, errorOutput));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Xid a string with html in.
|
||||
*/
|
||||
static public StringBuffer doXid (String html, IdsDataById datas, String webappPath, StringBuffer errorOutput)
|
||||
{
|
||||
return (doXid (html, datas, null, webappPath, errorOutput));
|
||||
}
|
||||
|
||||
/*
|
||||
* Xid a string with html in.
|
||||
*/
|
||||
static public StringBuffer doXid (String html, IdsDataById datas, TagsDataById tagsData, String webappPath, StringBuffer errorOutput)
|
||||
{
|
||||
StringBuffer result;
|
||||
|
||||
String htmlSource;
|
||||
if ((html.startsWith ("<!DOCTYPE")) ||
|
||||
(html.startsWith ("<!doctype")) ||
|
||||
(html.startsWith ("<html>")) ||
|
||||
(html.startsWith ("<HTML>")))
|
||||
{
|
||||
htmlSource = html;
|
||||
}
|
||||
else
|
||||
{
|
||||
htmlSource = "<html><head></head><body>\n" + html + "</body></html>";
|
||||
}
|
||||
|
||||
Document doc = null;
|
||||
|
||||
// StringBufferInputStream is deprecated so we use another solution.
|
||||
// (see http://www.developpez.net/forums/archive/index.php/t-14101.html).
|
||||
doc = buildTree (new ByteArrayInputStream (htmlSource.getBytes ()), errorOutput);
|
||||
|
||||
StringBuffer htmlTarget;
|
||||
htmlTarget = Presenter.process (doc, datas, tagsData, webappPath, errorOutput);
|
||||
|
||||
if (htmlTarget == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else if ((html.startsWith ("<!DOCTYPE")) ||
|
||||
(html.startsWith ("<!doctype")) ||
|
||||
(html.startsWith ("<html>")) ||
|
||||
(html.startsWith ("<HTML>")))
|
||||
{
|
||||
result = htmlTarget;
|
||||
}
|
||||
else
|
||||
{
|
||||
String bodyContent = extractBodyContent (htmlTarget);
|
||||
|
||||
if (bodyContent == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = new StringBuffer (bodyContent);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Xid a file with data.
|
||||
*/
|
||||
|
@ -1167,11 +921,15 @@ public class Presenter
|
|||
|
||||
// Parse the input file.
|
||||
result = db.parse (source);
|
||||
|
||||
|
||||
if (errorHandler.hasError ())
|
||||
{
|
||||
errorOutput.append (errorHandler.toString ());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DomPresenter.addMetaTag (result, "generator", "XID 0.0");
|
||||
}
|
||||
}
|
||||
catch (ParserConfigurationException exception)
|
||||
{
|
||||
|
@ -1195,36 +953,13 @@ public class Presenter
|
|||
result = null;
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
static protected Document fileToTree (String fileName, StringBuffer errorOutput)
|
||||
{
|
||||
Document result;
|
||||
|
||||
try
|
||||
{
|
||||
result = buildTree (new FileInputStream (new File (fileName)), errorOutput);
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
String errorMessage = "IOError during parsing." + exception.getMessage ();
|
||||
errorOutput.append (errorMessage);
|
||||
log.error (errorMessage);
|
||||
result = null;
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
@ -1564,4 +1299,28 @@ public class Presenter
|
|||
//
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Define in Presnter cause <object> needs this possibility.
|
||||
*/
|
||||
static protected Document fileToTree (String fileName, StringBuffer errorOutput)
|
||||
{
|
||||
Document result;
|
||||
|
||||
try
|
||||
{
|
||||
result = buildTree (new FileInputStream (new File (fileName)), errorOutput);
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
String errorMessage = "IOError during parsing." + exception.getMessage ();
|
||||
errorOutput.append (errorMessage);
|
||||
log.error (errorMessage);
|
||||
result = null;
|
||||
}
|
||||
|
||||
//
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 = StringPresenter.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 = StringPresenter.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 = StringPresenter.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 = StringPresenter.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>"));
|
||||
|
|
Loading…
Reference in a new issue