From 850415a83728c48dfcbff581f0808852324c82c3 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Fri, 23 Aug 2013 03:02:26 +0200 Subject: [PATCH] Fix recursive submethods. --- .../xidyn/presenters/FilePresenter.java | 59 ++++++++------ .../xidyn/presenters/URLPresenter.java | 76 ++++++++++++++----- 2 files changed, 93 insertions(+), 42 deletions(-) diff --git a/src/fr/devinsy/xidyn/presenters/FilePresenter.java b/src/fr/devinsy/xidyn/presenters/FilePresenter.java index 5d6fcad..492fa27 100644 --- a/src/fr/devinsy/xidyn/presenters/FilePresenter.java +++ b/src/fr/devinsy/xidyn/presenters/FilePresenter.java @@ -53,7 +53,11 @@ public class FilePresenter extends StringPresenter { StringBuffer result; - result = dynamize((TagDataManager) null); + // + update(); + + // + result = dynamize(); // return result; @@ -72,29 +76,7 @@ public class FilePresenter extends StringPresenter logger.info("dynamize file [" + this.sourceFilePathname + "]"); // - if (this.source == null) - { - 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; - } - } + update(); // Build the web page. result = super.dynamize(data); @@ -212,6 +194,35 @@ public class FilePresenter extends StringPresenter 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. */ diff --git a/src/fr/devinsy/xidyn/presenters/URLPresenter.java b/src/fr/devinsy/xidyn/presenters/URLPresenter.java index 0ddbd21..458b04f 100644 --- a/src/fr/devinsy/xidyn/presenters/URLPresenter.java +++ b/src/fr/devinsy/xidyn/presenters/URLPresenter.java @@ -56,7 +56,11 @@ public class URLPresenter extends StringPresenter { StringBuffer result; - result = dynamize((TagDataManager) null); + // + update(); + + // + result = super.dynamize(); // return result; @@ -73,24 +77,10 @@ public class URLPresenter extends StringPresenter logger.info("dynamize URL [" + this.sourcePathname + "]"); // - 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; - } + update(); - // Build the web page. - result = super.dynamize(data); - } + // Build the web page. + result = super.dynamize(data); // 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. */