Skip to content

Commit

Permalink
Merge pull request #9 from ansell/acs-pdf
Browse files Browse the repository at this point in the history
Support FindFullText with ACS DOIs
  • Loading branch information
koppor committed May 20, 2014
2 parents 3834269 + 57cbe70 commit f116e54
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
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")));
}
}

0 comments on commit f116e54

Please sign in to comment.