Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2772 issue fixed #3552

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/exporter/ExportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void actionPerformed(ActionEvent e) {

ExportFileFilter eff = (ExportFileFilter) ff;
String path = file.getPath();
if (!path.endsWith(eff.getExtension())) {
if (!path.endsWith(eff.getExtension().toString())) {
path = path + eff.getExtension();
}
file = new File(path);
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/jabref/gui/exporter/ExportFileFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import javax.swing.filechooser.FileFilter;

import org.jabref.logic.exporter.IExportFormat;
import org.jabref.logic.util.FileExtensions;

/**
* File filter that lets the user choose export format while choosing file to
Expand All @@ -14,13 +15,13 @@
public class ExportFileFilter extends FileFilter implements Comparable<ExportFileFilter> {

private final IExportFormat format;
private final String extension;
private final FileExtensions extension;
private final String name;


public ExportFileFilter(IExportFormat format) {
this.format = format;
this.extension = format.getExtension();
this.extension = format.getFileExtension();
this.name = format.getDisplayName() + " (*" + extension
+ ')';
}
Expand All @@ -29,7 +30,7 @@ public IExportFormat getExportFormat() {
return format;
}

public String getExtension() {
public FileExtensions getExtension() {
return extension;
}

Expand All @@ -38,7 +39,7 @@ public boolean accept(File file) {
if (file.isDirectory()) {
return true;
} else {
return file.getPath().toLowerCase(Locale.ROOT).endsWith(extension);
return file.getPath().toLowerCase(Locale.ROOT).endsWith(extension.toString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;

import com.sun.javafx.scene.control.skin.TextAreaSkin;
//import com.sun.javafx.scene.control.skin.TextAreaSkin;

public class EditorTextArea extends javafx.scene.control.TextArea implements Initializable {

Expand Down
38 changes: 18 additions & 20 deletions src/main/java/org/jabref/logic/exporter/BibTeXMLExportFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,27 @@
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import org.jabref.logic.importer.fileformat.bibtexml.Article;
import org.jabref.logic.importer.fileformat.bibtexml.Book;
import org.jabref.logic.importer.fileformat.bibtexml.Booklet;
import org.jabref.logic.importer.fileformat.bibtexml.Conference;
import org.jabref.logic.importer.fileformat.bibtexml.Entry;
import org.jabref.logic.importer.fileformat.bibtexml.File;
import org.jabref.logic.importer.fileformat.bibtexml.Inbook;
import org.jabref.logic.importer.fileformat.bibtexml.Incollection;
import org.jabref.logic.importer.fileformat.bibtexml.Inproceedings;
import org.jabref.logic.importer.fileformat.bibtexml.Manual;
import org.jabref.logic.importer.fileformat.bibtexml.Mastersthesis;
import org.jabref.logic.importer.fileformat.bibtexml.Misc;
import org.jabref.logic.importer.fileformat.bibtexml.Phdthesis;
import org.jabref.logic.importer.fileformat.bibtexml.Proceedings;
import org.jabref.logic.importer.fileformat.bibtexml.Techreport;
import org.jabref.logic.importer.fileformat.bibtexml.Unpublished;
import org.jabref.logic.util.FileExtensions;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.jabref.logic.importer.fileformat.bibtexml.Article;
import org.jabref.logic.importer.fileformat.bibtexml.Book;
import org.jabref.logic.importer.fileformat.bibtexml.Booklet;
import org.jabref.logic.importer.fileformat.bibtexml.Conference;
import org.jabref.logic.importer.fileformat.bibtexml.Entry;
import org.jabref.logic.importer.fileformat.bibtexml.File;
import org.jabref.logic.importer.fileformat.bibtexml.Inbook;
import org.jabref.logic.importer.fileformat.bibtexml.Incollection;
import org.jabref.logic.importer.fileformat.bibtexml.Inproceedings;
import org.jabref.logic.importer.fileformat.bibtexml.Manual;
import org.jabref.logic.importer.fileformat.bibtexml.Mastersthesis;
import org.jabref.logic.importer.fileformat.bibtexml.Misc;
import org.jabref.logic.importer.fileformat.bibtexml.Phdthesis;
import org.jabref.logic.importer.fileformat.bibtexml.Proceedings;
import org.jabref.logic.importer.fileformat.bibtexml.Techreport;
import org.jabref.logic.importer.fileformat.bibtexml.Unpublished;
/**
* Export format for the BibTeXML format.
*/
Expand All @@ -54,7 +52,7 @@ public class BibTeXMLExportFormat extends ExportFormat {


public BibTeXMLExportFormat() {
super("BibTeXML", "bibtexml", null, null, ".xml");
super("BibTeXML", "bibtexml", null, null, FileExtensions.XML);
}

@Override
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/org/jabref/logic/exporter/ExportFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.jabref.logic.layout.Layout;
import org.jabref.logic.layout.LayoutFormatterPreferences;
import org.jabref.logic.layout.LayoutHelper;
import org.jabref.logic.util.FileExtensions;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;

Expand All @@ -38,7 +39,7 @@ public class ExportFormat implements IExportFormat {
private String consoleName;
private String lfFileName;
private String directory;
private String extension;
private FileExtensions extension;
private Charset encoding; // If this value is set, it will be used to override
// the default encoding for the getCurrentBasePanel.
private LayoutFormatterPreferences layoutPreferences;
Expand All @@ -56,7 +57,7 @@ public class ExportFormat implements IExportFormat {
* @param directory Directory in which to find the layout file.
* @param extension Should contain the . (for instance .txt).
*/
public ExportFormat(String displayName, String consoleName, String lfFileName, String directory, String extension) {
public ExportFormat(String displayName, String consoleName, String lfFileName, String directory, FileExtensions extension) {
this.displayName = displayName;
this.consoleName = consoleName;
this.lfFileName = lfFileName;
Expand All @@ -76,8 +77,8 @@ public ExportFormat(String displayName, String consoleName, String lfFileName, S
* @param layoutPreferences Preferences for layout
* @param savePreferences Preferences for saving
*/
public ExportFormat(String displayName, String consoleName, String lfFileName, String directory, String extension,
LayoutFormatterPreferences layoutPreferences, SavePreferences savePreferences) {
public ExportFormat(String displayName, String consoleName, String lfFileName, String directory,
FileExtensions extension, LayoutFormatterPreferences layoutPreferences, SavePreferences savePreferences) {
this(displayName, consoleName, lfFileName, directory, extension);
this.layoutPreferences = layoutPreferences;
this.savePreferences = savePreferences;
Expand Down Expand Up @@ -131,7 +132,7 @@ public void setEncoding(Charset encoding) {
* @see IExportFormat#getExtension()
*/
@Override
public String getExtension() {
public FileExtensions getFileExtension() {
return extension;
}

Expand Down Expand Up @@ -239,7 +240,7 @@ public void performExport(final BibDatabaseContext databaseContext, final String
Layout defLayout;
LayoutHelper layoutHelper;
try (Reader reader = getReader(lfFileName + ".layout")) {
layoutHelper = new LayoutHelper(reader,layoutPreferences);
layoutHelper = new LayoutHelper(reader, layoutPreferences);
defLayout = layoutHelper.getLayoutFromText();
}
if (defLayout != null) {
Expand Down
53 changes: 22 additions & 31 deletions src/main/java/org/jabref/logic/exporter/ExportFormats.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.jabref.logic.l10n.Localization;
import org.jabref.logic.layout.LayoutFormatterPreferences;
import org.jabref.logic.util.FileExtensions;

public class ExportFormats {

Expand All @@ -21,41 +22,26 @@ private ExportFormats() {
public static void initAllExports(Map<String, ExportFormat> customFormats,
LayoutFormatterPreferences layoutPreferences, SavePreferences savePreferences) {

ExportFormats.EXPORT_FORMATS.clear();
EXPORT_FORMATS.clear();

// Initialize Build-In Export Formats
ExportFormats
.putFormat(new ExportFormat("HTML", "html", "html", null, ".html", layoutPreferences, savePreferences));
ExportFormats.putFormat(new ExportFormat(Localization.lang("Simple HTML"), "simplehtml", "simplehtml", null,
".html", layoutPreferences, savePreferences));
ExportFormats.putFormat(new ExportFormat("DocBook 4.4", "docbook", "docbook", null, ".xml", layoutPreferences,
savePreferences));
ExportFormats.putFormat(new ExportFormat("DIN 1505", "din1505", "din1505winword", "din1505", ".rtf",
layoutPreferences, savePreferences));
ExportFormats.putFormat(
new ExportFormat("BibO RDF", "bibordf", "bibordf", null, ".rdf", layoutPreferences, savePreferences));
ExportFormats.putFormat(new ExportFormat(Localization.lang("HTML table"), "tablerefs", "tablerefs", "tablerefs",
".html", layoutPreferences, savePreferences));
ExportFormats.putFormat(new ExportFormat(Localization.lang("HTML list"), "listrefs", "listrefs", "listrefs",
".html", layoutPreferences, savePreferences));
ExportFormats.putFormat(new ExportFormat(Localization.lang("HTML table (with Abstract & BibTeX)"),
"tablerefsabsbib", "tablerefsabsbib", "tablerefsabsbib", ".html", layoutPreferences, savePreferences));
ExportFormats.putFormat(new ExportFormat("Harvard RTF", "harvard", "harvard", "harvard", ".rtf",
layoutPreferences, savePreferences));
ExportFormats.putFormat(new ExportFormat("ISO 690 RTF", "iso690rtf", "iso690RTF", "iso690rtf", ".rtf",
layoutPreferences, savePreferences));
ExportFormats.putFormat(new ExportFormat("ISO 690", "iso690txt", "iso690", "iso690txt", ".txt",
layoutPreferences, savePreferences));
ExportFormats.putFormat(new ExportFormat("Endnote", "endnote", "EndNote", "endnote", ".txt", layoutPreferences,
savePreferences));
ExportFormats.putFormat(new ExportFormat("OpenOffice/LibreOffice CSV", "oocsv", "openoffice-csv", "openoffice",
".csv", layoutPreferences, savePreferences));
ExportFormat ef = new ExportFormat("RIS", "ris", "ris", "ris", ".ris", layoutPreferences, savePreferences);
putFormat(new ExportFormat("HTML", "html", "html", null, FileExtensions.HTML, layoutPreferences, savePreferences));
putFormat(new ExportFormat(Localization.lang("Simple HTML"), "simplehtml", "simplehtml", null, FileExtensions.HTML, layoutPreferences, savePreferences));
putFormat(new ExportFormat("DocBook 4.4", "docbook", "docbook", "", FileExtensions.XML, layoutPreferences, savePreferences));
putFormat(new ExportFormat("DIN 1505", "din1505", "din1505winword", "din1505", FileExtensions.RTF, layoutPreferences, savePreferences));
putFormat(new ExportFormat("BibO RDF", "bibordf", "bibordf", null, FileExtensions.RDF, layoutPreferences, savePreferences));
putFormat(new ExportFormat(Localization.lang("HTML table"), "tablerefs", "tablerefs", "tablerefs", FileExtensions.HTML, layoutPreferences, savePreferences));
putFormat(new ExportFormat(Localization.lang("HTML list"), "listrefs", "listrefs", "listrefs", FileExtensions.HTML, layoutPreferences, savePreferences));
putFormat(new ExportFormat(Localization.lang("HTML table (with Abstract & BibTeX)"), "tablerefsabsbib", "tablerefsabsbib", "tablerefsabsbib", FileExtensions.HTML, layoutPreferences, savePreferences));
putFormat(new ExportFormat("Harvard RTF", "harvard", "harvard", "harvard", FileExtensions.RTF, layoutPreferences, savePreferences));
putFormat(new ExportFormat("ISO 690 RTF", "iso690rtf", "iso690RTF", "iso690rtf", FileExtensions.RTF, layoutPreferences, savePreferences));
putFormat(new ExportFormat("ISO 690", "iso690txt", "iso690", "iso690txt", FileExtensions.TXT, layoutPreferences, savePreferences));
putFormat(new ExportFormat("Endnote", "endnote", "EndNote", "endnote", FileExtensions.TXT, layoutPreferences, savePreferences));
putFormat(new ExportFormat("OpenOffice/LibreOffice CSV", "oocsv", "openoffice-csv", "openoffice", FileExtensions.CSV, layoutPreferences, savePreferences));
ExportFormat ef = new ExportFormat("RIS", "ris", "ris", "ris", FileExtensions.RIS, layoutPreferences, savePreferences);
ef.setEncoding(StandardCharsets.UTF_8);
ExportFormats.putFormat(ef);
ExportFormats.putFormat(
new ExportFormat("MIS Quarterly", "misq", "misq", "misq", ".rtf", layoutPreferences, savePreferences));

putFormat(new ExportFormat("MIS Quarterly", "misq", "misq", "misq", FileExtensions.RTF, layoutPreferences, savePreferences));
ExportFormats.putFormat(new BibTeXMLExportFormat());
ExportFormats.putFormat(new OpenOfficeDocumentCreator());
ExportFormats.putFormat(new OpenDocumentSpreadsheetCreator());
Expand Down Expand Up @@ -121,4 +107,9 @@ private static void putFormat(IExportFormat format) {
ExportFormats.EXPORT_FORMATS.put(format.getConsoleName(), format);
}

// getExtension from ExportFormat map
public static FileExtensions getFileExtension(String extension) {
ExportFormat exportFormat = (ExportFormat) EXPORT_FORMATS.get(extension);
return exportFormat.getFileExtension();
}
}
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/logic/exporter/IExportFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.nio.charset.Charset;
import java.util.List;

import org.jabref.logic.util.FileExtensions;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;

Expand All @@ -19,7 +20,8 @@ public interface IExportFormat {
*/
String getDisplayName();

String getExtension();
FileExtensions getFileExtension();


/**
* Perform the export.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javax.xml.transform.stream.StreamResult;

import org.jabref.logic.msbib.MSBibDatabase;
import org.jabref.logic.util.FileExtensions;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;

Expand All @@ -25,7 +26,7 @@
class MSBibExportFormat extends ExportFormat {

public MSBibExportFormat() {
super("MS Office 2007", "MSBib", null, null, ".xml");
super("MS Office 2007", "MSBib", null, null, FileExtensions.XML);
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/jabref/logic/exporter/ModsExportFormat.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jabref.logic.exporter;

import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.charset.Charset;
Expand All @@ -14,6 +13,7 @@
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;

import org.jabref.logic.importer.fileformat.bibtexml.File;
import org.jabref.logic.importer.fileformat.mods.AbstractDefinition;
import org.jabref.logic.importer.fileformat.mods.CodeOrText;
import org.jabref.logic.importer.fileformat.mods.DateDefinition;
Expand Down Expand Up @@ -43,6 +43,7 @@
import org.jabref.logic.importer.fileformat.mods.TitleInfoDefinition;
import org.jabref.logic.importer.fileformat.mods.TypeOfResourceDefinition;
import org.jabref.logic.importer.fileformat.mods.UrlDefinition;
import org.jabref.logic.util.FileExtensions;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.FieldName;
Expand All @@ -61,7 +62,7 @@ class ModsExportFormat extends ExportFormat {


public ModsExportFormat() {
super("MODS", "mods", null, null, ".xml");
super("MODS", "mods", null, null, FileExtensions.XML);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javax.xml.transform.stream.StreamResult;

import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.FileExtensions;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand All @@ -45,7 +46,8 @@ public class OpenDocumentSpreadsheetCreator extends ExportFormat {
* Creates a new instance of OpenOfficeDocumentCreator
*/
public OpenDocumentSpreadsheetCreator() {
super(Localization.lang("OpenDocument spreadsheet"), "ods", null, null, ".ods");
super(Localization.lang("OpenDocument spreadsheet"), "ods", null, null, FileExtensions.CSV);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.jabref.logic.util.FileExtensions;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.database.BibDatabaseContext;
import org.jabref.model.entry.BibEntry;
Expand All @@ -43,7 +44,7 @@ public class OpenOfficeDocumentCreator extends ExportFormat {
* Creates a new instance of OpenOfficeDocumentCreator
*/
public OpenOfficeDocumentCreator() {
super("OpenOffice/LibreOffice Calc", "oocalc", null, null, ".sxc");
super("OpenOffice/LibreOffice Calc", "oocalc", null, null, FileExtensions.CSV);
}

@Override
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/org/jabref/logic/util/FileExtensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public enum FileExtensions {
CLASS(Localization.lang("%0 file", "CLASS"), "class"),
JAR(Localization.lang("%0 file", "JAR"), "jar"),
XML(Localization.lang("%0 file", "XML"), "xml"),
ZIP(Localization.lang("%0 file", "ZIP"), "zip");
ZIP(Localization.lang("%0 file", "ZIP"), "zip"),
HTML(Localization.lang("%0 file", "HTML"), "html"),
RTF(Localization.lang("%0 file", "RTF"), "rtf"),
CSV(Localization.lang("%0 file", "CSV"), "csv"),
RDF(Localization.lang("%0 file", "RDF"), "rdf");

private final String[] extension;
private final String description;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/jabref/preferences/CustomExportList.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import java.util.TreeMap;

import org.jabref.logic.exporter.ExportFormat;
import org.jabref.logic.exporter.ExportFormats;
import org.jabref.logic.exporter.SavePreferences;
import org.jabref.logic.journals.JournalAbbreviationLoader;
import org.jabref.logic.layout.LayoutFormatterPreferences;

import ca.odell.glazedlists.BasicEventList;
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.SortedList;
Expand Down Expand Up @@ -90,8 +90,7 @@ private Optional<ExportFormat> createFormat(List<String> s, LayoutFormatterPrefe
} else {
lfFileName = s.get(1);
}
ExportFormat format = new ExportFormat(s.get(0), s.get(0), lfFileName, null, s.get(2), layoutPreferences,
savePreferences);
ExportFormat format = new ExportFormat(s.get(0), s.get(0), lfFileName, null, ExportFormats.getFileExtension(s.get(2)), layoutPreferences, savePreferences);
format.setCustomExport(true);
return Optional.of(format);
}
Expand Down