| 1 | # $Id: Endnote.pm,v 1.2 2007-01-26 13:53:47 mike Exp $ | ||
| 2 | |||
| 3 | package Keystone::Resolver::plugins::Citation::Endnote; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | |||
| 8 | |||
| 9 | # I haven't read a specification for Endnote citation format, so this | ||
| 10 | # code will probably need refining. I am working entirely from a | ||
| 11 | # single example that I captured from a 1CATE services menu, which is | ||
| 12 | # stored at "../../../samples/citations/1kofkfks" | ||
| 13 | |||
| 14 | sub citation { | ||
| 15 | my $class = shift(); | ||
| 16 | my($openurl) = @_; | ||
| 17 | |||
| 18 | # Maps Endnote citations fields to OpenURL 1.0 referent fields. Where | ||
| 19 | # the RHS begins with an asterisk, it's a special-case recipe. | ||
| 20 | # | ||
| 21 | my @map = ( | ||
| 22 | TY => "*format", | ||
| 23 | AU => "*author", | ||
| 24 | TI => "atitle", | ||
| 25 | JO => "jtitle", | ||
| 26 | PY => "date", | ||
| 27 | VL => "volume", | ||
| 28 | IS => "issue", | ||
| 29 | SN => "issn", | ||
| 30 | UR => "*url", | ||
| 31 | ### spage? | ||
| 32 | ### epage? | ||
| 33 | # ER => ??? Not given in the example, not sure what it is | ||
| 34 | ); | ||
| 35 | |||
| 36 | my $text = ""; | ||
| 37 | while (@map) { | ||
| 38 | my $key = shift @map; | ||
| 39 | my $field = shift @map; | ||
| 40 | my $val; | ||
| 41 | if ($field =~ s/^\*//) { | ||
| 42 | $val = _special($openurl, $field); | ||
| 43 | } else { | ||
| 44 | $val = $openurl->rft($field); | ||
| 45 | } | ||
| 46 | $val = "" if !defined $val; | ||
| 47 | $text .= "$key - $val\n"; | ||
| 48 | } | ||
| 49 | |||
| 50 | return ("$text", "application/x-research-info-systems"); | ||
| 51 | } | ||
| 52 | |||
| 53 | |||
| 54 | sub _special { | ||
| 55 | my($openurl, $special) = @_; | ||
| 56 | |||
| 57 | if ($special eq "format") { | ||
| 58 | my $format = $openurl->descriptor("rft")->superdata1("val_fmt"); | ||
| 59 | # It should be something like "info:ofi/fmt:kev:mtx:journal" | ||
| 60 | $format =~ s/.*://; | ||
| 61 | return $format; | ||
| 62 | } elsif ($special eq "author") { | ||
| 63 | my $last = $openurl->rft("aulast"); | ||
| 64 | return undef if !defined $last; | ||
| 65 | my $first = $openurl->rft("aufirst"); | ||
| 66 | if (!defined $first) { | ||
| 67 | $first = $openurl->rft("auinit"); | ||
| 68 | return $last if !defined $first; | ||
| 69 | $first .= "." if $first !~ /\.$/; | ||
| 70 | } | ||
| 71 | return "$last, $first"; | ||
| 72 | } elsif ($special eq "url") { | ||
| 73 | return $openurl->v10url("svc_dat"); | ||
| 74 | } | ||
| 75 | |||
| 76 | return "[UNKNOWN SPECIAL $special]"; | ||
| 77 | } | ||
| 78 | |||
| 79 | |||
| 80 | 1; |