« blib/lib/Keystone/Resolver/plugins/Citation/APP.pm
↑ Summary
blib/lib/Keystone/Resolver/plugins/Citation/Endnote.pm »
| 1 | # $Id: Elsevier.pm,v 1.4 2007-05-24 17:04:09 mike Exp $ | ||
| 2 | |||
| 3 | package Keystone::ContentURL::Elsevier; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use URI::Escape qw(uri_escape_utf8); | ||
| 7 | use Digest::MD5; | ||
| 8 | |||
| 9 | |||
| 10 | # See ../../doc/providers/elsevier/GIS40R4P.pdf | ||
| 11 | # for a description of the process going on here. | ||
| 12 | # | ||
| 13 | # To use this module, create a Keystone::ContentURL::Elsevier object, | ||
| 14 | # passing in the Origin, Salt Version, Salt and Base-URL, that you've | ||
| 15 | # been allocated. If the Base-URL is omitted, the standard one is | ||
| 16 | # used. Thereafter, you can repeatedly call its url() method, passing | ||
| 17 | # in whatever metadata you have from the list of relevant elements. | ||
| 18 | # This will either return a URL for the article, or throw an exception | ||
| 19 | # (a string containing an error message) | ||
| 20 | |||
| 21 | sub new { | ||
| 22 | my $class = shift(); | ||
| 23 | my($origin, $saltVersion, $salt, $baseURL) = @_; | ||
| 24 | |||
| 25 | $baseURL = "http://www.sciencedirect.com/science" if !defined $baseURL; | ||
| 26 | return bless { | ||
| 27 | origin => $origin, | ||
| 28 | saltVersion => $saltVersion, | ||
| 29 | salt => $salt, | ||
| 30 | baseURL => $baseURL, | ||
| 31 | }, $class; | ||
| 32 | } | ||
| 33 | |||
| 34 | sub url { | ||
| 35 | my $this = shift(); | ||
| 36 | foreach my $param (@_) { | ||
| 37 | $param = uri_escape_utf8($param) if defined $param; | ||
| 38 | } | ||
| 39 | my($pii, $issn, $volume, $issue, $firstPage, $lastPage, $initial, | ||
| 40 | $surname, $year) = @_; | ||
| 41 | |||
| 42 | my($type, $key); | ||
| 43 | if (defined $pii) { | ||
| 44 | $type = "pii"; # "publisher identified item" | ||
| 45 | $key = $pii; | ||
| 46 | $key =~ s/[^a-zA-Z0-9]//; | ||
| 47 | } elsif (defined $issn && defined $volume && defined $firstPage) { | ||
| 48 | $issn =~ s/-//; | ||
| 49 | $type = "vol"; # Volume key (a.k.a. IVIP key) | ||
| 50 | $key = "$issn#$volume#$firstPage"; | ||
| 51 | $key .= "#$issue" if defined $issue; | ||
| 52 | } elsif (defined $surname && defined $year && defined $firstPage) { | ||
| 53 | $type = "ref"; # Reference key | ||
| 54 | $key = "$surname#$year#$firstPage"; | ||
| 55 | $key .= "#" if defined $lastPage || defined $initial; | ||
| 56 | $key .= "$lastPage" if defined $lastPage; | ||
| 57 | $key .= "#$initial" if defined $initial; | ||
| 58 | } else { | ||
| 59 | die "not enough metadata supplied for PII, _volkey or _refkey"; | ||
| 60 | } | ||
| 61 | |||
| 62 | # MD5 sum must be calculated on the _un_encoded values | ||
| 63 | my $query = ("_ob=GatewayURL&" . | ||
| 64 | "_origin=" . $this->{origin} . | ||
| 65 | "&_method=citationSearch" . | ||
| 66 | "&_${type}key=" . $key . | ||
| 67 | "&_version=" . $this->{saltVersion}); | ||
| 68 | my $md5 = Digest::MD5::md5_hex($query . $this->{salt}); | ||
| 69 | |||
| 70 | # Actual URL must use encoded values (particularly, "%23" for "#") | ||
| 71 | ### Does the Elsevier gateway expect us to encode UTF8 or Latin1? | ||
| 72 | $query = ("_ob=GatewayURL&" . | ||
| 73 | "_origin=" . uri_escape_utf8($this->{origin}) . | ||
| 74 | "&_method=citationSearch" . | ||
| 75 | "&_${type}key=" . uri_escape_utf8($key) . | ||
| 76 | "&_version=" . $this->{saltVersion}); | ||
| 77 | |||
| 78 | return $this->{baseURL} . "?$query&md5=$md5"; | ||
| 79 | } | ||
| 80 | |||
| 81 | |||
| 82 | 1; |