diff --git a/src/fr/devinsy/xidyn/data/TagDataManager.java b/src/fr/devinsy/xidyn/data/TagDataManager.java index 3838c83..06c1460 100644 --- a/src/fr/devinsy/xidyn/data/TagDataManager.java +++ b/src/fr/devinsy/xidyn/data/TagDataManager.java @@ -18,8 +18,9 @@ */ package fr.devinsy.xidyn.data; -/* - * +/** + * + * @author Christian Pierre MOMON (christian.momon@devinsy.fr) */ public class TagDataManager { @@ -200,6 +201,27 @@ public class TagDataManager return (result); } + /** + * + * @return + */ + public boolean isEmpty() + { + boolean result; + + if (this.idsDataById.isEmpty()) + { + result = true; + } + else + { + result = false; + } + + // + return result; + } + /** * */ diff --git a/src/fr/devinsy/xidyn/pages/Page.java b/src/fr/devinsy/xidyn/pages/Page.java index d450879..c0aa8c7 100644 --- a/src/fr/devinsy/xidyn/pages/Page.java +++ b/src/fr/devinsy/xidyn/pages/Page.java @@ -18,8 +18,18 @@ */ package fr.devinsy.xidyn.pages; +import java.io.File; +import java.net.URL; + +import org.w3c.dom.Document; + import fr.devinsy.xidyn.data.TagDataManager; +import fr.devinsy.xidyn.presenters.DomPresenter; +import fr.devinsy.xidyn.presenters.FilePresenter; import fr.devinsy.xidyn.presenters.Presenter; +import fr.devinsy.xidyn.presenters.PresenterFactory; +import fr.devinsy.xidyn.presenters.URLPresenter; +import fr.devinsy.xidyn.utils.XidynUtils; /** * @@ -29,6 +39,33 @@ public class Page extends TagDataManager private Presenter presenter; private StringBuffer lastDynamize; + /** + * + * @param source + */ + public Page(final CharSequence source) + { + this(PresenterFactory.create(source)); + } + + /** + * + * @param source + */ + public Page(final Document source) + { + this(new DomPresenter(source)); + } + + /** + * + * @param source + */ + public Page(final File source) + { + this(new FilePresenter(source)); + } + /** * */ @@ -47,6 +84,15 @@ public class Page extends TagDataManager } } + /** + * + * @param source + */ + public Page(final URL source) + { + this(new URLPresenter(source)); + } + /** * * @return @@ -56,7 +102,14 @@ public class Page extends TagDataManager { StringBuffer result; - this.lastDynamize = this.presenter.dynamize(this); + if (this.isEmpty()) + { + this.lastDynamize = this.presenter.dynamize(null); + } + else + { + this.lastDynamize = this.presenter.dynamize(this); + } result = this.lastDynamize; @@ -64,6 +117,122 @@ public class Page extends TagDataManager return result; } + /** + * + * @return + * @throws Exception + */ + public String dynamizeToString() throws Exception + { + String result; + + StringBuffer buffer = dynamize(); + + if (buffer == null) + { + result = null; + } + else + { + result = buffer.toString(); + } + + // + return result; + } + + /** + * + * @param id + * @param page + * @throws Exception + */ + public void include(final String id, final Page source) throws Exception + { + if ((id != null) && (source != null)) + { + // + StringBuffer content = source.dynamize(); + + // Extract start of content. + String contentStart; + if (content == null) + { + contentStart = null; + } + else if (content.length() < 7) + { + contentStart = content.toString(); + } + else + { + contentStart = content.subSequence(0, 6).toString(); + } + + // Set content. + String fixedContent; + if ((contentStart != null) && ((contentStart.startsWith("")))) + { + fixedContent = XidynUtils.extractBodyContent(content); + } + else + { + fixedContent = source.toString(); + } + + // + setContent(id, fixedContent); + } + } + + /** + * + * @param id + * @param page + * @throws Exception + */ + public void includePage(final String id, final CharSequence source) throws Exception + { + if ((id != null) && (source != null)) + { + Page page = PageFactory.instance().create(source); + + include(id, page); + } + } + + /** + * + * @param id + * @param page + * @throws Exception + */ + public void includePage(final String id, final Document source) throws Exception + { + if ((id != null) && (source != null)) + { + Page page = PageFactory.instance().create(source); + + include(id, page); + } + } + + /** + * + * @param id + * @param page + * @throws Exception + */ + public void includePage(final String id, final File source) throws Exception + { + if ((id != null) && (source != null)) + { + Page page = PageFactory.instance().create(source); + + include(id, page); + } + } + /** * * @return diff --git a/src/fr/devinsy/xidyn/pages/PageFactory.java b/src/fr/devinsy/xidyn/pages/PageFactory.java index 19280d4..95516b0 100644 --- a/src/fr/devinsy/xidyn/pages/PageFactory.java +++ b/src/fr/devinsy/xidyn/pages/PageFactory.java @@ -68,7 +68,55 @@ public class PageFactory * @param parameters * @return */ - public Page get(final Document source) + public Page create(final CharSequence source) + { + Page result; + + result = new Page(PresenterFactory.instance().get(source)); + + // + return result; + } + + /** + * + * @param source + * @param parameters + * @return + */ + public Page create(final Document source) + { + Page result; + + result = new Page(PresenterFactory.instance().get(source)); + + // + return result; + } + + /** + * + * @param source + * @param parameters + * @return + */ + public Page create(final File source) + { + Page result; + + result = new Page(PresenterFactory.instance().get(source)); + + // + return result; + } + + /** + * + * @param source + * @param parameters + * @return + */ + public Page create(final URL source) { Page result; @@ -94,7 +142,7 @@ public class PageFactory result = this.cache.get(key); if (result == null) { - result = get(source); + result = create(source); this.cache.put(key, result); } @@ -102,22 +150,6 @@ public class PageFactory return result; } - /** - * - * @param source - * @param parameters - * @return - */ - public Page get(final File source) - { - Page result; - - result = new Page(PresenterFactory.instance().get(source)); - - // - return result; - } - /** * * @param source @@ -141,22 +173,6 @@ public class PageFactory return result; } - /** - * - * @param source - * @param parameters - * @return - */ - public Page get(final String source) - { - Page result; - - result = new Page(PresenterFactory.instance().get(source)); - - // - return result; - } - /** * * @param source @@ -180,22 +196,6 @@ public class PageFactory return result; } - /** - * - * @param source - * @param parameters - * @return - */ - public Page get(final URL source) - { - Page result; - - result = new Page(PresenterFactory.instance().get(source)); - - // - return result; - } - /** * * @param source diff --git a/src/fr/devinsy/xidyn/presenters/PresenterFactory.java b/src/fr/devinsy/xidyn/presenters/PresenterFactory.java index 64db319..6f1abfa 100644 --- a/src/fr/devinsy/xidyn/presenters/PresenterFactory.java +++ b/src/fr/devinsy/xidyn/presenters/PresenterFactory.java @@ -61,6 +61,27 @@ public class PresenterFactory this.cache.clear(); } + /** + * + * @param source + * @return + */ + public Presenter get(final CharSequence source) + { + Presenter result; + + result = this.cache.get(source); + + if (result == null) + { + result = create(source); + this.cache.put(source, result); + } + + // + return result; + } + /** * * @param source @@ -103,27 +124,6 @@ public class PresenterFactory return result; } - /** - * - * @param source - * @return - */ - public Presenter get(final String source) - { - Presenter result; - - result = this.cache.get(source); - - if (result == null) - { - result = create(source); - this.cache.put(source, result); - } - - // - return result; - } - /** * * @param source @@ -159,6 +159,51 @@ public class PresenterFactory return result; } + /** + * + * @param source + * @return + */ + public static Presenter create(final CharSequence source) + { + Presenter result; + + if (source == null) + { + result = null; + } + else + { + String target = source.toString(); + if (target.startsWith("file://")) + { + result = new FilePresenter(target); + } + else if (target.matches(".+://.+")) + { + result = new URLPresenter(target); + } + else if (target.startsWith("/")) + { + if (new File(target).exists()) + { + result = new FilePresenter(target); + } + else + { + result = new URLPresenter(target); + } + } + else + { + result = new StringPresenter(target); + } + } + + // + return result; + } + /** * * @param source @@ -203,47 +248,6 @@ public class PresenterFactory return result; } - /** - * - * @param source - * @return - */ - public static Presenter create(final String source) - { - Presenter result; - - if (source == null) - { - result = null; - } - else if (source.startsWith("file://")) - { - result = new FilePresenter(source); - } - else if (source.matches(".+://.+")) - { - result = new URLPresenter(source); - } - else if (source.startsWith("/")) - { - if (new File(source).exists()) - { - result = new FilePresenter(source); - } - else - { - result = new URLPresenter(source); - } - } - else - { - result = new StringPresenter(source); - } - - // - return result; - } - /** * * @param source