diff --git a/src/main/java/net/sf/jabref/external/ACSPdfDownload.java b/src/main/java/net/sf/jabref/external/ACSPdfDownload.java new file mode 100644 index 00000000000..3673775e082 --- /dev/null +++ b/src/main/java/net/sf/jabref/external/ACSPdfDownload.java @@ -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; + } + } +} diff --git a/src/main/java/net/sf/jabref/external/FindFullText.java b/src/main/java/net/sf/jabref/external/FindFullText.java index 2ed50258c40..7d164573d49 100644 --- a/src/main/java/net/sf/jabref/external/FindFullText.java +++ b/src/main/java/net/sf/jabref/external/FindFullText.java @@ -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) { diff --git a/src/test/java/net/sf/jabref/external/AcsPdfTest.java b/src/test/java/net/sf/jabref/external/AcsPdfTest.java new file mode 100644 index 00000000000..009c81c2c32 --- /dev/null +++ b/src/test/java/net/sf/jabref/external/AcsPdfTest.java @@ -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"))); + } +}