w2l use thebibliography environment if not using BibTeX
git-svn-id: svn://svn.code.sf.net/p/writer2latex/code/trunk@257 f0f2a975-2e09-46c8-9428-3b39399b9f3c
This commit is contained in:
parent
6f46ed3177
commit
729e088fa2
10 changed files with 318 additions and 257 deletions
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Version 1.6 (2015-05-05)
|
||||
* Version 1.6 (2015-06-22)
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -28,10 +28,13 @@ package writer2latex.bibtex;
|
|||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import writer2latex.api.ConverterFactory;
|
||||
import writer2latex.api.MIMETypes;
|
||||
import writer2latex.api.OutputFile;
|
||||
|
@ -40,11 +43,10 @@ import writer2latex.latex.i18n.ClassicI18n;
|
|||
import writer2latex.latex.i18n.I18n;
|
||||
import writer2latex.util.ExportNameCollection;
|
||||
import writer2latex.office.BibMark;
|
||||
import writer2latex.office.BibMark.EntryType;;
|
||||
import writer2latex.office.BibMark.EntryType;
|
||||
import writer2latex.office.OfficeReader;
|
||||
|
||||
/**
|
||||
* <p>Class representing a BibTeX document.</p>
|
||||
*
|
||||
/** Class representing a BibTeX document
|
||||
*/
|
||||
public class BibTeXDocument implements OutputFile {
|
||||
private static final String FILE_EXTENSION = ".bib";
|
||||
|
@ -56,36 +58,57 @@ public class BibTeXDocument implements OutputFile {
|
|||
|
||||
private boolean bIsMaster;
|
||||
|
||||
/**
|
||||
* <p>Constructs a new BibTeX Document.</p>
|
||||
/** Constructs a new BibTeX Document based on an office document
|
||||
*
|
||||
* <p>This new document is empty. Bibliographic data must added
|
||||
* using the <code>put</code> method.</p>
|
||||
*
|
||||
* @param sName The name of the <code>BibTeXDocument</code>.
|
||||
* @param sName The name of the document
|
||||
* @param bIsMaster is this a master document?
|
||||
* @param ofr the office document
|
||||
*/
|
||||
public BibTeXDocument(String sName, boolean bIsMaster) {
|
||||
this.sName = trimDocumentName(sName);
|
||||
public BibTeXDocument(String sName, boolean bIsMaster, OfficeReader ofr) {
|
||||
this.bIsMaster = bIsMaster;
|
||||
loadEntries(ofr);
|
||||
// Use default config (only ascii, no extra font packages)
|
||||
i18n = new ClassicI18n(new LaTeXConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns the <code>Document</code> name with no file extension.</p>
|
||||
private void loadEntries(OfficeReader ofr) {
|
||||
List<Element> bibMarks = ofr.getBibliographyMarks();
|
||||
for (Element bibMark : bibMarks) {
|
||||
BibMark entry = new BibMark(bibMark);
|
||||
entries.put(entry.getIdentifier(),entry);
|
||||
exportNames.addName(entry.getIdentifier());
|
||||
}
|
||||
}
|
||||
|
||||
// Methods to query the content
|
||||
|
||||
/** Test whether or not this BibTeX document contains any entries
|
||||
*
|
||||
* @return true if there is one or more entries in the document
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return entries.size()>0;
|
||||
}
|
||||
|
||||
/** Get export name for an identifier
|
||||
*
|
||||
* @param sIdentifier the identifier
|
||||
* @return the export name
|
||||
*/
|
||||
public String getExportName(String sIdentifier) {
|
||||
return exportNames.getExportName(sIdentifier);
|
||||
}
|
||||
|
||||
/** Returns the document name without file extension
|
||||
*
|
||||
* @return The <code>Document</code> name with no file extension.
|
||||
* @return the document name without file extension
|
||||
*/
|
||||
public String getName() {
|
||||
return sName;
|
||||
}
|
||||
|
||||
// Implement writer2latex.api.OutputFile
|
||||
|
||||
/**
|
||||
* <p>Returns the <code>Document</code> name with file extension.</p>
|
||||
*
|
||||
* @return The <code>Document</code> name with file extension.
|
||||
*/
|
||||
@Override public String getFileName() {
|
||||
return new String(sName + FILE_EXTENSION);
|
||||
}
|
||||
|
@ -102,21 +125,7 @@ public class BibTeXDocument implements OutputFile {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Writes out the <code>Document</code> content to the specified
|
||||
* <code>OutputStream</code>.</p>
|
||||
*
|
||||
* <p>This method may not be thread-safe.
|
||||
* Implementations may or may not synchronize this
|
||||
* method. User code (i.e. caller) must make sure that
|
||||
* calls to this method are thread-safe.</p>
|
||||
*
|
||||
* @param os <code>OutputStream</code> to write out the
|
||||
* <code>Document</code> content.
|
||||
*
|
||||
* @throws IOException If any I/O error occurs.
|
||||
*/
|
||||
public void write(OutputStream os) throws IOException {
|
||||
@Override public void write(OutputStream os) throws IOException {
|
||||
// BibTeX files are plain ascii
|
||||
OutputStreamWriter osw = new OutputStreamWriter(os,"ASCII");
|
||||
osw.write("%% This file was converted to BibTeX by Writer2BibTeX ver. "+ConverterFactory.getVersion()+".\n");
|
||||
|
@ -155,43 +164,4 @@ public class BibTeXDocument implements OutputFile {
|
|||
osw.close();
|
||||
}
|
||||
|
||||
/*
|
||||
* <p>Check if this entry exists</p>
|
||||
*/
|
||||
public boolean containsKey(String sIdentifier) {
|
||||
return entries.containsKey(sIdentifier);
|
||||
}
|
||||
|
||||
/*
|
||||
* <p>Add an entry</p>
|
||||
*/
|
||||
public void put(BibMark entry) {
|
||||
entries.put(entry.getIdentifier(),entry);
|
||||
exportNames.addName(entry.getIdentifier());
|
||||
}
|
||||
|
||||
/*
|
||||
* <p>Get export name for an identifier</p>
|
||||
*/
|
||||
public String getExportName(String sIdentifier) {
|
||||
return exportNames.getExportName(sIdentifier);
|
||||
}
|
||||
|
||||
/*
|
||||
* Utility method to make sure the document name is stripped of any file
|
||||
* extensions before use.
|
||||
*/
|
||||
private String trimDocumentName(String name) {
|
||||
String temp = name.toLowerCase();
|
||||
|
||||
if (temp.endsWith(FILE_EXTENSION)) {
|
||||
// strip the extension
|
||||
int nlen = name.length();
|
||||
int endIndex = nlen - FILE_EXTENSION.length();
|
||||
name = name.substring(0,endIndex);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,75 +16,52 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
||||
* MA 02111-1307 USA
|
||||
*
|
||||
* Copyright: 2001-2010 by Henrik Just
|
||||
* Copyright: 2001-2015 by Henrik Just
|
||||
*
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* version 1.2 (2010-03-28)
|
||||
* Version 1.6 (2015-06-22)
|
||||
*
|
||||
*/
|
||||
|
||||
package writer2latex.bibtex;
|
||||
|
||||
import writer2latex.api.Config;
|
||||
//import writer2latex.api.ConverterResult;
|
||||
import writer2latex.base.ConverterBase;
|
||||
import writer2latex.latex.LaTeXConfig;
|
||||
import writer2latex.office.BibMark;
|
||||
import writer2latex.office.XMLString;
|
||||
import writer2latex.util.Misc;
|
||||
|
||||
//import writer2latex.xmerge.ConvertData;
|
||||
//import writer2latex.xmerge.OfficeDocument;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* <p>BibTeX export</p>
|
||||
*
|
||||
* <p>This class extracts bibliographic information from an OpenDocument text file to a BibTeX data file.</p>
|
||||
*
|
||||
/** This class exports bibliographic information from an OpenDocument text file to a BibTeX data file
|
||||
*/
|
||||
public final class Converter extends ConverterBase {
|
||||
|
||||
// Configuration - TODO: Doesn't really use it - should use some fake config
|
||||
// Implement converter API
|
||||
|
||||
// TODO: Doesn't really use the configuration - should use some fake config
|
||||
private LaTeXConfig config;
|
||||
|
||||
public Config getConfig() { return config; }
|
||||
|
||||
// Constructor
|
||||
|
||||
public Converter() {
|
||||
super();
|
||||
config = new LaTeXConfig();
|
||||
}
|
||||
|
||||
@Override public Config getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Convert the data passed into the <code>InputStream</code>
|
||||
* into BibTeX format.</p>
|
||||
// Extend converter base
|
||||
|
||||
/** Convert the document into BibTeX format.</p>
|
||||
*
|
||||
* @throws IOException If any I/O error occurs.
|
||||
* @throws IOException If any I/O error occurs.
|
||||
*/
|
||||
public void convertInner() throws IOException {
|
||||
@Override public void convertInner() throws IOException {
|
||||
sTargetFileName = Misc.trimDocumentName(sTargetFileName,".bib");
|
||||
|
||||
BibTeXDocument bibDoc = new BibTeXDocument(sTargetFileName,true);
|
||||
|
||||
// Collect all text:bibliography-mark elements from the content
|
||||
Element doc = ofr.getContent();
|
||||
NodeList list;
|
||||
list = doc.getElementsByTagName(XMLString.TEXT_BIBLIOGRAPHY_MARK);
|
||||
int nLen = list.getLength();
|
||||
for (int i=0; i<nLen; i++) {
|
||||
String sIdentifier = Misc.getAttribute(list.item(i),XMLString.TEXT_IDENTIFIER);
|
||||
if (sIdentifier!=null && !bibDoc.containsKey(sIdentifier)) {
|
||||
bibDoc.put(new BibMark(list.item(i)));
|
||||
}
|
||||
}
|
||||
BibTeXDocument bibDoc = new BibTeXDocument(sTargetFileName,true,ofr);
|
||||
|
||||
// Add result
|
||||
converterResult.addDocument(bibDoc);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue