-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ansell/acs-pdf
Support FindFullText with ACS DOIs
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))); | ||
} | ||
} |