BibTeX support
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@223 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
ceddd94461
commit
86c96621a7
13 changed files with 461 additions and 146 deletions
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.4 (2014-08-26)
|
||||
* Version 1.6 (2014-11-28)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -39,8 +39,8 @@ import writer2latex.latex.LaTeXConfig;
|
|||
import writer2latex.latex.i18n.ClassicI18n;
|
||||
import writer2latex.latex.i18n.I18n;
|
||||
import writer2latex.util.ExportNameCollection;
|
||||
//import writer2latex.util.Misc;
|
||||
import writer2latex.office.BibMark;
|
||||
import writer2latex.office.BibMark.EntryType;;
|
||||
|
||||
/**
|
||||
* <p>Class representing a BibTeX document.</p>
|
||||
|
@ -126,15 +126,15 @@ public class BibTeXDocument implements OutputFile {
|
|||
osw.write("{");
|
||||
osw.write(exportNames.getExportName(entry.getIdentifier()));
|
||||
osw.write(",\n");
|
||||
for (int i=0; i<BibMark.FIELD_COUNT; i++) {
|
||||
String sValue = entry.getField(i);
|
||||
for (EntryType entryType : EntryType.values()) {
|
||||
String sValue = entry.getField(entryType);
|
||||
if (sValue!=null) {
|
||||
if (i==BibMark.AUTHOR || i==BibMark.EDITOR) {
|
||||
if (entryType==EntryType.author || entryType==EntryType.editor) {
|
||||
// OOo uses ; to separate authors and editors - BibTeX uses and
|
||||
sValue = sValue.replaceAll(";" , " and ");
|
||||
}
|
||||
osw.write(" ");
|
||||
osw.write(getFieldName(i).toUpperCase());
|
||||
osw.write(BibTeXEntryMap.getFieldName(entryType).toUpperCase());
|
||||
osw.write(" = {");
|
||||
for (int j=0; j<sValue.length(); j++) {
|
||||
String s = i18n.convert(Character.toString(sValue.charAt(j)),false,"en");
|
||||
|
@ -151,47 +151,6 @@ public class BibTeXDocument implements OutputFile {
|
|||
osw.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> Return BibTeX name of field </p>
|
||||
*/
|
||||
public static final String getFieldName(int nField) {
|
||||
switch (nField) {
|
||||
case BibMark.ADDRESS: return "address";
|
||||
case BibMark.ANNOTE: return "annote";
|
||||
case BibMark.AUTHOR: return "author";
|
||||
case BibMark.BOOKTITLE: return "booktitle";
|
||||
case BibMark.CHAPTER: return "chapter";
|
||||
// case BibMark.CROSSREF: return "croosref"; // not in OOo
|
||||
case BibMark.EDITION: return "edition";
|
||||
case BibMark.EDITOR: return "editor";
|
||||
case BibMark.HOWPUBLISHED: return "howpublished";
|
||||
case BibMark.INSTITUTION: return "institution";
|
||||
case BibMark.JOURNAL: return "journal";
|
||||
// case BibMark.KEY: return "key"; // not in OOo
|
||||
case BibMark.MONTH: return "month";
|
||||
case BibMark.NOTE: return "note";
|
||||
case BibMark.NUMBER: return "number";
|
||||
case BibMark.ORGANIZATIONS: return "organization";
|
||||
case BibMark.PAGES: return "pages";
|
||||
case BibMark.PUBLISHER: return "publisher";
|
||||
case BibMark.SCHOOL: return "school";
|
||||
case BibMark.SERIES: return "series";
|
||||
case BibMark.TITLE: return "title";
|
||||
case BibMark.REPORT_TYPE: return "type";
|
||||
case BibMark.VOLUME: return "volume";
|
||||
case BibMark.YEAR: return "year";
|
||||
case BibMark.URL: return "url";
|
||||
case BibMark.CUSTOM1: return "custom1";
|
||||
case BibMark.CUSTOM2: return "custom2";
|
||||
case BibMark.CUSTOM3: return "custom3";
|
||||
case BibMark.CUSTOM4: return "custom4";
|
||||
case BibMark.CUSTOM5: return "custom5";
|
||||
case BibMark.ISBN: return "isbn";
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* <p>Check if this entry exists</p>
|
||||
*/
|
||||
|
|
109
source/java/writer2latex/bibtex/BibTeXEntryMap.java
Normal file
109
source/java/writer2latex/bibtex/BibTeXEntryMap.java
Normal file
|
@ -0,0 +1,109 @@
|
|||
/************************************************************************
|
||||
*
|
||||
* BibTeXEntryMap.java
|
||||
*
|
||||
* This library is free software); you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License version 2.1, as published by the Free Software Foundation.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library); if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2002-2014 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2014-11-28)
|
||||
*
|
||||
*/
|
||||
package writer2latex.bibtex;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import writer2latex.office.BibMark.EntryType;
|
||||
|
||||
/**
|
||||
* This class provides static methods to map the the entry types of an ODF
|
||||
* bibliography mark to and from BibTeX field names
|
||||
*
|
||||
*/
|
||||
public class BibTeXEntryMap {
|
||||
private static Map<EntryType, String> bibTeXFields = null;
|
||||
private static Map<String, EntryType> entryTypes = null;
|
||||
|
||||
private static void createMaps() {
|
||||
// Note the BibTeX fileds key and crossref are not supported in ODF
|
||||
bibTeXFields = new HashMap<EntryType, String>();
|
||||
bibTeXFields.put(EntryType.address, "address");
|
||||
bibTeXFields.put(EntryType.annote, "annote");
|
||||
bibTeXFields.put(EntryType.author, "author");
|
||||
bibTeXFields.put(EntryType.booktitle, "booktitle");
|
||||
bibTeXFields.put(EntryType.chapter, "chapter");
|
||||
bibTeXFields.put(EntryType.edition, "edition");
|
||||
bibTeXFields.put(EntryType.editor, "editor");
|
||||
bibTeXFields.put(EntryType.howpublished, "howpublished");
|
||||
bibTeXFields.put(EntryType.institution, "institution");
|
||||
bibTeXFields.put(EntryType.journal, "journal");
|
||||
bibTeXFields.put(EntryType.month, "month");
|
||||
bibTeXFields.put(EntryType.note, "note");
|
||||
bibTeXFields.put(EntryType.number, "number");
|
||||
bibTeXFields.put(EntryType.organizations, "organization");
|
||||
bibTeXFields.put(EntryType.pages, "pages");
|
||||
bibTeXFields.put(EntryType.publisher, "publisher");
|
||||
bibTeXFields.put(EntryType.school, "school");
|
||||
bibTeXFields.put(EntryType.series, "series");
|
||||
bibTeXFields.put(EntryType.title, "title");
|
||||
bibTeXFields.put(EntryType.report_type, "type");
|
||||
bibTeXFields.put(EntryType.volume, "volume");
|
||||
bibTeXFields.put(EntryType.year, "year");
|
||||
bibTeXFields.put(EntryType.url, "url");
|
||||
bibTeXFields.put(EntryType.custom1, "custom1");
|
||||
bibTeXFields.put(EntryType.custom2, "custom2");
|
||||
bibTeXFields.put(EntryType.custom3, "custom3");
|
||||
bibTeXFields.put(EntryType.custom4, "custom4");
|
||||
bibTeXFields.put(EntryType.custom5, "custom5");
|
||||
bibTeXFields.put(EntryType.isbn, "isbn");
|
||||
|
||||
entryTypes = new HashMap<String, EntryType>();
|
||||
for (EntryType entryType : bibTeXFields.keySet()) {
|
||||
entryTypes.put(bibTeXFields.get(entryType), entryType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return BibTeX field name corresponding to and entry type
|
||||
*
|
||||
* @param entryType
|
||||
* the entry type
|
||||
* @return the BibTeX field name, or null if there is no corresponding
|
||||
* BibTeX field
|
||||
*/
|
||||
public static final String getFieldName(EntryType entryType) {
|
||||
if (bibTeXFields == null) {
|
||||
createMaps();
|
||||
}
|
||||
return bibTeXFields.containsKey(entryType) ? bibTeXFields.get(entryType) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return entry type corresponding to a BibTeX field
|
||||
*
|
||||
* @param sFieldName
|
||||
* the BibTeX field name
|
||||
* @return the entry type, or null if there is no corresponding entry type
|
||||
*/
|
||||
public static final EntryType getEntryType(String sFieldName) {
|
||||
if (bibTeXFields == null) {
|
||||
createMaps();
|
||||
}
|
||||
return entryTypes.containsKey(sFieldName) ? entryTypes.get(sFieldName) : null;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue