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

Support FindFullText with ACS DOIs #9

Merged
merged 2 commits into from
May 20, 2014
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
44 changes: 44 additions & 0 deletions src/main/java/net/sf/jabref/external/ACSPdfDownload.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Copyright (C) 2014 Commonwealth Scientific and Industrial Research Organisation
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
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.external;

import java.net.URL;
import java.net.MalformedURLException;
import java.io.IOException;

/**
* FullTextFinder implementation that attempts to find PDF url from a ACS DOI.
*/
public class ACSPdfDownload implements FullTextFinder {

private static final String BASE_URL = "http://pubs.acs.org/doi/pdf/";

public ACSPdfDownload() {

}

public boolean supportsSite(URL url) {
return url.getHost().toLowerCase().contains("acs.org");
}

public URL findFullTextURL(URL url) throws IOException {
try {
return new URL(BASE_URL+url.getPath().substring("/doi/abs/".length()));
} catch (MalformedURLException e) {
return null;
}
}
}
1 change: 1 addition & 0 deletions src/main/java/net/sf/jabref/external/FindFullText.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class FindFullText {
public FindFullText() {
finders.add(new ScienceDirectPdfDownload());
finders.add(new SpringerLinkPdfDownload());
finders.add(new ACSPdfDownload());
}

public FindResult findFullText(BibtexEntry entry) {
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/net/sf/jabref/external/AcsPdfTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.sf.jabref.external;

import java.net.URL;

import junit.framework.TestCase;

public class AcsPdfTest extends TestCase {

public void testSupportsSite() throws Exception {
FullTextFinder acs = new ACSPdfDownload();
assertTrue(acs.supportsSite(new URL("http://pubs.acs.org/doi/abs/10.1021/bk-2006-STYG.ch014")));
assertFalse(acs.supportsSite(new URL("http://pubs.rsc.org/en/Content/ArticleLanding/2014/SC/c4sc00823e")));
}

public void testFindFullTextURL() throws Exception {
FullTextFinder acs = new ACSPdfDownload();
assertEquals(new URL("http://pubs.acs.org/doi/pdf/10.1021/bk-2006-STYG.ch014"),
acs.findFullTextURL(new URL("http://pubs.acs.org/doi/abs/10.1021/bk-2006-STYG.ch014")));
}
}