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

Add Worldcat fetcher #6035

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
7d72fd8
Add performSearch test case
GlennOlsson Feb 24, 2020
ee96fdc
Add basics of fetcher
GlennOlsson Feb 25, 2020
61a45fe
Start work on importer
GlennOlsson Feb 25, 2020
b257085
Create worldcat importer test
GlennOlsson Feb 26, 2020
27069f4
Clean up and document worldcat fetcher and importer
GlennOlsson Feb 27, 2020
caa7076
Add worldcat fetcher to webFetchers
GlennOlsson Feb 27, 2020
d303999
Fix tests
GlennOlsson Feb 27, 2020
e0ab537
Change to java.net.URL and fix formatting
GlennOlsson Mar 29, 2020
8503720
Move XML tests to own files
GlennOlsson Mar 29, 2020
c6b3e26
Add preferences field
GlennOlsson Mar 29, 2020
2e631c3
Fick checkstyle for main
GlennOlsson Mar 29, 2020
6a5db50
Fix checkstyle test
GlennOlsson Mar 29, 2020
6db97d7
Add to eng. language file
GlennOlsson Mar 29, 2020
f80f2fc
Update CHANGELOG.md
GlennOlsson Mar 29, 2020
b78b387
Update src/main/java/org/jabref/logic/importer/fileformat/WorldcatImp…
GlennOlsson Mar 31, 2020
bf6cb11
Update style and pass worldcat key directly
GlennOlsson Mar 31, 2020
85f01e0
Merge branch 'worldcat-fetcher' of github.com:augustjanse/jabref into…
GlennOlsson Mar 31, 2020
676f8e4
Update to non-static
GlennOlsson Mar 31, 2020
c6e2ea4
Update src/main/java/org/jabref/logic/importer/fetcher/WorldcatFetche…
GlennOlsson Apr 1, 2020
c7ef5f2
Update src/main/java/org/jabref/logic/importer/fetcher/WorldcatFetche…
GlennOlsson Apr 1, 2020
a6ed4e7
Update src/main/java/org/jabref/logic/importer/fetcher/WorldcatFetche…
GlennOlsson Apr 1, 2020
b8b91a4
Update src/main/java/org/jabref/logic/importer/fetcher/WorldcatFetche…
GlennOlsson Apr 1, 2020
f9fd6b7
Change name of apiKey
GlennOlsson Apr 1, 2020
ca3fd6e
Fix checkstyle
GlennOlsson Apr 1, 2020
8056dec
Fix changelog duplicate
GlennOlsson Apr 1, 2020
c1ed7cd
Parse XML in fetcher and send new XML to importer
GlennOlsson Apr 7, 2020
a8cb706
Change test-xml for importer
GlennOlsson Apr 7, 2020
5563170
Fix checkstyle
GlennOlsson Apr 7, 2020
bdf544c
Merge branch 'master' into worldcat-fetcher
GlennOlsson Apr 7, 2020
40f7f16
Fix duplication in CHANGELOG
GlennOlsson Apr 7, 2020
6725481
Wrapp bufferedReader and Stringwriter, and remove TODO comment
GlennOlsson Apr 7, 2020
0e73f64
Add descritpion to preferences
GlennOlsson Apr 10, 2020
434a00e
Fix traling spaces
GlennOlsson Apr 10, 2020
65f6de8
Change to https
GlennOlsson Apr 10, 2020
69da970
Remove null test
GlennOlsson Apr 10, 2020
f8d989a
Fix locality issue
GlennOlsson Apr 10, 2020
959f64a
Add link to worldcat as hyperlink
GlennOlsson Apr 12, 2020
2fa6fc4
Merge remote-tracking branch 'upstream/master' into worldcat-fetcher
calixtus Feb 1, 2021
fbd3003
Fixed merge errors and minor ide warnings
calixtus Feb 1, 2021
35b03ce
Fixed checkstyle errors and minor ide warnings
calixtus Feb 1, 2021
f32931d
Fixed test
calixtus Feb 1, 2021
025350b
Fix typo
koppor Feb 1, 2021
c0b5ab9
Fix changelog
koppor Feb 1, 2021
c134fb6
Merge remote-tracking branch 'upstream/master' into worldcat-fetcher
calixtus Feb 1, 2021
1f31ca8
Updated class packages
calixtus Feb 1, 2021
4b607a3
Merge remote-tracking branch 'augustjanse/worldcat-fetcher' into worl…
calixtus Feb 1, 2021
e3e1c6e
Merge remote-tracking branch 'upstream/master' into worldcat-fetcher
calixtus Feb 10, 2021
3ff24fb
Added WorldCat key secret to BuildInfo and fixed some minor IDE sugge…
calixtus Feb 10, 2021
194e3a8
Fixed http 505 response from server
calixtus Feb 11, 2021
6138fc6
Fixed dom import error
calixtus Feb 12, 2021
6503f87
Changed to use secret api key as default
calixtus Feb 13, 2021
97ec0f2
Merge branch 'master' into worldcat-fetcher
calixtus Mar 8, 2021
5612216
Merge remote-tracking branch 'upstream/main' into worldcat-fetcher
calixtus Jun 22, 2021
07d70d2
Fixed merge error
calixtus Jun 22, 2021
ea35891
Merge remote-tracking branch 'augustjanse/worldcat-fetcher' into worl…
calixtus Jul 7, 2021
9b95add
Merge remote-tracking branch 'upstream/main' into worldcat-fetcher
calixtus Jul 7, 2021
bb6257e
Work in progress
calixtus Jul 7, 2021
c59235d
Work in Progress
calixtus Jul 7, 2021
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We reintroduced the index column. [#5844](https://github.com/JabRef/jabref/pull/5844)
- Filenames of external files can no longer contain curly braces. [#5926](https://github.com/JabRef/jabref/pull/5926)
- We made the filters more easily accessible in the integrity check dialog. [#5955](https://github.com/JabRef/jabref/pull/5955)
- We added a WorldCcat fetcher. [#1065](https://github.com/JabRef/jabref/issues/1065) [#2581](https://github.com/JabRef/jabref/issues/2581). [WorldCat](http://www.worldcat.org/webservices/catalog/)
- We reimplemented and improved the dialog "Customize entry types". [#4719](https://github.com/JabRef/jabref/issues/4719)
- We added an [American Physical Society](https://journals.aps.org/) fetcher. [#818](https://github.com/JabRef/jabref/issues/818)
- We added an Worldcat fetcher. [#1065](https://github.com/JabRef/jabref/issues/1065) [#2581](https://github.com/JabRef/jabref/issues/2581). [Worldcat](http://www.worldcat.org/webservices/catalog/)
GlennOlsson marked this conversation as resolved.
Show resolved Hide resolved
GlennOlsson marked this conversation as resolved.
Show resolved Hide resolved
- We added possibility to enable/disable items quantity in groups. [#6042](https://github.com/JabRef/jabref/issues/6042)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private void setupToolBar() {

// Add menu for fetching bibliographic information
ContextMenu fetcherMenu = new ContextMenu();
for (EntryBasedFetcher fetcher : WebFetchers.getEntryBasedFetchers(entryEditorPreferences.getImportFormatPreferences())) {
for (EntryBasedFetcher fetcher : WebFetchers.getEntryBasedFetchers(entryEditorPreferences.getImportFormatPreferences(), entryEditorPreferences.getAPIApiKeyPreferences())) {
MenuItem fetcherMenuItem = new MenuItem(fetcher.getName());
fetcherMenuItem.setOnAction(event -> fetchAndMerge(fetcher));
fetcherMenu.getItems().add(fetcherMenuItem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jabref.gui.keyboard.KeyBindingRepository;
import org.jabref.logic.bibtex.FieldWriterPreferences;
import org.jabref.logic.bibtexkeypattern.BibtexKeyPatternPreferences;
import org.jabref.logic.importer.APIKeyPreferences;
import org.jabref.logic.importer.ImportFormatPreferences;
import org.jabref.model.entry.field.Field;

Expand All @@ -16,6 +17,7 @@ public class EntryEditorPreferences {
private final FieldWriterPreferences fieldWriterPreferences;
private final ImportFormatPreferences importFormatPreferences;
private final BibtexKeyPatternPreferences bibtexKeyPatternPreferences;
private final APIKeyPreferences apiKeyPreferences;
private final List<Field> customTabFieldNames;
private final boolean shouldShowRecommendationsTab;
private final boolean isMrdlibAccepted;
Expand All @@ -24,7 +26,7 @@ public class EntryEditorPreferences {
private boolean avoidOverwritingCiteKey;
private final boolean shouldShowLatexCitationsTab;

public EntryEditorPreferences(Map<String, Set<Field>> entryEditorTabList, FieldWriterPreferences fieldWriterPreferences, ImportFormatPreferences importFormatPreferences, List<Field> customTabFieldNames, boolean shouldShowRecommendationsTab, boolean isMrdlibAccepted, boolean shouldShowLatexCitationsTab, boolean showSourceTabByDefault, BibtexKeyPatternPreferences bibtexKeyPatternPreferences, KeyBindingRepository keyBindings, boolean avoidOverwritingCiteKey) {
public EntryEditorPreferences(Map<String, Set<Field>> entryEditorTabList, FieldWriterPreferences fieldWriterPreferences, ImportFormatPreferences importFormatPreferences, List<Field> customTabFieldNames, boolean shouldShowRecommendationsTab, boolean isMrdlibAccepted, boolean shouldShowLatexCitationsTab, boolean showSourceTabByDefault, BibtexKeyPatternPreferences bibtexKeyPatternPreferences, KeyBindingRepository keyBindings, boolean avoidOverwritingCiteKey, APIKeyPreferences apiKeyPreferences) {
this.entryEditorTabList = entryEditorTabList;
this.fieldWriterPreferences = fieldWriterPreferences;
this.importFormatPreferences = importFormatPreferences;
Expand All @@ -36,6 +38,7 @@ public EntryEditorPreferences(Map<String, Set<Field>> entryEditorTabList, FieldW
this.keyBindings = keyBindings;
this.avoidOverwritingCiteKey = avoidOverwritingCiteKey;
this.shouldShowLatexCitationsTab = shouldShowLatexCitationsTab;
this.apiKeyPreferences = apiKeyPreferences;
}

public Map<String, Set<Field>> getEntryEditorTabList() {
Expand All @@ -49,6 +52,10 @@ public FieldWriterPreferences getFieldWriterPreferences() {
public ImportFormatPreferences getImportFormatPreferences() {
return importFormatPreferences;
}

public APIKeyPreferences getAPIApiKeyPreferences() {
return apiKeyPreferences;
}

public List<Field> getCustomTabFieldNames() {
return customTabFieldNames;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/jabref/gui/preferences/ImportTab.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,20 @@
<TextField fx:id="fileDirPattern" GridPane.columnIndex="1" GridPane.rowIndex="1"
prefWidth="300" minWidth="300" maxWidth="300"/>
</GridPane>

<Label styleClass="sectionHeader" text="%API keys"/>
<GridPane hgap="4.0" vgap="4.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES"/>
<ColumnConstraints hgrow="SOMETIMES"/>
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="SOMETIMES"/>
<RowConstraints vgrow="SOMETIMES"/>
</rowConstraints>
<Label text="%Worldcat Fetcher Key" GridPane.rowIndex="1"/>
GlennOlsson marked this conversation as resolved.
Show resolved Hide resolved
<TextField fx:id="worldcatKey" GridPane.columnIndex="1" GridPane.rowIndex="1"
prefWidth="300" minWidth="300" maxWidth="300"/>
</GridPane>

</fx:root>
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/gui/preferences/ImportTabView.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class ImportTabView extends AbstractPreferenceTabView<ImportTabViewModel>

@FXML private ComboBox<String> fileNamePattern;
@FXML private TextField fileDirPattern;

@FXML private TextField worldcatKey;

public ImportTabView(JabRefPreferences preferences) {
this.preferences = preferences;
Expand All @@ -28,6 +30,8 @@ public void initialize () {
fileNamePattern.valueProperty().bindBidirectional(viewModel.fileNamePatternProperty());
fileNamePattern.itemsProperty().bind(viewModel.defaultFileNamePatternsProperty());
fileDirPattern.textProperty().bindBidirectional(viewModel.fileDirPatternProperty());

worldcatKey.textProperty().bindBidirectional(viewModel.apiKeyPatternProperty());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class ImportTabViewModel implements PreferenceTabViewModel {
private final StringProperty fileNamePatternProperty = new SimpleStringProperty();
private final StringProperty fileDirPatternProperty = new SimpleStringProperty();

private final StringProperty apiKeyPatternProperty = new SimpleStringProperty();
GlennOlsson marked this conversation as resolved.
Show resolved Hide resolved

private final DialogService dialogService;
private final JabRefPreferences preferences;

Expand All @@ -32,12 +34,14 @@ public ImportTabViewModel(DialogService dialogService, JabRefPreferences prefere
public void setValues() {
fileNamePatternProperty.setValue(preferences.get(JabRefPreferences.IMPORT_FILENAMEPATTERN));
fileDirPatternProperty.setValue(preferences.get(JabRefPreferences.IMPORT_FILEDIRPATTERN));
apiKeyPatternProperty.setValue(preferences.get(JabRefPreferences.IMPORT_API_WORLDCAT));
}

@Override
public void storeSettings() {
preferences.put(JabRefPreferences.IMPORT_FILENAMEPATTERN, fileNamePatternProperty.getValue());
preferences.put(JabRefPreferences.IMPORT_FILEDIRPATTERN, fileDirPatternProperty.getValue());
preferences.put(JabRefPreferences.IMPORT_API_WORLDCAT, apiKeyPatternProperty.getValue());
}

@Override
Expand All @@ -55,4 +59,6 @@ public List<String> getRestartWarnings() {
public StringProperty fileNamePatternProperty() { return fileNamePatternProperty; }

public StringProperty fileDirPatternProperty() { return fileDirPatternProperty; }

public StringProperty apiKeyPatternProperty() { return apiKeyPatternProperty; }
}
11 changes: 11 additions & 0 deletions src/main/java/org/jabref/logic/importer/APIKeyPreferences.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jabref.logic.importer;

public class APIKeyPreferences {
private final String worldcatKey;

public APIKeyPreferences(String worldcatKey) {
this.worldcatKey = worldcatKey;
}

public String getWorldcatKey() { return worldcatKey; }
}
4 changes: 3 additions & 1 deletion src/main/java/org/jabref/logic/importer/WebFetchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.jabref.logic.importer.fetcher.SpringerFetcher;
import org.jabref.logic.importer.fetcher.SpringerLink;
import org.jabref.logic.importer.fetcher.TitleFetcher;
import org.jabref.logic.importer.fetcher.WorldcatFetcher;
import org.jabref.logic.importer.fetcher.ZbMATH;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.StandardField;
Expand Down Expand Up @@ -127,13 +128,14 @@ public static SortedSet<IdBasedFetcher> getIdBasedFetchers(ImportFormatPreferenc
/**
* @return sorted set containing entry based fetchers
*/
public static SortedSet<EntryBasedFetcher> getEntryBasedFetchers(ImportFormatPreferences importFormatPreferences) {
public static SortedSet<EntryBasedFetcher> getEntryBasedFetchers(ImportFormatPreferences importFormatPreferences, APIKeyPreferences apiKeyPreferences) {
SortedSet<EntryBasedFetcher> set = new TreeSet<>(Comparator.comparing(WebFetcher::getName));
set.add(new AstrophysicsDataSystem(importFormatPreferences));
set.add(new DoiFetcher(importFormatPreferences));
set.add(new IsbnFetcher(importFormatPreferences));
set.add(new MathSciNet(importFormatPreferences));
set.add(new CrossRef());
set.add(new WorldcatFetcher(apiKeyPreferences.getWorldcatKey()));
return set;
}

Expand Down
216 changes: 216 additions & 0 deletions src/main/java/org/jabref/logic/importer/fetcher/WorldcatFetcher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
package org.jabref.logic.importer.fetcher;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.jabref.logic.importer.EntryBasedFetcher;
import org.jabref.logic.importer.FetcherException;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.importer.fileformat.WorldcatImporter;
import org.jabref.logic.net.URLDownload;
import org.jabref.model.database.BibDatabase;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
* EntryBasedFetcher that searches the Worldcat database
*
* @see https://www.oclc.org/developer/develop/web-services/worldcat-search-api/bibliographic-resource.en.html
*/
public class WorldcatFetcher implements EntryBasedFetcher {

private String WORLDCAT_OPEN_SEARCH_URL = "http://www.worldcat.org/webservices/catalog/search/opensearch?wskey=";
private String WORLDCAT_READ_URL = "http://www.worldcat.org/webservices/catalog/content/{OCLC-NUMBER}?recordSchema=info%3Asrw%2Fschema%2F1%2Fdc&wskey=";


GlennOlsson marked this conversation as resolved.
Show resolved Hide resolved
public WorldcatFetcher (String worldcatKey) {
WORLDCAT_OPEN_SEARCH_URL += worldcatKey;
WORLDCAT_READ_URL += worldcatKey;
}

@Override
public String getName () {
return "Worldcat Fetcher";
}

/**
* Create a open search query with specified title
* @param title the title to include in the query
* @return the earch query for the api
*/
private String getOpenSearchURL (String title) throws MalformedURLException {
String query = "&q=srw.ti+all+\"" + title + "\"";
URL url = new URL (WORLDCAT_OPEN_SEARCH_URL + query);
return url.toString ();
}

/**
* Make request to open search API of Worldcat, with specified title
* @param title the title of the search
* @return the body of the HTTP response
*/
private String makeOpenSearchRequest (String title) throws FetcherException {
try {
URLDownload urlDownload = new URLDownload (getOpenSearchURL (title));
URLDownload.bypassSSLVerification ();
String resp = urlDownload.asString ();

return resp;
} catch (MalformedURLException e) {
throw new FetcherException ("Bad url", e);
} catch (IOException e) {
throw new FetcherException ("Error with Open Search Request (Worldcat)", e);
}
}

/**
* Get more information about a article through its OCLC id. Picks the first
* element with this tag
* @param id the oclc id
* @return the XML element that contains all tags
*/
private Element getSpecificInfoOnOCLC (String id) throws IOException {
URLDownload urlDownload = new URLDownload (WORLDCAT_READ_URL.replace ("{OCLC-NUMBER}", id));
URLDownload.bypassSSLVerification ();
String resp = urlDownload.asString ();

Document mainDoc = parse (resp);
NodeList parentElemOfTags = mainDoc.getElementsByTagName ("oclcdcs");

return (Element) parentElemOfTags.item (0);
}

/**
* Parse a string to an xml document
* @param s the string to be parsed
* @return XML document representing the content of s
* @throws IllegalArgumentException if s is badly formated or other exception occurs during parsing
*/
private Document parse (String s) {
try {
BufferedReader r = new BufferedReader (new StringReader(s));
GlennOlsson marked this conversation as resolved.
Show resolved Hide resolved
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance ();
DocumentBuilder builder = factory.newDocumentBuilder ();

return builder.parse (new InputSource (r));
} catch (ParserConfigurationException e) {
throw new IllegalArgumentException ("Parser Config Exception: " + e.getMessage (), e);
} catch (SAXException e) {
throw new IllegalArgumentException ("SAX Exception: " + e.getMessage (), e);
} catch (IOException e) {
throw new IllegalArgumentException ("IO Exception: " + e.getMessage (), e);
}
}

/**
* Parse OpenSearch XML to retrieve OCLC-ids and fetch details about those.
* Returns new XML doc in the form
* <pre>
* {@literal <entries>}
* {@literal <entry>}
* OCLC DETAIL
* {@literal </entry>}
* ...
* {@literal </entries>}
* </pre>
* @param doc the open search result
* @return the new xml document
* @throws FetcherException
*/
private Document parseOpenSearchXML(Document doc) throws FetcherException {
try {
Element feed = (Element) doc.getElementsByTagName ("feed").item (0);
NodeList entryXMLList = feed.getElementsByTagName ("entry");

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance ();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder ();

Document newDoc = docBuilder.newDocument ();

Element root = newDoc.createElement ("entries");
newDoc.appendChild (root);
for (int i = 0; i < entryXMLList.getLength (); i++) {
Element xmlEntry = (Element) entryXMLList.item (i);

String oclc = xmlEntry.getElementsByTagName ("oclcterms:recordIdentifier").item (0).getTextContent ();
Element detailedInfo = getSpecificInfoOnOCLC (oclc);

Element newEntry = newDoc.createElement ("entry");
newEntry.appendChild (detailedInfo);

root.appendChild (newEntry);
}
return newDoc;
} catch (ParserConfigurationException e) {
throw new FetcherException("Error with XML creation (Worldcat fetcher)", e);
} catch (IOException e) {
throw new FetcherException("Error with OCLC parsing (Worldcat fetcher)", e);
}
}

@Override
public List<BibEntry> performSearch (BibEntry entry) throws FetcherException {
Optional<String> entryTitle = entry.getLatexFreeField (StandardField.TITLE);
if (entryTitle.isPresent ()) {
String openSearchXMLResponse = makeOpenSearchRequest (entryTitle.get ());
Document openSearchDocument = parse (openSearchXMLResponse);

Document detailedXML = parseOpenSearchXML (openSearchDocument);
String detailedXMLString;
try {
//Transform XML to String
TransformerFactory tf = TransformerFactory.newInstance ();
GlennOlsson marked this conversation as resolved.
Show resolved Hide resolved
Transformer t = tf.newTransformer ();
StringWriter sw = new StringWriter ();
GlennOlsson marked this conversation as resolved.
Show resolved Hide resolved
t.transform(new DOMSource (detailedXML), new StreamResult (sw));
detailedXMLString = sw.toString ();
} catch (TransformerException e) {
throw new FetcherException ("Could not transform XML", e);
}

//TODO: - Send xml as string to Importer
// - Parse the new kind of XML in importer

WorldcatImporter importer = new WorldcatImporter ();
ParserResult parserResult;
try {
tobiasdiez marked this conversation as resolved.
Show resolved Hide resolved
if (importer.isRecognizedFormat (detailedXMLString)) {
parserResult = importer.importDatabase (detailedXMLString);
} else {
// For displaying An ErrorMessage
BibDatabase errorBibDataBase = new BibDatabase ();
parserResult = new ParserResult (errorBibDataBase);
}
return parserResult.getDatabase ().getEntries ();
}
catch (IOException e) {
throw new FetcherException ("Could not perform search (Worldcat) ", e);
}
} else {
return new ArrayList<>();
}
}

}
Loading