Add doctype management.
This commit is contained in:
parent
cf6c2c775a
commit
394f69e66b
4 changed files with 47 additions and 8 deletions
Binary file not shown.
Binary file not shown.
|
@ -1,7 +1,7 @@
|
||||||
package fr.devinsy.xid;
|
package fr.devinsy.xid;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import org.w3c.dom.*;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,6 +17,7 @@ public class FilePresenter extends DomPresenter
|
||||||
|
|
||||||
protected String sourceFilePathname;
|
protected String sourceFilePathname;
|
||||||
protected long sourceFileTime;
|
protected long sourceFileTime;
|
||||||
|
protected String doctype;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@ -26,6 +27,7 @@ public class FilePresenter extends DomPresenter
|
||||||
this.sourceFilePathname = null;
|
this.sourceFilePathname = null;
|
||||||
this.sourceFileTime = 0;
|
this.sourceFileTime = 0;
|
||||||
this.doc = null;
|
this.doc = null;
|
||||||
|
this.doctype = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,6 +39,7 @@ public class FilePresenter extends DomPresenter
|
||||||
this.sourceFilePathname = filePathname;
|
this.sourceFilePathname = filePathname;
|
||||||
this.sourceFileTime = 0;
|
this.sourceFileTime = 0;
|
||||||
this.doc = null;
|
this.doc = null;
|
||||||
|
this.doctype = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +51,7 @@ public class FilePresenter extends DomPresenter
|
||||||
this.sourceFilePathname = filePathname;
|
this.sourceFilePathname = filePathname;
|
||||||
this.sourceFileTime = 0;
|
this.sourceFileTime = 0;
|
||||||
this.doc = null;
|
this.doc = null;
|
||||||
|
this.doctype = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,10 +85,10 @@ public class FilePresenter extends DomPresenter
|
||||||
{
|
{
|
||||||
StringBuffer result;
|
StringBuffer result;
|
||||||
|
|
||||||
String sourceFilePath = this.sourceFilePathname;
|
logger.info("doXid for file [" + this.sourceFilePathname + "]");
|
||||||
|
|
||||||
// Get the good tree.
|
// Get the good tree.
|
||||||
File source = new File (sourceFilePath);
|
File source = new File (this.sourceFilePathname);
|
||||||
|
|
||||||
if (source == null)
|
if (source == null)
|
||||||
{
|
{
|
||||||
|
@ -95,7 +99,7 @@ public class FilePresenter extends DomPresenter
|
||||||
}
|
}
|
||||||
else if (!source.exists ())
|
else if (!source.exists ())
|
||||||
{
|
{
|
||||||
String errorMessage = "source file defined but not found (" + sourceFilePath + ")";
|
String errorMessage = "source file defined but not found (" + this.sourceFilePathname + ")";
|
||||||
logger.error (errorMessage);
|
logger.error (errorMessage);
|
||||||
result = null;
|
result = null;
|
||||||
throw new Exception (errorMessage);
|
throw new Exception (errorMessage);
|
||||||
|
@ -104,8 +108,8 @@ public class FilePresenter extends DomPresenter
|
||||||
(this.sourceFileTime != source.lastModified ()))
|
(this.sourceFileTime != source.lastModified ()))
|
||||||
{
|
{
|
||||||
this.sourceFileTime = source.lastModified ();
|
this.sourceFileTime = source.lastModified ();
|
||||||
this.doc = Presenter.fileToTree (sourceFilePath);
|
this.doc = Presenter.fileToTree (this.sourceFilePathname);
|
||||||
|
this.doctype = getDoctype(this.sourceFilePathname);
|
||||||
if (this.doc != null)
|
if (this.doc != null)
|
||||||
{
|
{
|
||||||
Presenter.addMetaTag (doc, "generator", "XID 0.0");
|
Presenter.addMetaTag (doc, "generator", "XID 0.0");
|
||||||
|
@ -114,6 +118,9 @@ public class FilePresenter extends DomPresenter
|
||||||
|
|
||||||
// Build the web page.
|
// Build the web page.
|
||||||
StringWriter htmlCode = new StringWriter(Presenter.estimatedTargetLength(source.length()));
|
StringWriter htmlCode = new StringWriter(Presenter.estimatedTargetLength(source.length()));
|
||||||
|
htmlCode.write(doctype);
|
||||||
|
htmlCode.write('\n');
|
||||||
|
|
||||||
Presenter.doXid (htmlCode, doc, datas);
|
Presenter.doXid (htmlCode, doc, datas);
|
||||||
result = htmlCode.getBuffer();
|
result = htmlCode.getBuffer();
|
||||||
|
|
||||||
|
@ -122,6 +129,33 @@ public class FilePresenter extends DomPresenter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static public String getDoctype (String filePathname) throws Exception
|
||||||
|
{
|
||||||
|
String result;
|
||||||
|
|
||||||
|
//
|
||||||
|
BufferedReader in = new BufferedReader (new FileReader (filePathname));
|
||||||
|
String doctype = in.readLine();
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
logger.info("doctype=[" + doctype + "]");
|
||||||
|
|
||||||
|
//
|
||||||
|
if ((doctype.startsWith ("<!DOCTYPE")) ||
|
||||||
|
(doctype.startsWith ("<!doctype")))
|
||||||
|
{
|
||||||
|
result = doctype;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Xid a file without data.
|
* Xid a file without data.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -99,6 +99,11 @@ public class StringPresenter extends DomPresenter
|
||||||
}
|
}
|
||||||
|
|
||||||
StringWriter htmlCode = new StringWriter(Presenter.estimatedTargetLength(this.html.length()));
|
StringWriter htmlCode = new StringWriter(Presenter.estimatedTargetLength(this.html.length()));
|
||||||
|
if ((this.html.startsWith ("<!DOCTYPE")) ||
|
||||||
|
(this.html.startsWith ("<!doctype")))
|
||||||
|
{
|
||||||
|
htmlCode.write(this.html.substring(0, this.html.indexOf('>')));
|
||||||
|
}
|
||||||
Presenter.doXid (htmlCode, doc, datas);
|
Presenter.doXid (htmlCode, doc, datas);
|
||||||
StringBuffer htmlTarget = htmlCode.getBuffer();
|
StringBuffer htmlTarget = htmlCode.getBuffer();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue