Java 5 + Writer4LaTeX + bugfixes

git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@11 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
henrikjust 2009-03-30 07:38:37 +00:00
parent be54e842f4
commit 9241a44f6c
83 changed files with 2373 additions and 631 deletions

View file

@ -43,7 +43,7 @@ import writer2latex.latex.util.StyleMap;
public class CharStyleConverter extends StyleConverter {
// Cache of converted font declarations
private Hashtable fontDecls = new Hashtable();
private Hashtable<String, String> fontDecls = new Hashtable<String, String>();
// Which formatting should we export?
private boolean bIgnoreHardFontsize;
@ -434,7 +434,7 @@ public class CharStyleConverter extends StyleConverter {
String sFontFamilyGeneric = fd.getFontFamilyGeneric();
fontDecls.put(sName,nfssFamily(sFontFamily,sFontFamilyGeneric,sFontPitch));
}
return (String) fontDecls.get(sName);
return fontDecls.get(sName);
}
// The remaining methods are static helpers to convert single style properties

View file

@ -226,10 +226,10 @@ public final class ConverterPalette extends ConverterBase {
mathmlCv.appendDeclarations(packages,declarations);
// Add custom preamble
LinkedList customPreamble = config.getCustomPreamble();
LinkedList<String> customPreamble = config.getCustomPreamble();
int nCPLen = customPreamble.size();
for (int i=0; i<nCPLen; i++) {
declarations.append( (String) customPreamble.get(i) ).nl();
declarations.append( customPreamble.get(i) ).nl();
}
// Set \title, \author and \date (for \maketitle)

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.0 (2009-03-08)
* Version 1.2 (2009-03-26)
*
*/
@ -56,7 +56,7 @@ public class DrawConverter extends ConverterHelper {
private boolean bNeedOOoLaTeXPreamble = false;
// Keep track of floating frames (images, textboxes...)
private Stack floatingFramesStack = new Stack();
private Stack<LinkedList<Element>> floatingFramesStack = new Stack<LinkedList<Element>>();
private Element getFrame(Element onode) {
if (ofr.isOpenDocument()) return (Element) onode.getParentNode();
@ -65,7 +65,7 @@ public class DrawConverter extends ConverterHelper {
public DrawConverter(OfficeReader ofr, LaTeXConfig config, ConverterPalette palette) {
super(ofr,config,palette);
floatingFramesStack.push(new LinkedList());
floatingFramesStack.push(new LinkedList<Element>());
}
public void appendDeclarations(LaTeXDocumentPortion pack, LaTeXDocumentPortion decl) {
@ -301,7 +301,7 @@ public class DrawConverter extends ConverterHelper {
handleDrawImageAsChar(node,ldp,oc);
}
else {
((LinkedList) floatingFramesStack.peek()).add(node);
floatingFramesStack.peek().add(node);
}
}
@ -429,7 +429,7 @@ public class DrawConverter extends ConverterHelper {
makeDrawTextBox(node, ldp, oc);
}
else {
((LinkedList) floatingFramesStack.peek()).add(node);
floatingFramesStack.peek().add(node);
}
}
@ -461,7 +461,7 @@ public class DrawConverter extends ConverterHelper {
if (!bIsCaption) {
ldp.append("\\begin{minipage}{").append(sWidth).append("}").nl();
}
floatingFramesStack.push(new LinkedList());
floatingFramesStack.push(new LinkedList<Element>());
palette.getBlockCv().traverseBlockText(node,ldp,ic);
flushFloatingFrames(ldp,ic);
floatingFramesStack.pop();
@ -477,7 +477,7 @@ public class DrawConverter extends ConverterHelper {
public void flushFloatingFrames(LaTeXDocumentPortion ldp, Context oc) {
// todo: fix language
LinkedList floatingFrames = (LinkedList) floatingFramesStack.peek();
LinkedList floatingFrames = floatingFramesStack.peek();
int n = floatingFrames.size();
if (n==0) { return; }
for (int i=0; i<n; i++) {

View file

@ -60,12 +60,12 @@ public class FieldConverter extends ConverterHelper {
private ExportNameCollection seqrefnames = new ExportNameCollection(true);
// sequence declarations (maps name->text:sequence-decl element)
private Hashtable seqDecl = new Hashtable();
private Hashtable<String, Node> seqDecl = new Hashtable<String, Node>();
// first usage of sequence (maps name->text:sequence element)
private Hashtable seqFirst = new Hashtable();
private Hashtable<String, Element> seqFirst = new Hashtable<String, Element>();
private Vector postponedReferenceMarks = new Vector();
private Vector postponedBookmarks = new Vector();
private Vector<Element> postponedReferenceMarks = new Vector<Element>();
private Vector<Element> postponedBookmarks = new Vector<Element>();
private boolean bUseHyperref = false;
private boolean bUsesPageCount = false;
@ -128,11 +128,11 @@ public class FieldConverter extends ConverterHelper {
// The number format is fetched from the first occurence of the
// sequence in the text, while the outline level and the separation
// character are fetched from the declaration
Enumeration names = seqFirst.keys();
Enumeration<String> names = seqFirst.keys();
while (names.hasMoreElements()) {
// Get first text:sequence element
String sName = (String) names.nextElement();
Element first = (Element) seqFirst.get(sName);
String sName = names.nextElement();
Element first = seqFirst.get(sName);
// Collect data
String sNumFormat = Misc.getAttribute(first,XMLString.STYLE_NUM_FORMAT);
if (sNumFormat==null) { sNumFormat="1"; }
@ -525,13 +525,13 @@ public class FieldConverter extends ConverterHelper {
// Type out all postponed reference marks
int n = postponedReferenceMarks.size();
for (int i=0; i<n; i++) {
handleReferenceMark((Element) postponedReferenceMarks.get(i),ldp,oc);
handleReferenceMark(postponedReferenceMarks.get(i),ldp,oc);
}
postponedReferenceMarks.clear();
// Type out all postponed bookmarks
n = postponedBookmarks.size();
for (int i=0; i<n; i++) {
handleBookmark((Element) postponedBookmarks.get(i),ldp,oc);
handleBookmark(postponedBookmarks.get(i),ldp,oc);
}
postponedBookmarks.clear();
}

View file

@ -48,7 +48,7 @@ public class IndexConverter extends ConverterHelper {
private boolean bContainsAlphabeticalIndex = false;
private Vector postponedIndexMarks = new Vector();
private Vector<Element> postponedIndexMarks = new Vector<Element>();
/** <p>Construct a new <code>IndexConverter</code>.
* @param config the configuration to use
@ -201,7 +201,7 @@ public class IndexConverter extends ConverterHelper {
// Type out all postponed index marks
int n = postponedIndexMarks.size();
for (int i=0; i<n; i++) {
handleAlphabeticalIndexMark((Element) postponedIndexMarks.get(i),ldp,oc);
handleAlphabeticalIndexMark(postponedIndexMarks.get(i),ldp,oc);
}
postponedIndexMarks.clear();
}

View file

@ -145,7 +145,7 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
private static final int SAVE_IMAGES_IN_SUBDIR = 57;
private static final int DEBUG = 58;
protected LinkedList customPreamble = new LinkedList();
protected LinkedList<String> customPreamble = new LinkedList<String>();
protected StyleMap par = new StyleMap();
protected StyleMap parBlock = new StyleMap();
protected StyleMap text = new StyleMap();
@ -153,7 +153,7 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
protected StyleMap listItem = new StyleMap();
protected StyleMap textAttr = new StyleMap();
protected HeadingMap headingMap = new HeadingMap(5);
protected Hashtable mathSymbols = new Hashtable();
protected Hashtable<String, String> mathSymbols = new Hashtable<String, String>();
protected ReplacementTrie stringReplace = new ReplacementTrie();
public LaTeXConfig() {
@ -365,10 +365,10 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
protected void writeInner(Document dom) {
// Write math symbol map
Enumeration msEnum = mathSymbols.keys();
Enumeration<String> msEnum = mathSymbols.keys();
while (msEnum.hasMoreElements()) {
String sName = (String) msEnum.nextElement();
String sLatex = (String) mathSymbols.get(sName);
String sName = msEnum.nextElement();
String sLatex = mathSymbols.get(sName);
Element msNode = dom.createElement("math-symbol-map");
msNode.setAttribute("name",sName);
msNode.setAttribute("latex",sLatex);
@ -413,9 +413,9 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
}
private void writeStyleMap(Document dom, StyleMap sm, String sFamily) {
Enumeration smEnum = sm.getNames();
Enumeration<String> smEnum = sm.getNames();
while (smEnum.hasMoreElements()) {
String sName = (String) smEnum.nextElement();
String sName = smEnum.nextElement();
Element smNode = dom.createElement("style-map");
smNode.setAttribute("name",sName);
smNode.setAttribute("family",sFamily);
@ -434,11 +434,11 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
}
}
private void writeContent(Document dom, LinkedList list, String sElement) {
private void writeContent(Document dom, LinkedList<String> list, String sElement) {
Element node = dom.createElement(sElement);
int nLen = list.size();
for (int i=0; i<nLen; i++) {
node.appendChild( dom.createTextNode( (String) list.get(i) ) );
node.appendChild( dom.createTextNode( list.get(i) ) );
}
dom.getDocumentElement().appendChild(node);
}
@ -528,7 +528,7 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
public boolean splitToplevelSections() { return ((BooleanOption) options[SPLIT_TOPLEVEL_SECTIONS]).getValue(); }
public boolean saveImagesInSubdir() { return ((BooleanOption) options[SAVE_IMAGES_IN_SUBDIR]).getValue(); }
public Hashtable getMathSymbols() { return mathSymbols; }
public Hashtable<String, String> getMathSymbols() { return mathSymbols; }
public StyleMap getParStyleMap() { return par; }
public StyleMap getParBlockStyleMap() { return parBlock; }
@ -537,7 +537,7 @@ public class LaTeXConfig extends writer2latex.base.ConfigBase {
public StyleMap getListItemStyleMap() { return listItem; }
public StyleMap getTextAttributeStyleMap() { return textAttr; }
public HeadingMap getHeadingMap() { return headingMap; }
public LinkedList getCustomPreamble() { return customPreamble; }
public LinkedList<String> getCustomPreamble() { return customPreamble; }
}

View file

@ -36,7 +36,7 @@ import writer2latex.util.Misc;
number of lines, and may include subportions. */
public class LaTeXDocumentPortion {
private Vector nodes; // The collection of all nodes in this portion
private Vector<Object> nodes; // The collection of all nodes in this portion
private StringBuffer curText; // The currently active node (always the last node)
private boolean bEmpty; // Is the active node empty?
@ -45,7 +45,7 @@ public class LaTeXDocumentPortion {
public LaTeXDocumentPortion(boolean bWrap){
this.bWrap = bWrap;
nodes = new Vector();
nodes = new Vector<Object>();
curText = new StringBuffer();
bEmpty = true;
}

View file

@ -37,7 +37,7 @@ import writer2latex.latex.util.Context;
*/
public class ListStyleConverter extends StyleConverter {
boolean bNeedSaveEnumCounter = false;
private Hashtable listStyleLevelNames = new Hashtable();
private Hashtable<String, String[]> listStyleLevelNames = new Hashtable<String, String[]>();
/** <p>Constructs a new <code>ListStyleConverter</code>.</p>
*/
@ -99,7 +99,7 @@ public class ListStyleConverter extends StyleConverter {
ba.add("\\liststyle"+styleNames.getExportName(getDisplayName(sStyleName))+"\n","");
}
if (nLevel<=4) {
String sCounterName = ((String[]) listStyleLevelNames.get(sStyleName))[nLevel];
String sCounterName = listStyleLevelNames.get(sStyleName)[nLevel];
if (bContinue && style.isNumber(nLevel)) {
bNeedSaveEnumCounter = true;
ba.add("\\setcounter{saveenum}{\\value{"+sCounterName+"}}\n","");

View file

@ -53,7 +53,7 @@ public class NoteConverter extends ConverterHelper {
private boolean bContainsEndnotes = false;
private boolean bContainsFootnotes = false;
// Keep track of footnotes (inside minipage etc.), that should be typeset later
private LinkedList postponedFootnotes = new LinkedList();
private LinkedList<Element> postponedFootnotes = new LinkedList<Element>();
public NoteConverter(OfficeReader ofr, LaTeXConfig config, ConverterPalette palette) {
super(ofr,config,palette);
@ -115,7 +115,7 @@ public class NoteConverter extends ConverterHelper {
int n = postponedFootnotes.size();
if (n==1) {
ldp.append("\\footnotetext{");
traverseNoteBody((Element) postponedFootnotes.get(0),ldp,ic);
traverseNoteBody(postponedFootnotes.get(0),ldp,ic);
ldp.append("}").nl();
postponedFootnotes.clear();
}
@ -124,7 +124,7 @@ public class NoteConverter extends ConverterHelper {
ldp.append("\\addtocounter{footnote}{-"+n+"}").nl();
for (int i=0; i<n; i++) {
ldp.append("\\stepcounter{footnote}\\footnotetext{");
traverseNoteBody((Element) postponedFootnotes.get(i),ldp,ic);
traverseNoteBody(postponedFootnotes.get(i),ldp,ic);
ldp.append("}").nl();
}
postponedFootnotes.clear();

View file

@ -157,7 +157,7 @@ public class PageStyleConverter extends StyleConverter {
context.setInHeaderFooter(true);
Enumeration styles = ofr.getMasterPages().getStylesEnumeration();
Enumeration<Object> styles = ofr.getMasterPages().getStylesEnumeration();
ldp.append("% Pages styles").nl();
if (!config.useFancyhdr()) {
ldp.append("\\makeatletter").nl();
@ -385,7 +385,7 @@ public class PageStyleConverter extends StyleConverter {
boolean bIncludeHead = false;
boolean bIncludeFoot = false;
// Look through all applied page layouts and use largest heights
Enumeration masters = ofr.getMasterPages().getStylesEnumeration();
Enumeration<Object> masters = ofr.getMasterPages().getStylesEnumeration();
while (masters.hasMoreElements()) {
MasterPage master = (MasterPage) masters.nextElement();
if (styleNames.containsName(getDisplayName(master.getName()))) {

View file

@ -698,7 +698,7 @@ public final class StarMathConverter implements writer2latex.api.StarMathConvert
private SmTokenTable keywords=new SmTokenTable(SmTokenTable.keywords);
private SmTokenTable symbols=new SmTokenTable(SmTokenTable.symbols);
private LaTeXConfig config;
private Hashtable configSymbols;
private Hashtable<String, String> configSymbols;
private boolean bUseColor;
private SmToken curToken=new SmToken(); // contains the data of the current token
private SimpleInputBuffer buffer; // contains the starmath formula
@ -860,7 +860,7 @@ public final class StarMathConverter implements writer2latex.api.StarMathConvert
buffer.getChar();
String sIdent=buffer.getIdentifier();
if (configSymbols.containsKey(sIdent)) { // symbol defined in configuration
curToken.assign(Token.SPECIAL, (String) configSymbols.get(sIdent), 5);
curToken.assign(Token.SPECIAL, configSymbols.get(sIdent), 5);
}
else if (!symbols.lookup(sIdent,false,curToken))
curToken.assign(Token.IDENT, i18n.convert(sIdent,true,"en"), 5);

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.0 (2009-02-16)
* Version 1.2 (2009-03-26)
*
*/
@ -185,12 +185,12 @@ public class ClassicI18n extends I18n {
// End of static part of I18n!
// **** Global variables ****
private Hashtable babelLanguages; // mappings iso->babel language
private Hashtable<String,String> babelLanguages; // mappings iso->babel language
// Unicode translation
private Hashtable tableSet; // all tables
private Hashtable<String,UnicodeTable> tableSet; // all tables
private UnicodeTable table; // currently active table (top of stack)
private Stack tableStack; // stack of active tables
private Stack<UnicodeTable> tableStack; // stack of active tables
private UnicodeStringParser ucparser; // Unicode string parser
// Collected data
@ -231,7 +231,7 @@ public class ClassicI18n extends I18n {
if (config.useEurosym()) sSymbols+="|eurosym";
if (config.useTipa()) sSymbols+="|tipa";
tableSet = new Hashtable();
tableSet = new Hashtable<String,UnicodeTable>();
UnicodeTableHandler handler=new UnicodeTableHandler(tableSet, sSymbols);
SAXParserFactory factory=SAXParserFactory.newInstance();
InputStream is = this.getClass().getResourceAsStream("symbols.xml");
@ -244,9 +244,9 @@ public class ClassicI18n extends I18n {
t.printStackTrace();
}
// put root table at top of stack
tableStack = new Stack();
tableStack.push((UnicodeTable) tableSet.get("root"));
table = (UnicodeTable) tableSet.get("root");
tableStack = new Stack<UnicodeTable>();
tableStack.push(tableSet.get("root"));
table = tableSet.get("root");
}
/** Construct a new I18n for general use
@ -386,8 +386,8 @@ public class ClassicI18n extends I18n {
// If no name is specified we should keep the current table
// Otherwise try to find the table, and use root if it's not available
if (sName!=null) {
table = (UnicodeTable) tableSet.get(sName);
if (table==null) { table = (UnicodeTable) tableSet.get("root"); }
table = tableSet.get(sName);
if (table==null) { table = tableSet.get("root"); }
}
tableStack.push(table);
}
@ -396,7 +396,7 @@ public class ClassicI18n extends I18n {
*/
public void popSpecialTable() {
tableStack.pop();
table = (UnicodeTable) tableStack.peek();
table = tableStack.peek();
}
/** Get the number of characters defined in the current table
@ -632,7 +632,7 @@ public class ClassicI18n extends I18n {
// todo: support automatic choice of inputenc (see comments)?
private String getBabelLanguage(String sLang) {
if (babelLanguages.containsKey(sLang)) {
return (String) babelLanguages.get(sLang);
return babelLanguages.get(sLang);
}
else {
return "english"; // interpret unknown languages as English
@ -640,7 +640,7 @@ public class ClassicI18n extends I18n {
}
private void prepareBabelLanguages() {
babelLanguages = new Hashtable();
babelLanguages = new Hashtable<String,String>();
babelLanguages.put("en", "english"); // latin1
babelLanguages.put("bg", "bulgarian"); // cp1251?
babelLanguages.put("cs", "czech"); // latin2

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.0 (2009-02-16)
* Version 1.2 (2009-03-26)
*
*/
@ -49,7 +49,7 @@ public abstract class I18n {
// Collected data
protected String sDefaultLanguage; // The default iso language to use
protected HashSet languages = new HashSet(); // All languages used
protected HashSet<String> languages = new HashSet<String>(); // All languages used
// **** Constructors ****

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.0 (2009-02-17)
* Version 1.2 (2009-03-26)
*
*/
@ -31,9 +31,10 @@ import java.util.Hashtable;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
// Helper classs: SAX handler to parse symbols.xml from jar
class UnicodeTableHandler extends DefaultHandler{
private Hashtable tableSet; // collection of all tables
/** Helper classs: SAX handler to parse symbols.xml from jar
*/
public class UnicodeTableHandler extends DefaultHandler{
private Hashtable<String,UnicodeTable> tableSet; // collection of all tables
private UnicodeTable table; // the current table
private String sSymbolSets;
private boolean bGlobalReadThisSet;
@ -42,7 +43,12 @@ class UnicodeTableHandler extends DefaultHandler{
private int nFontencs = 0; // The currently active fontencodings
private boolean b8bit = false;
UnicodeTableHandler(Hashtable tableSet, String sSymbolSets){
/** Create a new <code>UnicodeTableHandler</code>
*
* @param tableSet the <code>Hashtable</code> to fill with tables read from the file
* @param sSymbolSets string containing table names to read (separated by |)
*/
public UnicodeTableHandler(Hashtable<String,UnicodeTable> tableSet, String sSymbolSets){
this.sSymbolSets = sSymbolSets;
this.tableSet = tableSet;
}
@ -63,7 +69,7 @@ class UnicodeTableHandler extends DefaultHandler{
}
else if (qName.equals("special-symbol-set")) {
// start a new special symbol set; this requires a new table
table = new UnicodeTable((UnicodeTable) tableSet.get("root"));
table = new UnicodeTable(tableSet.get("root"));
tableSet.put(attributes.getValue("name"),table);
// Read it if it requires nothing, or something we read

View file

@ -20,7 +20,7 @@
*
* All Rights Reserved.
*
* Version 1.0 (2009-02-17)
* Version 1.2 (2009-03-26)
*
*/

View file

@ -30,7 +30,7 @@ import java.util.Hashtable;
import java.util.Enumeration;
public class StyleMap {
private Hashtable items = new Hashtable();
private Hashtable<String, StyleMapItem> items = new Hashtable<String, StyleMapItem>();
public void put(String sName, String sBefore, String sAfter, boolean bLineBreak, boolean bVerbatim) {
StyleMapItem item = new StyleMapItem();
@ -67,32 +67,32 @@ public class StyleMap {
}
public String getBefore(String sName) {
return ((StyleMapItem) items.get(sName)).sBefore;
return items.get(sName).sBefore;
}
public String getAfter(String sName) {
return ((StyleMapItem) items.get(sName)).sAfter;
return items.get(sName).sAfter;
}
public String getNext(String sName) {
String sNext = ((StyleMapItem) items.get(sName)).sNext;
String sNext = items.get(sName).sNext;
return sNext.substring(1,sNext.length()-1);
}
public boolean isNext(String sName, String sNext) {
String sNext1 = ((StyleMapItem) items.get(sName)).sNext;
String sNext1 = items.get(sName).sNext;
return sNext1.indexOf(";"+sNext+";")>-1;
}
public boolean getLineBreak(String sName) {
return contains(sName) && ((StyleMapItem) items.get(sName)).bLineBreak;
return contains(sName) && items.get(sName).bLineBreak;
}
public boolean getVerbatim(String sName) {
return contains(sName) && ((StyleMapItem) items.get(sName)).bVerbatim;
return contains(sName) && items.get(sName).bVerbatim;
}
public Enumeration getNames() {
public Enumeration<String> getNames() {
return items.keys();
}