Writer2xhtml custom config ui + API changes

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@53 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2010-03-15 08:49:05 +00:00
parent 6c82e57709
commit e0cb22dd2e
23 changed files with 221 additions and 43 deletions

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-23)
* Version 1.2 (2010-03-15)
*
*/
@ -49,5 +49,20 @@ public interface OutputFile {
* @return the file name of this <code>OutputFile</code>
*/
public String getFileName();
/** Get the MIME type of the <code>OutputFile</code>.
*
* @return string reprensentation of the MIME type
*/
public String getMIMEType();
/** Get the sequence number of this <code>OutputFile</code>.
* The master document has the sequence number 0.
* Other files which are part of the main document flow has a unique, positive sequence number.
* Auxiliary files like images always has the sequence number -1.
*
* @return the sequence number
*/
public int getSequenceNumber();
}

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-06-05)
* Version 1.2 (2010-03-15)
*
*/
@ -36,6 +36,7 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter;
import writer2latex.api.ConverterFactory;
import writer2latex.api.MIMETypes;
import writer2latex.latex.LaTeXConfig;
import writer2latex.latex.i18n.ClassicI18n;
import writer2latex.latex.i18n.I18n;
@ -101,6 +102,13 @@ public class BibTeXDocument implements Document {
return new String(sName + FILE_EXTENSION);
}
public String getMIMEType() {
return MIMETypes.BIBTEX;
}
public int getSequenceNumber() {
return -1;
}
/**
* <p>Writes out the <code>Document</code> content to the specified
@ -234,5 +242,6 @@ public class BibTeXDocument implements Document {
return name;
}
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-02-26)
* Version 1.2 (2010-03-15)
*
*/
@ -57,7 +57,7 @@ public final class ConverterPalette extends ConverterBase {
// The main outfile
private LaTeXDocument texDoc;
// Various data used in conversion
private Context mainContext; // main context
private CSVList globalOptions; // global options
@ -174,7 +174,7 @@ public final class ConverterPalette extends ConverterBase {
info = new Info(ofr,config,this);
// Create master document and add this
this.texDoc = new LaTeXDocument(sTargetFileName,config.getWrapLinesAfter());
this.texDoc = new LaTeXDocument(sTargetFileName,config.getWrapLinesAfter(),0);
if (config.getBackend()!=LaTeXConfig.XETEX) {
texDoc.setEncoding(ClassicI18n.writeJavaEncoding(config.getInputencoding()));
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-02-19)
* Version 1.2 (2010-03-15)
*
*/
@ -490,7 +490,7 @@ public class DrawConverter extends ConverterHelper {
public void flushFloatingFrames(LaTeXDocumentPortion ldp, Context oc) {
// todo: fix language
LinkedList floatingFrames = floatingFramesStack.peek();
LinkedList<Element> floatingFrames = floatingFramesStack.peek();
int n = floatingFrames.size();
if (n==0) { return; }
for (int i=0; i<n; i++) {

View file

@ -16,16 +16,17 @@
* 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-23)
* Version 1.2 (2010-03-15)
*
*/
package writer2latex.latex;
import writer2latex.api.MIMETypes;
import writer2latex.xmerge.Document;
import java.io.IOException;
@ -47,6 +48,8 @@ public class LaTeXDocument implements Document {
private int nWrap;
private LaTeXDocumentPortion contents;
private int nSequenceNumber = -1;
/**
* <p>Constructs a new LaTeX Document.</p>
@ -56,10 +59,12 @@ public class LaTeXDocument implements Document {
*
* @param sName The name of the <code>LaTeXDocument</code>.
* @param nWrap Lines should be wrapped after this position
* @param nSequenceNumber this file has this sequence number in the result
*/
public LaTeXDocument(String sName,int nWrap) {
public LaTeXDocument(String sName,int nWrap, int nSequenceNumber) {
this.nWrap = nWrap;
this.sName = trimDocumentName(sName);
this.nSequenceNumber = nSequenceNumber;
contents = new LaTeXDocumentPortion(true);
}
@ -95,7 +100,14 @@ public class LaTeXDocument implements Document {
return new String(sName + FILE_EXTENSION);
}
public String getMIMEType() {
return MIMETypes.LATEX;
}
public int getSequenceNumber() {
return nSequenceNumber;
}
/**
* <p>Writes out the <code>Document</code> content to the specified
* <code>OutputStream</code>.</p>
@ -148,5 +160,6 @@ public class LaTeXDocument implements Document {
return name;
}
}

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.0 (2009-02-17)
* Version 1.2 (2010-03-15)
*
*/
@ -45,6 +45,9 @@ public class SectionConverter extends ConverterHelper {
// Filenames for external sections
private ExportNameCollection fileNames = new ExportNameCollection(true);
// Current sequence number (until this class creates further LaTeX files, the master file is the only document)
private int nSequenceNumber = 0;
/** <p>Constructs a new <code>SectionStyleConverter</code>.</p>
*/
@ -80,7 +83,7 @@ public class SectionConverter extends ConverterHelper {
LaTeXDocumentPortion sectionLdp = ldp;
if (sFileName!=null) {
LaTeXDocument newDoc = new LaTeXDocument(sFileName,config.getWrapLinesAfter());
LaTeXDocument newDoc = new LaTeXDocument(sFileName,config.getWrapLinesAfter(),++nSequenceNumber);
if (config.getBackend()!=LaTeXConfig.XETEX) {
newDoc.setEncoding(ClassicI18n.writeJavaEncoding(config.getInputencoding()));
}

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-03-26)
* Version 1.2 (2010-03-15)
*
*/
@ -286,9 +286,9 @@ public class ClassicI18n extends I18n {
// Load babel with the used languages
CSVList babelopt = new CSVList(",");
Iterator langiter = languages.iterator();
Iterator<String> langiter = languages.iterator();
while (langiter.hasNext()) {
String sLang = (String) langiter.next();
String sLang = langiter.next();
if (!sLang.equals(sDefaultLanguage)) {
if ("el".equals(sLang) && this.polytonicGreek()) {
babelopt.addValue("polutonikogreek");

View file

@ -16,9 +16,9 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* Copyright: 2002-2009 by Henrik Just
* Copyright: 2002-2010 by Henrik Just
*
* Version 1.0 (2009-09-14)
* Version 1.2 (2010-03-15)
*
* All Rights Reserved.
*/
@ -143,7 +143,7 @@ public class TableReader {
// (Calc exports a lot of empty rows at columns bottom/right)
int nRows = cells.size();
for (int nRow=0; nRow<nRows; nRow++) {
LinkedList row = cells.get(nRow);
LinkedList<Element> row = cells.get(nRow);
nCols = row.size();
int nMaxCol = 0;
int nMaxRow = 0;
@ -443,7 +443,7 @@ public class TableReader {
public Element getCell(int nRow, int nCol) {
if (nRow<0 || nRow>=cells.size()) { return null; }
LinkedList row = cells.get(nRow);
LinkedList<Element> row = cells.get(nRow);
if (nCol<0 || nCol>=row.size()) { return null; }
return (Element) row.get(nCol);
}

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-03-02)
* Version 1.2 (2010-03-15)
*
*/
@ -69,7 +69,7 @@ public class BatchConverterImpl extends BatchConverterBase {
}
public void readTemplate(InputStream is) throws IOException {
template = new XhtmlDocument("Template",XhtmlDocument.XHTML10);
template = new XhtmlDocument("Template",XhtmlDocument.XHTML10,-1);
try {
template.read(is);
}
@ -89,7 +89,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);
XhtmlDocument htmlDoc = new XhtmlDocument("index",XhtmlDocument.XHTML10,0);
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-03-02)
* Version 1.2 (2010-03-15)
*
*/
@ -102,7 +102,7 @@ public class Converter extends ConverterBase {
// override
public void readTemplate(InputStream is) throws IOException {
template = new XhtmlDocument("Template",nType);
template = new XhtmlDocument("Template",nType,-1);
template.read(is);
}
@ -441,7 +441,7 @@ public class Converter extends ConverterBase {
// Prepare next output file
public Element nextOutFile() {
if (nOutFileIndex>=0) { textCv.insertFootnotes(htmlDoc.getContentNode()); }
htmlDoc = new XhtmlDocument(getOutFileName(++nOutFileIndex,false),nType);
htmlDoc = new XhtmlDocument(getOutFileName(++nOutFileIndex,false),nType,nOutFileIndex);
htmlDoc.setConfig(config);
if (template!=null) { htmlDoc.readFromTemplate(template); }
else if (bNeedHeaderFooter) { htmlDoc.createHeaderFooter(); }

View file

@ -20,13 +20,12 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-03-04)
* Version 1.2 (2010-03-15)
*
*/
package writer2latex.xhtml;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Element;

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.2 (2010-03-03)
* Version 1.2 (2010-03-15)
*
*/
@ -42,6 +42,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
//import javax.xml.parsers.ParserConfigurationException;
import writer2latex.api.MIMETypes;
import writer2latex.xmerge.DOMDocument;
import java.io.InputStream;
@ -77,6 +78,9 @@ public class XhtmlDocument extends DOMDocument {
// Type of document
private int nType;
// Sequence number
private int nSequenceNumber;
// Configuration
private String sEncoding = "UTF-8";
@ -111,10 +115,12 @@ public class XhtmlDocument extends DOMDocument {
* writer2latex.xmerge.DOMDocument.
* @param name <code>Document</code> name.
* @param nType the type of document
* @param nSequenceNumber the sequence number of this file in the export
*/
public XhtmlDocument(String name, int nType) {
public XhtmlDocument(String name, int nType, int nSequenceNumber) {
super(name,sExtension[nType]);
this.nType = nType;
this.nSequenceNumber = nSequenceNumber;
// Define publicId and systemId
String sPublicId = null;
String sSystemId = null;
@ -161,6 +167,20 @@ public class XhtmlDocument extends DOMDocument {
setContentDOM(contentDOM);
}
@Override public String getMIMEType() {
switch (nType) {
case XHTML10: return MIMETypes.XHTML;
case XHTML11: return MIMETypes.XHTML_MATHML; // TODO: Change the constant names in MIMETypes, this is a bit confusing...
case XHTML_MATHML: return MIMETypes.XHTML_MATHML;
case XHTML_MATHML_XSL: return MIMETypes.XHTML_MATHML_XSL;
}
return "";
}
@Override public int getSequenceNumber() {
return nSequenceNumber;
}
public Element getHeadNode() { return headNode; }

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-23)
* Version 1.2 (2010-03-15)
*
*/
@ -161,5 +161,15 @@ public class BinaryGraphicsDocument implements Document {
* @return String The document's MIME type.
*/
public String getDocumentMIMEType(){ return sMimeType; }
public String getMIMEType() {
return sMimeType;
}
public int getSequenceNumber() {
return -1;
}
}

View file

@ -37,7 +37,7 @@
************************************************************************/
// This version is adapted for writer2latex
// Version 1.0 (2008-11-23)
// Version 1.2 (2010-03-15)
package writer2latex.xmerge;
@ -393,6 +393,15 @@ public class DOMDocument
return doc;
}
// TODO: We need these because we implement OutputFile (don't do that..)
public String getMIMEType() {
return "";
}
public int getSequenceNumber() {
return -1;
}
}

View file

@ -37,7 +37,7 @@
************************************************************************/
// This version is adapted for Writer2LaTeX
// Version 1.0 (2008-11-22)
// Version 1.2 (2010-03-15)
package writer2latex.xmerge;
@ -1282,5 +1282,15 @@ public class OfficeDocument
manifestRoot.appendChild(docRoot);
}
// TODO: We need these because we implement OutputFile (but in fact we shouldn't)
public String getMIMEType() {
return "";
}
public int getSequenceNumber() {
return -1;
}
}