Improved parameter types. Optimized null data in page dynamize.

This commit is contained in:
Christian P. MOMON 2016-09-19 01:04:54 +02:00
parent c29b1df967
commit c5bd4b1261
4 changed files with 310 additions and 115 deletions

View file

@ -18,8 +18,9 @@
*/ */
package fr.devinsy.xidyn.data; package fr.devinsy.xidyn.data;
/* /**
* *
* @author Christian Pierre MOMON (christian.momon@devinsy.fr)
*/ */
public class TagDataManager public class TagDataManager
{ {
@ -200,6 +201,27 @@ public class TagDataManager
return (result); return (result);
} }
/**
*
* @return
*/
public boolean isEmpty()
{
boolean result;
if (this.idsDataById.isEmpty())
{
result = true;
}
else
{
result = false;
}
//
return result;
}
/** /**
* *
*/ */

View file

@ -18,8 +18,18 @@
*/ */
package fr.devinsy.xidyn.pages; 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.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.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 Presenter presenter;
private StringBuffer lastDynamize; 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 * @return
@ -56,7 +102,14 @@ public class Page extends TagDataManager
{ {
StringBuffer result; StringBuffer result;
if (this.isEmpty())
{
this.lastDynamize = this.presenter.dynamize(null);
}
else
{
this.lastDynamize = this.presenter.dynamize(this); this.lastDynamize = this.presenter.dynamize(this);
}
result = this.lastDynamize; result = this.lastDynamize;
@ -64,6 +117,122 @@ public class Page extends TagDataManager
return result; 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("<?")) || (contentStart.startsWith("<!")) || (contentStart.startsWith("<html>"))))
{
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 * @return

View file

@ -68,7 +68,55 @@ public class PageFactory
* @param parameters * @param parameters
* @return * @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; Page result;
@ -94,7 +142,7 @@ public class PageFactory
result = this.cache.get(key); result = this.cache.get(key);
if (result == null) if (result == null)
{ {
result = get(source); result = create(source);
this.cache.put(key, result); this.cache.put(key, result);
} }
@ -102,22 +150,6 @@ public class PageFactory
return result; 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 * @param source
@ -141,22 +173,6 @@ public class PageFactory
return result; 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 * @param source
@ -180,22 +196,6 @@ public class PageFactory
return result; 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 * @param source

View file

@ -61,6 +61,27 @@ public class PresenterFactory
this.cache.clear(); 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 * @param source
@ -103,27 +124,6 @@ public class PresenterFactory
return result; 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 * @param source
@ -159,6 +159,51 @@ public class PresenterFactory
return result; 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 * @param source
@ -203,47 +248,6 @@ public class PresenterFactory
return result; 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 * @param source