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)
{
System.out.println("Hello World!");
System.out.println("Hello World!");
//test ();
//test ();
//
Data datas;
IdData tag;
//
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");
// Step #01.
{
System.out.println ("----------------------------");
errorMessage = new StringBuffer ();
html = StringPresenter.doXid ("<div id='name'>a name</div >", datas, errorMessage);
// Populate attributes.
datas = new Data ();
datas.setContent ("name", "Superman");
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);
StringBuffer html;
try
{
html = StringPresenter.doXid ("<div id='name'>a 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 (\"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");
// 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");
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 ();
html = StringPresenter.doXid ("<div id='lastname'>a last name</div >", datas, errorMessage);
// 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");
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);
StringBuffer html;
try
{
html = StringPresenter.doXid ("<ul>\n <li id='words'>a word</li>\n</ul>", datas);
}
catch (Exception exception)
{
System.out.println("Error " + exception.getMessage());
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.
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");
// 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");
errorMessage = new StringBuffer ();
html = StringPresenter.doXid ("<ul>\n <li id='words'>a word</li>\n</ul>", datas, errorMessage);
StringBuffer source = new StringBuffer ();
source.append ("<table>\n");
source.append (" <tr id='identity'><td>noid</td><td id='first_name'>Jean</td><td id='last_name'>Reve</td></tr>\n");
source.append ("</table>");
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);
String htmlSource = source.toString ();
StringBuffer html;
try
{
html = StringPresenter.doXid (htmlSource, datas);
}
catch (Exception exception)
{
System.out.println("Error " + exception.getMessage());
html = 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 (html);
}
// Populate attributes of Test 03.
System.out.println ("----------------------------");
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");
// 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 ("<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 ();
StringBuffer source = new StringBuffer ();
source.append ("<table>\n");
source.append (" <tr id='identity'><td>noid</td><td id='first_name'>Jean</td><td id='last_name'>Reve</td></tr>\n");
source.append ("</table>");
htmlSource = source.toString ();
html = StringPresenter.doXid (htmlSource, datas, errorMessage);
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);
// #05.1
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_FIRST_ROW);
System.out.println ("ONLY_FIRST_ROW:");
StringBuffer html;
try
{
html = StringPresenter.doXid (htmlSource, datas);
}
catch (Exception exception)
{
System.out.println(exception.getMessage());
html = null;
}
System.out.println (html);
System.out.println ("");
// Populate attributes of Test 03.
System.out.println ("----------------------------");
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);
// #05.2
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_FIRST_TWO_ROWS);
System.out.println ("ONLY_FIRST_TWO_ROWS:");
try
{
html = StringPresenter.doXid (htmlSource, datas);
}
catch (Exception exception)
{
System.out.println("Error " + exception.getMessage());
html = null;
}
System.out.println (html);
System.out.println ("");
errorMessage = new 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");
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.3
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_ROWS_WITH_ID);
System.out.println ("ONLY_ROWS_WITH_ID:");
try
{
html = StringPresenter.doXid (htmlSource, datas);
}
catch (Exception exception)
{
System.out.println("Error " + exception.getMessage());
html = null;
}
System.out.println (html);
System.out.println ("");
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_FIRST_ROW);
System.out.println ("ONLY_FIRST_ROW:");
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 = 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 = 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.4
datas.setIterationStrategy ("identities", IdData.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
System.out.println ("ONLY_ROWS_WITHOUT_ID:");
try
{
html = StringPresenter.doXid (htmlSource, datas);
}
catch (Exception exception)
{
System.out.println("Error " + 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.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;
if (this.doc == null)
{
String errorMessage = "source not defined";
errorOutput.append (errorMessage);
logger.error (errorMessage);
result = null;
throw new Exception (errorMessage);
}
else
{
// 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.
*/
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;
result = Presenter.process (doc, datas, webappPath, errorOutput);
result = Presenter.process (doc, datas, webappPath);
//
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;
@ -89,22 +89,22 @@ public class FilePresenter extends DomPresenter
if (source == null)
{
String errorMessage = "source file not defined";
errorOutput.append (errorMessage);
logger.error (errorMessage);
result = null;
throw new Exception (errorMessage);
}
else if (!source.exists ())
{
String errorMessage = "source file defined but not found (" + sourceFilePath + ")";
errorOutput.append (errorMessage);
logger.error (errorMessage);
result = null;
throw new Exception (errorMessage);
}
else if ((this.doc == null) ||
(this.sourceFileTime != source.lastModified ()))
{
this.sourceFileTime = source.lastModified ();
this.doc = Presenter.fileToTree (sourceFilePath, errorOutput);
this.doc = Presenter.fileToTree (sourceFilePath);
if (this.doc != null)
{
@ -113,7 +113,7 @@ public class FilePresenter extends DomPresenter
}
// Build the web page.
result = Presenter.doXid (doc, datas, errorOutput);
result = Presenter.doXid (doc, datas);
//
return (result);
@ -123,11 +123,11 @@ public class FilePresenter extends DomPresenter
/*
* Xid a file without data.
*/
static public StringBuffer doXid (String fileName, StringBuffer errorOutput)
static public StringBuffer doXid (String fileName) throws Exception
{
StringBuffer result;
Document doc = Presenter.fileToTree (fileName, errorOutput);
Document doc = Presenter.fileToTree (fileName);
if (doc == null)
{
@ -137,7 +137,7 @@ public class FilePresenter extends DomPresenter
{
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
{
static final public char INDEX_SEPARATOR = '_';
static protected int bufferSize = 2048;
static protected org.apache.log4j.Logger logger;
static
@ -25,17 +26,42 @@ public class Presenter
/*
* 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;
result = Presenter.process (doc, datas, errorOutput);
result = Presenter.process (doc, datas);
//
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;
result = processChildren (node, datas, "", errorOutput);
result = processChildren (node, datas, "");
//
return (result);
@ -133,8 +159,7 @@ public class Presenter
*/
static protected StringBuffer processChildren (Node node,
IdsDataById datas,
String suffix,
StringBuffer errorOutput)
String suffix) throws Exception
{
StringBuffer result;
result = new StringBuffer ();
@ -190,12 +215,12 @@ public class Presenter
lineCounter += 1;
if (lineCounter == 1)
{
result.append (process (children.item (childIndex), datas, suffix, errorOutput));
result.append (process (children.item (childIndex), datas, suffix));
}
}
else
{
result.append (process (children.item (childIndex), datas, suffix, errorOutput));
result.append (process (children.item (childIndex), datas, suffix));
}
}
break;
@ -210,12 +235,12 @@ public class Presenter
if ((lineCounter == 1) || (lineCounter == 2))
{
result.append (process (children.item (childIndex), datas, suffix, errorOutput));
result.append (process (children.item (childIndex), datas, suffix));
}
}
else
{
result.append (process (children.item (childIndex), datas, suffix, errorOutput));
result.append (process (children.item (childIndex), datas, suffix));
}
}
break;
@ -230,12 +255,12 @@ public class Presenter
if ((attrs2 != null) &&
(attrs2.getNamedItem ("id") != null))
{
result.append (process (children.item (childIndex), datas, suffix, errorOutput));
result.append (process (children.item (childIndex), datas, suffix));
}
}
else
{
result.append (process (children.item (childIndex), datas, suffix, errorOutput));
result.append (process (children.item (childIndex), datas, suffix));
}
}
break;
@ -249,12 +274,12 @@ public class Presenter
if ((attrs2 == null) ||
(attrs2.getNamedItem ("id") == null))
{
result.append (process (children.item(childIndex), datas, suffix, errorOutput));
result.append (process (children.item(childIndex), datas, suffix));
}
}
else
{
result.append (process (children.item (childIndex), datas, suffix, errorOutput));
result.append (process (children.item (childIndex), datas, suffix));
}
}
break;
@ -262,7 +287,7 @@ public class Presenter
case ALL_ROWS:
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;
}
@ -286,13 +311,12 @@ public class Presenter
static protected StringBuffer processElementWithId (Node node,
NamedNodeMap attrs,
Node idAttr,
IdsDataById datas,
StringBuffer errorOutput)
IdsDataById datas) throws Exception
{
StringBuffer result;
result = processElementWithId (node, attrs, idAttr, datas, "", errorOutput);
result = processElementWithId (node, attrs, idAttr, datas, "");
//
return (result);
@ -311,11 +335,10 @@ public class Presenter
* The ID.
*/
static protected StringBuffer processElementWithId (Node node,
NamedNodeMap attrs,
Node idAttr,
IdsDataById datas,
String suffix,
StringBuffer errorOutput)
NamedNodeMap attrs,
Node idAttr,
IdsDataById datas,
String suffix) throws Exception
{
StringBuffer result;
result = new StringBuffer ();
@ -331,7 +354,7 @@ public class Presenter
if (dataCore == null)
{
result.append (Presenter.processElementBasically (node, datas, suffix, errorOutput));
result.append (Presenter.processElementBasically (node, datas, suffix));
}
else if (dataCore instanceof IdData)
{
@ -373,7 +396,7 @@ public class Presenter
if ((data == null) ||
(data.display () == null))
{
result.append (processChildren (node, datas, suffix, errorOutput));
result.append (processChildren (node, datas, suffix));
}
else
{
@ -420,7 +443,7 @@ public class Presenter
// Insert data.
if ((data == null) || (data.display () == null))
{
result.append (processChildren (node, datas, suffix, errorOutput));
result.append (processChildren (node, datas, suffix));
}
else
{
@ -438,7 +461,7 @@ public class Presenter
// Manage a Hashmap.
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');
}
}
@ -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;
result = Presenter.process (node, datas, "", errorOutput);
result = Presenter.process (node, datas, "");
//
return (result);
@ -473,7 +496,7 @@ public class Presenter
* 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");
String TRANSITIONAL_DTD = "xhtml1-transitional.dtd";
@ -517,7 +540,7 @@ public class Presenter
// 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;
}
@ -535,12 +558,11 @@ public class Presenter
attrs,
idAttr,
datas,
suffix,
errorOutput));
suffix));
}
else
{
result.append (Presenter.processElementBasically (node, datas, suffix, errorOutput));
result.append (Presenter.processElementBasically (node, datas, suffix));
}
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;
result = processElementBasically (node, datas, "", errorOutput);
result = processElementBasically (node, datas, "");
//
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;
logger.debug("processElementBasically - started");
@ -648,7 +670,7 @@ public class Presenter
{
result.append('>');
result.append (processChildren (node, datas, suffix, errorOutput));
result.append (processChildren (node, datas, suffix));
result.append("</");
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;
@ -699,36 +721,38 @@ public class Presenter
// Parse the input file.
result = db.parse (source);
System.out.println("ZO4");
if (errorHandler.hasError ())
{
errorOutput.append (errorHandler.toString ());
System.out.println("ZO4a");
throw new Exception (errorHandler.toString ());
}
else
{
{System.out.println("ZO4b");
DomPresenter.addMetaTag (result, "generator", "XID 0.0");
}
System.out.println("ZO5");
}
catch (ParserConfigurationException exception)
{
String errorMessage = "Parser configuration exception: " + exception.getMessage ();
errorOutput.append (errorMessage);
logger.error (errorMessage);
result = null;
throw new Exception (errorMessage);
}
catch (SAXException exception)
{
String errorMessage = "Error during SAX parsing: " + exception.getMessage ();
errorOutput.append (errorMessage);
logger.error (errorMessage);
result = null;
throw new Exception (errorMessage);
}
catch (IOException exception)
{
String errorMessage = "IOError during parsing." + exception.getMessage ();
errorOutput.append (errorMessage);
logger.error (errorMessage);
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.
*/
static protected Document fileToTree (String fileName, StringBuffer errorOutput)
static protected Document fileToTree (String fileName) throws Exception
{
Document result;
try
{
result = buildTree (new FileInputStream (new File (fileName)), errorOutput);
result = buildTree (new FileInputStream (new File (fileName)));
}
catch (IOException exception)
{
String errorMessage = "IOError during parsing." + exception.getMessage ();
errorOutput.append (errorMessage);
logger.error (errorMessage);
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;
@ -82,9 +82,9 @@ public class StringPresenter extends DomPresenter
// Build doc from this.html.
String htmlSource;
if ((this.html.startsWith ("<!DOCTYPE")) ||
(this.html.startsWith ("<!doctype")) ||
(this.html.startsWith ("<html>")) ||
(this.html.startsWith ("<HTML>")))
(this.html.startsWith ("<!doctype")) ||
(this.html.startsWith ("<html>")) ||
(this.html.startsWith ("<HTML>")))
{
htmlSource = html;
}
@ -95,11 +95,11 @@ public class StringPresenter extends DomPresenter
// 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);
doc = buildTree (new ByteArrayInputStream (htmlSource.getBytes ()));
}
StringBuffer htmlTarget;
htmlTarget = Presenter.doXid (doc, datas, errorOutput);
htmlTarget = Presenter.doXid (doc, datas);
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.
*/
static public StringBuffer doXid (String html, IdsDataById datas, StringBuffer errorOutput)
static public StringBuffer doXid (String html, IdsDataById datas) throws Exception
{
StringBuffer result;
StringPresenter presenter = new StringPresenter (html);
result = presenter.doXid (datas, errorOutput);
result = presenter.doXid (datas);
//
return (result);