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

Integrate GVK plugin #378

Merged
merged 13 commits into from
Nov 25, 2015
Merged
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: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Andreas Amann
Andreas Rudert
Behrouz Javanmardi
Bernd Kalbfuss
Bernhard Tempel
Brian Quistorff
Brian Van Essen
captain123
Expand Down Expand Up @@ -49,6 +50,7 @@ Hannes Restel
Igor Chernyavsky
Igor Steinmacher
Ingvar Jackal
Jan Frederik Maas
Jan Kubovy
Janosch Kutscherauer
Jason Pickering
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by
- Feature: New LabelPattern `[keywordsN]`, where N is optional. Returns the first N keywords. If no N is specified ("`[keywords]`"), all keywords are returned. Spaces are removed.
- Update supported LookAndFeels
- Show replaced journal abbreviations on console
- Integrated [GVK-Plugin](http://www.gbv.de/wikis/cls/Jabref-GVK-Plugin)
- The three options to manage file references are moved to their own separated group in the Tools menu.

### Fixed
Expand Down
1 change: 1 addition & 0 deletions scripts/generate-authors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ cd "$(dirname "$(readlink -f "$BASH_SOURCE")")/.."
John Zedlewski
Samin Muhammad Ridwanul Karim
Stefan Robert
Bernhard Tempel
EOF

# %aN = author name, %aE = author email
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/net/sf/jabref/bibtex/EntryTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,15 @@ private static void initBibtexEntryTypes() {
* or null if it does not exist.
*/
public static EntryType getType(String name) {
EntryType entryType = ALL_TYPES.get(name.toLowerCase());
if (entryType == null) {
return null;
}
return entryType;
return ALL_TYPES.get(name.toLowerCase());
}

/**
* This method returns the standard BibtexEntryType for the
* name of a type, or null if it does not exist.
*/
public static EntryType getStandardType(String name) {
EntryType entryType = STANDARD_TYPES.get(name.toLowerCase());
if (entryType == null) {
return null;
} else {
return entryType;
}
return STANDARD_TYPES.get(name.toLowerCase());
}

public static void addOrModifyCustomEntryType(CustomEntryType type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public EntryFetchers() {
entryFetchers.add(new DBLPFetcher());
entryFetchers.add(new DiVAtoBibTeXFetcher());
entryFetchers.add(new DOItoBibTeXFetcher());
entryFetchers.add(new GVKFetcher());
entryFetchers.add(new IEEEXploreFetcher());
entryFetchers.add(new INSPIREFetcher());
entryFetchers.add(new ISBNtoBibTeXFetcher());
Expand Down
186 changes: 186 additions & 0 deletions src/main/java/net/sf/jabref/importer/fetcher/GVKFetcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/**
* License: GPLv2, but Jan Frederik Maas agreed to change license upon request
*/
package net.sf.jabref.importer.fetcher;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import javax.swing.JPanel;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.SAXException;

import net.sf.jabref.importer.ImportInspector;
import net.sf.jabref.importer.OutputPrinter;
import net.sf.jabref.logic.l10n.Localization;
import net.sf.jabref.model.entry.BibtexEntry;

import java.net.URLEncoder;

/**
* Fetch or search from GVK http://gso.gbv.de/sru/DB=2.1/
*/
public class GVKFetcher implements EntryFetcher {

private static final Log LOGGER = LogFactory.getLog(GVKFetcher.class);

HashMap<String, String> searchKeys = new HashMap<>();


public GVKFetcher() {
searchKeys.put("all", "pica.all%3D");
searchKeys.put("tit", "pica.tit%3D");
searchKeys.put("per", "pica.per%3D");
searchKeys.put("thm", "pica.thm%3D");
searchKeys.put("slw", "pica.slw%3D");
searchKeys.put("txt", "pica.txt%3D");
searchKeys.put("num", "pica.num%3D");
searchKeys.put("kon", "pica.kon%3D");
searchKeys.put("ppn", "pica.ppn%3D");
searchKeys.put("bkl", "pica.bkl%3D");
searchKeys.put("erj", "pica.erj%3D");
}

/**
* Necessary for JabRef
*/
@Override
public void stopFetching() {
// not supported
}

@Override
public String getHelpPage() {
return "GVKHelp.html";
}

@Override
public JPanel getOptionsPanel() {
return null;
}

@Override
public String getTitle() {
return "GVK (Gemeinsamer Verbundkatalog)";
}

@Override
public boolean processQuery(String query, ImportInspector dialog, OutputPrinter frame) {
String gvkQuery = "";

query = query.trim();

String[] qterms = query.split("\\s");

// Null abfangen!
if (qterms.length == 0) {
return false;
}

// Jeden einzelnen Suchbegriff URL-Encodieren
for (int x = 0; x < qterms.length; x++) {
try {
qterms[x] = URLEncoder.encode(qterms[x], "UTF-8");
} catch (UnsupportedEncodingException e) {
LOGGER.error("Unsupported encoding", e);
}
}

if (searchKeys.containsKey(qterms[0])) {
gvkQuery = processComplexQuery(qterms);
} else {
gvkQuery = "pica.all%3D";
gvkQuery = gvkQuery.concat(qterms[0]);

for (int x = 1; x < qterms.length; x++) {
gvkQuery = gvkQuery.concat("%20");
gvkQuery = gvkQuery.concat(qterms[x]);
}
}

List<BibtexEntry> bibs = fetchGVK(gvkQuery);

for (BibtexEntry entry : bibs) {
dialog.addEntry(entry);
}

if (bibs.size() == 0) {
frame.showMessage(Localization.lang("No references found"));
}

return true;
}

private String processComplexQuery(String[] s) {
String result = "";
boolean lastWasKey = false;

for (int x = 0; x < s.length; x++) {
if (searchKeys.containsKey(s[x])) {
if (!(x == 0)) {
result = result.concat("%20and%20" + searchKeys.get(s[x]));
} else {
result = searchKeys.get(s[x]);
}
lastWasKey = true;
} else {
if (!lastWasKey) {
result = result.concat("%20");
}
String encoded = s[x];
encoded = encoded.replaceAll(",", "%2C");
encoded = encoded.replaceAll("\\?", "%3F");

result = result.concat(encoded);
lastWasKey = false;
}
}
return (result);
}

private List<BibtexEntry> fetchGVK(String query) {
List<BibtexEntry> result;

String urlPrefix = "http://sru.gbv.de/gvk?version=1.1&operation=searchRetrieve&query=";
String urlQuery = query;
String urlSuffix = "&maximumRecords=50&recordSchema=picaxml&sortKeys=Year%2C%2C1";

String searchstring = (urlPrefix + urlQuery + urlSuffix);
LOGGER.debug(searchstring);
try {
URI uri = null;
try {
uri = new URI(searchstring);
} catch (URISyntaxException e) {
LOGGER.error("URI malformed error", e);
return Collections.EMPTY_LIST;
}
URL url = uri.toURL();
try (InputStream is = url.openStream()) {
result = (new GVKParser()).parseEntries(is);
}
} catch (IOException e) {
LOGGER.error("GVK plugin: An I/O exception occurred", e);
return Collections.EMPTY_LIST;
} catch (ParserConfigurationException e) {
LOGGER.error("GVK plugin: An internal parser error occurred", e);
return Collections.EMPTY_LIST;
} catch (SAXException e) {
LOGGER.error("An internal parser error occurred", e);
return Collections.EMPTY_LIST;
}

return result;
}

}
Loading