Description: This is the diff between the debian branch and the v_2.10 tag in upstream git; the debian branch was created for us with the purpose to disable the mrDlib functionality which needs libraries not packaged in Debian yet. Origin: upstream git Forwarded: not-needed Author: Oliver Kopp Reviewed-by: gregor herrmann Last-Update: 2015-05-19 --- a/src/main/java/net/sf/jabref/ImportSettingsTab.java +++ b/src/main/java/net/sf/jabref/ImportSettingsTab.java @@ -44,10 +44,8 @@ private JRadioButton radioButtonXmp; private JRadioButton radioButtonPDFcontent; - private JRadioButton radioButtonMrDlib; private JRadioButton radioButtonNoMeta; private JRadioButton radioButtononlyAttachPDF; - private JRadioButton radioButtonUpdateEmptyFields; private JCheckBox useDefaultPDFImportStyle; private JTextField fileNamePattern; @@ -59,17 +57,12 @@ radioButtonNoMeta = new JRadioButton(Globals.lang("Create_blank_entry_linking_the_PDF")); radioButtonXmp = new JRadioButton(Globals.lang("Create_entry_based_on_XMP_data")); radioButtonPDFcontent = new JRadioButton(Globals.lang("Create_entry_based_on_content")); - radioButtonMrDlib = new JRadioButton(Globals.lang("Create_entry_based_on_data_fetched_from")+" Mr.DLib"); radioButtononlyAttachPDF = new JRadioButton(Globals.lang("Only_attach_PDF")); - radioButtonUpdateEmptyFields = new JRadioButton(Globals.lang("Update_empty_fields_with_data_fetched_from") - +" Mr.DLib"); ButtonGroup bg = new ButtonGroup(); bg.add(radioButtonNoMeta); bg.add(radioButtonXmp); bg.add(radioButtonPDFcontent); - bg.add(radioButtonMrDlib); bg.add(radioButtononlyAttachPDF); - bg.add(radioButtonUpdateEmptyFields); useDefaultPDFImportStyle = new JCheckBox(Globals.lang("Always use this PDF import style (and do not ask for each import)")); @@ -96,15 +89,9 @@ builder.append(radioButtonPDFcontent); builder.nextLine(); builder.append(pan); - builder.append(radioButtonMrDlib); - builder.nextLine(); - builder.append(pan); builder.append(radioButtononlyAttachPDF); builder.nextLine(); builder.append(pan); - builder.append(radioButtonUpdateEmptyFields); - builder.nextLine(); - builder.append(pan); builder.append(useDefaultPDFImportStyle); builder.nextLine(); @@ -136,15 +123,9 @@ case ImportDialog.CONTENT: radioButtonPDFcontent.setSelected(true); break; - case ImportDialog.MRDLIB: - radioButtonMrDlib.setSelected(true); - break; case ImportDialog.ONLYATTACH: radioButtononlyAttachPDF.setSelected(true); break; - case ImportDialog.UPDATEEMPTYFIELDS: - radioButtonUpdateEmptyFields.setSelected(true); - break; default: // fallback radioButtonPDFcontent.setSelected(true); @@ -162,12 +143,9 @@ style = ImportDialog.XMP; else if (radioButtonPDFcontent.isSelected()) style = ImportDialog.CONTENT; - else if (radioButtonMrDlib.isSelected()) - style = ImportDialog.MRDLIB; else if (radioButtononlyAttachPDF.isSelected()) style = ImportDialog.ONLYATTACH; - else if (radioButtonUpdateEmptyFields.isSelected()) - style = ImportDialog.UPDATEEMPTYFIELDS; + else throw new IllegalStateException(); Globals.prefs.putInt(PREF_IMPORT_DEFAULT_PDF_IMPORT_STYLE, style); Globals.prefs.put(PREF_IMPORT_FILENAMEPATTERN, fileNamePattern.getText()); } --- a/src/main/java/net/sf/jabref/JabRefFrame.java +++ b/src/main/java/net/sf/jabref/JabRefFrame.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2003-2012 JabRef contributors. +/* Copyright (C) 2003-2011 JabRef contributors. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -39,8 +39,6 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import org.java.ayatana.ApplicationMenu; - import net.sf.jabref.export.*; import net.sf.jabref.external.ExternalFileTypeEditor; import net.sf.jabref.external.PushToApplicationButton; @@ -574,13 +572,6 @@ } } }); - - // The following sets up integration with Unity's global menu, but currently (Nov 18, 2012) - // this doesn't work with OpenJDK 6 (leads to crash), only with 7. - String javaVersion = System.getProperty("java.version", null); - if (javaVersion.compareTo("1.7") >= 0) - ApplicationMenu.tryInstall(this); - } public void setWindowTitle() { --- a/src/main/java/spl/PdfImporter.java +++ b/src/main/java/spl/PdfImporter.java @@ -19,12 +19,8 @@ import net.sf.jabref.undo.UndoableInsertEntry; import net.sf.jabref.util.XMPUtil; -import org.sciplore.beans.Document; - import spl.filter.PdfFileFilter; import spl.gui.ImportDialog; -import spl.gui.MetaDataListDialog; - /** * Created by IntelliJ IDEA. @@ -129,7 +125,6 @@ BibtexEntryType type; InputStream in = null; List localRes = null; - MetaDataListDialog metaDataListDialog; switch (choice) { case ImportDialog.XMP: //SplDatabaseChangeListener dataListener = new SplDatabaseChangeListener(frame, panel, entryTable, fileName); @@ -222,88 +217,10 @@ } res.add(entry); break; - case ImportDialog.MRDLIB: - metaDataListDialog = new MetaDataListDialog(fileName, true); - Tools.centerRelativeToWindow(metaDataListDialog, frame); - metaDataListDialog.showDialog(); - Document document = metaDataListDialog.getXmlDocuments(); - entry = null; // to satisfy the Java compiler - if(document != null /*&& documents.getDocuments() != null && documents.getDocuments().size() > 0*/ && metaDataListDialog.getResult() == JOptionPane.OK_OPTION){ - int selected = metaDataListDialog.getTableMetadata().getSelectedRow(); - if(selected > -1 /*&& selected < documents.getDocuments().size()*/){ - //Document document = documents/*.getDocuments().get(selected)*/; - String id = Util.createNeutralId(); - entry = new BibtexEntry(id); - if(fieldExists(document.getType())){ - type = BibtexEntryType.getStandardType(document.getType()); - if(type == null){ - type = BibtexEntryType.ARTICLE; - } - entry.setType(type); - } - else{ - entry.setType(BibtexEntryType.ARTICLE); - } - ArrayList list = new ArrayList(); - list.add(entry); - Util.setAutomaticFields(list, true, true, false); - //insertFields(entry.getRequiredFields(), entry, document); - insertFields(BibtexFields.getAllFieldNames(), entry, document); - //insertFields(entry.getOptionalFields(), entry, document); - panel.database().insertEntry(entry); - dfh = new DroppedFileHandler(frame, panel); - dfh.linkPdfToEntry(fileName, entryTable, entry); - LabelPatternUtil.makeLabel(panel.metaData(), panel.database(), entry); - } - else{ - entry = createNewBlankEntry(fileName); - } - } - else if(metaDataListDialog.getResult() == JOptionPane.CANCEL_OPTION ){ - continue; - } - else if(metaDataListDialog.getResult() == JOptionPane.NO_OPTION ){ - entry = createNewBlankEntry(fileName); - } - else if(document == null /*|| document.getDocuments() == null || document.getDocuments().size() <= 0*/ && metaDataListDialog.getResult() == JOptionPane.OK_OPTION){ - entry = createNewBlankEntry(fileName); - } - assert(entry != null); - res.add(entry); - break; case ImportDialog.NOMETA: entry = createNewBlankEntry(fileName); res.add(entry); break; - case ImportDialog.UPDATEEMPTYFIELDS: - metaDataListDialog = new MetaDataListDialog(fileName, false); - Tools.centerRelativeToWindow(metaDataListDialog, frame); - metaDataListDialog.showDialog(); - document = metaDataListDialog.getXmlDocuments(); - if(document != null /*&& document.getDocuments() != null && document.getDocuments().size() > 0*/ && metaDataListDialog.getResult() == JOptionPane.OK_OPTION){ - int selected = metaDataListDialog.getTableMetadata().getSelectedRow(); - if(selected > -1 /*&& selected < document.getDocuments().size()*/){ - //XmlDocument document = documents.getDocuments().get(selected); - entry = entryTable.getEntryAt(dropRow); - if(fieldExists(document.getType())){ - type = BibtexEntryType.getStandardType(document.getType()); - if(type != null){ - entry.setType(type); - } - } - //insertFields(entry.getRequiredFields(), entry, document); - insertFields(BibtexFields.getAllFieldNames(), entry, document); - //insertFields(entry.getOptionalFields(), entry, document); - - dfh = new DroppedFileHandler(frame, panel); - dfh.linkPdfToEntry(fileName, entryTable, dropRow); - } - } - break; - case ImportDialog.ONLYATTACH: - dfh = new DroppedFileHandler(frame, panel); - dfh.linkPdfToEntry(fileName, entryTable, dropRow); - break; } } @@ -322,58 +239,6 @@ return newEntry; } - private void insertFields(String[] fields, BibtexEntry entry, Document xmlDocument) { - DocumentWrapper document = new DocumentWrapper(xmlDocument); - for(String field : fields){ - if(entry.getField(field) != null){ - continue; - } - if(field.equalsIgnoreCase("author")){ - entry.setField(field, document.getAuthors("and")); - } - if(field.equalsIgnoreCase("title")){ - entry.setField(field, document.getTitle()); - } - if(field.equalsIgnoreCase("abstract")){ - entry.setField(field, document.getAbstract()); - } - /*if(field.equalsIgnoreCase("keywords")){ - entry.setField(field, document.getKeyWords()); - }*/ - if(field.equalsIgnoreCase("doi")){ - entry.setField(field, document.getDoi()); - } - /*if(field.equalsIgnoreCase("pages")){ - entry.setField(field, document.getPages()); - } - if(field.equalsIgnoreCase("volume")){ - entry.setField(field, document.getVolume()); - } - if(field.equalsIgnoreCase("number")){ - entry.setField(field, document.getNumber()); - }*/ - if(field.equalsIgnoreCase("year")){ - entry.setField(field, document.getYear()); - } - /*if(field.equalsIgnoreCase("month")){ - entry.setField(field, document.getMonth()); - } - if(field.equalsIgnoreCase("day")){ - entry.setField(field, document.getDay()); - } - if(field.equalsIgnoreCase("booktitle")){ - entry.setField(field, document.getVenue()); - } - if(field.equalsIgnoreCase("journal")){ - entry.setField(field, document.getVenue()); - }*/ - } - } - - private boolean fieldExists(String string) { - return string != null && !string.isEmpty(); - } - private BibtexEntry createNewEntry() { // Find out what type is wanted. --- a/src/main/java/spl/gui/ImportDialog.java +++ b/src/main/java/spl/gui/ImportDialog.java @@ -17,19 +17,15 @@ public final static int NOMETA = 0; public final static int XMP = 1; public final static int CONTENT = 2; - public final static int MRDLIB = 3; public final static int ONLYATTACH = 4; - public final static int UPDATEEMPTYFIELDS = 5; private JPanel contentPane; private JCheckBox checkBoxDoNotShowAgain; private JCheckBox useDefaultPDFImportStyle; private JRadioButton radioButtonXmp; private JRadioButton radioButtonPDFcontent; - private JRadioButton radioButtonMrDlib; private JRadioButton radioButtonNoMeta; private JRadioButton radioButtononlyAttachPDF; - private JRadioButton radioButtonUpdateEmptyFields; private int result; public ImportDialog(boolean targetIsARow, String fileName) { @@ -59,15 +55,7 @@ radioButtonNoMeta = new JRadioButton(Globals.lang("Create_blank_entry_linking_the_PDF")); radioButtonXmp = new JRadioButton(Globals.lang("Create_entry_based_on_XMP_data")); radioButtonPDFcontent = new JRadioButton(Globals.lang("Create_entry_based_on_content")); - radioButtonMrDlib = new JRadioButton(Globals.lang("Create_entry_based_on_data_fetched_from")); radioButtononlyAttachPDF = new JRadioButton(Globals.lang("Only_attach_PDF")); - radioButtonUpdateEmptyFields = new JRadioButton(Globals.lang("Update_empty_fields_with_data_fetched_from")); - JLabel labelMrDlib1 = new JLabel("Mr._dLib"); - labelMrDlib1.setFont(new Font(labelMrDlib1.getFont().getName(), Font.BOLD, 13)); - labelMrDlib1.setForeground(new Color(-16776961)); - JLabel labelMrDlib2 = new JLabel("Mr._dLib"); - labelMrDlib2.setFont(new Font(labelMrDlib1.getFont().getName(), Font.BOLD, 13)); - labelMrDlib2.setForeground(new Color(-16776961)); JButton buttonOK = new JButton(Globals.lang("Ok")); JButton buttonCancel = new JButton(Globals.lang("Cancel")); checkBoxDoNotShowAgain = new JCheckBox(Globals.lang("Do not show this box again for this import")); @@ -77,12 +65,8 @@ b.append(radioButtonNoMeta, 3); b.append(radioButtonXmp, 3); b.append(radioButtonPDFcontent, 3); - b.append(radioButtonMrDlib); - b.append(labelMrDlib1); b.appendSeparator(Globals.lang("Update_Existing_Entry")); b.append(radioButtononlyAttachPDF, 3); - b.append(radioButtonUpdateEmptyFields); - b.append(labelMrDlib2); b.nextLine(); b.append(checkBoxDoNotShowAgain); b.append(useDefaultPDFImportStyle); @@ -100,8 +84,6 @@ if (!targetIsARow1) { this.radioButtononlyAttachPDF.setEnabled(false); - this.radioButtonUpdateEmptyFields.setEnabled(false); - labelMrDlib2.setEnabled(false); } String fileName1 = fileName; String name = new File(fileName1).getName(); @@ -110,8 +92,6 @@ } else { labelFileName.setText(new File(fileName1).getName().substring(0, 33) + "..."); } - labelMrDlib1.addMouseListener(new LabelLinkListener(labelMrDlib1, "www.mr-dlib.org/docs/pdf_metadata_extraction.php")); - labelMrDlib2.addMouseListener(new LabelLinkListener(labelMrDlib2, "www.mr-dlib.org/docs/pdf_metadata_extraction.php")); this.setTitle(LocalizationSupport.message("Import_Metadata_From_PDF")); setModal(true); @@ -122,9 +102,7 @@ bg.add(radioButtonNoMeta); bg.add(radioButtonXmp); bg.add(radioButtonPDFcontent); - bg.add(radioButtonMrDlib); bg.add(radioButtononlyAttachPDF); - bg.add(radioButtonUpdateEmptyFields); buttonOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -161,15 +139,9 @@ case CONTENT: radioButtonPDFcontent.setSelected(true); break; - case MRDLIB: - radioButtonMrDlib.setSelected(true); - break; case ONLYATTACH: radioButtononlyAttachPDF.setSelected(true); break; - case UPDATEEMPTYFIELDS: - radioButtonUpdateEmptyFields.setSelected(true); - break; default: // fallback radioButtonPDFcontent.setSelected(true); @@ -204,14 +176,10 @@ return XMP; else if (radioButtonPDFcontent.isSelected()) return CONTENT; - else if (radioButtonMrDlib.isSelected()) - return MRDLIB; else if (radioButtonNoMeta.isSelected()) return NOMETA; else if (radioButtononlyAttachPDF.isSelected()) return ONLYATTACH; - else if (radioButtonUpdateEmptyFields.isSelected()) - return UPDATEEMPTYFIELDS; else throw new IllegalStateException(); } --- a/src/main/java/spl/DocumentWrapper.java +++ b/src/main/java/spl/DocumentWrapper.java @@ -1,244 +0,0 @@ -package spl; - -import java.util.List; - -import org.sciplore.beans.Abstract; -import org.sciplore.beans.Author; -import org.sciplore.beans.Document; -import org.sciplore.formatter.Bean; -import org.sciplore.formatter.SimpleTypeElementBean; - -/** - * Created by IntelliJ IDEA. - * User: Christoph Arbeit - * Date: 10.09.2010 - * Time: 20:02:51 - * To change this template use File | Settings | File Templates. - */ -public class DocumentWrapper { - - Document xmlDocument; - - public DocumentWrapper(Document xmlDocument) { - this.xmlDocument = xmlDocument; - } - - public Document getXmlDocument() { - return xmlDocument; - } - - public void setXmlDocument(Document xmlDocument) { - this.xmlDocument = xmlDocument; - } - - public String getTitle(){ - if(this.hasTitle()){ - return xmlDocument.getTitle().getValue(); - } - else{ - return ""; - } - } - - public boolean hasTitle(){ - return (xmlDocument.getTitle() != null && xmlDocument.getTitle().getValue() != null && !xmlDocument.getTitle().getValue().isEmpty()); - } - - public String getAbstract(){ - if(this.hasAbstract()){ - return ((Abstract)xmlDocument.getAbstract()).getValue(); - } - else{ - return ""; - } - } - - public boolean hasAbstract(){ - return (xmlDocument.getAbstract() != null && ((Abstract)xmlDocument.getAbstract()).getValue() != null && !((Abstract)xmlDocument.getAbstract()).getValue().isEmpty()); - } - - public String getAuthors(String seperator){ - if(this.hasAuthors()){ - List authors = xmlDocument.getAuthors().getCollection(); - authors = DocumentsWrapper.sortAuthors(authors); - String value = ""; - int i = 1; - for(Bean author : authors){ - if(i < authors.size()){ - value = value + getNameComplete((Author)author); - value = value + " " + seperator + " "; - } - else{ - value = value + getNameComplete((Author)author); - } - i++; - } - return value; - } - else{ - return ""; - } - } - - public boolean hasAuthors(){ - return (xmlDocument.getAuthors() != null && xmlDocument.getAuthors().getCollection() != null && !xmlDocument.getAuthors().getCollection().isEmpty()); - } - - /* public String getKeyWords(){ - if(this.hasKeyWords()){ - List keywords = xmlDocument.getKeywords().getKeywords(); - String value = ""; - int i = 1; - for(XmlKeyword keyword : keywords){ - if(i < keywords.size()){ - value = value + keyword.getValue(); - value = value + ", "; - } - else{ - value = value + keyword.getValue(); - } - i++; - } - return value; - } - else{ - return ""; - } - } - - public boolean hasKeyWords(){ - return (xmlDocument.getKeywords() != null && xmlDocument.getKeywords().getKeywords() != null && !xmlDocument.getKeywords().getKeywords().isEmpty()); - } -*/ - - public String getDoi(){ - if(this.hasDoi()){ - return this.getSimpleTypeValue(xmlDocument.getDoi()); - } - else{ - return ""; - } - } - - public boolean hasDoi(){ - return (xmlDocument.getDoi() != null && this.getSimpleTypeValue(xmlDocument.getDoi()) != null && !this.getSimpleTypeValue(xmlDocument.getDoi()).isEmpty()); - } -/* - public String getPages(){ - if(this.hasPages()){ - return xmlDocument.getPages().getValue(); - } - else{ - return ""; - } - } - - public boolean hasPages(){ - return (xmlDocument.getPages() != null && xmlDocument.getPages().getValue() != null && !xmlDocument.getPages().getValue().isEmpty()); - } - - public String getVolume(){ - if(this.hasVolume()){ - return xmlDocument.getVolume().getValue(); - } - else{ - return ""; - } - } - - public boolean hasVolume(){ - return (xmlDocument.getVolume() != null && xmlDocument.getVolume().getValue() != null && !xmlDocument.getVolume().getValue().isEmpty()); - } - - public String getNumber(){ - if(this.hasNumber()){ - return xmlDocument.getNumber().getValue(); - } - else{ - return ""; - } - } - - public boolean hasNumber(){ - return (xmlDocument.getNumber() != null && xmlDocument.getNumber().getValue() != null && !xmlDocument.getNumber().getValue().isEmpty()); - } -*/ - - public String getYear(){ - if(this.hasYear()){ - return this.getSimpleTypeValue(xmlDocument.getYear()); - } - else{ - return ""; - } - } - - public boolean hasYear(){ - return (this.getSimpleTypeValue(xmlDocument.getYear()) != null && !this.getSimpleTypeValue(xmlDocument.getYear()).isEmpty() && !this.getSimpleTypeValue(xmlDocument.getYear()).equalsIgnoreCase("null")); - } - -/* - public String getMonth(){ - if(this.hasMonth()){ - return xmlDocument.getPublishdate().getMonth(); - } - else{ - return ""; - } - } - - public boolean hasMonth(){ - return (xmlDocument.getPublishdate() != null && xmlDocument.getPublishdate().getMonth() != null && !xmlDocument.getPublishdate().getMonth().isEmpty()); - } - - public String getDay(){ - if(this.hasDay()){ - return xmlDocument.getPublishdate().getDay(); - } - else{ - return ""; - } - } - - public boolean hasDay(){ - return (xmlDocument.getPublishdate() != null && xmlDocument.getPublishdate().getDay() != null && !xmlDocument.getPublishdate().getDay().isEmpty()); - } - - /* - public String getVenue() { - if(this.hasVenue()){ - return xmlDocument.getVenue().getValue(); - } - else{ - return ""; - } - } - - public boolean hasVenue(){ - return (xmlDocument.getVenue() != null && xmlDocument.getVenue().getValue() != null && !xmlDocument.getVenue().getValue().isEmpty()); - }*/ - - private String getNameComplete(Author author){ - if(author == null) return ""; - String result = ""; - if(getSimpleTypeValue(author.getName_First()) != null) - result = result + getSimpleTypeValue(author.getName_First()).trim() + " "; - if(getSimpleTypeValue(author.getName_Middle()) != null) - result = result + getSimpleTypeValue(author.getName_Middle()).trim() + " "; - if(getSimpleTypeValue(author.getName_Last_Prefix()) != null) - result = result + getSimpleTypeValue(author.getName_Last_Prefix()).trim() + " "; - if(getSimpleTypeValue(author.getName_Last()) != null) - result = result + getSimpleTypeValue(author.getName_Last()).trim() + " "; - if(getSimpleTypeValue(author.getName_Last_Suffix()) != null) - result = result + getSimpleTypeValue(author.getName_Last_Suffix()).trim() + " "; - return result.trim(); - } - - private String getSimpleTypeValue(Bean bean){ - if(bean == null || !(bean instanceof SimpleTypeElementBean)) return null; - SimpleTypeElementBean simpleTypeElementBean = (SimpleTypeElementBean)bean; - if(simpleTypeElementBean.getValue() == null || simpleTypeElementBean.getValue().equalsIgnoreCase("null") || simpleTypeElementBean.getValue().length() <= 0) return null; - return simpleTypeElementBean.getValue(); - } - -} --- a/src/main/java/spl/DocumentsWrapper.java +++ b/src/main/java/spl/DocumentsWrapper.java @@ -1,132 +0,0 @@ -package spl; - -import java.util.ArrayList; -import java.util.List; -import java.util.Vector; - -import org.sciplore.beans.Author; -import org.sciplore.beans.Document; -import org.sciplore.beans.Year; -import org.sciplore.formatter.Bean; -import org.sciplore.formatter.SimpleTypeElementBean; - -/** - * Created by IntelliJ IDEA. - * User: Christoph Arbeit - * Date: 09.09.2010 - * Time: 10:56:50 - * To change this template use File | Settings | File Templates. - */ -public class DocumentsWrapper { - - Document xmlDocuments; - - public DocumentsWrapper(Document documents) { - this.xmlDocuments = documents; - } - - public Document getXmlDocuments() { - return xmlDocuments; - } - - public void setXmlDocuments(Document xmlDocuments) { - this.xmlDocuments = xmlDocuments; - } - - public List> getDocuments(){ - List> documents = new ArrayList>(); - //List xmlDocuments = this.xmlDocuments.getDocuments(); - //for(XmlDocument xmlDocument : xmlDocuments){ - Document xmlDocument = xmlDocuments; - Vector vector = new Vector(); - if(xmlDocument.getTitle() != null){ - vector.add(xmlDocument.getTitle().getValue()); - } - else{ - vector.add(""); - } - if(xmlDocument.getAuthors() != null){ - List authors = xmlDocument.getAuthors().getCollection(); - authors = sortAuthors(authors); - String value = ""; - int i = 1; - for(Bean author : authors){ - if(i < authors.size()){ - value = value + getNameComplete(((Author)author)); - value = value + ", "; - } - else{ - value = value + getNameComplete(((Author)author)); - } - i++; - } - vector.add(value); - } - else{ - vector.add(""); - } - if(xmlDocument.getYear() != null && ((Year)xmlDocument.getYear()).getValue() != null && !((Year)xmlDocument.getYear()).getValue().equalsIgnoreCase("null")){ - vector.add(((Year)xmlDocument.getYear()).getValue()); - } - /*if(xmlDocument.getPublishdate() != null && xmlDocument.getPublishdate().getYear() != null && !xmlDocument.getPublishdate().getYear().equalsIgnoreCase("null")){ - vector.add(xmlDocument.getPublishdate().getYear()); - }*/ - else{ - vector.add(""); - } - documents.add(vector); - //} - return documents; - } - - private String getNameComplete(Author author){ - if(author == null) return ""; - String result = ""; - if(getSimpleTypeValue(author.getName_First()) != null) - result = result + getSimpleTypeValue(author.getName_First()).trim() + " "; - if(getSimpleTypeValue(author.getName_Middle()) != null) - result = result + getSimpleTypeValue(author.getName_Middle()).trim() + " "; - if(getSimpleTypeValue(author.getName_Last_Prefix()) != null) - result = result + getSimpleTypeValue(author.getName_Last_Prefix()).trim() + " "; - if(getSimpleTypeValue(author.getName_Last()) != null) - result = result + getSimpleTypeValue(author.getName_Last()).trim() + " "; - if(getSimpleTypeValue(author.getName_Last_Suffix()) != null) - result = result + getSimpleTypeValue(author.getName_Last_Suffix()).trim() + " "; - return result.trim(); - } - - private String getSimpleTypeValue(Bean bean){ - if(bean == null || !(bean instanceof SimpleTypeElementBean)) return null; - SimpleTypeElementBean simpleTypeElementBean = (SimpleTypeElementBean)bean; - if(simpleTypeElementBean.getValue() == null || simpleTypeElementBean.getValue().equalsIgnoreCase("null") || simpleTypeElementBean.getValue().length() <= 0) return null; - return simpleTypeElementBean.getValue(); - } - - protected static List sortAuthors(List authors){ - boolean unsorted = true; - Bean temp; - - while (unsorted){ - unsorted = false; - for (int i = 0; i < authors.size() - 1; i++){ - int rank = 99; - int otherRank = 99; - if(((Author)authors.get(i)).getRank() != null && !((Author)authors.get(i)).getRank().equalsIgnoreCase("null")){ - rank = Integer.parseInt(((Author)authors.get(i)).getRank()); - } - if(((Author)authors.get(i + 1)).getRank() != null && !((Author)authors.get(i + 1)).getRank().equalsIgnoreCase("null")){ - otherRank = Integer.parseInt(((Author)authors.get(i + 1)).getRank()); - } - - if (rank > otherRank) { - temp = authors.get(i); - authors.set(i, authors.get(i + 1)); - authors.set(i + 1, temp); - unsorted = true; - } - } - } - - return authors; - } -} --- a/src/main/java/spl/SplWebClient.java +++ b/src/main/java/spl/SplWebClient.java @@ -1,195 +0,0 @@ -package spl; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; - -import javax.ws.rs.core.MediaType; - -import org.sciplore.beans.Author; -import org.sciplore.beans.Document; -import org.sciplore.deserialize.creator.AuthorBeanCreator; -import org.sciplore.deserialize.creator.AuthorsBeanCreator; -import org.sciplore.deserialize.creator.DefaultStringCreator; -import org.sciplore.deserialize.creator.DocumentBeanCreator; -import org.sciplore.deserialize.creator.DocumentsBeanCreator; -import org.sciplore.deserialize.creator.ObjectCreator; -import org.sciplore.deserialize.creator.TitleBeanCreator; -import org.sciplore.deserialize.creator.YearBeanCreator; -import org.sciplore.deserialize.reader.ObjectCreatorMapper; -import org.sciplore.deserialize.reader.XmlResourceReader; -import org.sciplore.formatter.Bean; -import org.sciplore.formatter.SimpleTypeElementBean; - -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.multipart.FormDataMultiPart; - -/** - * Created by IntelliJ IDEA. - * User: Christoph Arbeit - * Date: 09.09.2010 - * Time: 10:35:20 - * To change this template use File | Settings | File Templates. - */ -public class SplWebClient { - - private static Client CLIENT = Client.create(); - static{ - CLIENT.setConnectTimeout(1000); - CLIENT.setReadTimeout(70000); - } - private static WebResource WEBRESOURCE = CLIENT.resource( "http://api.mr-dlib.org/" ); - private static WebResource INTERNETRESOURCE = CLIENT.resource( "http://www.google.com" ); - //private static WebResource WEBRESOURCE = CLIENT.resource( "http://localhost:8080/rest/" ); - - public static Document metadata; - - public static WebServiceStatus getMetaData(File file){ - try{ - if(!isWebServiceAvailable()){ - if(isInternetAvailable()){ - return WebServiceStatus.WEBSERVICE_DOWN; - } - else{ - return WebServiceStatus.NO_INTERNET; - } - } - if(isWebServiceOutDated()){ - return WebServiceStatus.OUTDATED; - } - if(!isMetaDataServiceAvailable()){ - return WebServiceStatus.UNAVAILABLE; - } - FileInputStream fin = new FileInputStream(file); - byte[] data = new byte[(int)file.length()]; - fin.read(data); - - FormDataMultiPart formDataMultiPart = new FormDataMultiPart(); - formDataMultiPart.field("file", data, MediaType.APPLICATION_OCTET_STREAM_TYPE); - formDataMultiPart.field("source", "jabref", MediaType.TEXT_PLAIN_TYPE); - formDataMultiPart.field("filename", file.getName(), MediaType.TEXT_PLAIN_TYPE); - - - ClientResponse response = WEBRESOURCE.path("documents").type(MediaType.MULTIPART_FORM_DATA_TYPE).post(ClientResponse.class, formDataMultiPart); - //System.out.println(response.getEntity(String.class)); - if(response.getClientResponseStatus() == ClientResponse.Status.OK && response.hasEntity()){ - String entity = response.getEntity(String.class); - byte[] bytes = new byte[0]; - try { - bytes = entity.getBytes("UTF-8"); - } catch (UnsupportedEncodingException e) { - return null; - } - InputStream is = new ByteArrayInputStream(bytes); - if(is != null){ - ObjectCreatorMapper resourceMapper = new ObjectCreatorMapper(); - ObjectCreator stringCreator = new DefaultStringCreator(); - // initialize Mapper - resourceMapper.addCreator("documents", new DocumentsBeanCreator()); - resourceMapper.addCreator("authors", new AuthorsBeanCreator()); - resourceMapper.addCreator("document", new DocumentBeanCreator()); - resourceMapper.addCreator("title", new TitleBeanCreator()); - resourceMapper.addCreator("year", new YearBeanCreator()); - resourceMapper.addCreator("author", new AuthorBeanCreator()); - - resourceMapper.addCreator("name_first", stringCreator); - resourceMapper.addCreator("name_middle", stringCreator); - resourceMapper.addCreator("name_last", stringCreator); - resourceMapper.addCreator("name_last_prefix", stringCreator); - resourceMapper.addCreator("name_last_suffix", stringCreator); - - // initialize xml reader - XmlResourceReader reader = new XmlResourceReader(resourceMapper); - - // parse given file -> create object tree - Document docs = (Document)reader.parse(is); - for(Bean author : docs.getAuthors().getCollection()){ - Author temp = (Author)author; - System.out.println(((SimpleTypeElementBean)temp.getName_Last()).getValue() + " " + temp.getRank()); - } - // XmlDocuments documents = JAXB.unmarshal(is, XmlDocuments.class); - SplWebClient.metadata = docs; - return WebServiceStatus.OK; - } - else{ - return WebServiceStatus.NO_METADATA; - } - } - if(response.getClientResponseStatus() == ClientResponse.Status.SERVICE_UNAVAILABLE){ - return WebServiceStatus.UNAVAILABLE; - } - }catch(Exception e){ - System.out.println(Tools.getStackTraceAsString(e)); - //Todo logging - } - return WebServiceStatus.NO_METADATA; - } - - public static boolean isWebServiceOutDated(){ - try{ - ClientResponse response = WEBRESOURCE.path("service/versioncheck/" + Tools.WEBSERVICE_APP_ID + "/current").get(ClientResponse.class); - if(response.getClientResponseStatus() == ClientResponse.Status.OK && response.hasEntity()){ - String entity = response.getEntity(String.class); - byte[] bytes = entity.getBytes(); - InputStream is = new ByteArrayInputStream(bytes); - if(is != null){ - /*XmlApplication app = JAXB.unmarshal(is, XmlApplication.class); - if(app != null){ - if(app.getVersion() != null && !app.getVersion().equalsIgnoreCase(Tools.WEBSERVICE_VERSION_SHORT)){ - return true; - } - }*/ - } - } - }catch(Exception e){ - //Todo logging - } - return false; - } - - public static boolean isMetaDataServiceAvailable(){ - try{ - ClientResponse response = WEBRESOURCE.path("service/metadata/available").get(ClientResponse.class); - if(response.getClientResponseStatus() == ClientResponse.Status.OK && response.hasEntity()){ - String entity = response.getEntity(String.class); - if(entity != null && entity.equalsIgnoreCase("false")){ - return false; - } - } - }catch(Exception e){ - //Todo logging - } - return true; - } - - public static boolean isWebServiceAvailable(){ - try{ - ClientResponse response = WEBRESOURCE.path("service/metadata/available").get(ClientResponse.class); - }catch(Exception e){ - return false; - } - return true; - } - - public static boolean isInternetAvailable(){ - try{ - ClientResponse response = INTERNETRESOURCE.get(ClientResponse.class); - }catch(Exception e){ - return false; - } - return true; - } - - public enum WebServiceStatus { - OK, - NO_METADATA, - UNAVAILABLE, - OUTDATED, - WEBSERVICE_DOWN, - NO_INTERNET - } -} --- a/src/main/java/spl/gui/MetaDataListDialog.java +++ b/src/main/java/spl/gui/MetaDataListDialog.java @@ -1,297 +0,0 @@ -package spl.gui; - - -import java.awt.BorderLayout; -import java.awt.CardLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.Vector; - -import javax.swing.*; -import javax.swing.table.DefaultTableModel; - -import net.sf.jabref.Globals; -import net.sf.jabref.MetaData; -import net.sf.jabref.Util; - -import org.sciplore.beans.Document; - -import spl.DocumentsWrapper; -import spl.SplWebClient; -import spl.listener.LabelLinkListener; -import spl.localization.LocalizationSupport; - -import com.jgoodies.forms.builder.ButtonBarBuilder; - -public class MetaDataListDialog extends JDialog { - private JPanel contentPane; - private JTable tableMetadata; - private JButton buttonOK; - private JButton buttonCancel; - private JLabel labelFetch; - private JLabel iconLabel; - private JButton blankButton; - private JLabel labelLogo; - private JButton moreInformationButton; - private JPanel panelMetadata; - private DefaultTableModel tableModel; - private int result; - private Document xmlDocuments; - private String fileName; - private SplWebClient.WebServiceStatus webserviceStatus; - private Component thisDialog; - private boolean showBlankButton; - private CardLayout cardLayou = new CardLayout(); - - public MetaDataListDialog(String fileName, boolean showBlankButton) { - $$$setupUI$$$(); - this.showBlankButton = showBlankButton; - this.thisDialog = this; - this.fileName = fileName; - this.labelLogo.addMouseListener(new LabelLinkListener(this.labelLogo, "www.mr-dlib.org")); - this.setTitle(LocalizationSupport.message("Mr._dLib_Metadata_Entries_Associated_With_PDF_File")); - this.tableMetadata.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - setContentPane(contentPane); - pack(); - setModal(true); - getRootPane().setDefaultButton(buttonOK); - - buttonOK.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onOK(); - } - }); - - buttonCancel.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onCancel(); - } - }); - - blankButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onBlank(); - } - }); - - moreInformationButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onInfo(); - } - }); - - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - onCancel(); - } - }); - - contentPane.registerKeyboardAction(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onCancel(); - } - }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - - cardLayou.show(panelMetadata, "panelWait"); - //this.scrollPane.setVisible(false); - //this.blankButton.setVisible(false); - this.moreInformationButton.setVisible(true); - this.setSize(616, 366); - } - - private void onInfo() { - try { - Util.openExternalViewer(new MetaData(), "http://www.mr-dlib.org/docs/jabref_metadata_extraction_alpha.php", "url"); - } catch (IOException exc) { - exc.printStackTrace(); - } - } - - private void onBlank() { - this.result = JOptionPane.NO_OPTION; - dispose(); - } - - private void onOK() { - this.result = JOptionPane.OK_OPTION; - dispose(); - } - - private void onCancel() { - this.result = JOptionPane.CANCEL_OPTION; - dispose(); - } - - public void showDialog() { - SwingWorker worker = new SwingWorker() { - @Override - public Void doInBackground() { - System.out.println("Starting Webclient..."); - webserviceStatus = SplWebClient.getMetaData(new File(fileName)); - return null; - } - - @Override - public void done() { - if (webserviceStatus == SplWebClient.WebServiceStatus.OK) { - xmlDocuments = SplWebClient.metadata; - if (xmlDocuments != null /*&& xmlDocuments.getDocuments() != null && xmlDocuments.getDocuments().size() > 0*/) { - DocumentsWrapper documents = new DocumentsWrapper(xmlDocuments); - List> vectorList = documents.getDocuments(); - for (Vector vector : vectorList) { - tableModel.addRow(vector); - } - - tableMetadata.getSelectionModel().setSelectionInterval(0, 0); - cardLayou.show(panelMetadata, "scrollPane"); - //panelWait.setVisible(false); - //scrollPane.setVisible(true); - moreInformationButton.setVisible(true); - } else { - iconLabel.setVisible(false); - labelFetch.setText(LocalizationSupport.message("No_metadata_found.")); - blankButton.setVisible(showBlankButton); - } - } - if (webserviceStatus == SplWebClient.WebServiceStatus.NO_METADATA) { - iconLabel.setVisible(false); - labelFetch.setText(LocalizationSupport.message("No_metadata_found.")); - blankButton.setVisible(showBlankButton); - } - if (webserviceStatus == SplWebClient.WebServiceStatus.UNAVAILABLE) { - iconLabel.setVisible(false); - labelFetch.setText(LocalizationSupport.message("Mr._dLib_web_service_is_temporarily_unavailable.")); - blankButton.setVisible(showBlankButton); - } - if (webserviceStatus == SplWebClient.WebServiceStatus.OUTDATED) { - iconLabel.setVisible(false); - labelFetch.setText(LocalizationSupport.message("The_Mr._dLib_web_service_version_you_trying_to_access_is_outdated.")); - blankButton.setVisible(showBlankButton); - JOptionPane.showMessageDialog(thisDialog, LocalizationSupport.message("This_JabRef_version_is_trying_to_access_an_old_version_of_Mr._dLib's_webservice_that_is_not_working_any_more.\nPlease_visit_http://jabref.sourceforge.net_or_http://www.mr-dlib.org_for_more_information_and_updates."), LocalizationSupport.message("Web_Service_Version_Outdated"), JOptionPane.INFORMATION_MESSAGE); - } - if (webserviceStatus == SplWebClient.WebServiceStatus.WEBSERVICE_DOWN) { - iconLabel.setVisible(false); - labelFetch.setText(LocalizationSupport.message("Mr._dLib_web_service_is_temporarily_down._Please_try_again_later.")); - blankButton.setVisible(showBlankButton); - } - if (webserviceStatus == SplWebClient.WebServiceStatus.NO_INTERNET) { - iconLabel.setVisible(false); - labelFetch.setText(LocalizationSupport.message("No_Internet_Connection.")); - blankButton.setVisible(showBlankButton); - JOptionPane.showMessageDialog(thisDialog, LocalizationSupport.message("You_are_not_connected_to_the_Internet._To_access_Mr._dLib_web_service_an_internet_connection_is_needed."), LocalizationSupport.message("No_Internet_Connection."), JOptionPane.INFORMATION_MESSAGE); - } - } - }; - worker.execute(); - this.pack(); - this.setVisible(true); - } - - public Document getXmlDocuments() { - return xmlDocuments; - } - - private void createUIComponents() { - this.tableModel = new MyTableModel(); - this.tableModel.addColumn(LocalizationSupport.message("Title")); - this.tableModel.addColumn(LocalizationSupport.message("Author(s)")); - this.tableModel.addColumn(LocalizationSupport.message("Published_Year")); - this.tableMetadata = new JTable(this.tableModel); - } - - public JTable getTableMetadata() { - return tableMetadata; - } - - public int getResult() { - return result; - } - - public JButton getBlankButton() { - return blankButton; - } - - private void $$$setupUI$$$() { - createUIComponents(); - contentPane = new JPanel(); - contentPane.setLayout(new BorderLayout()); - labelLogo = new JLabel(); - labelLogo.setIcon(new ImageIcon(getClass().getResource("/spl/gui/mrdlib header.png"))); - labelLogo.setText(""); - contentPane.add(labelLogo, BorderLayout.NORTH); - panelMetadata = new JPanel(); - panelMetadata.setLayout(cardLayou); - - - panelMetadata.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), null)); - JScrollPane scrollPane = new JScrollPane(); - scrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLoweredBevelBorder(), null)); - tableMetadata.setAutoCreateRowSorter(false); - tableMetadata.setEnabled(true); - tableMetadata.setFillsViewportHeight(true); - tableMetadata.setShowVerticalLines(true); - scrollPane.setViewportView(tableMetadata); - panelMetadata.add(scrollPane, "scrollPane"); - JPanel panelWait = new JPanel(); - panelWait.setLayout(new BorderLayout()); - panelWait.setBackground(new Color(-1)); - panelMetadata.add(panelWait, "panelWait"); - panelWait.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLoweredBevelBorder(), null)); - iconLabel = new JLabel(); - iconLabel.setBackground(new Color(-1)); - iconLabel.setHorizontalAlignment(SwingConstants.CENTER); - iconLabel.setHorizontalTextPosition(SwingConstants.TRAILING); - iconLabel.setIcon(new ImageIcon(getClass().getResource("/spl/gui/ajax-loader.gif"))); - iconLabel.setText(""); - panelWait.add(iconLabel, BorderLayout.CENTER); - labelFetch = new JLabel(); - labelFetch.setHorizontalAlignment(JLabel.CENTER); - labelFetch.setFont(new Font(labelFetch.getFont().getName(), labelFetch.getFont().getStyle(), 13)); - labelFetch.setText(Globals.lang("Fetching Metadata...")); - panelWait.add(labelFetch, BorderLayout.SOUTH); - - cardLayou.show(panelMetadata, "panelWait"); - panelMetadata.setPreferredSize(new Dimension(400, 200)); - contentPane.add(panelMetadata, BorderLayout.CENTER); - - buttonOK = new JButton(Globals.lang("Ok")); - buttonCancel = new JButton(Globals.lang("Cancel")); - moreInformationButton = new JButton(Globals.lang("More information")); - ButtonBarBuilder bb = new ButtonBarBuilder(); - bb.addGlue(); - bb.addButton(moreInformationButton); - bb.addButton(buttonOK); - bb.addButton(buttonCancel); - bb.addGlue(); - blankButton = new JButton(); - blankButton.setText(""); - contentPane.add(bb.getPanel(), BorderLayout.SOUTH); - iconLabel.setLabelFor(scrollPane); - - - } - - public JComponent $$$getRootComponent$$$() { - return contentPane; - } - - public static class MyTableModel extends DefaultTableModel { - - @Override - public boolean isCellEditable(int row, int column) { - return false; - } - } - -}