Refactor step.

This commit is contained in:
Christian P. MOMON 2016-09-08 02:33:23 +02:00
parent 87ace3a70a
commit 3b2de97563
8 changed files with 355 additions and 150 deletions

View file

@ -24,7 +24,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import fr.devinsy.xidyn.data.TagDataListById;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.utils.XidynUtils;
@ -197,38 +196,4 @@ public class DomPresenter implements Presenter
{
}
/**
*
* @param doc
* @param data
* @return
* @throws Exception
*/
public static StringBuffer dynamize(final Document doc, final TagDataListById data) throws Exception
{
StringBuffer result;
result = DomPresenterCore.dynamize(doc, data);
//
return result;
}
/**
*
* @param doc
* @param data
* @return
* @throws Exception
*/
public static StringBuffer dynamize(final Document doc, final TagDataManager data) throws Exception
{
StringBuffer result;
result = DomPresenterCore.dynamize(doc, data);
//
return result;
}
}

View file

@ -262,34 +262,4 @@ public class FilePresenter extends StringPresenter
}
}
}
/**
* Dynamize a file without data.
*/
public static StringBuffer dynamize(final String filePathname) throws Exception
{
StringBuffer result;
FilePresenter presenter = new FilePresenter(filePathname);
result = presenter.dynamize((TagDataManager) null);
//
return (result);
}
/**
* Dynamize a file.
*/
public static StringBuffer dynamize(final String filePathname, final TagDataManager datas) throws Exception
{
StringBuffer result;
FilePresenter presenter = new FilePresenter(filePathname);
result = presenter.dynamize(datas);
//
return (result);
}
}

View file

@ -21,6 +21,8 @@ package fr.devinsy.xidyn.presenters;
import java.io.File;
import java.net.URL;
import org.w3c.dom.Document;
import fr.devinsy.xidyn.data.TagDataManager;
/**
@ -32,6 +34,21 @@ public class GenericPresenter implements Presenter
private Presenter presenter;
/**
*
*/
public GenericPresenter(final Document source)
{
if (source == null)
{
throw new NullPointerException("source is null");
}
else
{
this.presenter = PresenterFactory.create(source);
}
}
/**
*
*/
@ -43,7 +60,7 @@ public class GenericPresenter implements Presenter
}
else
{
this.presenter = PresenterFactory.get(source);
this.presenter = PresenterFactory.create(source);
}
}
@ -58,7 +75,7 @@ public class GenericPresenter implements Presenter
}
else
{
this.presenter = PresenterFactory.get(source);
this.presenter = PresenterFactory.create(source);
}
}
@ -73,7 +90,7 @@ public class GenericPresenter implements Presenter
}
else
{
this.presenter = PresenterFactory.get(source);
this.presenter = PresenterFactory.create(source);
}
}
@ -147,6 +164,22 @@ public class GenericPresenter implements Presenter
return result;
}
/**
*
* @param source
*/
public void setSource(final Document source)
{
if (source == null)
{
throw new NullPointerException("source is null");
}
else
{
this.presenter = PresenterFactory.create(source);
}
}
/**
*
* @param source
@ -159,7 +192,7 @@ public class GenericPresenter implements Presenter
}
else
{
this.presenter = PresenterFactory.get(source);
this.presenter = PresenterFactory.create(source);
}
}
@ -175,7 +208,7 @@ public class GenericPresenter implements Presenter
}
else
{
this.presenter = PresenterFactory.get(source);
this.presenter = PresenterFactory.create(source);
}
}
@ -191,7 +224,7 @@ public class GenericPresenter implements Presenter
}
else
{
this.presenter = PresenterFactory.get(source);
this.presenter = PresenterFactory.create(source);
}
}

View file

@ -23,20 +23,170 @@ import java.net.URL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import fr.devinsy.xidyn.utils.cache.Cache;
/**
*
*/
public class PresenterFactory
{
/**
* http://thecodersbreakfast.net/index.php?post/2008/02/25/26-de-la-bonne-
* implementation-du-singleton-en-java
*/
private static class SingletonHolder
{
private final static PresenterFactory INSTANCE = new PresenterFactory();
}
private static Logger logger = LoggerFactory.getLogger(PresenterFactory.class);
private Cache<Presenter> cache;
/**
*
*/
private PresenterFactory()
{
this.cache = new Cache<Presenter>();
}
/**
*
*/
public void clear()
{
this.cache.clear();
}
/**
*
* @param source
* @return
*/
public static Presenter get(final File source)
public Presenter get(final Document source)
{
Presenter result;
result = this.cache.get(source);
if (result == null)
{
result = create(source);
this.cache.put(source, result);
}
//
return result;
}
/**
*
* @param source
* @return
*/
public Presenter get(final File source)
{
Presenter result;
result = this.cache.get(source);
if (result == null)
{
result = create(source);
this.cache.put(source, 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
* @return
*/
public Presenter get(final URL source)
{
Presenter result;
result = this.cache.get(source);
if (result == null)
{
result = create(source);
this.cache.put(source, result);
}
//
return result;
}
/**
*
* @return
*/
public int size()
{
int result;
result = this.cache.size();
//
return result;
}
/**
*
* @param source
* @return
*/
public static Presenter create(final Document source)
{
Presenter result;
if (source == null)
{
result = null;
}
else
{
result = new DomPresenter(source);
}
//
return result;
}
/**
*
* @param source
* @return
*/
public static Presenter create(final File source)
{
Presenter result;
@ -58,7 +208,7 @@ public class PresenterFactory
* @param source
* @return
*/
public static Presenter get(final String source)
public static Presenter create(final String source)
{
Presenter result;
@ -99,7 +249,7 @@ public class PresenterFactory
* @param source
* @return
*/
public static Presenter get(final URL source)
public static Presenter create(final URL source)
{
Presenter result;
@ -115,4 +265,13 @@ public class PresenterFactory
//
return result;
}
/**
*
* @return
*/
public static PresenterFactory instance()
{
return SingletonHolder.INSTANCE;
}
}

View file

@ -0,0 +1,152 @@
/**
* Copyright (C) 2006-2016 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.presenters;
import java.io.File;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import fr.devinsy.xidyn.data.TagDataListById;
import fr.devinsy.xidyn.data.TagDataManager;
/**
*
*/
public class PresenterUtils
{
private static Logger logger = LoggerFactory.getLogger(PresenterUtils.class);
/**
*
*/
private PresenterUtils()
{
}
/**
*
* @param doc
* @param data
* @return
* @throws Exception
*/
public static StringBuffer dynamize(final Document doc, final TagDataListById data) throws Exception
{
StringBuffer result;
result = DomPresenterCore.dynamize(doc, data);
//
return result;
}
/**
*
* @param doc
* @param data
* @return
* @throws Exception
*/
public static StringBuffer dynamize(final Document doc, final TagDataManager data) throws Exception
{
StringBuffer result;
result = DomPresenterCore.dynamize(doc, data);
//
return result;
}
/**
* Dynamize a file without data.
*/
public static StringBuffer dynamize(final File source) throws Exception
{
StringBuffer result;
FilePresenter presenter = new FilePresenter(source);
result = presenter.dynamize((TagDataManager) null);
//
return (result);
}
/**
* Dynamize a file.
*/
public static StringBuffer dynamize(final File source, final TagDataManager datas) throws Exception
{
StringBuffer result;
FilePresenter presenter = new FilePresenter(source);
result = presenter.dynamize(datas);
//
return (result);
}
/**
* Dynamize a string with HTML in, or with file path name in, or with URL
* in.
*/
public static StringBuffer dynamize(final String source, final TagDataManager datas) throws Exception
{
StringBuffer result;
Presenter presenter = PresenterFactory.create(source);
result = presenter.dynamize(datas);
//
return (result);
}
/**
*
* @param source
* @return
*/
public static boolean hasHtmlTag(final String source)
{
boolean result;
if (source == null)
{
result = false;
}
else
{
if (source.matches("<[hH][tT][mM][lL]>"))
{
result = true;
}
else
{
result = false;
}
}
//
return result;
}
}

View file

@ -232,48 +232,4 @@ public class StringPresenter implements Presenter
{
// Nothing to do.
}
/**
* Dynamize a string with HTML in.
*/
public static StringBuffer dynamize(final String html, final TagDataManager datas) throws Exception
{
StringBuffer result;
StringPresenter presenter = new StringPresenter(html);
result = presenter.dynamize(datas);
//
return (result);
}
/**
*
* @param source
* @return
*/
public static boolean hasHtmlTag(final String source)
{
boolean result;
if (source == null)
{
result = false;
}
else
{
if (source.matches("<[hH][tT][mM][lL]>"))
{
result = true;
}
else
{
result = false;
}
}
//
return result;
}
}

View file

@ -212,7 +212,7 @@ public class TranslatorPresenter implements Presenter
if (language == null)
{
//
result = PresenterFactory.get(this.defaultSource);
result = PresenterFactory.create(this.defaultSource);
if (result.isAvailable())
{
@ -226,7 +226,7 @@ public class TranslatorPresenter implements Presenter
else
{
String adaptedSource = FileTools.addBeforeExtension(this.defaultSource, "-" + language);
result = PresenterFactory.get(adaptedSource);
result = PresenterFactory.create(adaptedSource);
if (result.isAvailable())
{

View file

@ -350,34 +350,4 @@ public class URLPresenter extends StringPresenter
}
}
}
/**
* Dynamize a file without data.
*/
public static StringBuffer dynamize(final String filePathname) throws Exception
{
StringBuffer result;
URLPresenter presenter = new URLPresenter(filePathname);
result = presenter.dynamize((TagDataManager) null);
//
return (result);
}
/**
* Dynamize a file.
*/
public static StringBuffer dynamize(final String filePathname, final TagDataManager datas) throws Exception
{
StringBuffer result;
URLPresenter presenter = new URLPresenter(filePathname);
result = presenter.dynamize(datas);
//
return (result);
}
}