diff --git a/build.xml b/build.xml index d7752f1..47c1d06 100644 --- a/build.xml +++ b/build.xml @@ -1,6 +1,6 @@ - + diff --git a/demo/Demo.java b/demo/Demo.java index 48539c3..aab625c 100644 --- a/demo/Demo.java +++ b/demo/Demo.java @@ -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 ("
a name
", datas, errorMessage); + html = StringPresenter.doXid ("
a name
", 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 ("
a last name
", datas, errorMessage); + html = StringPresenter.doXid ("
a last name
", 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 ("
    \n
  • a word
  • \n
", datas, errorMessage); + html = StringPresenter.doXid ("
    \n
  • a word
  • \n
", datas, errorMessage); System.out.println ("datas = new Data ();"); System.out.println ("datas.setContent (\"words\", 0, \"alpha\");"); @@ -139,7 +139,7 @@ class Demo source.append (" noidJeanReve\n"); source.append (""); 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 ("

three

\n"); source.append (""); htmlSource = source.toString (); - html = Presenter.doXid (htmlSource, datas, errorMessage); + html = StringPresenter.doXid (htmlSource, datas, errorMessage); System.out.println (htmlSource); System.out.println ("+"); diff --git a/demo/Demo.java~ b/demo/Demo.java~ deleted file mode 100644 index 4d43a2f..0000000 --- a/demo/Demo.java~ +++ /dev/null @@ -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 ("
a name
", datas, errorMessage); - - 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 (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 ("
a last name
", 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 ("
a last name
"); - 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 ("
    \n
  • a word
  • \n
", 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 ("
    "); - System.out.println ("
  • a word
  • "); - System.out.println ("
"); - 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 ("\n"); - source.append (" \n"); - source.append ("
noidun nomun prenom
"); - 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 ("\n"); - source.append (" \n"); - source.append (" \n"); - source.append (" \n"); - source.append ("
noidun nomun prenom
noidun nomun prenom
noidun nomun prenom
"); - 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 ("
", "class", "aDivClass"); - datas.setAttribute ("
", "style", "background-color: #000000;"); - datas.setAttribute ("number", "style", "background-color: #0000FF;"); - - errorMessage = new StringBuffer (); - source = new StringBuffer (); - source.append ("
\n"); - source.append ("

one

\n"); - source.append ("
\n"); - source.append ("
\n"); - source.append ("

three

\n"); - source.append ("
"); - 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 (\"
\", \"class\", \"aDivClass\");"); - System.out.println ("datas.setAttribute (\"
\", \"style\", \"background-color: #000000;\");"); - System.out.println ("datas.setAttribute (\"number\", \"style\", \"background-color: #0000FF;\");"); - - System.out.println ("=>"); - System.out.println (html); - } -} diff --git a/src/xid/Data.java b/src/xid/Data.java index a67a58a..98a30ce 100644 --- a/src/xid/Data.java +++ b/src/xid/Data.java @@ -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 ()); + } } diff --git a/src/xid/Presenter.java b/src/xid/Presenter.java index 947ddca..faeb250 100644 --- a/src/xid/Presenter.java +++ b/src/xid/Presenter.java @@ -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 ("")) || - (html.startsWith (""))) - { - htmlSource = html; - } - else - { - htmlSource = "\n" + 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 ("")) || - (html.startsWith (""))) - { - 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 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); + } } diff --git a/test/xid/test/Test.java b/test/xid/test/Test.java index 5ec5b99..ceed3c6 100644 --- a/test/xid/test/Test.java +++ b/test/xid/test/Test.java @@ -83,7 +83,7 @@ class Test datas.setContent ("name", "Superman"); errorMessage = new StringBuffer (); - html = Presenter.doXid ("
a name
", datas, errorMessage); + html = StringPresenter.doXid ("
a name
", datas, errorMessage); System.out.println (check ("only content change", html, "
Superman
")); @@ -97,7 +97,7 @@ class Test datas.setAttribute ("lastname", "class", "nameClass"); errorMessage = new StringBuffer (); - html = Presenter.doXid ("
a last name
", datas, errorMessage); + html = StringPresenter.doXid ("
a last name
", datas, errorMessage); System.out.println (check ("content and attributes", html, "
Spiderman
")); // Populate attributes of Test 03. @@ -112,7 +112,7 @@ class Test errorMessage = new StringBuffer (); - html = Presenter.doXid ("
    \n
  • a word
  • \n
", datas, errorMessage); + html = StringPresenter.doXid ("
    \n
  • a word
  • \n
", datas, errorMessage); System.out.println (check ("list assertion 1", html, "
  • alpha
  • ")); System.out.println (check ("list assertion 2", html, "
  • bravo
  • ")); @@ -138,7 +138,7 @@ class Test source.append (" noidun nomun prenom\n"); source.append (""); htmlSource = source.toString (); - html = Presenter.doXid (htmlSource, datas, errorMessage); + html = StringPresenter.doXid (htmlSource, datas, errorMessage); System.out.println (check ("table 1 assertion 1", html, "noidJembaEpo")); System.out.println (check ("table 1 assertion 2", html, "noidMomonChristian"));