Writer2xhtml help content + XHTML template fixes
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@60 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
a1102046c3
commit
0e243c0ad7
20 changed files with 551 additions and 186 deletions
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-04-16)
|
||||
* Version 1.2 (2010-04-23)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -32,8 +32,8 @@ package writer2latex.api;
|
|||
public class ConverterFactory {
|
||||
|
||||
// Version information
|
||||
private static final String VERSION = "1.1.2";
|
||||
private static final String DATE = "2010-04-16";
|
||||
private static final String VERSION = "1.1.3";
|
||||
private static final String DATE = "2010-04-23";
|
||||
|
||||
/** Return the Writer2LaTeX version in the form
|
||||
* (major version).(minor version).(patch level)<br/>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-03-15)
|
||||
* Version 1.2 (2010-04-23)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -96,20 +96,23 @@ public class BatchConverterImpl extends BatchConverterBase {
|
|||
|
||||
org.w3c.dom.Document htmlDOM = htmlDoc.getContentDOM();
|
||||
|
||||
// Declare charset (we need this for xhtml because we have no <?xml ... ?>)
|
||||
Element meta = htmlDOM.createElement("meta");
|
||||
meta.setAttribute("http-equiv","Content-Type");
|
||||
meta.setAttribute("content","text/html; charset="+htmlDoc.getEncoding().toLowerCase());
|
||||
htmlDoc.getHeadNode().appendChild(meta);
|
||||
|
||||
// Add link to stylesheet
|
||||
if (config.xhtmlCustomStylesheet().length()>0) {
|
||||
Element htmlStyle = htmlDOM.createElement("link");
|
||||
htmlStyle.setAttribute("rel","stylesheet");
|
||||
htmlStyle.setAttribute("type","text/css");
|
||||
htmlStyle.setAttribute("media","all");
|
||||
htmlStyle.setAttribute("href",config.xhtmlCustomStylesheet());
|
||||
htmlDoc.getHeadNode().appendChild(htmlStyle);
|
||||
Element head = htmlDoc.getHeadNode();
|
||||
if (head!=null) {
|
||||
// Declare charset (we need this for xhtml because we have no <?xml ... ?>)
|
||||
Element meta = htmlDOM.createElement("meta");
|
||||
meta.setAttribute("http-equiv","Content-Type");
|
||||
meta.setAttribute("content","text/html; charset="+htmlDoc.getEncoding().toLowerCase());
|
||||
head.appendChild(meta);
|
||||
|
||||
// Add link to stylesheet
|
||||
if (config.xhtmlCustomStylesheet().length()>0) {
|
||||
Element htmlStyle = htmlDOM.createElement("link");
|
||||
htmlStyle.setAttribute("rel","stylesheet");
|
||||
htmlStyle.setAttribute("type","text/css");
|
||||
htmlStyle.setAttribute("media","all");
|
||||
htmlStyle.setAttribute("href",config.xhtmlCustomStylesheet());
|
||||
head.appendChild(htmlStyle);
|
||||
}
|
||||
}
|
||||
|
||||
// Add uplink to header and footer
|
||||
|
@ -140,7 +143,10 @@ public class BatchConverterImpl extends BatchConverterBase {
|
|||
}
|
||||
|
||||
// Add title and heading
|
||||
htmlDoc.getTitleNode().appendChild(htmlDOM.createTextNode(sHeading));
|
||||
Element title = htmlDoc.getTitleNode();
|
||||
if (title!=null) {
|
||||
title.appendChild(htmlDOM.createTextNode(sHeading));
|
||||
}
|
||||
Element h1 = htmlDOM.createElement("h1");
|
||||
htmlDoc.getContentNode().appendChild(h1);
|
||||
h1.appendChild(htmlDOM.createTextNode(sHeading));
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-04-13)
|
||||
* Version 1.2 (2010-04-23)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -259,12 +259,13 @@ public class Converter extends ConverterBase {
|
|||
|
||||
// Export styles (temp.)
|
||||
for (int i=0; i<=nOutFileIndex; i++) {
|
||||
Document dom = outFiles.get(i).getContentDOM();
|
||||
NodeList hlist = dom.getElementsByTagName("head");
|
||||
Node styles = styleCv.exportStyles(dom);
|
||||
if (styles!=null) {
|
||||
hlist.item(0).appendChild(styles);
|
||||
}
|
||||
Element head = outFiles.get(i).getHeadNode();
|
||||
if (head!=null) {
|
||||
Node styles = styleCv.exportStyles(outFiles.get(i).getContentDOM());
|
||||
if (styles!=null) {
|
||||
head.appendChild(styles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create headers & footers (if nodes are available)
|
||||
|
@ -531,66 +532,71 @@ public class Converter extends ConverterBase {
|
|||
}
|
||||
|
||||
// Add title (required by xhtml)
|
||||
String sTitle = metaData.getTitle();
|
||||
if (sTitle==null) { // use filename as fallback
|
||||
sTitle = htmlDoc.getFileName();
|
||||
}
|
||||
htmlDoc.getTitleNode().appendChild( htmlDOM.createTextNode(sTitle) );
|
||||
|
||||
// Declare charset (we need this for xhtml because we have no <?xml ... ?>)
|
||||
if (nType==XhtmlDocument.XHTML10) {
|
||||
Element meta = htmlDOM.createElement("meta");
|
||||
meta.setAttribute("http-equiv","Content-Type");
|
||||
meta.setAttribute("content","text/html; charset="+htmlDoc.getEncoding().toLowerCase());
|
||||
htmlDoc.getHeadNode().appendChild(meta);
|
||||
}
|
||||
|
||||
// Add meta data (for EPUB the meta data belongs to the .opf file)
|
||||
if (!bOPS) {
|
||||
// "Traditional" meta data
|
||||
//createMeta("generator","Writer2LaTeX "+Misc.VERSION);
|
||||
createMeta("description",metaData.getDescription());
|
||||
createMeta("keywords",metaData.getKeywords());
|
||||
|
||||
// Dublin core meta data (optional)
|
||||
// Format as recommended on dublincore.org
|
||||
// Declare meta data profile
|
||||
if (config.xhtmlUseDublinCore()) {
|
||||
htmlDoc.getHeadNode().setAttribute("profile","http://dublincore.org/documents/dcq-html/");
|
||||
// Add link to declare namespace
|
||||
Element dclink = htmlDOM.createElement("link");
|
||||
dclink.setAttribute("rel","schema.DC");
|
||||
dclink.setAttribute("href","http://purl.org/dc/elements/1.1/");
|
||||
htmlDoc.getHeadNode().appendChild(dclink);
|
||||
// Insert the actual meta data
|
||||
createMeta("DC.title",metaData.getTitle());
|
||||
// DC.subject actually contains subject+keywords, so we merge them
|
||||
String sDCSubject = "";
|
||||
if (metaData.getSubject()!=null && metaData.getSubject().length()>0) {
|
||||
sDCSubject = metaData.getSubject();
|
||||
}
|
||||
if (metaData.getKeywords()!=null && metaData.getKeywords().length()>0) {
|
||||
if (sDCSubject.length()>0) { sDCSubject+=", "; }
|
||||
sDCSubject += metaData.getKeywords();
|
||||
}
|
||||
createMeta("DC.subject",sDCSubject);
|
||||
createMeta("DC.description",metaData.getDescription());
|
||||
createMeta("DC.creator",metaData.getCreator());
|
||||
createMeta("DC.date",metaData.getDate());
|
||||
createMeta("DC.language",metaData.getLanguage());
|
||||
Element title = htmlDoc.getTitleNode();
|
||||
if (title!=null) {
|
||||
String sTitle = metaData.getTitle();
|
||||
if (sTitle==null) { // use filename as fallback
|
||||
sTitle = htmlDoc.getFileName();
|
||||
}
|
||||
title.appendChild( htmlDOM.createTextNode(sTitle) );
|
||||
}
|
||||
|
||||
// Add link to stylesheet, if producing nomral XHTML
|
||||
if (!bOPS && config.xhtmlCustomStylesheet().length()>0) {
|
||||
Element htmlStyle = htmlDOM.createElement("link");
|
||||
htmlStyle.setAttribute("rel","stylesheet");
|
||||
htmlStyle.setAttribute("type","text/css");
|
||||
htmlStyle.setAttribute("media","all");
|
||||
htmlStyle.setAttribute("href",config.xhtmlCustomStylesheet());
|
||||
htmlDoc.getHeadNode().appendChild(htmlStyle);
|
||||
}
|
||||
/* later....
|
||||
|
||||
Element head = htmlDoc.getHeadNode();
|
||||
if (head!=null) {
|
||||
// Declare charset (we need this for xhtml because we have no <?xml ... ?>)
|
||||
if (nType==XhtmlDocument.XHTML10) {
|
||||
Element meta = htmlDOM.createElement("meta");
|
||||
meta.setAttribute("http-equiv","Content-Type");
|
||||
meta.setAttribute("content","text/html; charset="+htmlDoc.getEncoding().toLowerCase());
|
||||
head.appendChild(meta);
|
||||
}
|
||||
|
||||
// Add meta data (for EPUB the meta data belongs to the .opf file)
|
||||
if (!bOPS) {
|
||||
// "Traditional" meta data
|
||||
//createMeta("generator","Writer2LaTeX "+Misc.VERSION);
|
||||
createMeta(head,"description",metaData.getDescription());
|
||||
createMeta(head,"keywords",metaData.getKeywords());
|
||||
|
||||
// Dublin core meta data (optional)
|
||||
// Format as recommended on dublincore.org
|
||||
// Declare meta data profile
|
||||
if (config.xhtmlUseDublinCore()) {
|
||||
head.setAttribute("profile","http://dublincore.org/documents/dcq-html/");
|
||||
// Add link to declare namespace
|
||||
Element dclink = htmlDOM.createElement("link");
|
||||
dclink.setAttribute("rel","schema.DC");
|
||||
dclink.setAttribute("href","http://purl.org/dc/elements/1.1/");
|
||||
head.appendChild(dclink);
|
||||
// Insert the actual meta data
|
||||
createMeta(head,"DC.title",metaData.getTitle());
|
||||
// DC.subject actually contains subject+keywords, so we merge them
|
||||
String sDCSubject = "";
|
||||
if (metaData.getSubject()!=null && metaData.getSubject().length()>0) {
|
||||
sDCSubject = metaData.getSubject();
|
||||
}
|
||||
if (metaData.getKeywords()!=null && metaData.getKeywords().length()>0) {
|
||||
if (sDCSubject.length()>0) { sDCSubject+=", "; }
|
||||
sDCSubject += metaData.getKeywords();
|
||||
}
|
||||
createMeta(head,"DC.subject",sDCSubject);
|
||||
createMeta(head,"DC.description",metaData.getDescription());
|
||||
createMeta(head,"DC.creator",metaData.getCreator());
|
||||
createMeta(head,"DC.date",metaData.getDate());
|
||||
createMeta(head,"DC.language",metaData.getLanguage());
|
||||
}
|
||||
}
|
||||
|
||||
// Add link to stylesheet, if producing nomral XHTML
|
||||
if (!bOPS && config.xhtmlCustomStylesheet().length()>0) {
|
||||
Element htmlStyle = htmlDOM.createElement("link");
|
||||
htmlStyle.setAttribute("rel","stylesheet");
|
||||
htmlStyle.setAttribute("type","text/css");
|
||||
htmlStyle.setAttribute("media","all");
|
||||
htmlStyle.setAttribute("href",config.xhtmlCustomStylesheet());
|
||||
head.appendChild(htmlStyle);
|
||||
}
|
||||
/* later....
|
||||
if (nSplit>0 && !config.xhtmlIgnoreStyles()) {
|
||||
Element htmlStyle = htmlDOM.createElement("link");
|
||||
htmlStyle.setAttribute("rel","stylesheet");
|
||||
|
@ -599,18 +605,18 @@ public class Converter extends ConverterBase {
|
|||
htmlStyle.setAttribute("href",oooDoc.getName()+"-styles.css");
|
||||
htmlHead.appendChild(htmlStyle);
|
||||
}*/
|
||||
// Note: For single output file, styles are exported to the doc at the end.
|
||||
// Note: For single output file, styles are exported to the doc at the end.
|
||||
|
||||
// Add link to included style sheet if producing OPS content
|
||||
if (bOPS && styleSheet!=null) {
|
||||
Element sty = htmlDOM.createElement("link");
|
||||
sty.setAttribute("rel", "stylesheet");
|
||||
sty.setAttribute("type", "text/css");
|
||||
sty.setAttribute("media", "all");
|
||||
sty.setAttribute("href", styleSheet.getFileName());
|
||||
htmlDoc.getHeadNode().appendChild(sty);
|
||||
// Add link to included style sheet if producing OPS content
|
||||
if (bOPS && styleSheet!=null) {
|
||||
Element sty = htmlDOM.createElement("link");
|
||||
sty.setAttribute("rel", "stylesheet");
|
||||
sty.setAttribute("type", "text/css");
|
||||
sty.setAttribute("media", "all");
|
||||
sty.setAttribute("href", styleSheet.getFileName());
|
||||
head.appendChild(sty);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Recreate nested sections, if any
|
||||
if (!textCv.sections.isEmpty()) {
|
||||
|
@ -710,12 +716,12 @@ public class Converter extends ConverterBase {
|
|||
}
|
||||
|
||||
|
||||
private void createMeta(String sName, String sValue) {
|
||||
private void createMeta(Element head, String sName, String sValue) {
|
||||
if (sValue==null) { return; }
|
||||
Element meta = htmlDOM.createElement("meta");
|
||||
meta.setAttribute("name",sName);
|
||||
meta.setAttribute("content",sValue);
|
||||
htmlDoc.getHeadNode().appendChild(meta);
|
||||
head.appendChild(meta);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.2 (2010-03-15)
|
||||
* Version 1.2 (2010-04-23)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -116,27 +116,7 @@ public class XhtmlDocument extends DOMDocument {
|
|||
public XhtmlDocument(String name, int nType) {
|
||||
super(name,sExtension[nType]);
|
||||
this.nType = nType;
|
||||
// Define publicId and systemId
|
||||
String sPublicId = null;
|
||||
String sSystemId = null;
|
||||
switch (nType) {
|
||||
case XHTML10 :
|
||||
sPublicId = "-//W3C//DTD XHTML 1.0 Strict//EN";
|
||||
sSystemId = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
|
||||
break;
|
||||
case XHTML11 :
|
||||
sPublicId = "-//W3C//DTD XHTML 1.1//EN";
|
||||
sSystemId = "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";
|
||||
break;
|
||||
case XHTML_MATHML :
|
||||
case XHTML_MATHML_XSL :
|
||||
sPublicId = "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN";
|
||||
sSystemId = "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd";
|
||||
//sSystemId = "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd"; (old version)
|
||||
/* An alternative is to use XHTML + MathML + SVG:
|
||||
sPublicId = "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN",
|
||||
sSystemId = "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"); */
|
||||
}
|
||||
|
||||
|
||||
// create DOM
|
||||
Document contentDOM = null;
|
||||
|
@ -144,7 +124,8 @@ public class XhtmlDocument extends DOMDocument {
|
|||
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = builderFactory.newDocumentBuilder();
|
||||
DOMImplementation domImpl = builder.getDOMImplementation();
|
||||
DocumentType doctype = domImpl.createDocumentType("html", sPublicId, sSystemId);
|
||||
String[] sDocType = getDoctypeStrings();
|
||||
DocumentType doctype = domImpl.createDocumentType("html", sDocType[0], sDocType[1]);
|
||||
contentDOM = domImpl.createDocument("http://www.w3.org/1999/xhtml","html",doctype);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
|
@ -216,24 +197,67 @@ public class XhtmlDocument extends DOMDocument {
|
|||
}
|
||||
|
||||
public void readFromTemplate(XhtmlDocument template) {
|
||||
// Remove all current child nodes
|
||||
Element root = getContentDOM().getDocumentElement();
|
||||
Node child = root.getFirstChild();
|
||||
while (child!=null) {
|
||||
root.removeChild(child);
|
||||
child = root.getFirstChild();
|
||||
}
|
||||
// create a new DOM
|
||||
Document templateDOM = template.getContentDOM();
|
||||
Document newDOM = null;
|
||||
try {
|
||||
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = builderFactory.newDocumentBuilder();
|
||||
DOMImplementation domImpl = builder.getDOMImplementation();
|
||||
String[] sDocType = getDoctypeStrings();
|
||||
DocumentType doctype = domImpl.createDocumentType("html", sDocType[0], sDocType[1]);
|
||||
newDOM = domImpl.createDocument("http://www.w3.org/1999/xhtml",
|
||||
templateDOM.getDocumentElement().getTagName(),doctype);
|
||||
setContentDOM(newDOM);
|
||||
|
||||
// Import attributes on root element
|
||||
Element templateRoot = templateDOM.getDocumentElement();
|
||||
Element newRoot = newDOM.getDocumentElement();
|
||||
NamedNodeMap attributes = templateRoot.getAttributes();
|
||||
int nCount = attributes.getLength();
|
||||
for (int i=0; i<nCount; i++) {
|
||||
Node attrNode = attributes.item(i);
|
||||
newRoot.setAttribute(attrNode.getNodeName(), attrNode.getNodeValue());
|
||||
}
|
||||
|
||||
// Import all child nodes from template
|
||||
NodeList children = templateRoot.getChildNodes();
|
||||
int nLen = children.getLength();
|
||||
for (int i=0; i<nLen; i++) {
|
||||
newRoot.appendChild(getContentDOM().importNode(children.item(i),true));
|
||||
}
|
||||
|
||||
// Import all child nodes from template
|
||||
Element templateRoot = template.getContentDOM().getDocumentElement();
|
||||
NodeList children = templateRoot.getChildNodes();
|
||||
int nLen = children.getLength();
|
||||
for (int i=0; i<nLen; i++) {
|
||||
root.appendChild(getContentDOM().importNode(children.item(i),true));
|
||||
// get the entry point nodes
|
||||
collectNodes();
|
||||
}
|
||||
|
||||
// get the entry point nodes
|
||||
collectNodes();
|
||||
catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getDoctypeStrings() {
|
||||
// Define publicId and systemId
|
||||
String sPublicId = null;
|
||||
String sSystemId = null;
|
||||
switch (nType) {
|
||||
case XHTML10 :
|
||||
sPublicId = "-//W3C//DTD XHTML 1.0 Strict//EN";
|
||||
sSystemId = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
|
||||
break;
|
||||
case XHTML11 :
|
||||
sPublicId = "-//W3C//DTD XHTML 1.1//EN";
|
||||
sSystemId = "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";
|
||||
break;
|
||||
case XHTML_MATHML :
|
||||
case XHTML_MATHML_XSL :
|
||||
sPublicId = "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN";
|
||||
sSystemId = "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd";
|
||||
//sSystemId = "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd"; (old version)
|
||||
/* An alternative is to use XHTML + MathML + SVG:
|
||||
sPublicId = "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN",
|
||||
sSystemId = "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"); */
|
||||
}
|
||||
return new String[] { sPublicId, sSystemId };
|
||||
}
|
||||
|
||||
private void collectNodes(Element elm) {
|
||||
|
@ -275,8 +299,8 @@ public class XhtmlDocument extends DOMDocument {
|
|||
|
||||
Element elm = getContentDOM().getDocumentElement();
|
||||
collectNodes(elm);
|
||||
if (contentNode==null) { contentNode = bodyNode; }
|
||||
if (titleNode==null) {
|
||||
if (contentNode==null) { contentNode = bodyNode!=null ? bodyNode : elm; }
|
||||
if (headNode!=null && titleNode==null) {
|
||||
titleNode = getContentDOM().createElement("title");
|
||||
headNode.appendChild(titleNode);
|
||||
}
|
||||
|
@ -361,8 +385,8 @@ public class XhtmlDocument extends DOMDocument {
|
|||
// Add a BOM if the user desires so
|
||||
if (bAddBOM) { osw.write("\uFEFF"); }
|
||||
|
||||
// Omit xml prolog for pure xhtml documents (to be browser safe)
|
||||
if (nType==XHTML_MATHML || nType==XHTML_MATHML_XSL) {
|
||||
// Omit xml prolog for pure xhtml 1.0 strict documents (to be browser safe)
|
||||
if (nType!=XHTML10) {
|
||||
osw.write("<?xml version=\"1.0\" encoding=\""+sEncoding+"\" ?>\n");
|
||||
}
|
||||
// Either specify doctype or xsl transformation (the user may require
|
||||
|
@ -374,11 +398,14 @@ public class XhtmlDocument extends DOMDocument {
|
|||
osw.write("<?xml-stylesheet type=\"text/xsl\" href=\""+sXsltPath+sSlash+"pmathml.xsl\"?>\n");
|
||||
}
|
||||
else if (!bNoDoctype) {
|
||||
osw.write("<!DOCTYPE html PUBLIC \"");
|
||||
osw.write(getContentDOM().getDoctype().getPublicId());
|
||||
osw.write("\" \"");
|
||||
osw.write(getContentDOM().getDoctype().getSystemId());
|
||||
osw.write("\">\n");
|
||||
DocumentType docType = getContentDOM().getDoctype();
|
||||
if (docType!=null) {
|
||||
osw.write("<!DOCTYPE html PUBLIC \"");
|
||||
osw.write(docType.getPublicId());
|
||||
osw.write("\" \"");
|
||||
osw.write(docType.getSystemId());
|
||||
osw.write("\">\n");
|
||||
}
|
||||
}
|
||||
Element doc = getContentDOM().getDocumentElement();
|
||||
optimize(doc,null,null);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue