w2phtml/src/main/java/writer2latex/xhtml/Parser.java

126 lines
4.8 KiB
Java

/************************************************************************
*
* ConverterHelper.java
*
* Copyright: 2002-2015 by Henrik Just
*
* This file is part of Writer2LaTeX.
*
* Writer2LaTeX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Writer2LaTeX 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Writer2LaTeX. If not, see <http://www.gnu.org/licenses/>.
*
* Version 1.6 (2015-06-15)
*
*/
package writer2latex.xhtml;
import org.w3c.dom.Element;
import writer2latex.office.OfficeReader;
import writer2latex.xhtml.content.DrawParser;
import writer2latex.xhtml.content.MathParser;
import writer2latex.xhtml.content.TableParser;
import writer2latex.xhtml.content.TextParser;
import writer2latex.xhtml.style.CellStyleParser;
import writer2latex.xhtml.style.FrameStyleParser;
import writer2latex.xhtml.style.HeadingStyleParser;
import writer2latex.xhtml.style.ListStyleParser;
import writer2latex.xhtml.style.PageStyleParser;
import writer2latex.xhtml.style.ParStyleParser;
import writer2latex.xhtml.style.PresentationStyleParser;
import writer2latex.xhtml.style.RowStyleParser;
import writer2latex.xhtml.style.SectionStyleParser;
import writer2latex.xhtml.style.Styles;
import writer2latex.xhtml.style.TableStyleParser;
import writer2latex.xhtml.style.TextStyleParser;
/** A <code>ConverterHelper</code> is responsible for conversion of some specific content into XHTML.
*/
public class Parser {
// Member variables providing our content (set in constructor)
protected OfficeReader ofr;
protected XhtmlConfig config;
protected Converter converter;
/** Construct a new converter helper based on a
*
* @param ofr the office reader used to access the source document
* @param config the configuration to use
* @param converter the main converter to which the helper belongs
*/
protected Parser(OfficeReader ofr, XhtmlConfig config, Converter converter) {
this.ofr = ofr;
this.config = config;
this.converter = converter;
}
// Convenience accessor methods to other converter helpers (only needed to save some typing)
protected Styles getStyleCv() { return converter.getStylesParser(); }
protected TextStyleParser getTextSc() { return converter.getStylesParser().getTextSc(); }
protected ParStyleParser getParSc() { return converter.getStylesParser().getParSc(); }
protected HeadingStyleParser getHeadingSc() { return converter.getStylesParser().getHeadingSc(); }
protected ListStyleParser getListSc() { return converter.getStylesParser().getListSc(); }
protected SectionStyleParser getSectionSc() { return converter.getStylesParser().getSectionSc(); }
protected TableStyleParser getTableSc() { return converter.getStylesParser().getTableSc(); }
protected RowStyleParser getRowSc() { return converter.getStylesParser().getRowSc(); }
protected CellStyleParser getCellSc() { return converter.getStylesParser().getCellSc(); }
protected FrameStyleParser getFrameSc() { return converter.getStylesParser().getFrameSc(); }
protected PresentationStyleParser getPresentationSc() { return converter.getStylesParser().getPresentationSc(); }
protected PageStyleParser getPageSc() { return converter.getStylesParser().getPageSc(); }
protected TextParser getTextCv() { return converter.getTextParser(); }
protected TableParser getTableCv() { return converter.getTableParser(); }
protected DrawParser getDrawCv() { return converter.getDrawParser(); }
protected MathParser getMathCv() { return converter.getMathParser(); }
/** Apply style information to an XHTML node
*
* @param info the style to apply
* @param hnode the XHTML node
*/
public void writeStyle(StyleInfo info, Element hnode) {
if (info.sClass!=null) {
hnode.setAttribute("class",info.sClass);
}
if (!info.props.isEmpty()) {
hnode.setAttribute("style",info.props.toString());
}
if (info.sLang!=null) {
hnode.setAttribute("xml:lang",info.sLang);
if (converter.getType()==XhtmlDocument.XHTML10 || converter.getType()==XhtmlDocument.HTML5) {
hnode.setAttribute("lang",info.sLang); // HTML4 compatibility/polyglot HTML5S
}
}
if (info.sDir!=null) {
hnode.setAttribute("dir",info.sDir);
}
}
}