diff --git a/demo/XidynDemo.java b/demo/XidynDemo.java
index b622b8f..422084c 100644
--- a/demo/XidynDemo.java
+++ b/demo/XidynDemo.java
@@ -6,9 +6,9 @@ import org.apache.log4j.Level;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import fr.devinsy.xidyn.SimpleTagData;
-import fr.devinsy.xidyn.StringPresenter;
-import fr.devinsy.xidyn.TagDataManager;
+import fr.devinsy.xidyn.data.SimpleTagData;
+import fr.devinsy.xidyn.data.TagDataManager;
+import fr.devinsy.xidyn.presenters.StringPresenter;
/**
*
diff --git a/src/fr/devinsy/xidyn/DomPresenter.java b/src/fr/devinsy/xidyn/DomPresenter.java
deleted file mode 100644
index 12ad011..0000000
--- a/src/fr/devinsy/xidyn/DomPresenter.java
+++ /dev/null
@@ -1,126 +0,0 @@
-package fr.devinsy.xidyn;
-
-import java.io.StringWriter;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-
-/**
- *
- */
-public class DomPresenter extends Presenter
-{
- static final public char INDEX_SEPARATOR = '_';
-
- static private Logger logger = LoggerFactory.getLogger(DomPresenter.class);
- protected Document doc;
-
- /**
- *
- */
- public DomPresenter()
- {
- this.doc = null;
- }
-
- /**
- *
- */
- public DomPresenter(final Document doc)
- {
- setSource(doc);
- }
-
- /**
- *
- */
- public Document getDOM()
- {
- Document result;
-
- result = this.doc;
-
- //
- return (result);
- }
-
- /**
- *
- */
- public StringBuffer dynamize(final TagDataListById datas) throws Exception
- {
- StringBuffer result;
-
- if (this.doc == null)
- {
- String errorMessage = "source not defined";
- logger.error(errorMessage);
- result = null;
- throw new Exception(errorMessage);
- }
- else
- {
- // Build the web page.
- StringWriter htmlCode = new StringWriter();
- Presenter.dynamize(htmlCode, this.doc, datas);
- result = new StringBuffer(htmlCode.toString());
- }
-
- //
- return (result);
- }
-
- /**
- *
- */
- public StringBuffer dynamize(final TagDataManager datas) throws Exception
- {
- return (dynamize(datas.getIdsDataById()));
- }
-
- /**
- *
- */
- public void setDOM(final Document doc)
- {
- this.doc = doc;
- }
-
- /*
- *
- */
- public void setSource(final Document doc)
- {
- this.doc = doc;
- addMetaTag(this.doc, "generator", "XID 0.0");
- }
-
- /**
- *
- */
- public Object getSource()
- {
- Object result;
-
- result = this.doc;
-
- //
- return (result);
- }
-
- /**
- * Xid a file with data.
- */
- static public StringBuffer dynamize(final Document doc, final TagDataListById datas) throws Exception
- {
- StringBuffer result;
-
- StringWriter htmlCode = new StringWriter();
- Presenter.process(htmlCode, doc, datas);
- result = htmlCode.getBuffer();
-
- //
- return (result);
- }
-}
diff --git a/src/fr/devinsy/xidyn/SimpleTagData.java b/src/fr/devinsy/xidyn/data/SimpleTagData.java
similarity index 92%
rename from src/fr/devinsy/xidyn/SimpleTagData.java
rename to src/fr/devinsy/xidyn/data/SimpleTagData.java
index 6d549c2..00dc024 100644
--- a/src/fr/devinsy/xidyn/SimpleTagData.java
+++ b/src/fr/devinsy/xidyn/data/SimpleTagData.java
@@ -1,4 +1,4 @@
-package fr.devinsy.xidyn;
+package fr.devinsy.xidyn.data;
import java.io.Serializable;
diff --git a/src/fr/devinsy/xidyn/TagAttributes.java b/src/fr/devinsy/xidyn/data/TagAttributes.java
similarity index 91%
rename from src/fr/devinsy/xidyn/TagAttributes.java
rename to src/fr/devinsy/xidyn/data/TagAttributes.java
index fdd2e7f..d7cb754 100644
--- a/src/fr/devinsy/xidyn/TagAttributes.java
+++ b/src/fr/devinsy/xidyn/data/TagAttributes.java
@@ -1,4 +1,4 @@
-package fr.devinsy.xidyn;
+package fr.devinsy.xidyn.data;
import java.util.HashMap;
diff --git a/src/fr/devinsy/xidyn/TagData.java b/src/fr/devinsy/xidyn/data/TagData.java
similarity index 83%
rename from src/fr/devinsy/xidyn/TagData.java
rename to src/fr/devinsy/xidyn/data/TagData.java
index df7c3cb..aa7d332 100644
--- a/src/fr/devinsy/xidyn/TagData.java
+++ b/src/fr/devinsy/xidyn/data/TagData.java
@@ -1,4 +1,4 @@
-package fr.devinsy.xidyn;
+package fr.devinsy.xidyn.data;
/*
* Xid uses three class to describe data:
diff --git a/src/fr/devinsy/xidyn/TagDataListById.java b/src/fr/devinsy/xidyn/data/TagDataListById.java
similarity index 86%
rename from src/fr/devinsy/xidyn/TagDataListById.java
rename to src/fr/devinsy/xidyn/data/TagDataListById.java
index 2870f34..10bc51a 100644
--- a/src/fr/devinsy/xidyn/TagDataListById.java
+++ b/src/fr/devinsy/xidyn/data/TagDataListById.java
@@ -1,4 +1,4 @@
-package fr.devinsy.xidyn;
+package fr.devinsy.xidyn.data;
import java.util.HashMap;
diff --git a/src/fr/devinsy/xidyn/TagDataListByIndex.java b/src/fr/devinsy/xidyn/data/TagDataListByIndex.java
similarity index 82%
rename from src/fr/devinsy/xidyn/TagDataListByIndex.java
rename to src/fr/devinsy/xidyn/data/TagDataListByIndex.java
index ea11a9d..f67ffbc 100644
--- a/src/fr/devinsy/xidyn/TagDataListByIndex.java
+++ b/src/fr/devinsy/xidyn/data/TagDataListByIndex.java
@@ -1,4 +1,4 @@
-package fr.devinsy.xidyn;
+package fr.devinsy.xidyn.data;
import java.util.Vector;
diff --git a/src/fr/devinsy/xidyn/TagDataManager.java b/src/fr/devinsy/xidyn/data/TagDataManager.java
similarity index 94%
rename from src/fr/devinsy/xidyn/TagDataManager.java
rename to src/fr/devinsy/xidyn/data/TagDataManager.java
index 3a4b193..78dd9c7 100644
--- a/src/fr/devinsy/xidyn/TagDataManager.java
+++ b/src/fr/devinsy/xidyn/data/TagDataManager.java
@@ -1,4 +1,4 @@
-package fr.devinsy.xidyn;
+package fr.devinsy.xidyn.data;
/*
*
diff --git a/src/fr/devinsy/xidyn/Presenter.java b/src/fr/devinsy/xidyn/presenters/DomPresenter.java
similarity index 78%
rename from src/fr/devinsy/xidyn/Presenter.java
rename to src/fr/devinsy/xidyn/presenters/DomPresenter.java
index 3d799d2..725877d 100644
--- a/src/fr/devinsy/xidyn/Presenter.java
+++ b/src/fr/devinsy/xidyn/presenters/DomPresenter.java
@@ -1,9 +1,10 @@
-package fr.devinsy.xidyn;
+package fr.devinsy.xidyn.presenters;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Iterator;
@@ -24,22 +25,140 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
+import fr.devinsy.xidyn.data.SimpleTagData;
+import fr.devinsy.xidyn.data.TagAttributes;
+import fr.devinsy.xidyn.data.TagData;
+import fr.devinsy.xidyn.data.TagDataListById;
+import fr.devinsy.xidyn.data.TagDataListByIndex;
+import fr.devinsy.xidyn.data.TagDataManager;
+
/**
*
*/
-public class Presenter
+public class DomPresenter extends Presenter
{
- static private Logger logger = LoggerFactory.getLogger(Presenter.class);
static final public char INDEX_SEPARATOR = '_';
+ static private Logger logger = LoggerFactory.getLogger(DomPresenter.class);
+ protected Document doc;
/**
*
*/
- static protected void addMetaTag(final Document doc, final String name, final String content)
+ public DomPresenter()
+ {
+ this.doc = null;
+ }
+
+ /**
+ *
+ */
+ public DomPresenter(final Document doc)
+ {
+ setSource(doc);
+ }
+
+ /**
+ *
+ */
+ @Override
+ public StringBuffer dynamize(final TagDataListById datas) throws Exception
+ {
+ StringBuffer result;
+
+ if (this.doc == null)
+ {
+ String errorMessage = "source not defined";
+ logger.error(errorMessage);
+ result = null;
+ throw new Exception(errorMessage);
+ }
+ else
+ {
+ // Build the web page.
+ StringWriter htmlCode = new StringWriter();
+ DomPresenter.dynamize(htmlCode, this.doc, datas);
+ result = new StringBuffer(htmlCode.toString());
+ }
+
+ //
+ return (result);
+ }
+
+ /**
+ *
+ */
+ @Override
+ public StringBuffer dynamize(final TagDataManager datas) throws Exception
+ {
+ return (dynamize(datas.getIdsDataById()));
+ }
+
+ /**
+ *
+ */
+ public Document getDOM()
+ {
+ Document result;
+
+ result = this.doc;
+
+ //
+ return (result);
+ }
+
+ /**
+ *
+ */
+ @Override
+ public Object getSource()
+ {
+ Object result;
+
+ result = this.doc;
+
+ //
+ return (result);
+ }
+
+ /**
+ *
+ */
+ @Override
+ public boolean isOutdated()
+ {
+ boolean result;
+
+ result = false;
+
+ //
+ return result;
+ }
+
+ /**
+ *
+ */
+ public void setDOM(final Document doc)
+ {
+ this.doc = doc;
+ }
+
+ /**
+ *
+ */
+ public void setSource(final Document doc)
+ {
+ this.doc = doc;
+ DomPresenter.addMetaTag(this.doc, "generator", "XIDYN 1.0.0");
+ }
+
+ /**
+ *
+ */
+ static public void addMetaTag(final Document doc, final String name, final String content)
{
// Find head tag.
- Node headNode = Presenter.findHeadNode(doc);
+ Node headNode = findHeadNode(doc);
Node metaNode = doc.createElement("meta");
@@ -57,7 +176,7 @@ public class Presenter
/**
*
*/
- static protected Document buildTree(final InputStream source) throws Exception
+ static public Document buildDom(final InputStream source) throws Exception
{
Document result;
@@ -131,80 +250,39 @@ public class Presenter
return (result);
}
+ /**
+ * Xidyn a file with data.
+ */
+ static public StringBuffer dynamize(final Document doc, final TagDataListById datas) throws Exception
+ {
+ StringBuffer result;
+
+ StringWriter htmlCode = new StringWriter();
+ DomPresenter.dynamize(htmlCode, doc, datas);
+ result = htmlCode.getBuffer();
+
+ //
+ return (result);
+ }
+
/**
* Dynamize a file with data.
*/
static public void dynamize(final Writer result, final Document doc, final TagDataListById data) throws Exception
{
- Presenter.process(result, doc, data);
- }
-
- /**
- * Good estimation of the target length able to optimize performance.
- */
- static int estimatedTargetLength(final long sourceLength)
- {
- int result;
-
- if (sourceLength < 1000)
- {
- result = (int) (sourceLength * 5);
- }
- else if (sourceLength < 50000)
- {
- result = (int) (sourceLength * 2);
- }
- else if (sourceLength < 800000)
- {
- result = (100000);
- }
- else
- {
- result = (int) (sourceLength + 30000);
- }
-
- //
- return (result);
- }
-
- /**
- *
- */
- static public String extractBodyContent(final StringBuffer data)
- {
- String result = null;
-
- // Extract the body content.
- String dataLowerCase = data.toString().toLowerCase();
-
- int startBody = dataLowerCase.indexOf("
");
- int endBody = dataLowerCase.indexOf("");
-
- // Note: as failed search is improbable, no care about complexity
- // in failed search case.
- if ((startBody == -1) || (endBody == -1))
- {
- result = null;
- }
- else
- {
- result = data.substring(startBody + 6, endBody).trim();
- }
-
- //
- return (result);
+ process(result, doc, data);
}
/**
* Define in Presenter cause