Introduced XidynException usage. Fixed Factory get.

This commit is contained in:
Christian P. MOMON 2018-06-04 14:12:29 +02:00
parent d0cfebfa3a
commit 4eb8aa4c83
21 changed files with 628 additions and 204 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016,2017 Christian Pierre MOMON * Copyright (C) 2016-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -24,6 +24,7 @@ import java.util.Locale;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.DomPresenter; import fr.devinsy.xidyn.presenters.DomPresenter;
import fr.devinsy.xidyn.presenters.FilePresenter; import fr.devinsy.xidyn.presenters.FilePresenter;
@ -148,10 +149,10 @@ public class Page extends TagDataManager
* Dynamize. * Dynamize.
* *
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public StringBuffer dynamize() throws Exception public StringBuffer dynamize() throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -174,10 +175,10 @@ public class Page extends TagDataManager
* Dynamize to string. * Dynamize to string.
* *
* @return the string * @return the string
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public String dynamizeToString() throws Exception public String dynamizeToString() throws XidynException
{ {
String result; String result;
@ -203,10 +204,10 @@ public class Page extends TagDataManager
* the id * the id
* @param source * @param source
* the source * the source
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public void include(final String id, final Page source) throws Exception public void include(final String id, final Page source) throws XidynException
{ {
if ((id != null) && (source != null)) if ((id != null) && (source != null))
{ {
@ -251,10 +252,10 @@ public class Page extends TagDataManager
* the id * the id
* @param source * @param source
* the source * the source
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public void includePage(final String id, final CharSequence source) throws Exception public void includePage(final String id, final CharSequence source) throws XidynException
{ {
if ((id != null) && (source != null)) if ((id != null) && (source != null))
{ {
@ -271,10 +272,10 @@ public class Page extends TagDataManager
* the id * the id
* @param source * @param source
* the source * the source
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public void includePage(final String id, final Document source) throws Exception public void includePage(final String id, final Document source) throws XidynException
{ {
if ((id != null) && (source != null)) if ((id != null) && (source != null))
{ {
@ -291,10 +292,10 @@ public class Page extends TagDataManager
* the id * the id
* @param source * @param source
* the source * the source
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public void includePage(final String id, final File source) throws Exception public void includePage(final String id, final File source) throws XidynException
{ {
if ((id != null) && (source != null)) if ((id != null) && (source != null))
{ {
@ -311,10 +312,10 @@ public class Page extends TagDataManager
* the id * the id
* @param source * @param source
* the source * the source
* @throws Exception * @throws throws
* the exception * XidynException the exception
*/ */
public void includePage(final String id, final URL source) throws Exception public void includePage(final String id, final URL source) throws XidynException
{ {
if ((id != null) && (source != null)) if ((id != null) && (source != null))
{ {
@ -350,10 +351,10 @@ public class Page extends TagDataManager
* Last version. * Last version.
* *
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public StringBuffer lastVersion() throws Exception public StringBuffer lastVersion() throws XidynException
{ {
StringBuffer result; StringBuffer result;

View file

@ -22,6 +22,8 @@ import java.io.File;
import java.net.URL; import java.net.URL;
import java.util.Locale; import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import fr.devinsy.strings.StringsUtils; import fr.devinsy.strings.StringsUtils;
@ -35,6 +37,8 @@ import fr.devinsy.xidyn.utils.cache.Cache;
*/ */
public class PageFactory public class PageFactory
{ {
private static Logger logger = LoggerFactory.getLogger(PageFactory.class);
/** /**
* http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne- * http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne-
* implementation-du-singleton-en-java * implementation-du-singleton-en-java
@ -183,7 +187,7 @@ public class PageFactory
{ {
Page result; Page result;
String key = StringsUtils.toStringSeparatedBy(keys, "-").toString(); String key = StringsUtils.toStringSeparatedBy(keys, "-");
result = this.cache.get(key); result = this.cache.get(key);
if (result == null) if (result == null)
@ -209,12 +213,12 @@ public class PageFactory
{ {
Page result; Page result;
String key = StringsUtils.toStringSeparatedBy(keys, "-").toString(); String key = StringsUtils.toStringSeparatedBy(keys, "-");
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);
} }
@ -235,12 +239,12 @@ public class PageFactory
{ {
Page result; Page result;
String key = StringsUtils.toStringSeparatedBy(keys, "-").toString(); String key = StringsUtils.toStringSeparatedBy(keys, "-");
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);
} }
@ -261,12 +265,12 @@ public class PageFactory
{ {
Page result; Page result;
String key = StringsUtils.toStringSeparatedBy(keys, "-").toString(); String key = StringsUtils.toStringSeparatedBy(keys, "-");
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);
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2006-2017 Christian Pierre MOMON * Copyright (C) 2006-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -24,6 +24,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.utils.XidynUtils; import fr.devinsy.xidyn.utils.XidynUtils;
@ -33,6 +34,7 @@ import fr.devinsy.xidyn.utils.XidynUtils;
public class DomPresenter implements Presenter public class DomPresenter implements Presenter
{ {
private static Logger logger = LoggerFactory.getLogger(DomPresenter.class); private static Logger logger = LoggerFactory.getLogger(DomPresenter.class);
private Document dom; private Document dom;
private boolean isOutdated; private boolean isOutdated;
private StringBuffer defaultHtmlTarget; private StringBuffer defaultHtmlTarget;
@ -61,7 +63,7 @@ public class DomPresenter implements Presenter
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public StringBuffer dynamize() throws Exception public StringBuffer dynamize() throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -81,7 +83,7 @@ public class DomPresenter implements Presenter
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public StringBuffer dynamize(final TagDataManager data) throws Exception public StringBuffer dynamize(final TagDataManager data) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -94,7 +96,7 @@ public class DomPresenter implements Presenter
String errorMessage = "source not defined"; String errorMessage = "source not defined";
logger.error(errorMessage); logger.error(errorMessage);
result = null; result = null;
throw new Exception(errorMessage); throw new XidynException(errorMessage);
} }
else else
{ {
@ -163,7 +165,7 @@ public class DomPresenter implements Presenter
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isOutdated() throws Exception public boolean isOutdated() throws XidynException
{ {
boolean result; boolean result;
@ -202,7 +204,7 @@ public class DomPresenter implements Presenter
* @see fr.devinsy.xidyn.presenters.Presenter#update() * @see fr.devinsy.xidyn.presenters.Presenter#update()
*/ */
@Override @Override
public void update() throws Exception public void update() throws XidynException
{ {
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2006-2017 Christian Pierre MOMON * Copyright (C) 2006-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -18,6 +18,7 @@
*/ */
package fr.devinsy.xidyn.presenters; package fr.devinsy.xidyn.presenters;
import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -32,6 +33,7 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.SimpleTagData; import fr.devinsy.xidyn.data.SimpleTagData;
import fr.devinsy.xidyn.data.TagAttributes; import fr.devinsy.xidyn.data.TagAttributes;
import fr.devinsy.xidyn.data.TagData; import fr.devinsy.xidyn.data.TagData;
@ -59,13 +61,20 @@ public class DomPresenterCore
* the doc * the doc
* @param data * @param data
* the data * the data
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public static void dynamize(final Appendable result, final Document doc, final TagDataListById data) throws Exception public static void dynamize(final Appendable result, final Document doc, final TagDataListById data) throws XidynException
{
try
{ {
process(result, doc, data); process(result, doc, data);
} }
catch (IOException exception)
{
throw new XidynException("IO Error detected: " + exception.getMessage(), exception);
}
}
/** /**
* Dynamize a doc with data. * Dynamize a doc with data.
@ -76,10 +85,10 @@ public class DomPresenterCore
* the doc * the doc
* @param data * @param data
* the data * the data
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public static void dynamize(final Appendable result, final Document doc, final TagDataManager data) throws Exception public static void dynamize(final Appendable result, final Document doc, final TagDataManager data) throws XidynException
{ {
dynamize(result, doc, data.getIdsDataById()); dynamize(result, doc, data.getIdsDataById());
} }
@ -92,10 +101,10 @@ public class DomPresenterCore
* @param data * @param data
* the data * the data
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public static StringBuffer dynamize(final Document doc, final TagDataListById data) throws Exception public static StringBuffer dynamize(final Document doc, final TagDataListById data) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -115,10 +124,10 @@ public class DomPresenterCore
* @param data * @param data
* the data * the data
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public static StringBuffer dynamize(final Document doc, final TagDataManager data) throws Exception public static StringBuffer dynamize(final Document doc, final TagDataManager data) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -298,10 +307,10 @@ public class DomPresenterCore
* the node * the node
* @param data * @param data
* the data * the data
* @throws Exception * @throws IOException
* the exception * the exception
*/ */
private static void process(final Appendable result, final Node node, final TagDataListById data) throws Exception private static void process(final Appendable result, final Node node, final TagDataListById data) throws IOException
{ {
process(result, node, data, ""); process(result, node, data, "");
} }
@ -317,10 +326,10 @@ public class DomPresenterCore
* the datas * the datas
* @param suffix * @param suffix
* the suffix * the suffix
* @throws Exception * @throws IOException
* the exception * the exception
*/ */
private static void process(final Appendable result, final Node node, final TagDataListById datas, final String suffix) throws Exception private static void process(final Appendable result, final Node node, final TagDataListById datas, final String suffix) throws IOException
{ {
logger.debug("process - started"); logger.debug("process - started");
String TRANSITIONAL_DTD = "xhtml1-transitional.dtd"; String TRANSITIONAL_DTD = "xhtml1-transitional.dtd";
@ -579,10 +588,10 @@ public class DomPresenterCore
* the node * the node
* @param datas * @param datas
* the datas * the datas
* @throws Exception * @throws IOException
* the exception * the exception
*/ */
private static void processChildren(final Appendable result, final Node node, final TagDataListById datas) throws Exception private static void processChildren(final Appendable result, final Node node, final TagDataListById datas) throws IOException
{ {
processChildren(result, node, datas, ""); processChildren(result, node, datas, "");
} }
@ -598,10 +607,10 @@ public class DomPresenterCore
* the datas * the datas
* @param suffix * @param suffix
* the suffix * the suffix
* @throws Exception * @throws IOException
* the exception * the exception
*/ */
private static void processChildren(final Appendable result, final Node node, final TagDataListById datas, final String suffix) throws Exception private static void processChildren(final Appendable result, final Node node, final TagDataListById datas, final String suffix) throws IOException
{ {
// Get the iteration strategy. // Get the iteration strategy.
SimpleTagData.IterationStrategy strategy; SimpleTagData.IterationStrategy strategy;
@ -738,10 +747,10 @@ public class DomPresenterCore
* the node * the node
* @param datas * @param datas
* the datas * the datas
* @throws Exception * @throws IOException
* the exception * the exception
*/ */
private static void processElementBasically(final Appendable result, final Node node, final TagDataListById datas) throws Exception private static void processElementBasically(final Appendable result, final Node node, final TagDataListById datas) throws IOException
{ {
processElementBasically(result, node, datas, ""); processElementBasically(result, node, datas, "");
} }
@ -757,10 +766,10 @@ public class DomPresenterCore
* the datas * the datas
* @param suffix * @param suffix
* the suffix * the suffix
* @throws Exception * @throws IOException
* the exception * the exception
*/ */
private static void processElementBasically(final Appendable result, final Node node, final TagDataListById datas, final String suffix) throws Exception private static void processElementBasically(final Appendable result, final Node node, final TagDataListById datas, final String suffix) throws IOException
{ {
logger.debug("processElementBasically - started [{}]", node.getNodeName()); logger.debug("processElementBasically - started [{}]", node.getNodeName());
@ -806,10 +815,10 @@ public class DomPresenterCore
* The ID. * The ID.
* @param datas * @param datas
* the datas * the datas
* @throws Exception * @throws IOException
* the exception * the exception
*/ */
private static void processElementWithId(final Appendable result, final Node node, final NamedNodeMap attrs, final Node idAttr, final TagDataListById datas) throws Exception private static void processElementWithId(final Appendable result, final Node node, final NamedNodeMap attrs, final Node idAttr, final TagDataListById datas) throws IOException
{ {
processElementWithId(result, node, attrs, idAttr, datas, ""); processElementWithId(result, node, attrs, idAttr, datas, "");
} }
@ -830,10 +839,10 @@ public class DomPresenterCore
* the datas * the datas
* @param suffix * @param suffix
* the suffix * the suffix
* @throws Exception * @throws IOException
* the exception * the exception
*/ */
private static void processElementWithId(final Appendable result, final Node node, final NamedNodeMap attrs, final Node idAttr, final TagDataListById datas, final String suffix) throws Exception private static void processElementWithId(final Appendable result, final Node node, final NamedNodeMap attrs, final Node idAttr, final TagDataListById datas, final String suffix) throws IOException
{ {
String tag = node.getNodeName(); String tag = node.getNodeName();

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2006-2017 Christian Pierre MOMON * Copyright (C) 2006-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -19,12 +19,14 @@
package fr.devinsy.xidyn.presenters; package fr.devinsy.xidyn.presenters;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.utils.XidynUtils; import fr.devinsy.xidyn.utils.XidynUtils;
@ -73,7 +75,7 @@ public class FilePresenter extends StringPresenter
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public StringBuffer dynamize() throws Exception public StringBuffer dynamize() throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -93,7 +95,7 @@ public class FilePresenter extends StringPresenter
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public StringBuffer dynamize(final TagDataManager data) throws Exception public StringBuffer dynamize(final TagDataManager data) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -163,7 +165,7 @@ public class FilePresenter extends StringPresenter
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isOutdated() throws Exception public boolean isOutdated() throws XidynException
{ {
boolean result; boolean result;
@ -246,14 +248,13 @@ public class FilePresenter extends StringPresenter
setSource(file); setSource(file);
} }
/** /* (non-Javadoc)
* Update. * @see fr.devinsy.xidyn.presenters.StringPresenter#update()
*
* @throws Exception
* the exception
*/ */
@Override @Override
public void update() throws Exception public void update() throws XidynException
{
try
{ {
// //
if (this.source == null) if (this.source == null)
@ -266,7 +267,7 @@ public class FilePresenter extends StringPresenter
{ {
String errorMessage = "source file defined but not found (" + this.sourceFilePathname + ")"; String errorMessage = "source file defined but not found (" + this.sourceFilePathname + ")";
logger.error(errorMessage); logger.error(errorMessage);
throw new Exception(errorMessage); throw new XidynException(errorMessage);
} }
else else
{ {
@ -278,4 +279,9 @@ public class FilePresenter extends StringPresenter
} }
} }
} }
catch (IOException exception)
{
throw new XidynException(exception);
}
}
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2006-2017 Christian Pierre MOMON * Copyright (C) 2006-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2006-2017 Christian Pierre MOMON * Copyright (C) 2006-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -21,6 +21,8 @@ package fr.devinsy.xidyn.presenters;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.xidyn.XidynException;
/** /**
* The Class FilePresentersProxy. * The Class FilePresentersProxy.
*/ */
@ -34,10 +36,10 @@ public class FilePresentersProxy
/** /**
* Instantiates a new file presenters proxy. * Instantiates a new file presenters proxy.
* *
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
protected FilePresentersProxy() throws Exception protected FilePresentersProxy() throws XidynException
{ {
this.presenters = new FilePresenters(); this.presenters = new FilePresenters();
} }
@ -48,10 +50,10 @@ public class FilePresentersProxy
* @param source * @param source
* the source * the source
* @return the by source * @return the by source
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public FilePresenter getBySource(final String source) throws Exception public FilePresenter getBySource(final String source) throws XidynException
{ {
FilePresenter result; FilePresenter result;
@ -77,10 +79,10 @@ public class FilePresentersProxy
* Instance. * Instance.
* *
* @return the file presenters proxy * @return the file presenters proxy
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public static FilePresentersProxy instance() throws Exception public static FilePresentersProxy instance() throws XidynException
{ {
FilePresentersProxy result; FilePresentersProxy result;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2006-2017 Christian Pierre MOMON * Copyright (C) 2006-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -23,6 +23,7 @@ import java.net.URL;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.data.TagDataManager;
/** /**
@ -110,7 +111,7 @@ public class GenericPresenter implements Presenter
* @see fr.devinsy.xidyn.presenters.Presenter#dynamize() * @see fr.devinsy.xidyn.presenters.Presenter#dynamize()
*/ */
@Override @Override
public StringBuffer dynamize() throws Exception public StringBuffer dynamize() throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -124,7 +125,7 @@ public class GenericPresenter implements Presenter
* @see fr.devinsy.xidyn.presenters.Presenter#dynamize(fr.devinsy.xidyn.data.TagDataManager) * @see fr.devinsy.xidyn.presenters.Presenter#dynamize(fr.devinsy.xidyn.data.TagDataManager)
*/ */
@Override @Override
public StringBuffer dynamize(final TagDataManager datas) throws Exception public StringBuffer dynamize(final TagDataManager datas) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -166,7 +167,7 @@ public class GenericPresenter implements Presenter
* @see fr.devinsy.xidyn.presenters.Presenter#isOutdated() * @see fr.devinsy.xidyn.presenters.Presenter#isOutdated()
*/ */
@Override @Override
public boolean isOutdated() throws Exception public boolean isOutdated() throws XidynException
{ {
boolean result; boolean result;
@ -254,10 +255,10 @@ public class GenericPresenter implements Presenter
* @param language * @param language
* the language * the language
* @return the string * @return the string
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public String toString(final String language) throws Exception public String toString(final String language) throws XidynException
{ {
String result; String result;
@ -271,7 +272,7 @@ public class GenericPresenter implements Presenter
* @see fr.devinsy.xidyn.presenters.Presenter#update() * @see fr.devinsy.xidyn.presenters.Presenter#update()
*/ */
@Override @Override
public void update() throws Exception public void update() throws XidynException
{ {
this.presenter.update(); this.presenter.update();
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2006-2017 Christian Pierre MOMON * Copyright (C) 2006-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -18,6 +18,7 @@
*/ */
package fr.devinsy.xidyn.presenters; package fr.devinsy.xidyn.presenters;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.data.TagDataManager;
/** /**
@ -32,15 +33,14 @@ import fr.devinsy.xidyn.data.TagDataManager;
*/ */
public interface Presenter public interface Presenter
{ {
/** /**
* Dynamize. * Dynamize.
* *
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public StringBuffer dynamize() throws Exception; public StringBuffer dynamize() throws XidynException;
/** /**
* Dynamize. * Dynamize.
@ -48,10 +48,10 @@ public interface Presenter
* @param datas * @param datas
* the datas * the datas
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public StringBuffer dynamize(final TagDataManager datas) throws Exception; public StringBuffer dynamize(final TagDataManager datas) throws XidynException;
/** /**
* Gets the source. * Gets the source.
@ -71,16 +71,16 @@ public interface Presenter
* Checks if is outdated. * Checks if is outdated.
* *
* @return true, if is outdated * @return true, if is outdated
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public boolean isOutdated() throws Exception; public boolean isOutdated() throws XidynException;
/** /**
* Update. * Update.
* *
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public void update() throws Exception; public void update() throws XidynException;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2006-2017 Christian Pierre MOMON * Copyright (C) 2006-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -35,6 +35,8 @@ import fr.devinsy.xidyn.utils.cache.Cache;
*/ */
public class PresenterFactory public class PresenterFactory
{ {
private static Logger logger = LoggerFactory.getLogger(PresenterFactory.class);
/** /**
* http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne- * http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne-
* implementation-du-singleton-en-java * implementation-du-singleton-en-java
@ -44,8 +46,6 @@ public class PresenterFactory
private final static PresenterFactory INSTANCE = new PresenterFactory(); private final static PresenterFactory INSTANCE = new PresenterFactory();
} }
private static Logger logger = LoggerFactory.getLogger(PresenterFactory.class);
private Cache<Presenter> cache; private Cache<Presenter> cache;
/** /**

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2006-2017 Christian Pierre MOMON * Copyright (C) 2006-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -24,6 +24,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataListById; import fr.devinsy.xidyn.data.TagDataListById;
import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.data.TagDataManager;
@ -49,10 +50,10 @@ public class PresenterUtils
* @param data * @param data
* the data * the data
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public static StringBuffer dynamize(final Document doc, final TagDataListById data) throws Exception public static StringBuffer dynamize(final Document doc, final TagDataListById data) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -70,10 +71,10 @@ public class PresenterUtils
* @param data * @param data
* the data * the data
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public static StringBuffer dynamize(final Document doc, final TagDataManager data) throws Exception public static StringBuffer dynamize(final Document doc, final TagDataManager data) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -89,10 +90,10 @@ public class PresenterUtils
* @param source * @param source
* the source * the source
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public static StringBuffer dynamize(final File source) throws Exception public static StringBuffer dynamize(final File source) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -112,10 +113,10 @@ public class PresenterUtils
* @param datas * @param datas
* the datas * the datas
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public static StringBuffer dynamize(final File source, final TagDataManager datas) throws Exception public static StringBuffer dynamize(final File source, final TagDataManager datas) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -128,18 +129,17 @@ public class PresenterUtils
} }
/** /**
* Dynamize a string with HTML in, or with file path name in, or with URL * Dynamize a string with HTML in, or with file path name in, or with URL in.
* in.
* *
* @param source * @param source
* the source * the source
* @param datas * @param datas
* the datas * the datas
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public static StringBuffer dynamize(final String source, final TagDataManager datas) throws Exception public static StringBuffer dynamize(final String source, final TagDataManager datas) throws XidynException
{ {
StringBuffer result; StringBuffer result;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2006-2017 Christian Pierre MOMON * Copyright (C) 2006-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -24,6 +24,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.utils.XidynUtils; import fr.devinsy.xidyn.utils.XidynUtils;
@ -61,7 +62,7 @@ public class StringPresenter implements Presenter
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public StringBuffer dynamize() throws Exception public StringBuffer dynamize() throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -75,7 +76,7 @@ public class StringPresenter implements Presenter
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public StringBuffer dynamize(final TagDataManager data) throws Exception public StringBuffer dynamize(final TagDataManager data) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -89,7 +90,7 @@ public class StringPresenter implements Presenter
String errorMessage = "source not defined"; String errorMessage = "source not defined";
logger.error(errorMessage); logger.error(errorMessage);
result = null; result = null;
throw new Exception(errorMessage); throw new XidynException(errorMessage);
} }
else else
{ {
@ -200,7 +201,7 @@ public class StringPresenter implements Presenter
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean isOutdated() throws Exception public boolean isOutdated() throws XidynException
{ {
boolean result; boolean result;
@ -234,7 +235,7 @@ public class StringPresenter implements Presenter
* @see fr.devinsy.xidyn.presenters.Presenter#update() * @see fr.devinsy.xidyn.presenters.Presenter#update()
*/ */
@Override @Override
public void update() throws Exception public void update() throws XidynException
{ {
// Nothing to do. // Nothing to do.
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2006-2017 Christian Pierre MOMON * Copyright (C) 2006-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -23,6 +23,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import fr.devinsy.util.FileTools; import fr.devinsy.util.FileTools;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.data.TagDataManager;
/** /**
@ -58,7 +59,7 @@ public class TranslatorPresenter implements Presenter
* @see fr.devinsy.xidyn.presenters.Presenter#dynamize() * @see fr.devinsy.xidyn.presenters.Presenter#dynamize()
*/ */
@Override @Override
public StringBuffer dynamize() throws Exception public StringBuffer dynamize() throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -82,10 +83,10 @@ public class TranslatorPresenter implements Presenter
* @param locale * @param locale
* the locale * the locale
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public StringBuffer dynamize(final Locale locale) throws Exception public StringBuffer dynamize(final Locale locale) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -113,10 +114,10 @@ public class TranslatorPresenter implements Presenter
* @param language * @param language
* the language * the language
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public StringBuffer dynamize(final String language) throws Exception public StringBuffer dynamize(final String language) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -130,7 +131,7 @@ public class TranslatorPresenter implements Presenter
* @see fr.devinsy.xidyn.presenters.Presenter#dynamize(fr.devinsy.xidyn.data.TagDataManager) * @see fr.devinsy.xidyn.presenters.Presenter#dynamize(fr.devinsy.xidyn.data.TagDataManager)
*/ */
@Override @Override
public StringBuffer dynamize(final TagDataManager datas) throws Exception public StringBuffer dynamize(final TagDataManager datas) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -156,10 +157,10 @@ public class TranslatorPresenter implements Presenter
* @param locale * @param locale
* the locale * the locale
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public StringBuffer dynamize(final TagDataManager datas, final Locale locale) throws Exception public StringBuffer dynamize(final TagDataManager datas, final Locale locale) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -189,10 +190,10 @@ public class TranslatorPresenter implements Presenter
* @param language * @param language
* the language * the language
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public StringBuffer dynamize(final TagDataManager datas, final String language) throws Exception public StringBuffer dynamize(final TagDataManager datas, final String language) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -208,10 +209,10 @@ public class TranslatorPresenter implements Presenter
* @param locale * @param locale
* the locale * the locale
* @return the presenter * @return the presenter
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public Presenter getPresenter(final Locale locale) throws Exception public Presenter getPresenter(final Locale locale) throws XidynException
{ {
Presenter result; Presenter result;
@ -239,10 +240,10 @@ public class TranslatorPresenter implements Presenter
* @param language * @param language
* the language * the language
* @return the presenter * @return the presenter
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public Presenter getPresenter(final String language) throws Exception public Presenter getPresenter(final String language) throws XidynException
{ {
Presenter result; Presenter result;
@ -264,7 +265,7 @@ public class TranslatorPresenter implements Presenter
} }
else else
{ {
throw new Exception("Undefined default language file."); throw new XidynException("Undefined default language file.");
} }
} }
else else
@ -335,7 +336,7 @@ public class TranslatorPresenter implements Presenter
* @see fr.devinsy.xidyn.presenters.Presenter#isOutdated() * @see fr.devinsy.xidyn.presenters.Presenter#isOutdated()
*/ */
@Override @Override
public boolean isOutdated() throws Exception public boolean isOutdated() throws XidynException
{ {
return false; return false;
} }
@ -346,10 +347,10 @@ public class TranslatorPresenter implements Presenter
* @param locale * @param locale
* the locale * the locale
* @return the string * @return the string
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public String toString(final Locale locale) throws Exception public String toString(final Locale locale) throws XidynException
{ {
String result; String result;
@ -377,10 +378,10 @@ public class TranslatorPresenter implements Presenter
* @param language * @param language
* the language * the language
* @return the string * @return the string
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public String toString(final String language) throws Exception public String toString(final String language) throws XidynException
{ {
String result; String result;
@ -402,7 +403,7 @@ public class TranslatorPresenter implements Presenter
* @see fr.devinsy.xidyn.presenters.Presenter#update() * @see fr.devinsy.xidyn.presenters.Presenter#update()
*/ */
@Override @Override
public void update() throws Exception public void update() throws XidynException
{ {
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2006-2017 Christian Pierre MOMON * Copyright (C) 2006-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -25,6 +25,7 @@ import java.net.URL;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager; import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.utils.XidynUtils; import fr.devinsy.xidyn.utils.XidynUtils;
@ -76,11 +77,11 @@ public class URLPresenter extends StringPresenter
* No need to be synchronized. * No need to be synchronized.
* *
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
@Override @Override
public StringBuffer dynamize() throws Exception public StringBuffer dynamize() throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -100,11 +101,11 @@ public class URLPresenter extends StringPresenter
* @param data * @param data
* the data * the data
* @return the string buffer * @return the string buffer
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
@Override @Override
public StringBuffer dynamize(final TagDataManager data) throws Exception public StringBuffer dynamize(final TagDataManager data) throws XidynException
{ {
StringBuffer result; StringBuffer result;
@ -204,11 +205,12 @@ public class URLPresenter extends StringPresenter
* @throws IOException * @throws IOException
*/ */
@Override @Override
public boolean isOutdated() throws Exception public boolean isOutdated() throws XidynException
{ {
boolean result; boolean result;
// try
{
if (super.isOutdated()) if (super.isOutdated())
{ {
result = true; result = true;
@ -221,6 +223,11 @@ public class URLPresenter extends StringPresenter
{ {
result = false; result = false;
} }
}
catch (IOException exception)
{
throw new XidynException(exception);
}
// //
return result; return result;
@ -332,11 +339,11 @@ public class URLPresenter extends StringPresenter
/** /**
* No need to be synchronized. * No need to be synchronized.
* *
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
@Override @Override
public void update() throws Exception public void update() throws XidynException
{ {
// //
if (this.source == null) if (this.source == null)
@ -367,7 +374,7 @@ public class URLPresenter extends StringPresenter
*/ */
String errorMessage = "source file defined but not readable (" + this.source.toString() + ")"; String errorMessage = "source file defined but not readable (" + this.source.toString() + ")";
logger.error(errorMessage); logger.error(errorMessage);
throw new Exception(errorMessage); throw new XidynException(errorMessage);
} }
} }
} }

View file

@ -1,5 +1,5 @@
/** /**
* Copyright (C) 2006-2017 Christian Pierre MOMON * Copyright (C) 2006-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -43,6 +43,8 @@ import org.w3c.dom.NodeList;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import fr.devinsy.xidyn.XidynException;
/** /**
* The Class XidynUtils. * The Class XidynUtils.
*/ */
@ -89,10 +91,10 @@ public class XidynUtils
* @param source * @param source
* the source * the source
* @return the document * @return the document
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public static Document buildDom(final InputStream source) throws Exception public static Document buildDom(final InputStream source) throws XidynException
{ {
Document result; Document result;
@ -129,7 +131,8 @@ public class XidynUtils
if (errorHandler.hasError()) if (errorHandler.hasError())
{ {
// Most time, error is (with StringPresenter): // Most time, error is (with StringPresenter):
// "Error at line 1 : Document root element "html", must match DOCTYPE root "null". // "Error at line 1 : Document root element "html", must match DOCTYPE root
// "null".
// Error at line 1 : Document is invalid: no grammar found. // Error at line 1 : Document is invalid: no grammar found.
// We ignore it. STU // We ignore it. STU
logger.debug(errorHandler.toString()); logger.debug(errorHandler.toString());
@ -140,21 +143,21 @@ public class XidynUtils
String errorMessage = "Parser configuration exception: " + exception.getMessage(); String errorMessage = "Parser configuration exception: " + exception.getMessage();
logger.error(errorMessage); logger.error(errorMessage);
result = null; result = null;
throw new Exception(errorMessage, exception); throw new XidynException(errorMessage, exception);
} }
catch (SAXException exception) catch (SAXException exception)
{ {
String errorMessage = "Error during SAX parsing: " + exception.getMessage(); String errorMessage = "Error during SAX parsing: " + exception.getMessage();
logger.error(errorMessage); logger.error(errorMessage);
result = null; result = null;
throw new Exception(errorMessage, exception); throw new XidynException(errorMessage, exception);
} }
catch (IOException exception) catch (IOException exception)
{ {
String errorMessage = "IOError during parsing." + exception.getMessage(); String errorMessage = "IOError during parsing." + exception.getMessage();
logger.error(errorMessage); logger.error(errorMessage);
result = null; result = null;
throw new Exception(errorMessage, exception); throw new XidynException(errorMessage, exception);
} }
// //
@ -167,10 +170,10 @@ public class XidynUtils
* @param source * @param source
* the source * the source
* @return the document * @return the document
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public static Document buildDom(final String source) throws Exception public static Document buildDom(final String source) throws XidynException
{ {
Document result; Document result;
@ -207,7 +210,8 @@ public class XidynUtils
if (errorHandler.hasError()) if (errorHandler.hasError())
{ {
// Most time, error is (with StringPresenter): // Most time, error is (with StringPresenter):
// "Error at line 1 : Document root element "html", must match DOCTYPE root "null". // "Error at line 1 : Document root element "html", must match DOCTYPE root
// "null".
// Error at line 1 : Document is invalid: no grammar found. // Error at line 1 : Document is invalid: no grammar found.
// We ignore it. STU // We ignore it. STU
logger.debug(errorHandler.toString()); logger.debug(errorHandler.toString());
@ -218,21 +222,21 @@ public class XidynUtils
String errorMessage = "Parser configuration exception: " + exception.getMessage(); String errorMessage = "Parser configuration exception: " + exception.getMessage();
logger.error(errorMessage); logger.error(errorMessage);
result = null; result = null;
throw new Exception(errorMessage, exception); throw new XidynException(errorMessage, exception);
} }
catch (SAXException exception) catch (SAXException exception)
{ {
String errorMessage = "Error during SAX parsing: " + exception.getMessage(); String errorMessage = "Error during SAX parsing: " + exception.getMessage();
logger.error(errorMessage); logger.error(errorMessage);
result = null; result = null;
throw new Exception(errorMessage, exception); throw new XidynException(errorMessage, exception);
} }
catch (IOException exception) catch (IOException exception)
{ {
String errorMessage = "IOError during parsing." + exception.getMessage(); String errorMessage = "IOError during parsing." + exception.getMessage();
logger.error(errorMessage); logger.error(errorMessage);
result = null; result = null;
throw new Exception(errorMessage, exception); throw new XidynException(errorMessage, exception);
} }
// //
@ -311,12 +315,11 @@ public class XidynUtils
/** /**
* This method extracts the string before the <i>html</i> tag. * This method extracts the string before the <i>html</i> tag.
* *
* A possible way is to use pattern searching for * A possible way is to use pattern searching for <i>$(.*)&lt;html&gt;.*^</i>.
* <i>$(.*)&lt;html&gt;.*^</i>. But if there is no <i>html</i> tag, all the * But if there is no <i>html</i> tag, all the source is read for nothing.
* source is read for nothing.
* *
* A best way is to analyze each &lt; while it is a XML tag or a DOCTYPE tag * A best way is to analyze each &lt; while it is a XML tag or a DOCTYPE tag or
* or the &lt;HTML&gt; tag. * the &lt;HTML&gt; tag.
* *
* Uses cases: * Uses cases:
* *
@ -327,8 +330,8 @@ public class XidynUtils
* *
* @param source * @param source
* the source * the source
* @return the string before the <i>html</i> tag or null if no <i>html</i> * @return the string before the <i>html</i> tag or null if no <i>html</i> tag
* tag found. So, "" if there is a <i>html</i> tag without doctype. * found. So, "" if there is a <i>html</i> tag without doctype.
*/ */
public static String extractDoctype(final String source) public static String extractDoctype(final String source)
{ {
@ -397,7 +400,7 @@ public class XidynUtils
* @param source * @param source
* the source * the source
* @return the document * @return the document
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public static Document fileToDom(final File source) throws Exception public static Document fileToDom(final File source) throws Exception
@ -711,8 +714,8 @@ public class XidynUtils
} }
/** /**
* Any ampersand lt;, ampersand gt; and ampersand amp; sequences in text * Any ampersand lt;, ampersand gt; and ampersand amp; sequences in text nodes
* nodes get read in as symbols. This method converts them back to entities. * get read in as symbols. This method converts them back to entities.
* *
* @param source * @param source
* String that is to have the entities restored.. * String that is to have the entities restored..
@ -773,10 +776,10 @@ public class XidynUtils
* @param source * @param source
* the source * the source
* @return the document * @return the document
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public static Document urlToDom(final URL source) throws Exception public static Document urlToDom(final URL source) throws XidynException
{ {
Document result; Document result;
@ -789,7 +792,7 @@ public class XidynUtils
String errorMessage = "IOError during parsing." + exception.getMessage(); String errorMessage = "IOError during parsing." + exception.getMessage();
logger.error(errorMessage); logger.error(errorMessage);
result = null; result = null;
throw new Exception(errorMessage, exception); throw new XidynException(errorMessage, exception);
} }
// //

View file

@ -20,6 +20,8 @@ package fr.devinsy.xidyn.views;
import java.util.Locale; import java.util.Locale;
import fr.devinsy.xidyn.XidynException;
/** /**
* The Interface CharterView. * The Interface CharterView.
*/ */
@ -35,10 +37,10 @@ public interface CharterView extends View
* @param content * @param content
* the content * the content
* @return the html * @return the html
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public StringBuffer getHtml(final Long userId, final Locale language, final CharSequence content) throws Exception; public StringBuffer getHtml(final Long userId, final Locale language, final CharSequence content) throws XidynException;
} }
// //////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////

View file

@ -18,6 +18,8 @@
*/ */
package fr.devinsy.xidyn.views; package fr.devinsy.xidyn.views;
import fr.devinsy.xidyn.XidynException;
/** /**
* The Interface View. * The Interface View.
*/ */
@ -27,10 +29,10 @@ public interface View
* Gets the html. * Gets the html.
* *
* @return the html * @return the html
* @throws Exception * @throws XidynException
* the exception * the exception
*/ */
public StringBuffer getHtml() throws Exception; public StringBuffer getHtml() throws XidynException;
} }

View file

@ -0,0 +1,148 @@
/*
* Copyright (C) 2006-2017 Christian Pierre MOMON
*
* This file is part of Xidyn.
*
* Xidyn is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xidyn is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Xidyn. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.xidyn.views;
import java.util.HashMap;
import java.util.Map;
import fr.devinsy.xidyn.XidynException;
/**
* The Class ViewCache.
*/
public class ViewCache
{
private Map<String, ViewCacheItem> cache;
/**
* Instantiates a new view cache.
*/
public ViewCache()
{
this.cache = new HashMap<String, ViewCacheItem>();
}
/**
* Gets the HT ml.
*
* @param key
* the key
* @return the HT ml
* @throws XidynException
* the exception
*/
public String getHTMl(final String key) throws XidynException
{
String result;
ViewCacheItem item = this.cache.get(key);
if (item == null)
{
result = null;
}
else
{
if (item.isDeprecated())
{
item.update();
}
result = item.view().getHtml().toString();
}
//
return result;
}
/**
* Gets the view.
*
* @param key
* the key
* @return the view
*/
public View getView(final String key)
{
View result;
ViewCacheItem item = this.cache.get(key);
if (item == null)
{
result = null;
}
else
{
result = item.view();
}
//
return result;
}
/**
* Checks if is empty.
*
* @return true, if is empty
*/
public boolean isEmpty()
{
boolean result;
result = this.cache.isEmpty();
//
return result;
}
/**
* Purge.
*/
public void purge()
{
for (ViewCacheItem item : this.cache.values())
{
}
}
/**
* Put.
*
* @param view
* the view
* @param key
* the key
* @return the string
*/
public String put(final View view, final String key)
{
String result;
ViewCacheItem item = new ViewCacheItem(view);
this.cache.put(key, item);
//
result = item.html().toString();
//
return result;
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -0,0 +1,175 @@
/*
* Copyright (C) 2006-2017 Christian Pierre MOMON
*
* This file is part of Xidyn.
*
* Xidyn is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xidyn is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Xidyn. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.xidyn.views;
import java.util.Date;
/**
* The Class ViewCacheItem.
*/
public class ViewCacheItem
{
private View view;
private long creationDate;
private long editionDate;
private long lastUseDate;
private StringBuffer html;
/**
* Instantiates a new view cache item.
*
* @param source
* the source
*/
public ViewCacheItem(final View source)
{
this.view = source;
this.creationDate = time();
update();
this.editionDate = this.creationDate;
this.lastUseDate = this.creationDate;
}
/**
* Creation date.
*
* @return the long
*/
public long creationDate()
{
long result;
result = this.creationDate;
//
return result;
}
/**
* Edition date.
*
* @return the long
*/
public long editionDate()
{
long result;
result = this.editionDate;
//
return result;
}
/**
* Html.
*
* @return the string buffer
*/
public StringBuffer html()
{
return this.html;
}
/**
* Checks if is deprecated.
*
* @return true, if is deprecated
*/
public boolean isDeprecated()
{
boolean result;
if ((this.view == null) || (this.html == null))
{
result = true;
}
else
{
// TODO
// result = this.view.isOutdated();
result = false;
}
//
return result;
}
/**
* Last use date.
*
* @return the long
*/
public long lastUseDate()
{
long result;
result = this.lastUseDate;
//
return result;
}
/**
* Last use time.
*
* @return the long
*/
public long lastUseTime()
{
return this.lastUseDate;
}
/**
* Update.
*/
public void update()
{
this.editionDate = time();
this.lastUseDate = this.editionDate;
// TODO
// this.html = this.view.getHtml();
}
/**
* View.
*
* @return the view
*/
public View view()
{
return this.view;
}
/**
* Time.
*
* @return the long
*/
public static long time()
{
long result;
result = new Date().getTime();
//
return result;
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -0,0 +1,60 @@
/*
* Copyright (C) 2006-2017 Christian Pierre MOMON
*
* This file is part of Xidyn.
*
* Xidyn is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Xidyn is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Xidyn. If not, see <http://www.gnu.org/licenses/>
*/
package fr.devinsy.xidyn.views;
import java.io.Serializable;
/**
* The Class ViewProxy.
*/
public class ViewProxy implements Serializable
{
/**
*
*/
private static class Holder
{
private final static ViewProxy INSTANCE = new ViewProxy();
}
private static final long serialVersionUID = -5517300613792689510L;
/**
* Instance.
*
* @return the view proxy
*/
public ViewProxy instance()
{
return Holder.INSTANCE;
}
/**
* http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne-
* implementation-du-singleton-en-java
*
* @return the object
*/
private Object readResolve()
{
return Holder.INSTANCE;
}
}
// ////////////////////////////////////////////////////////////////////////

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2016,2017 Christian Pierre MOMON * Copyright (C) 2016-2018 Christian Pierre MOMON
* *
* This file is part of Xidyn. * This file is part of Xidyn.
* *
@ -37,7 +37,7 @@ public class PageFactoryTest
public void before() public void before()
{ {
BasicConfigurator.configure(); BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR); Logger.getRootLogger().setLevel(Level.INFO);
} }
/** /**