Jump to content
Wiki Home
EPrints Home
Bazaar
Files
Main menu
Main menu
move to sidebar
hide
Navigation
Front Page
EPrints 3 Manual
EPrints Training Course
EPrints Glossary
Installing EPrints
How-to Configure EPrints
EPrints 3.2+ API
EPrints 3 Reference
EPrints Plugins
Wiki
All categories
Recent changes
Main Page
Help
EPrints Documentation
Search
Search
Appearance
Log in
Request account
Personal tools
Log in
Request account
Pages for logged out editors
learn more
Contributions
Talk
Editing
Autocompletion
(section)
Page
Discussion
British English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== external source === This takes all the ideas above, and extends them to make an API call to an external data source. This has the advantage that you are always referring to the authoritative source, but the disadvantage that you are reliant on both the network being up and the external source being available. It breaks down into two parts: * the autocompleter call in the web page * the script being called For an example, here is one way to query the RoMEO data directly: First, set the autocompleter in the eprints workflow: <pre> <component type="Field::Multi"> <title>Article Publication Details</title> <field ref="publication" input_lookup_url="{$config{perl_url}}/get_journals" /> <field ref="publisher" /> <field ref="issn" /> </component> </pre> Next have the script: <pre> use strict; use HTTP::Request; use LWP::UserAgent; use XML::Twig; use Data::Dumper; use EPrints; my $journal_data = {}; sub urldecode{ my ($url) = @_; $url =~ s/%([0-9a-f][0-9a-f])/pack("C",hex($1))/egi; $url =~ s/\x2B/ /; # swap '+' for ' ' return $url; } # XML::Twig's routine for dealing with a journal entry sub process_journal { my ( $twig, $journal ) = @_; # get the components my $title = urldecode( $journal->first_child('jtitle')->text ); my $zetoc = urldecode( $journal->first_child('zetocpub')->text ) if $journal->first_child('zetocpub'); my $romeo = urldecode( $journal->first_child('romeopub')->text ) if $journal->first_child('romeopub'); my $issn = urldecode( $journal->first_child('issn')->text ) if $journal->first_child('issn'); my $publisher = $romeo; $publisher = $zetoc if (not $publisher && $zetoc); # build a lub of html based on the components my $html .= "<li>$title"; $html .= "<br />published by $publisher" if $publisher; $html .= "<ul>"; if ($title) { $html .= "<li id='for:value:component:_publication'>$title</li>"; } if ($publisher) { $html .= "<li id='for:value:component:_publisher'>$publisher</li>"; } if ($issn) { $html .= "<li id='for:value:component:_issn'>$issn</li>"; } $html .= "</ul></li>\n"; warn "\n\n$html\n\n"; # save the html $journal_data->{$title} = $html; 1; } ## end process_journal # get a list of journals that match the query sub get_journals { my $journal = shift; my @html = (); if ($journal) { return ("<ul><li>keep typing....</li></ul>") if (length($journal) < 3); $journal =~ s/\s+/\+/; my $query = "http://www.sherpa.ac.uk/romeoapi.php?qtype=starts&jtitle=$journal"; my $request = HTTP::Request->new( GET => "$query" ); my $ua = LWP::UserAgent->new(); my $response = $ua->request($request); my $content = $response->content(); my $twig = XML::Twig->new( 'keep_encoding' => 1, 'TwigRoots' => { 'journals' => 1 }, 'TwigHandlers' => { 'journal' => \&process_journal, } ); $twig->parse($content); if (scalar keys %{$journal_data}) { push @html, "<ul class='journals'>\n"; foreach my $title (sort keys %{$journal_data}) { push @html, "$journal_data->{$title}\n"; } ## end of foreach my $title (sort keys %{$journal_data}) push @html, "</ul>\n"; } ## end of if (scalar keys %{$journal_data}) ... } else { push @html, "<!-- No journal name supplied -->\n"; } return (join "\n", @html) } ## end get_journals my $session = EPrints::Session->new(); # we need the send an initial content-type print <<END; <?xml version="1.0" encoding="UTF-8" ?> END # then we send the fragment of html for the autocompleter print get_journals( lc $session->param( "q" ) ); $session->terminate; </pre>
Summary:
Please note that all contributions to EPrints Documentation may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
EPrints Documentation:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)