Normalize indentation.

This commit is contained in:
Christian P. MOMON 2013-07-01 01:34:26 +02:00
parent 68006d388d
commit a0c4e3dcdf

View file

@ -13,7 +13,8 @@ import org.slf4j.LoggerFactory;
/** /**
* *
*/ */
public class URLPresenter extends DomPresenter { public class URLPresenter extends DomPresenter
{
static private Logger logger = LoggerFactory.getLogger(URLPresenter.class); static private Logger logger = LoggerFactory.getLogger(URLPresenter.class);
private String sourcePathname; private String sourcePathname;
@ -24,7 +25,8 @@ public class URLPresenter extends DomPresenter {
/** /**
* *
*/ */
public URLPresenter() { public URLPresenter()
{
setSource((URL) null); setSource((URL) null);
} }
@ -32,21 +34,24 @@ public class URLPresenter extends DomPresenter {
* @throws MalformedURLException * @throws MalformedURLException
* *
*/ */
public URLPresenter(final String source) { public URLPresenter(final String source)
{
setSource(source); setSource(source);
} }
/** /**
* *
*/ */
public URLPresenter(final URL source) { public URLPresenter(final URL source)
{
setSource(source); setSource(source);
} }
/** /**
* No need to be synchronized. * No need to be synchronized.
*/ */
public StringBuffer dynamize() throws Exception { public StringBuffer dynamize() throws Exception
{
StringBuffer result; StringBuffer result;
result = dynamize((TagDataListById) null); result = dynamize((TagDataListById) null);
@ -59,31 +64,40 @@ public class URLPresenter extends DomPresenter {
* No need to be synchronized. * No need to be synchronized.
*/ */
@Override @Override
public StringBuffer dynamize(final TagDataListById datas) throws Exception { public StringBuffer dynamize(final TagDataListById datas) throws Exception
{
StringBuffer result; StringBuffer result;
logger.info("dynamize URL [" + this.sourcePathname + "]"); logger.info("dynamize URL [" + this.sourcePathname + "]");
if (this.sourceURL == null) { if (this.sourceURL == null)
{
String errorMessage = "source file defined but not found (" + this.sourcePathname + ")"; String errorMessage = "source file defined but not found (" + this.sourcePathname + ")";
logger.error(errorMessage); logger.error(errorMessage);
result = null; result = null;
throw new Exception(errorMessage); throw new Exception(errorMessage);
} else if (datas == null) { }
else if (datas == null)
{
result = new StringBuffer(sourceURL.openConnection().getContentLength()); result = new StringBuffer(sourceURL.openConnection().getContentLength());
BufferedReader in = new BufferedReader(new InputStreamReader(this.sourceURL.openStream())); BufferedReader in = new BufferedReader(new InputStreamReader(this.sourceURL.openStream()));
String line; String line;
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null)
{
result.append(line); result.append(line);
} }
in.close(); in.close();
} else { }
else
{
long lastModified = sourceURL.openConnection().getLastModified(); long lastModified = sourceURL.openConnection().getLastModified();
if ((this.doc == null) || (this.sourceFileTime != lastModified)) { if ((this.doc == null) || (this.sourceFileTime != lastModified))
{
this.sourceFileTime = lastModified; this.sourceFileTime = lastModified;
this.doc = Presenter.buildTree(this.sourceURL.openStream()); this.doc = Presenter.buildTree(this.sourceURL.openStream());
this.doctype = "<!DOCTYPE HTML>"; // TODO Made generic. this.doctype = "<!DOCTYPE HTML>"; // TODO Made generic.
if (this.doc != null) { if (this.doc != null)
{
Presenter.addMetaTag(doc, "generator", "XID 0.0"); Presenter.addMetaTag(doc, "generator", "XID 0.0");
} }
} }
@ -105,7 +119,8 @@ public class URLPresenter extends DomPresenter {
* *
*/ */
@Override @Override
public StringBuffer dynamize(final TagDataManager datas) throws Exception { public StringBuffer dynamize(final TagDataManager datas) throws Exception
{
return (dynamize(datas.getIdsDataById())); return (dynamize(datas.getIdsDataById()));
} }
@ -113,7 +128,8 @@ public class URLPresenter extends DomPresenter {
* *
*/ */
@Override @Override
public String getSource() { public String getSource()
{
String result; String result;
result = this.sourceURL.toString(); result = this.sourceURL.toString();
@ -125,18 +141,27 @@ public class URLPresenter extends DomPresenter {
/** /**
* *
*/ */
public void setSource(final String source) { public void setSource(final String source)
{
URL url; URL url;
if (source == null) { if (source == null)
{
url = null; url = null;
} else if (source.matches(".+://.+")) { }
try { else if (source.matches(".+://.+"))
{
try
{
url = new URL(source); url = new URL(source);
} catch (final MalformedURLException exception) { }
catch (final MalformedURLException exception)
{
logger.warn("UNKNOWN PROTOCOL [" + source + "]"); logger.warn("UNKNOWN PROTOCOL [" + source + "]");
url = null; url = null;
} }
} else { }
else
{
url = URLPresenter.class.getResource(source); url = URLPresenter.class.getResource(source);
} }
@ -148,10 +173,14 @@ public class URLPresenter extends DomPresenter {
* @param source * @param source
* @throws MalformedURLException * @throws MalformedURLException
*/ */
public void setSource(final URL source) { public void setSource(final URL source)
if (source == null) { {
if (source == null)
{
this.sourcePathname = null; this.sourcePathname = null;
} else { }
else
{
this.sourcePathname = source.toString(); this.sourcePathname = source.toString();
} }
this.sourceURL = source; this.sourceURL = source;
@ -163,7 +192,8 @@ public class URLPresenter extends DomPresenter {
/** /**
* Dynamize a file without data. * Dynamize a file without data.
*/ */
static public StringBuffer dynamize(final String filePathname) throws Exception { static public StringBuffer dynamize(final String filePathname) throws Exception
{
StringBuffer result; StringBuffer result;
URLPresenter presenter = new URLPresenter(filePathname); URLPresenter presenter = new URLPresenter(filePathname);
@ -177,7 +207,8 @@ public class URLPresenter extends DomPresenter {
/** /**
* Dynamize a file. * Dynamize a file.
*/ */
static public StringBuffer dynamize(final String filePathname, final TagDataManager datas) throws Exception { static public StringBuffer dynamize(final String filePathname, final TagDataManager datas) throws Exception
{
StringBuffer result; StringBuffer result;
URLPresenter presenter = new URLPresenter(filePathname); URLPresenter presenter = new URLPresenter(filePathname);
@ -194,7 +225,8 @@ public class URLPresenter extends DomPresenter {
* @return * @return
* @throws Exception * @throws Exception
*/ */
static public String getDoctype(final String filePathname) throws Exception { static public String getDoctype(final String filePathname) throws Exception
{
String result; String result;
// //
@ -205,9 +237,12 @@ public class URLPresenter extends DomPresenter {
logger.info("doctype=[" + doctype + "]"); logger.info("doctype=[" + doctype + "]");
// //
if ((doctype.startsWith("<!DOCTYPE")) || (doctype.startsWith("<!doctype"))) { if ((doctype.startsWith("<!DOCTYPE")) || (doctype.startsWith("<!doctype")))
{
result = doctype; result = doctype;
} else { }
else
{
result = null; result = null;
} }