From 5f71765185928d19b08faf3ae3667a974858b3f9 Mon Sep 17 00:00:00 2001 From: Peter Ansell Date: Tue, 6 May 2014 16:32:57 +1000 Subject: [PATCH 1/2] Support FindFullText with ACS DOIs --- .../sf/jabref/external/ACSPdfDownload.java | 44 +++++++++++++++++++ .../net/sf/jabref/external/FindFullText.java | 1 + .../net/sf/jabref/external/AcsPdfTest.java | 20 +++++++++ 3 files changed, 65 insertions(+) create mode 100644 src/main/java/net/sf/jabref/external/ACSPdfDownload.java create mode 100644 src/test/java/net/sf/jabref/external/AcsPdfTest.java 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..fd759353f4f --- /dev/null +++ b/src/main/java/net/sf/jabref/external/ACSPdfDownload.java @@ -0,0 +1,44 @@ +/* Copyright (C) 2003-2011 JabRef contributors. + 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"))); + } +} From 57cbe70e1be14f7b8f8754e05f6b722ed72ce887 Mon Sep 17 00:00:00 2001 From: Peter Ansell Date: Wed, 7 May 2014 11:02:09 +1000 Subject: [PATCH 2/2] add CSIRO copyright 2014 --- src/main/java/net/sf/jabref/external/ACSPdfDownload.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/sf/jabref/external/ACSPdfDownload.java b/src/main/java/net/sf/jabref/external/ACSPdfDownload.java index fd759353f4f..3673775e082 100644 --- a/src/main/java/net/sf/jabref/external/ACSPdfDownload.java +++ b/src/main/java/net/sf/jabref/external/ACSPdfDownload.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2003-2011 JabRef contributors. +/* 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