From ecedb8bbced9f2bc5ea8cb98a49dc88c7e0e9e22 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Wed, 21 Sep 2016 04:24:53 +0200 Subject: [PATCH] Added locale management in factories (Presenter and Page). --- src/fr/devinsy/xidyn/pages/PageFactory.java | 20 +++++++++--- .../xidyn/presenters/PresenterFactory.java | 32 +++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/fr/devinsy/xidyn/pages/PageFactory.java b/src/fr/devinsy/xidyn/pages/PageFactory.java index 95516b0..1dbc6cc 100644 --- a/src/fr/devinsy/xidyn/pages/PageFactory.java +++ b/src/fr/devinsy/xidyn/pages/PageFactory.java @@ -20,6 +20,7 @@ package fr.devinsy.xidyn.pages; import java.io.File; import java.net.URL; +import java.util.Locale; import org.w3c.dom.Document; @@ -65,7 +66,6 @@ public class PageFactory /** * * @param source - * @param parameters * @return */ public Page create(final CharSequence source) @@ -81,7 +81,6 @@ public class PageFactory /** * * @param source - * @param parameters * @return */ public Page create(final Document source) @@ -97,7 +96,6 @@ public class PageFactory /** * * @param source - * @param parameters * @return */ public Page create(final File source) @@ -113,7 +111,21 @@ public class PageFactory /** * * @param source - * @param parameters + * @return + */ + public Page create(final File source, final Locale locale) + { + Page result; + + result = new Page(PresenterFactory.instance().get(source, locale)); + + // + return result; + } + + /** + * + * @param source * @return */ public Page create(final URL source) diff --git a/src/fr/devinsy/xidyn/presenters/PresenterFactory.java b/src/fr/devinsy/xidyn/presenters/PresenterFactory.java index 6f1abfa..e276f2c 100644 --- a/src/fr/devinsy/xidyn/presenters/PresenterFactory.java +++ b/src/fr/devinsy/xidyn/presenters/PresenterFactory.java @@ -20,11 +20,13 @@ package fr.devinsy.xidyn.presenters; import java.io.File; import java.net.URL; +import java.util.Locale; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; +import fr.devinsy.util.FileTools; import fr.devinsy.xidyn.utils.cache.Cache; /** @@ -124,6 +126,36 @@ public class PresenterFactory return result; } + /** + * + * @param source + * @return + */ + public Presenter get(final File source, final Locale locale) + { + Presenter result; + + if (locale == null) + { + result = get(source); + } + else + { + File localizedSource = new File(FileTools.addBeforeExtension(source.getAbsolutePath(), "-" + locale.getLanguage())); + + result = this.cache.get(localizedSource); + + if (result == null) + { + result = create(localizedSource); + this.cache.put(localizedSource, result); + } + } + + // + return result; + } + /** * * @param source