Add use of Exception for error management.

This commit is contained in:
Christian P. MOMON 2010-02-25 01:22:06 +01:00
parent 9273559c7f
commit d4dc85485d
9 changed files with 372 additions and 259 deletions

View file

@ -25,187 +25,277 @@ class XidDemo
*/ */
public static void main (String[] args) public static void main (String[] args)
{ {
System.out.println("Hello World!"); System.out.println("Hello World!");
//test (); //test ();
// //
Data datas; Data datas;
IdData tag; IdData tag;
String htmlSource;
StringBuffer html;
StringBuffer errorMessage;
// Populate attributes of Test 03. // Step #01.
System.out.println ("----------------------------"); {
datas = new Data (); System.out.println ("----------------------------");
datas.setContent ("name", "Superman");
errorMessage = new StringBuffer (); // Populate attributes.
html = StringPresenter.doXid ("<div id='name'>a name</div >", datas, errorMessage); datas = new Data ();
datas.setContent ("name", "Superman");
System.out.println ("datas = new Data ();"); StringBuffer html;
System.out.println ("datas.setContent (\"name\", \"Superman\");"); try
System.out.println ("+"); {
System.out.println ("<div id='name'>a name</div >"); html = StringPresenter.doXid ("<div id='name'>a name</div >", datas);
System.out.println ("=>"); }
System.out.println (html); catch (Exception exception)
{
System.out.println("Error " + exception.getMessage());
html = 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 (html);
}
// Populate attributes of Test 03. // Step #02.
System.out.println ("----------------------------"); {
datas = new Data (); System.out.println ("----------------------------");
datas.setContent ("lastname", "Spiderman"); // Populate attributes.
datas.appendAttribute ("lastname", "style", "background: blue;"); datas = new Data ();
datas.appendAttribute ("lastname", "style", "foreground: red;"); datas.setContent ("lastname", "Spiderman");
datas.setAttribute ("lastname", "class", "nameClass"); datas.appendAttribute ("lastname", "style", "background: blue;");
datas.appendAttribute ("lastname", "style", "foreground: red;");
datas.setAttribute ("lastname", "class", "nameClass");
StringBuffer html;
try
{
html = StringPresenter.doXid ("<div id='lastname'>a last name</div >", datas);
}
catch (Exception exception)
{
System.out.println("Error " + exception.getMessage());
html = 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 ("<div id='lastname'>a last name</div>");
System.out.println ("=>");
System.out.println (html);
}
errorMessage = new StringBuffer (); // Step #03.
html = StringPresenter.doXid ("<div id='lastname'>a last name</div >", datas, errorMessage); {
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");
System.out.println ("datas = new Data ();"); StringBuffer html;
System.out.println ("datas.setContent (\"lastname\", \"Spiderman\");"); try
System.out.println ("datas.appendAttribute (\"lastname\", \"style\", \"background: blue;\");"); {
System.out.println ("datas.appendAttribute (\"lastname\", \"style\", \"foreground: red;\");"); html = StringPresenter.doXid ("<ul>\n <li id='words'>a word</li>\n</ul>", datas);
System.out.println ("datas.setAttribute (\"lastname\", \"class\", \"nameClass\");"); }
System.out.println ("+"); catch (Exception exception)
System.out.println ("<div id='lastname'>a last name</div>"); {
System.out.println ("=>"); System.out.println("Error " + exception.getMessage());
System.out.println (html); html = 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 (html);
}
// Populate attributes of Test 03. // Step #04.
System.out.println ("----------------------------"); {
datas = new Data (); System.out.println ("----------------------------");
datas.setContent ("words", 0, "alpha"); // Populate attributes.
datas.setContent ("words", 1, "bravo"); datas = new Data ();
datas.setContent ("words", 2, "charlie"); datas.setContent ("identity", 0, "last_name", "Jemba");
datas.setContent ("words", 3, "delta"); datas.setContent ("identity", 0, "first_name", "Epo");
datas.setContent ("words", 4, "echo"); datas.setContent ("identity", 1, "last_name", "Momon");
datas.setContent ("words", 5, "fox"); datas.setContent ("identity", 1, "first_name", "Christian");
datas.setContent ("identity", 2, "last_name", "Tronche");
datas.setContent ("identity", 2, "first_name", "Christophe");
errorMessage = new StringBuffer (); StringBuffer source = new StringBuffer ();
html = StringPresenter.doXid ("<ul>\n <li id='words'>a word</li>\n</ul>", datas, errorMessage); 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>");
System.out.println ("datas = new Data ();"); String htmlSource = source.toString ();
System.out.println ("datas.setContent (\"words\", 0, \"alpha\");"); StringBuffer html;
System.out.println ("datas.setContent (\"words\", 1, \"bravo\");"); try
System.out.println ("datas.setContent (\"words\", 2, \"charlie\");"); {
System.out.println ("datas.setContent (\"words\", 3, \"delta\");"); html = StringPresenter.doXid (htmlSource, datas);
System.out.println ("datas.setContent (\"words\", 4, \"echo\");"); }
System.out.println ("datas.setContent (\"words\", 5, \"fox\");"); catch (Exception exception)
System.out.println ("+"); {
System.out.println ("<ul>"); System.out.println("Error " + exception.getMessage());
System.out.println (" <li id='words'>a word</li>"); html = null;
System.out.println ("</ul>"); }
System.out.println ("=>");
System.out.println (html); 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 (html);
}
// Populate attributes of Test 03. // Step #05.
System.out.println ("----------------------------"); {
datas = new Data (); System.out.println ("----------------------------");
datas.setContent ("identity", 0, "last_name", "Jemba"); // Populate attributes.
datas.setContent ("identity", 0, "first_name", "Epo"); datas = new Data ();
datas.setContent ("identity", 1, "last_name", "Momon"); datas.setContent ("identity", 0, "last_name", "Jemba");
datas.setContent ("identity", 1, "first_name", "Christian"); datas.setContent ("identity", 0, "first_name", "Epo");
datas.setContent ("identity", 2, "last_name", "Tronche"); datas.setContent ("identity", 1, "last_name", "Momon");
datas.setContent ("identity", 2, "first_name", "Christophe"); 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 ("<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 ("=>");
errorMessage = new StringBuffer (); // #05.1
StringBuffer source = new StringBuffer (); datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_FIRST_ROW);
source.append ("<table>\n"); System.out.println ("ONLY_FIRST_ROW:");
source.append (" <tr id='identity'><td>noid</td><td id='first_name'>Jean</td><td id='last_name'>Reve</td></tr>\n"); StringBuffer html;
source.append ("</table>"); try
htmlSource = source.toString (); {
html = StringPresenter.doXid (htmlSource, datas, errorMessage); html = StringPresenter.doXid (htmlSource, datas);
}
System.out.println ("datas = new Data ();"); catch (Exception exception)
System.out.println ("datas.setContent (\"identity\", 0, \"last_name\", \"Jemba\");"); {
System.out.println ("datas.setContent (\"identity\", 0, \"first_name\", \"Epo\");"); System.out.println(exception.getMessage());
System.out.println ("datas.setContent (\"identity\", 1, \"last_name\", \"Momon\");"); html = null;
System.out.println ("datas.setContent (\"identity\", 1, \"first_name\", \"Christian\");"); }
System.out.println ("datas.setContent (\"identity\", 2, \"last_name\", \"Tronche\");"); System.out.println (html);
System.out.println ("datas.setContent (\"identity\", 2, \"first_name\", \"Christophe\");"); System.out.println ("");
System.out.println ("+");
System.out.println (htmlSource);
System.out.println ("=>");
System.out.println (html);
// Populate attributes of Test 03. // #05.2
System.out.println ("----------------------------"); datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_FIRST_TWO_ROWS);
datas = new Data (); System.out.println ("ONLY_FIRST_TWO_ROWS:");
datas.setContent ("identity", 0, "last_name", "Jemba"); try
datas.setContent ("identity", 0, "first_name", "Epo"); {
datas.setContent ("identity", 1, "last_name", "Momon"); html = StringPresenter.doXid (htmlSource, datas);
datas.setContent ("identity", 1, "first_name", "Christian"); }
datas.setContent ("identity", 2, "last_name", "Tronche"); catch (Exception exception)
datas.setContent ("identity", 2, "first_name", "Christophe"); {
//datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID); System.out.println("Error " + exception.getMessage());
//datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID); html = null;
//datas.setIterationStrategy ("identity", IdsDataByIndex.IterationStrategy.ALL_ROWS); }
System.out.println (html);
System.out.println ("");
errorMessage = new StringBuffer (); // #05.3
source = new StringBuffer (); datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_ROWS_WITH_ID);
source.append ("<table id=\"identities\">\n"); System.out.println ("ONLY_ROWS_WITH_ID:");
source.append (" <tr id='the_head'><th>noid</th><th>First Name</th><th>Last Name</th></tr>\n"); try
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"); html = StringPresenter.doXid (htmlSource, datas);
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"); catch (Exception exception)
htmlSource = source.toString (); {
System.out.println("Error " + exception.getMessage());
System.out.println ("datas = new Data ();"); html = null;
System.out.println ("datas.setContent (\"identity\", 0, \"first_name\", \"Epo\");"); }
System.out.println ("datas.setContent (\"identity\", 0, \"last_name\", \"Jemba\");"); System.out.println (html);
System.out.println ("datas.setContent (\"identity\", 1, \"first_name\", \"Christian\");"); System.out.println ("");
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 ("=>");
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_FIRST_ROW); // #05.4
System.out.println ("ONLY_FIRST_ROW:"); datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
html = StringPresenter.doXid (htmlSource, datas, errorMessage); System.out.println ("ONLY_ROWS_WITHOUT_ID:");
System.out.println (html); try
{
System.out.println (""); html = StringPresenter.doXid (htmlSource, datas);
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_FIRST_TWO_ROWS); }
System.out.println ("ONLY_FIRST_TWO_ROWS:"); catch (Exception exception)
html = StringPresenter.doXid (htmlSource, datas, errorMessage); {
System.out.println (html); System.out.println("Error " + exception.getMessage());
html = null;
System.out.println (""); }
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_ROWS_WITH_ID); System.out.println (html);
System.out.println ("ONLY_ROWS_WITH_ID:"); System.out.println ("");
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 = 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 = StringPresenter.doXid (htmlSource, datas, errorMessage);
System.out.println (html);
} // #05.5
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ALL_ROWS);
System.out.println ("ALL_ROWS:");
try
{
html = StringPresenter.doXid (htmlSource, datas);
}
catch (Exception exception)
{
System.out.println("Error " + exception.getMessage());
html = null;
}
System.out.println (html);
}
}
} }

View file

@ -94,29 +94,29 @@ public class DomPresenter extends Presenter
/* /*
* *
*/ */
public StringBuffer doXid (Data datas, StringBuffer errorOutput) public StringBuffer doXid (Data datas) throws Exception
{ {
return (doXid (datas.getIdsDataById (), errorOutput)); return (doXid (datas.getIdsDataById ()));
} }
/* /*
* *
*/ */
public StringBuffer doXid (IdsDataById datas, StringBuffer errorOutput) public StringBuffer doXid (IdsDataById datas) throws Exception
{ {
StringBuffer result; StringBuffer result;
if (this.doc == null) if (this.doc == null)
{ {
String errorMessage = "source not defined"; String errorMessage = "source not defined";
errorOutput.append (errorMessage);
logger.error (errorMessage); logger.error (errorMessage);
result = null; result = null;
throw new Exception (errorMessage);
} }
else else
{ {
// Build the web page. // Build the web page.
result = Presenter.doXid (this.doc, datas, errorOutput); result = Presenter.doXid (this.doc, datas);
} }
// //
@ -127,11 +127,11 @@ public class DomPresenter extends Presenter
/* /*
* Xid a file with data. * Xid a file with data.
*/ */
static public StringBuffer doXid (Document doc, IdsDataById datas, String webappPath, StringBuffer errorOutput) static public StringBuffer doXid (Document doc, IdsDataById datas, String webappPath) throws Exception
{ {
StringBuffer result; StringBuffer result;
result = Presenter.process (doc, datas, webappPath, errorOutput); result = Presenter.process (doc, datas, webappPath);
// //
return (result); return (result);

View file

@ -68,16 +68,16 @@ public class FilePresenter extends DomPresenter
/* /*
* *
*/ */
public StringBuffer doXid (Data datas, StringBuffer errorOutput) public StringBuffer doXid (Data datas) throws Exception
{ {
return (doXid (datas.getIdsDataById (), errorOutput)); return (doXid (datas.getIdsDataById ()));
} }
/* /*
* *
*/ */
public StringBuffer doXid (IdsDataById datas, StringBuffer errorOutput) public StringBuffer doXid (IdsDataById datas) throws Exception
{ {
StringBuffer result; StringBuffer result;
@ -89,22 +89,22 @@ public class FilePresenter extends DomPresenter
if (source == null) if (source == null)
{ {
String errorMessage = "source file not defined"; String errorMessage = "source file not defined";
errorOutput.append (errorMessage);
logger.error (errorMessage); logger.error (errorMessage);
result = null; result = null;
throw new Exception (errorMessage);
} }
else if (!source.exists ()) else if (!source.exists ())
{ {
String errorMessage = "source file defined but not found (" + sourceFilePath + ")"; String errorMessage = "source file defined but not found (" + sourceFilePath + ")";
errorOutput.append (errorMessage);
logger.error (errorMessage); logger.error (errorMessage);
result = null; result = null;
throw new Exception (errorMessage);
} }
else if ((this.doc == null) || else if ((this.doc == null) ||
(this.sourceFileTime != source.lastModified ())) (this.sourceFileTime != source.lastModified ()))
{ {
this.sourceFileTime = source.lastModified (); this.sourceFileTime = source.lastModified ();
this.doc = Presenter.fileToTree (sourceFilePath, errorOutput); this.doc = Presenter.fileToTree (sourceFilePath);
if (this.doc != null) if (this.doc != null)
{ {
@ -113,7 +113,7 @@ public class FilePresenter extends DomPresenter
} }
// Build the web page. // Build the web page.
result = Presenter.doXid (doc, datas, errorOutput); result = Presenter.doXid (doc, datas);
// //
return (result); return (result);
@ -123,11 +123,11 @@ public class FilePresenter extends DomPresenter
/* /*
* Xid a file without data. * Xid a file without data.
*/ */
static public StringBuffer doXid (String fileName, StringBuffer errorOutput) static public StringBuffer doXid (String fileName) throws Exception
{ {
StringBuffer result; StringBuffer result;
Document doc = Presenter.fileToTree (fileName, errorOutput); Document doc = Presenter.fileToTree (fileName);
if (doc == null) if (doc == null)
{ {
@ -137,7 +137,7 @@ public class FilePresenter extends DomPresenter
{ {
Presenter.addMetaTag (doc, "generator", "XID 0.0"); Presenter.addMetaTag (doc, "generator", "XID 0.0");
result = Presenter.doXid (doc, null, errorOutput); result = Presenter.doXid (doc, null);
} }
// //

View file

@ -14,6 +14,7 @@ import org.w3c.dom.*;
public class Presenter public class Presenter
{ {
static final public char INDEX_SEPARATOR = '_'; static final public char INDEX_SEPARATOR = '_';
static protected int bufferSize = 2048;
static protected org.apache.log4j.Logger logger; static protected org.apache.log4j.Logger logger;
static static
@ -25,17 +26,42 @@ public class Presenter
/* /*
* Xid a file with data. * Xid a file with data.
*/ */
static public StringBuffer doXid (Document doc, IdsDataById datas, StringBuffer errorOutput) static public StringBuffer doXid (Document doc, IdsDataById datas) throws Exception
{ {
StringBuffer result; StringBuffer result;
result = Presenter.process (doc, datas, errorOutput); result = Presenter.process (doc, datas);
// //
return (result); return (result);
} }
/*
*
*/
static public int bufferSize()
{
int result;
result = bufferSize;
//
return(result);
}
/*
*
*/
static public void setBufferSize(int value)
{
if (bufferSize > 0)
{
bufferSize = value;
}
}
/* /*
* *
*/ */
@ -117,11 +143,11 @@ public class Presenter
/* /*
* *
*/ */
static protected StringBuffer processChildren (Node node, IdsDataById datas, StringBuffer errorOutput) static protected StringBuffer processChildren (Node node, IdsDataById datas) throws Exception
{ {
StringBuffer result; StringBuffer result;
result = processChildren (node, datas, "", errorOutput); result = processChildren (node, datas, "");
// //
return (result); return (result);
@ -133,8 +159,7 @@ public class Presenter
*/ */
static protected StringBuffer processChildren (Node node, static protected StringBuffer processChildren (Node node,
IdsDataById datas, IdsDataById datas,
String suffix, String suffix) throws Exception
StringBuffer errorOutput)
{ {
StringBuffer result; StringBuffer result;
result = new StringBuffer (); result = new StringBuffer ();
@ -190,12 +215,12 @@ public class Presenter
lineCounter += 1; lineCounter += 1;
if (lineCounter == 1) if (lineCounter == 1)
{ {
result.append (process (children.item (childIndex), datas, suffix, errorOutput)); result.append (process (children.item (childIndex), datas, suffix));
} }
} }
else else
{ {
result.append (process (children.item (childIndex), datas, suffix, errorOutput)); result.append (process (children.item (childIndex), datas, suffix));
} }
} }
break; break;
@ -210,12 +235,12 @@ public class Presenter
if ((lineCounter == 1) || (lineCounter == 2)) if ((lineCounter == 1) || (lineCounter == 2))
{ {
result.append (process (children.item (childIndex), datas, suffix, errorOutput)); result.append (process (children.item (childIndex), datas, suffix));
} }
} }
else else
{ {
result.append (process (children.item (childIndex), datas, suffix, errorOutput)); result.append (process (children.item (childIndex), datas, suffix));
} }
} }
break; break;
@ -230,12 +255,12 @@ public class Presenter
if ((attrs2 != null) && if ((attrs2 != null) &&
(attrs2.getNamedItem ("id") != null)) (attrs2.getNamedItem ("id") != null))
{ {
result.append (process (children.item (childIndex), datas, suffix, errorOutput)); result.append (process (children.item (childIndex), datas, suffix));
} }
} }
else else
{ {
result.append (process (children.item (childIndex), datas, suffix, errorOutput)); result.append (process (children.item (childIndex), datas, suffix));
} }
} }
break; break;
@ -249,12 +274,12 @@ public class Presenter
if ((attrs2 == null) || if ((attrs2 == null) ||
(attrs2.getNamedItem ("id") == null)) (attrs2.getNamedItem ("id") == null))
{ {
result.append (process (children.item(childIndex), datas, suffix, errorOutput)); result.append (process (children.item(childIndex), datas, suffix));
} }
} }
else else
{ {
result.append (process (children.item (childIndex), datas, suffix, errorOutput)); result.append (process (children.item (childIndex), datas, suffix));
} }
} }
break; break;
@ -262,7 +287,7 @@ public class Presenter
case ALL_ROWS: case ALL_ROWS:
for (int childIndex = 0; childIndex < childrenCount; childIndex++) for (int childIndex = 0; childIndex < childrenCount; childIndex++)
{ {
result.append (process (children.item(childIndex), datas, suffix, errorOutput)); result.append (process (children.item(childIndex), datas, suffix));
} }
break; break;
} }
@ -286,13 +311,12 @@ public class Presenter
static protected StringBuffer processElementWithId (Node node, static protected StringBuffer processElementWithId (Node node,
NamedNodeMap attrs, NamedNodeMap attrs,
Node idAttr, Node idAttr,
IdsDataById datas, IdsDataById datas) throws Exception
StringBuffer errorOutput)
{ {
StringBuffer result; StringBuffer result;
result = processElementWithId (node, attrs, idAttr, datas, "", errorOutput); result = processElementWithId (node, attrs, idAttr, datas, "");
// //
return (result); return (result);
@ -311,11 +335,10 @@ public class Presenter
* The ID. * The ID.
*/ */
static protected StringBuffer processElementWithId (Node node, static protected StringBuffer processElementWithId (Node node,
NamedNodeMap attrs, NamedNodeMap attrs,
Node idAttr, Node idAttr,
IdsDataById datas, IdsDataById datas,
String suffix, String suffix) throws Exception
StringBuffer errorOutput)
{ {
StringBuffer result; StringBuffer result;
result = new StringBuffer (); result = new StringBuffer ();
@ -331,7 +354,7 @@ public class Presenter
if (dataCore == null) if (dataCore == null)
{ {
result.append (Presenter.processElementBasically (node, datas, suffix, errorOutput)); result.append (Presenter.processElementBasically (node, datas, suffix));
} }
else if (dataCore instanceof IdData) else if (dataCore instanceof IdData)
{ {
@ -373,7 +396,7 @@ public class Presenter
if ((data == null) || if ((data == null) ||
(data.display () == null)) (data.display () == null))
{ {
result.append (processChildren (node, datas, suffix, errorOutput)); result.append (processChildren (node, datas, suffix));
} }
else else
{ {
@ -420,7 +443,7 @@ public class Presenter
// Insert data. // Insert data.
if ((data == null) || (data.display () == null)) if ((data == null) || (data.display () == null))
{ {
result.append (processChildren (node, datas, suffix, errorOutput)); result.append (processChildren (node, datas, suffix));
} }
else else
{ {
@ -438,7 +461,7 @@ public class Presenter
// Manage a Hashmap. // Manage a Hashmap.
IdsDataById data = (IdsDataById) tags.elementAt (nLine); IdsDataById data = (IdsDataById) tags.elementAt (nLine);
result.append (Presenter.processElementWithId (node, attrs, idAttr, data, Integer.toString (nLine), errorOutput)); result.append (Presenter.processElementWithId (node, attrs, idAttr, data, Integer.toString (nLine)));
result.append ('\n'); result.append ('\n');
} }
} }
@ -458,11 +481,11 @@ public class Presenter
/** /**
* *
*/ */
static protected StringBuffer process (Node node, IdsDataById datas, StringBuffer errorOutput) static protected StringBuffer process (Node node, IdsDataById datas) throws Exception
{ {
StringBuffer result; StringBuffer result;
result = Presenter.process (node, datas, "", errorOutput); result = Presenter.process (node, datas, "");
// //
return (result); return (result);
@ -473,7 +496,7 @@ public class Presenter
* Recursive method that processes a node and any child nodes. * Recursive method that processes a node and any child nodes.
* *
*/ */
static protected StringBuffer process (Node node, IdsDataById datas, String suffix, StringBuffer errorOutput) static protected StringBuffer process (Node node, IdsDataById datas, String suffix) throws Exception
{ {
logger.debug ("process - started"); logger.debug ("process - started");
String TRANSITIONAL_DTD = "xhtml1-transitional.dtd"; String TRANSITIONAL_DTD = "xhtml1-transitional.dtd";
@ -517,7 +540,7 @@ public class Presenter
// Log.write(Log.TRACE,"systemId = " + systemId); // Log.write(Log.TRACE,"systemId = " + systemId);
} }
result.append (Presenter.process (((Document) node).getDocumentElement(), datas, suffix, errorOutput)); result.append (Presenter.process (((Document) node).getDocumentElement(), datas, suffix));
break; break;
} }
@ -535,12 +558,11 @@ public class Presenter
attrs, attrs,
idAttr, idAttr,
datas, datas,
suffix, suffix));
errorOutput));
} }
else else
{ {
result.append (Presenter.processElementBasically (node, datas, suffix, errorOutput)); result.append (Presenter.processElementBasically (node, datas, suffix));
} }
break; break;
@ -607,11 +629,11 @@ public class Presenter
/* /*
* *
*/ */
static StringBuffer processElementBasically (Node node, IdsDataById datas,StringBuffer errorOutput) static StringBuffer processElementBasically (Node node, IdsDataById datas) throws Exception
{ {
StringBuffer result; StringBuffer result;
result = processElementBasically (node, datas, "", errorOutput); result = processElementBasically (node, datas, "");
// //
return (result); return (result);
@ -621,7 +643,7 @@ public class Presenter
/* /*
* *
*/ */
static StringBuffer processElementBasically (Node node, IdsDataById datas, String suffix, StringBuffer errorOutput) static StringBuffer processElementBasically (Node node, IdsDataById datas, String suffix) throws Exception
{ {
StringBuffer result; StringBuffer result;
logger.debug("processElementBasically - started"); logger.debug("processElementBasically - started");
@ -648,7 +670,7 @@ public class Presenter
{ {
result.append('>'); result.append('>');
result.append (processChildren (node, datas, suffix, errorOutput)); result.append (processChildren (node, datas, suffix));
result.append("</"); result.append("</");
result.append(node.getNodeName()); result.append(node.getNodeName());
@ -666,7 +688,7 @@ public class Presenter
/* /*
* *
*/ */
static protected Document buildTree (InputStream source, StringBuffer errorOutput) static protected Document buildTree (InputStream source) throws Exception
{ {
Document result; Document result;
@ -699,36 +721,38 @@ public class Presenter
// Parse the input file. // Parse the input file.
result = db.parse (source); result = db.parse (source);
System.out.println("ZO4");
if (errorHandler.hasError ()) if (errorHandler.hasError ())
{ {
errorOutput.append (errorHandler.toString ()); System.out.println("ZO4a");
throw new Exception (errorHandler.toString ());
} }
else else
{ {System.out.println("ZO4b");
DomPresenter.addMetaTag (result, "generator", "XID 0.0"); DomPresenter.addMetaTag (result, "generator", "XID 0.0");
} }
System.out.println("ZO5");
} }
catch (ParserConfigurationException exception) catch (ParserConfigurationException exception)
{ {
String errorMessage = "Parser configuration exception: " + exception.getMessage (); String errorMessage = "Parser configuration exception: " + exception.getMessage ();
errorOutput.append (errorMessage);
logger.error (errorMessage); logger.error (errorMessage);
result = null; result = null;
throw new Exception (errorMessage);
} }
catch (SAXException exception) catch (SAXException exception)
{ {
String errorMessage = "Error during SAX parsing: " + exception.getMessage (); String errorMessage = "Error during SAX parsing: " + exception.getMessage ();
errorOutput.append (errorMessage);
logger.error (errorMessage); logger.error (errorMessage);
result = null; result = null;
throw new Exception (errorMessage);
} }
catch (IOException exception) catch (IOException exception)
{ {
String errorMessage = "IOError during parsing." + exception.getMessage (); String errorMessage = "IOError during parsing." + exception.getMessage ();
errorOutput.append (errorMessage);
logger.error (errorMessage); logger.error (errorMessage);
result = null; result = null;
throw new Exception (errorMessage);
} }
// //
@ -737,7 +761,6 @@ public class Presenter
/* /*
* *
*/ */
@ -1082,20 +1105,20 @@ public class Presenter
/* /*
* Define in Presnter cause <object> needs this possibility. * Define in Presnter cause <object> needs this possibility.
*/ */
static protected Document fileToTree (String fileName, StringBuffer errorOutput) static protected Document fileToTree (String fileName) throws Exception
{ {
Document result; Document result;
try try
{ {
result = buildTree (new FileInputStream (new File (fileName)), errorOutput); result = buildTree (new FileInputStream (new File (fileName)));
} }
catch (IOException exception) catch (IOException exception)
{ {
String errorMessage = "IOError during parsing." + exception.getMessage (); String errorMessage = "IOError during parsing." + exception.getMessage ();
errorOutput.append (errorMessage);
logger.error (errorMessage); logger.error (errorMessage);
result = null; result = null;
throw new Exception (errorMessage, exception);
} }
// //

View file

@ -65,15 +65,15 @@ public class StringPresenter extends DomPresenter
/* /*
* *
*/ */
public StringBuffer doXid (Data datas, StringBuffer errorOutput) public StringBuffer doXid (Data datas) throws Exception
{ {
return (doXid (datas.getIdsDataById (), errorOutput)); return (doXid (datas.getIdsDataById ()));
} }
/* /*
* *
*/ */
public StringBuffer doXid (IdsDataById datas, StringBuffer errorOutput) public StringBuffer doXid (IdsDataById datas) throws Exception
{ {
StringBuffer result; StringBuffer result;
@ -82,9 +82,9 @@ public class StringPresenter extends DomPresenter
// Build doc from this.html. // Build doc from this.html.
String htmlSource; String htmlSource;
if ((this.html.startsWith ("<!DOCTYPE")) || if ((this.html.startsWith ("<!DOCTYPE")) ||
(this.html.startsWith ("<!doctype")) || (this.html.startsWith ("<!doctype")) ||
(this.html.startsWith ("<html>")) || (this.html.startsWith ("<html>")) ||
(this.html.startsWith ("<HTML>"))) (this.html.startsWith ("<HTML>")))
{ {
htmlSource = html; htmlSource = html;
} }
@ -95,11 +95,11 @@ public class StringPresenter extends DomPresenter
// StringBufferInputStream is deprecated so we use another solution. // StringBufferInputStream is deprecated so we use another solution.
// (see http://www.developpez.net/forums/archive/index.php/t-14101.html). // (see http://www.developpez.net/forums/archive/index.php/t-14101.html).
doc = buildTree (new ByteArrayInputStream (htmlSource.getBytes ()), errorOutput); doc = buildTree (new ByteArrayInputStream (htmlSource.getBytes ()));
} }
StringBuffer htmlTarget; StringBuffer htmlTarget;
htmlTarget = Presenter.doXid (doc, datas, errorOutput); htmlTarget = Presenter.doXid (doc, datas);
if (htmlTarget == null) if (htmlTarget == null)
{ {
@ -134,22 +134,22 @@ public class StringPresenter extends DomPresenter
/* /*
* *
*/ */
static public StringBuffer doXid (String html, Data datas, StringBuffer errorOutput) static public StringBuffer doXid (String html, Data datas) throws Exception
{ {
return (doXid (html, datas.getIdsDataById (), errorOutput)); return (doXid (html, datas.getIdsDataById ()));
} }
/* /*
* Xid a string with html in. * Xid a string with html in.
*/ */
static public StringBuffer doXid (String html, IdsDataById datas, StringBuffer errorOutput) static public StringBuffer doXid (String html, IdsDataById datas) throws Exception
{ {
StringBuffer result; StringBuffer result;
StringPresenter presenter = new StringPresenter (html); StringPresenter presenter = new StringPresenter (html);
result = presenter.doXid (datas, errorOutput); result = presenter.doXid (datas);
// //
return (result); return (result);