Fix recursive submethods.

This commit is contained in:
Christian P. MOMON 2013-08-23 03:02:26 +02:00
parent 87b352e933
commit 850415a837
2 changed files with 93 additions and 42 deletions

View file

@ -53,7 +53,11 @@ public class FilePresenter extends StringPresenter
{ {
StringBuffer result; StringBuffer result;
result = dynamize((TagDataManager) null); //
update();
//
result = dynamize();
// //
return result; return result;
@ -72,29 +76,7 @@ public class FilePresenter extends StringPresenter
logger.info("dynamize file [" + this.sourceFilePathname + "]"); logger.info("dynamize file [" + this.sourceFilePathname + "]");
// //
if (this.source == null) update();
{
String errorMessage = "source not defined";
logger.error(errorMessage);
result = null;
throw new Exception(errorMessage);
}
else if (!source.exists())
{
String errorMessage = "source file defined but not found (" + this.sourceFilePathname + ")";
logger.error(errorMessage);
result = null;
throw new Exception(errorMessage);
}
else
{
long currentTime = this.source.lastModified();
if ((super.getSource() == null) || (this.sourceTime != currentTime))
{
super.setSource(XidynUtils.load(this.source));
this.sourceTime = currentTime;
}
}
// Build the web page. // Build the web page.
result = super.dynamize(data); result = super.dynamize(data);
@ -212,6 +194,35 @@ public class FilePresenter extends StringPresenter
setSource(file); setSource(file);
} }
/**
* @throws Exception
*/
public void update() throws Exception
{
//
if (this.source == null)
{
String errorMessage = "source not defined";
logger.error(errorMessage);
throw new NullPointerException(errorMessage);
}
else if (!source.exists())
{
String errorMessage = "source file defined but not found (" + this.sourceFilePathname + ")";
logger.error(errorMessage);
throw new Exception(errorMessage);
}
else
{
long currentTime = this.source.lastModified();
if ((super.getSource() == null) || (this.sourceTime != currentTime))
{
super.setSource(XidynUtils.load(this.source));
this.sourceTime = currentTime;
}
}
}
/** /**
* Dynamize a file without data. * Dynamize a file without data.
*/ */

View file

@ -56,7 +56,11 @@ public class URLPresenter extends StringPresenter
{ {
StringBuffer result; StringBuffer result;
result = dynamize((TagDataManager) null); //
update();
//
result = super.dynamize();
// //
return result; return result;
@ -73,24 +77,10 @@ public class URLPresenter extends StringPresenter
logger.info("dynamize URL [" + this.sourcePathname + "]"); logger.info("dynamize URL [" + this.sourcePathname + "]");
// //
if (this.source == null) update();
{
String errorMessage = "source not defined";
logger.error(errorMessage);
throw new NullPointerException(errorMessage);
}
else
{
long currentSourceTime = this.source.openConnection().getLastModified();
if ((super.getSource() == null) || (this.sourceTime != currentSourceTime))
{
super.setSource(XidynUtils.load(this.source));
this.sourceTime = currentSourceTime;
}
// Build the web page. // Build the web page.
result = super.dynamize(data); result = super.dynamize(data);
}
// //
return (result); return (result);
@ -194,6 +184,56 @@ public class URLPresenter extends StringPresenter
} }
} }
/**
*
*/
@Override
public String toString()
{
String result;
try
{
//
update();
//
result = super.getSource();
}
catch (final IOException exception)
{
result = null;
}
//
return result;
}
/**
* No need to be synchronized.
*
* @throws IOException
*/
public void update() throws IOException
{
//
if (this.source == null)
{
String errorMessage = "source not defined";
logger.error(errorMessage);
throw new NullPointerException(errorMessage);
}
else
{
long currentSourceTime = this.source.openConnection().getLastModified();
if ((super.getSource() == null) || (this.sourceTime != currentSourceTime))
{
super.setSource(XidynUtils.load(this.source));
this.sourceTime = currentSourceTime;
}
}
}
/** /**
* Dynamize a file without data. * Dynamize a file without data.
*/ */