Some new Writer2xhtml options

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@48 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2010-03-05 08:43:18 +00:00
parent ccc8741301
commit 5311ac0b6b
20 changed files with 365 additions and 186 deletions

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2009 by Henrik Just
* Copyright: 2002-2010 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.2 (2009-09-05)
* Version 1.2 (2010-03-02)
*
*/
@ -90,11 +90,7 @@ public class BatchConverterImpl extends BatchConverterBase {
public OutputFile createIndexFile(String sHeading, IndexPageEntry[] entries) {
// Create the index page (with header/footer or from template)
XhtmlDocument htmlDoc = new XhtmlDocument("index",XhtmlDocument.XHTML10);
htmlDoc.setEncoding(config.xhtmlEncoding());
htmlDoc.setNoDoctype(config.xhtmlNoDoctype());
htmlDoc.setAddBOM(config.xhtmlAddBOM());
htmlDoc.setUseNamedEntities(config.useNamedEntities());
htmlDoc.setHexadecimalEntities(config.hexadecimalEntities());
htmlDoc.setConfig(config);
if (template!=null) { htmlDoc.readFromTemplate(template); }
else { htmlDoc.createHeaderFooter(); }

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-02-26)
* Version 1.2 (2010-03-02)
*
*/
@ -442,12 +442,7 @@ public class Converter extends ConverterBase {
public Element nextOutFile() {
if (nOutFileIndex>=0) { textCv.insertFootnotes(htmlDoc.getContentNode()); }
htmlDoc = new XhtmlDocument(getOutFileName(++nOutFileIndex,false),nType);
htmlDoc.setEncoding(config.xhtmlEncoding());
htmlDoc.setNoDoctype(config.xhtmlNoDoctype());
htmlDoc.setAddBOM(config.xhtmlAddBOM());
htmlDoc.setUseNamedEntities(config.useNamedEntities());
htmlDoc.setHexadecimalEntities(config.hexadecimalEntities());
htmlDoc.setXsltPath(config.getXsltPath());
htmlDoc.setConfig(config);
if (template!=null) { htmlDoc.readFromTemplate(template); }
else if (bNeedHeaderFooter) { htmlDoc.createHeaderFooter(); }
outFiles.add(nOutFileIndex,htmlDoc);

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-02-19)
* Version 1.2 (2010-03-03)
*
*/
@ -305,9 +305,13 @@ public class DrawConverter extends ConverterHelper {
if (MIMETypes.MATH.equals(object.getType()) || MIMETypes.ODF.equals(object.getType())) { // Formula!
EmbeddedXMLObject xmlObject = (EmbeddedXMLObject) object;
// Document settings = object.getSettingsDOM();
Element replacementImage = null;
if (ofr.isOpenDocument()) { // look for replacement image
replacementImage = Misc.getChildByTagName(getFrame(onode),XMLString.DRAW_IMAGE);
}
try {
hnode.appendChild(converter.createTextNode(" "));
getMathCv().convert(xmlObject.getContentDOM().getDocumentElement(),hnode);
getMathCv().convert(replacementImage,xmlObject.getContentDOM().getDocumentElement(),hnode);
hnode.appendChild(converter.createTextNode(" "));
}
catch (SAXException e) {
@ -341,8 +345,12 @@ public class DrawConverter extends ConverterHelper {
formula = Misc.getChildByTagName(onode,XMLString.MATH_MATH);
}
if (formula != null) {
Element replacementImage = null;
if (ofr.isOpenDocument()) { // look for replacement image
replacementImage = Misc.getChildByTagName(getFrame(onode),XMLString.DRAW_IMAGE);
}
hnode.appendChild(converter.createTextNode(" "));
getMathCv().convert(formula,hnode);
getMathCv().convert(replacementImage,formula,hnode);
hnode.appendChild(converter.createTextNode(" "));
}
else { // unsupported object

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2010 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-11-22)
* Version 1.2 (2010-03-01)
*
*/
@ -79,7 +79,7 @@ public class FrameStyleConverter extends StyleWithPropertiesConverterHelper {
.append(getDefaultTagName(null))
.append(".").append(getClassNamePrefix())
.append(styleNames.getExportName(sDisplayName))
.append(" p {").append(props.toString()).append("}\n");
.append(" p {").append(props.toString()).append("}").append(config.prettyPrint() ? "\n" : " ");
}
}
}

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2010 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-11-22)
* Version 1.2 (2010-03-01)
*
*/
@ -100,7 +100,8 @@ public class ListStyleConverter extends StyleConverterHelper {
buf.append(styleNames.getExportName(sDisplayName));
buf.append(" {");
buf.append(props.toString());
buf.append("}\n");
buf.append("}");
buf.append(config.prettyPrint() ? "\n" : " ");
}
}
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-02-19)
* Version 1.2 (2010-03-04)
*
*/
@ -33,48 +33,106 @@ import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import writer2latex.office.*;
import writer2latex.util.Misc;
import writer2latex.xmerge.BinaryGraphicsDocument;
import writer2latex.latex.StarMathConverter;
/** This class converts formulas: Either as MathML, as an image or as plain text (StarMath or LaTeX format)
*/
public class MathConverter extends ConverterHelper {
private StarMathConverter smc = null;
private boolean bSupportMathML;
private boolean bUseImage;
private boolean bUseLaTeX;
/** Create a new <code>MathConverter</code>
*
* @param ofr the OfficeReader to query about the document
* @param config the configuration determining the type of export
* @param converter the converter instance
* @param bSupportMathML true if the formula should be exported as MathML
*/
public MathConverter(OfficeReader ofr, XhtmlConfig config, Converter converter,
boolean bSupportMathML) {
super(ofr,config,converter);
this.bSupportMathML = bSupportMathML;
this.bUseImage = config.formulas()==XhtmlConfig.IMAGE_LATEX || config.formulas()==XhtmlConfig.IMAGE_STARMATH;
this.bUseLaTeX = config.formulas()==XhtmlConfig.IMAGE_LATEX || config.formulas()==XhtmlConfig.LATEX;
if (bUseLaTeX) { smc = new StarMathConverter(); }
}
public void convert(Node onode, Node hnode) {
/** Convert a formula
*
* @param image image version of the formula (or null if no image is available)
* @param onode the math node
* @param hnode the xhtml node to which content should be added
*/
public void convert(Node image, Node onode, Node hnode) {
if (bSupportMathML) {
convertNode(onode,hnode);
convertAsMathML(onode,hnode);
}
else {
Document htmlDOM = hnode.getOwnerDocument();
NodeList annotationList = ((Element) onode).getElementsByTagName(XMLString.ANNOTATION); // Since OOo 3.2
if (annotationList.getLength()>0) {
annotationList = ((Element) onode).getElementsByTagName(XMLString.MATH_ANNOTATION);
}
if (annotationList.getLength()>0 && annotationList.item(0).hasChildNodes()) {
// Insert the StarMath annotation as a kbd element
Element kbd = htmlDOM.createElement("kbd");
hnode.appendChild(kbd);
NodeList list = annotationList.item(0).getChildNodes();
int nLen = list.getLength();
for (int i=0; i<nLen; i++) {
Node child = list.item(i);
if (child.getNodeType()==Node.TEXT_NODE) {
kbd.appendChild(htmlDOM.createTextNode(child.getNodeValue()));
}
}
}
else {
hnode.appendChild(htmlDOM.createTextNode("[Warning: formula ignored]"));
}
convertAsImageOrText(image,onode,hnode);
}
}
// For plain xhtml: Convert the formula as an image or as plain text
private void convertAsImageOrText(Node image, Node onode, Node hnode) {
NodeList annotationList = ((Element) onode).getElementsByTagName(XMLString.ANNOTATION); // Since OOo 3.2
if (annotationList.getLength()==0) {
annotationList = ((Element) onode).getElementsByTagName(XMLString.MATH_ANNOTATION);
}
if (annotationList.getLength()>0 && annotationList.item(0).hasChildNodes()) {
// First create the annotation (either StarMath or LaTeX)
String sAnnotation = "";
Node child = annotationList.item(0).getFirstChild();
while (child!=null) {
sAnnotation+=child.getNodeValue();
child = child.getNextSibling();
}
if (bUseLaTeX) { sAnnotation = smc.convert(sAnnotation); }
public void convertNode(Node onode, Node hnode) {
// Next insert the image if required and available
if (bUseImage) {
// Get the image from the ImageLoader
String sHref = Misc.getAttribute(onode,XMLString.XLINK_HREF);
if (sHref==null || sHref.length()==0 || ofr.isInPackage(sHref)) {
BinaryGraphicsDocument bgd = converter.getImageLoader().getImage(image);
if (bgd!=null) {
String sMIME = bgd.getDocumentMIMEType();
if (MIMETypes.PNG.equals(sMIME) || MIMETypes.JPEG.equals(sMIME) || MIMETypes.GIF.equals(sMIME)) {
converter.addDocument(bgd);
// Create the image and add the StarMath/LaTeX formula as alternative text
Element img = converter.createElement("img");
img.setAttribute("src",bgd.getFileName());
img.setAttribute("class", "formula");
img.setAttribute("alt",sAnnotation);
hnode.appendChild(img);
return;
}
}
}
}
// Otherwise insert the StarMath/LaTeX annotation as a kbd element
Element kbd = converter.createElement("kbd");
kbd.setAttribute("class", "formula");
hnode.appendChild(kbd);
kbd.appendChild(converter.createTextNode(sAnnotation));
}
else {
hnode.appendChild(converter.createTextNode("[Warning: formula ignored]"));
}
}
// For xhtml+mathml: Insert the mathml, removing the namespace (if any) and the annotation
public void convertAsMathML(Node onode, Node hnode) {
if (onode.getNodeType()==Node.ELEMENT_NODE) {
if (onode.getNodeName().equals(XMLString.SEMANTICS)) { // Since OOo 3.2
// ignore this construction
@ -120,7 +178,7 @@ public class MathConverter extends ConverterHelper {
if (list==null) { return; }
int nLen = list.getLength();
for (int i=0; i<nLen; i++) {
convertNode(list.item(i),hnode);
convertAsMathML(list.item(i),hnode);
}
}
@ -144,7 +202,7 @@ public class MathConverter extends ConverterHelper {
// This method maps {Open|Star}Symbol private use area to real unicode
// positions. This is the same table as in w2l/latex/style/symbols.xml.
// The named entities list is contributed by Bruno Mascret
// The list is contributed by Bruno Mascret
private char replacePrivateChar(char c) {
switch (c) {
case '\uE002': return '\u2666';

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2010 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-09-08)
* Version 1.2 (2010-03-01)
*
*/
@ -105,7 +105,8 @@ public class PageStyleConverter extends StyleConverterHelper {
// The export the results
buf.append(sIndent)
.append(".masterpage").append(styleNames.getExportName(sDisplayName))
.append(" {").append(info.props.toString()).append("}\n");
.append(" {").append(info.props.toString()).append("}")
.append(config.prettyPrint() ? "\n" : " ");
}
return buf.toString();
}

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2010 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-09-08)
* Version 1.2 (2010-03-01)
*
*/
@ -86,7 +86,7 @@ public class ParStyleConverter extends StyleWithPropertiesConverterHelper {
applyProperties(style,props,true);
props.addValue("clear","left");
buf.append(sIndent).append("h").append(i)
.append(" {").append(props.toString()).append("}\n");
.append(" {").append(props.toString()).append("}").append(config.prettyPrint() ? "\n" : " ");
}
}
}

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2010 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-11-22)
* Version 1.2 (2010-03-01)
*
*/
@ -102,7 +102,8 @@ public class PresentationStyleConverter extends FrameStyleConverter {
buf.append(sIndent)
.append("li.outline")
.append(styleNames.getExportName(sDisplayName))
.append(" p {").append(props.toString()).append("}\n");
.append(" p {").append(props.toString()).append("}")
.append(config.prettyPrint() ? "\n" : " ");
}
}
}

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2010 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-11-22)
* Version 1.2 (2010-02-27)
*
*/
@ -120,7 +120,7 @@ class StyleConverter extends ConverterHelper {
// Export used styles to CSS
public Node exportStyles(Document htmlDOM) {
String sIndent = " ";
String sIndent = config.prettyPrint() ? " " : "";
StringBuffer buf = new StringBuffer();
@ -135,7 +135,7 @@ class StyleConverter extends ConverterHelper {
// text properties only!
getTextSc().cssTextCommon(defaultStyle,props,true);
buf.append(sIndent)
.append("body {").append(props.toString()).append("}\n");
.append("body {").append(props.toString()).append("}").append(config.prettyPrint() ? "\n" : " ");
}
}
@ -161,9 +161,9 @@ class StyleConverter extends ConverterHelper {
Element htmlStyle = htmlDOM.createElement("style");
htmlStyle.setAttribute("media","all");
htmlStyle.setAttribute("type","text/css");
htmlStyle.appendChild(htmlDOM.createTextNode("\n"));
htmlStyle.appendChild(htmlDOM.createTextNode(config.prettyPrint() ? "\n" : " "));
htmlStyle.appendChild(htmlDOM.createTextNode(buf.toString()));
htmlStyle.appendChild(htmlDOM.createTextNode(" "));
if (config.prettyPrint()) { htmlStyle.appendChild(htmlDOM.createTextNode(" ")); }
return htmlStyle;
}
else {

View file

@ -16,11 +16,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2008 by Henrik Just
* Copyright: 2002-2010 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.0 (2008-11-22)
* Version 1.2 (2010-03-03)
*
*/
@ -62,7 +62,7 @@ public abstract class StyleWithPropertiesConverterHelper
StyleWithProperties style = (StyleWithProperties) getStyles().getStyle(sStyleName);
info.sTagName = getDefaultTagName(style);
if (style!=null) {
applyLang(style,info);
if (config.multilingual()) { applyLang(style,info); }
applyDirection(style,info);
if (style.isAutomatic()) {
// Apply parent style + hard formatting
@ -108,7 +108,8 @@ public abstract class StyleWithPropertiesConverterHelper
buf.append(styleNames.getExportName(sDisplayName));
buf.append(" {");
buf.append(props.toString());
buf.append("}\n");
buf.append("}");
buf.append(config.prettyPrint() ? "\n" : " ");
// TODO: Create a method "getStyleDeclarationsInner"
// to be used by eg. FrameStyleConverter
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-02-14)
* Version 1.2 (2010-03-04)
*
*/
@ -38,7 +38,7 @@ import writer2latex.util.Misc;
public class XhtmlConfig extends writer2latex.base.ConfigBase {
// Implement configuration methods
protected int getOptionCount() { return 37; }
protected int getOptionCount() { return 42; }
protected String getDefaultConfigPath() { return "/writer2latex/xhtml/config/"; }
// Override setOption: To be backwards compatible, we must accept options
@ -55,6 +55,12 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
public static final int IGNORE_STYLES = 1;
public static final int IGNORE_HARD = 2;
public static final int CONVERT_ALL = 3;
// Formulas (for xhtml 1.0 strict)
public static final int STARMATH = 0;
public static final int LATEX = 1;
public static final int IMAGE_STARMATH = 2;
public static final int IMAGE_LATEX = 3;
// Options
private static final int IGNORE_HARD_LINE_BREAKS = 0;
@ -66,34 +72,39 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
private static final int ENCODING = 6;
private static final int USE_NAMED_ENTITIES = 7;
private static final int HEXADECIMAL_ENTITIES = 8;
private static final int CUSTOM_STYLESHEET = 9;
private static final int FORMATTING = 10;
private static final int FRAME_FORMATTING = 11;
private static final int SECTION_FORMATTING = 12;
private static final int TABLE_FORMATTING = 13;
private static final int IGNORE_TABLE_DIMENSIONS = 14;
private static final int USE_DUBLIN_CORE = 15;
private static final int NOTES = 16;
private static final int CONVERT_TO_PX = 17;
private static final int SCALING = 18;
private static final int COLUMN_SCALING = 19;
private static final int FLOAT_OBJECTS = 20;
private static final int TABSTOP_STYLE = 21;
private static final int USE_LIST_HACK = 22;
private static final int SPLIT_LEVEL = 23;
private static final int REPEAT_LEVELS = 24;
private static final int CALC_SPLIT = 25;
private static final int DISPLAY_HIDDEN_SHEETS = 26;
private static final int DISPLAY_HIDDEN_ROWS_COLS = 27;
private static final int DISPLAY_FILTERED_ROWS_COLS = 28;
private static final int APPLY_PRINT_RANGES = 29;
private static final int USE_TITLE_AS_HEADING = 30;
private static final int USE_SHEET_NAMES_AS_HEADINGS = 31;
private static final int XSLT_PATH = 32;
private static final int SAVE_IMAGES_IN_SUBDIR = 33;
private static final int UPLINK = 34;
private static final int DIRECTORY_ICON = 35;
private static final int DOCUMENT_ICON = 36;
private static final int PRETTY_PRINT = 9;
private static final int MULTILINGUAL = 10;
private static final int TEMPLATE_IDS = 11;
private static final int SEPARATE_STYLESHEET = 12;
private static final int CUSTOM_STYLESHEET = 13;
private static final int FORMATTING = 14;
private static final int FRAME_FORMATTING = 15;
private static final int SECTION_FORMATTING = 16;
private static final int TABLE_FORMATTING = 17;
private static final int IGNORE_TABLE_DIMENSIONS = 18;
private static final int USE_DUBLIN_CORE = 19;
private static final int NOTES = 20;
private static final int CONVERT_TO_PX = 21;
private static final int SCALING = 22;
private static final int COLUMN_SCALING = 23;
private static final int FLOAT_OBJECTS = 24;
private static final int TABSTOP_STYLE = 25;
private static final int USE_LIST_HACK = 26;
private static final int FORMULAS = 27;
private static final int SPLIT_LEVEL = 28;
private static final int REPEAT_LEVELS = 29;
private static final int CALC_SPLIT = 30;
private static final int DISPLAY_HIDDEN_SHEETS = 31;
private static final int DISPLAY_HIDDEN_ROWS_COLS = 32;
private static final int DISPLAY_FILTERED_ROWS_COLS = 33;
private static final int APPLY_PRINT_RANGES = 34;
private static final int USE_TITLE_AS_HEADING = 35;
private static final int USE_SHEET_NAMES_AS_HEADINGS = 36;
private static final int XSLT_PATH = 37;
private static final int SAVE_IMAGES_IN_SUBDIR = 38;
private static final int UPLINK = 39;
private static final int DIRECTORY_ICON = 40;
private static final int DOCUMENT_ICON = 41;
protected XhtmlStyleMap xpar = new XhtmlStyleMap();
protected XhtmlStyleMap xtext = new XhtmlStyleMap();
@ -113,6 +124,10 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
options[ENCODING] = new Option("encoding","UTF-8");
options[USE_NAMED_ENTITIES] = new BooleanOption("use_named_entities","false");
options[HEXADECIMAL_ENTITIES] = new BooleanOption("hexadecimal_entities","true");
options[PRETTY_PRINT] = new BooleanOption("pretty_print","true");
options[MULTILINGUAL] = new BooleanOption("multilingual","true");
options[TEMPLATE_IDS] = new Option("template_ids","");
options[SEPARATE_STYLESHEET] = new BooleanOption("separate_stylesheet","false");
options[CUSTOM_STYLESHEET] = new Option("custom_stylesheet","");
options[FORMATTING] = new XhtmlFormatOption("formatting","convert_all");
options[FRAME_FORMATTING] = new XhtmlFormatOption("frame_formatting","convert_all");
@ -127,6 +142,15 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
options[FLOAT_OBJECTS] = new BooleanOption("float_objects","true");
options[TABSTOP_STYLE] = new Option("tabstop_style","");
options[USE_LIST_HACK] = new BooleanOption("use_list_hack","false");
options[FORMULAS] = new IntegerOption("formulas","starmath") {
public void setString(String sValue) {
super.setString(sValue);
if ("latex".equals(sValue)) { nValue = LATEX; }
else if ("image+latex".equals(sValue)) { nValue = IMAGE_LATEX; }
else if ("starmath".equals(sValue)) { nValue = STARMATH; }
else { nValue = IMAGE_STARMATH; }
}
};
options[SPLIT_LEVEL] = new IntegerOption("split_level","0") {
public void setString(String sValue) {
super.setString(sValue);
@ -219,6 +243,10 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
public String xhtmlEncoding() { return options[ENCODING].getString(); }
public boolean useNamedEntities() { return ((BooleanOption) options[USE_NAMED_ENTITIES]).getValue(); }
public boolean hexadecimalEntities() { return ((BooleanOption) options[HEXADECIMAL_ENTITIES]).getValue(); }
public boolean prettyPrint() { return ((BooleanOption) options[PRETTY_PRINT]).getValue(); }
public boolean multilingual() { return ((BooleanOption) options[MULTILINGUAL]).getValue(); }
public String templateIds() { return options[TEMPLATE_IDS].getString(); }
public boolean separateStylesheet() { return ((BooleanOption) options[SEPARATE_STYLESHEET]).getValue(); }
public String xhtmlCustomStylesheet() { return options[CUSTOM_STYLESHEET].getString(); }
public int xhtmlFormatting() { return ((XhtmlFormatOption) options[FORMATTING]).getValue(); }
public int xhtmlFrameFormatting() { return ((XhtmlFormatOption) options[FRAME_FORMATTING]).getValue(); }
@ -233,6 +261,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase {
public boolean xhtmlFloatObjects() { return ((BooleanOption) options[FLOAT_OBJECTS]).getValue(); }
public String getXhtmlTabstopStyle() { return options[TABSTOP_STYLE].getString(); }
public boolean xhtmlUseListHack() { return ((BooleanOption) options[USE_LIST_HACK]).getValue(); }
public int formulas() { return ((IntegerOption) options[FORMULAS]).getValue(); }
public int getXhtmlSplitLevel() { return ((IntegerOption) options[SPLIT_LEVEL]).getValue(); }
public int getXhtmlRepeatLevels() { return ((IntegerOption) options[REPEAT_LEVELS]).getValue(); }
public boolean xhtmlCalcSplit() { return ((BooleanOption) options[CALC_SPLIT]).getValue(); }

View file

@ -16,15 +16,14 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2009 by Henrik Just
* Copyright: 2002-2010 by Henrik Just
*
* All Rights Reserved.
*
* Version 1.2 (2009-09-05)
* Version 1.2 (2010-03-03)
*
*/
//TODO: Remove redundant lang and dir attributes
//TODO: Add named entities outside ISO-latin 1
package writer2latex.xhtml;
@ -86,7 +85,12 @@ public class XhtmlDocument extends DOMDocument {
private char cLimit = 65535;
private boolean bNoDoctype = false;
private boolean bAddBOM = false;
private boolean bPrettyPrint = true;
private String sXsltPath = "";
private String sContentId = "content";
private String sHeaderId = "header";
private String sFooterId = "footer";
private String sPanelId = "panel";
// Content
private Element headNode = null;
@ -176,13 +180,13 @@ public class XhtmlDocument extends DOMDocument {
public void createHeaderFooter() {
headerNode = getContentDOM().createElement("div");
headerNode.setAttribute("id","header");
headerNode.setAttribute("id",sHeaderId);
bodyNode.appendChild(headerNode);
contentNode = getContentDOM().createElement("div");
contentNode.setAttribute("id","content");
contentNode.setAttribute("id",sContentId);
bodyNode.appendChild(contentNode);
footerNode = getContentDOM().createElement("div");
footerNode.setAttribute("id","footer");
footerNode.setAttribute("id",sFooterId);
bodyNode.appendChild(footerNode);
}
@ -230,10 +234,10 @@ public class XhtmlDocument extends DOMDocument {
}
else if ("div".equals(sTagName)) {
String sId = elm.getAttribute("id");
if ("content".equals(sId)) { contentNode = elm; }
else if ("header".equals(sId)) { headerNode = elm; }
else if ("footer".equals(sId)) { footerNode = elm; }
else if ("panel".equals(sId)) { panelNode = elm; }
if (sContentId.equals(sId)) { contentNode = elm; }
else if (sHeaderId.equals(sId)) { headerNode = elm; }
else if (sFooterId.equals(sId)) { footerNode = elm; }
else if (sPanelId.equals(sId)) { panelNode = elm; }
}
Node child = elm.getFirstChild();
@ -262,44 +266,71 @@ public class XhtmlDocument extends DOMDocument {
headNode.appendChild(titleNode);
}
}
public void setEncoding(String s) {
s = s.toUpperCase();
if ("UTF-16".equals(s)) {
sEncoding = s;
public void setConfig(XhtmlConfig config) {
sEncoding = config.xhtmlEncoding().toUpperCase();
if ("UTF-16".equals(sEncoding)) {
cLimit = 65535;
}
else if ("ISO-8859-1".equals(s)) {
sEncoding = s;
else if ("ISO-8859-1".equals(sEncoding)) {
cLimit = 255;
}
else if ("US-ASCII".equals(s)) {
sEncoding = s;
else if ("US-ASCII".equals(sEncoding)) {
cLimit = 127;
}
else {
sEncoding = "UTF-8";
cLimit = 65535;
}
bAddBOM = config.xhtmlAddBOM();
bNoDoctype = config.xhtmlNoDoctype();
bPrettyPrint = config.prettyPrint();
bUseNamedEntities = config.useNamedEntities();
bHexadecimalEntities = config.hexadecimalEntities();
sXsltPath = config.getXsltPath();
String[] sTemplateIds = config.templateIds().split(",");
int nIdCount = sTemplateIds.length;
if (nIdCount>0) sContentId = sTemplateIds[0].trim(); else sContentId = "content";
if (nIdCount>1) sHeaderId = sTemplateIds[1].trim(); else sHeaderId = "header";
if (nIdCount>2) sFooterId = sTemplateIds[2].trim(); else sFooterId = "footer";
if (nIdCount>3) sPanelId = sTemplateIds[3].trim(); else sPanelId = "panel";
}
public String getEncoding() { return sEncoding; }
public void setNoDoctype(boolean b) { bNoDoctype = b; }
public void setAddBOM(boolean b) { bAddBOM = b; }
public void setUseNamedEntities(boolean b) {
bUseNamedEntities = b;
}
public void setHexadecimalEntities(boolean b) {
bHexadecimalEntities = b;
}
public void setXsltPath(String s) { sXsltPath = s; }
public String getFileExtension() { return super.getFileExtension(); }
private void optimize(Element node, String sLang, String sDir) {
if (node.hasAttribute("xml:lang")) {
if (node.getAttribute("xml:lang").equals(sLang)) {
node.removeAttribute("xml:lang");
if (node.hasAttribute("lang")) {
node.removeAttribute("lang");
}
}
else {
sLang = node.getAttribute("xml:lang");
}
}
if (node.hasAttribute("xml:dir")) {
if (node.getAttribute("xml:dir").equals(sDir)) {
node.removeAttribute("xml:dir");
}
else {
sDir = node.getAttribute("xml:dir");
}
}
Node child = node.getFirstChild();
while (child!=null) {
if (child.getNodeType()==Node.ELEMENT_NODE) {
optimize((Element)child, sLang, sDir);
}
child = child.getNextSibling();
}
}
/**
* Write out content to the supplied <code>OutputStream</code>.
@ -334,7 +365,9 @@ public class XhtmlDocument extends DOMDocument {
osw.write(getContentDOM().getDoctype().getSystemId());
osw.write("\">\n");
}
write(getContentDOM().getDocumentElement(),0,osw);
Element doc = getContentDOM().getDocumentElement();
optimize(doc,null,null);
write(doc,0,osw);
osw.flush();
osw.close();
}
@ -357,7 +390,7 @@ public class XhtmlDocument extends DOMDocument {
osw.write("<"+node.getNodeName());
writeAttributes(node,osw);
osw.write(" />");
if (nLevel>=0) { osw.write("\n"); }
if (bPrettyPrint && nLevel>=0) { osw.write("\n"); }
}
else if (node.hasChildNodes()) {
// Block pretty print from this node?
@ -374,7 +407,7 @@ public class XhtmlDocument extends DOMDocument {
osw.write("<"+node.getNodeName());
writeAttributes(node,osw);
osw.write(">");
if (nLevel>=0 && !bBlockPrettyPrint) { osw.write("\n"); }
if (bPrettyPrint && nLevel>=0 && !bBlockPrettyPrint) { osw.write("\n"); }
// Print children
for (int i = 0; i < nLen; i++) {
int nNextLevel;
@ -385,7 +418,7 @@ public class XhtmlDocument extends DOMDocument {
// Print end tag
if (nLevel>=0 && !bBlockPrettyPrint) { writeSpaces(nLevel,osw); }
osw.write("</"+node.getNodeName()+">");
if (nLevel>=0) { osw.write("\n"); }
if (bPrettyPrint && nLevel>=0) { osw.write("\n"); }
}
else { // empty element
if (nLevel>=0) { writeSpaces(nLevel,osw); }
@ -398,7 +431,7 @@ public class XhtmlDocument extends DOMDocument {
else {
osw.write(" />");
}
if (nLevel>=0) { osw.write("\n"); }
if (bPrettyPrint && nLevel>=0) { osw.write("\n"); }
}
break;
case Node.TEXT_NODE:
@ -409,7 +442,7 @@ public class XhtmlDocument extends DOMDocument {
osw.write("<!-- ");
write(node.getNodeValue(),osw);
osw.write(" -->");
if (nLevel>=0) { osw.write("\n"); }
if (bPrettyPrint && nLevel>=0) { osw.write("\n"); }
}
}
@ -427,7 +460,9 @@ public class XhtmlDocument extends DOMDocument {
}
private void writeSpaces(int nCount, OutputStreamWriter osw) throws IOException {
for (int i=0; i<nCount; i++) { osw.write(" "); }
if (bPrettyPrint) {
for (int i=0; i<nCount; i++) { osw.write(" "); }
}
}
private void write(String s, OutputStreamWriter osw) throws IOException {