diff --git a/src/fr/devinsy/xidyn/pages/PageFactory.java b/src/fr/devinsy/xidyn/pages/PageFactory.java index 1dbc6cc..f29414f 100644 --- a/src/fr/devinsy/xidyn/pages/PageFactory.java +++ b/src/fr/devinsy/xidyn/pages/PageFactory.java @@ -138,6 +138,21 @@ public class PageFactory return result; } + /** + * + * @param source + * @return + */ + public Page create(final URL source, final Locale locale) + { + Page result; + + result = new Page(PresenterFactory.instance().get(source, locale)); + + // + return result; + } + /** * * @param source diff --git a/src/fr/devinsy/xidyn/presenters/PresenterFactory.java b/src/fr/devinsy/xidyn/presenters/PresenterFactory.java index 660bce0..159546f 100644 --- a/src/fr/devinsy/xidyn/presenters/PresenterFactory.java +++ b/src/fr/devinsy/xidyn/presenters/PresenterFactory.java @@ -19,6 +19,7 @@ package fr.devinsy.xidyn.presenters; import java.io.File; +import java.net.MalformedURLException; import java.net.URL; import java.util.Locale; @@ -84,6 +85,46 @@ public class PresenterFactory return result; } + /** + * + * @param source + * @return + */ + public Presenter get(final CharSequence source, final Locale locale) + { + Presenter result; + + if (source == null) + { + result = null; + } + else if (locale == null) + { + result = get(source); + } + else + { + String localizedSource = FileTools.addBeforeExtension(source.toString(), "-" + locale.getLanguage()); + + result = this.cache.get(localizedSource); + + if (result == null) + { + result = create(localizedSource); + + if ((result == null) || (!result.isAvailable())) + { + result = create(source); + } + + this.cache.put(localizedSource, result); + } + } + + // + return result; + } + /** * * @param source @@ -187,6 +228,57 @@ public class PresenterFactory return result; } + /** + * + * @param source + * @return + * @throws MalformedURLException + */ + public Presenter get(final URL source, final Locale locale) + { + Presenter result; + + try + { + if (source == null) + { + result = null; + } + else if (locale == null) + { + result = get(source); + } + else + { + URL localizedSource; + + localizedSource = new URL(FileTools.addBeforeExtension(source.getPath(), "-" + locale.getLanguage())); + + result = this.cache.get(localizedSource); + + if (result == null) + { + result = create(localizedSource); + + if ((result == null) || (!result.isAvailable())) + { + result = create(source); + } + + this.cache.put(localizedSource, result); + } + } + } + catch (MalformedURLException exception) + { + logger.error(exception.getMessage(), exception); + result = null; + } + + // + return result; + } + /** * * @return @@ -246,6 +338,39 @@ public class PresenterFactory return result; } + /** + * + * @param source + * @return + */ + public static Presenter create(final CharSequence source, final Locale locale) + { + Presenter result; + + if (source == null) + { + result = null; + } + else if (locale == null) + { + result = create(source); + } + else + { + String localizedSource = FileTools.addBeforeExtension(source.toString(), "-" + locale.getLanguage()); + + result = create(localizedSource); + + if ((result == null) || (!result.isAvailable())) + { + result = create(source); + } + } + + // + return result; + } + /** * * @param source @@ -346,6 +471,47 @@ public class PresenterFactory return result; } + /** + * + * @param source + * @return + */ + public static Presenter create(final URL source, final Locale locale) + { + Presenter result; + + try + { + if (source == null) + { + result = null; + } + else if (locale == null) + { + result = create(source); + } + else + { + URL localizedSource = new URL(FileTools.addBeforeExtension(source.getPath(), "-" + locale.getLanguage())); + + result = create(localizedSource); + + if ((result == null) || (!result.isAvailable())) + { + result = create(source); + } + } + } + catch (MalformedURLException exception) + { + logger.error(exception.getMessage(), exception); + result = null; + } + + // + return result; + } + /** * * @return