source: gsdl/trunk/perllib/plugins/FavouritesPlugin.pm@ 16104

Last change on this file since 16104 was 16104, checked in by kjdon, 13 years ago

tried to make the 'xxxplugin processing file' print statements more consistent. They are now done in read (or read_into_doc_obj) and not process

  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1###########################################################################
2#
3# FavouritesPlug.pm -- Plugin for Internet Explorer Favourites files
4# By Stephen De Gabrielle
5#
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# Copyright (C) 2005 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27# hacked together by Stephen De Gabrielle from various plugins
28# especially SRCPlug by John McPherson Nov 2000
29
30package FavouritesPlugin;
31
32use ReadTextFile;
33use strict;
34no strict 'refs'; # allow filehandles to be variables and viceversa
35
36sub BEGIN {
37 @FavouritesPlugin::ISA = ('ReadTextFile');
38}
39
40my $arguments =
41 [ { 'name' => "process_exp",
42 'desc' => "{BasePlugin.process_exp}",
43 'type' => "regexp",
44 'deft' => &get_default_process_exp(),
45 'reqd' => "no" } ];
46
47my $options = { 'name' => "FavouritesPlugin",
48 'desc' => "{FavouritesPlugin.desc}",
49 'abstract' => "no",
50 'inherits' => "yes",
51 'args' => $arguments };
52
53
54sub new {
55 my ($class) = shift(@_);
56 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
57 push(@$pluginlist, $class);
58
59 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
60 push(@{$hashArgOptLists->{"OptList"}},$options);
61
62 my $self = new ReadTextFile($pluginlist, $inputargs, $hashArgOptLists);
63
64 return bless $self, $class;
65}
66
67
68sub get_default_process_exp
69{
70 # URL is extension for single bookmarks under windows.
71 return q^(?i)\.URL$^;
72}
73
74
75# do plugin specific processing of doc_obj
76sub process {
77 my $self = shift (@_);
78 my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
79 my $outhandle = $self->{'outhandle'};
80
81 my $section = $doc_obj->get_top_section();
82
83 # don't want mg to turn escape chars into actual values
84 $$textref =~ s/\\/\\\\/g;
85
86 # use filename (minus the .url extension) as the title
87 my $title = $file;
88 $title =~ s/.url$//i;
89 $doc_obj->add_utf8_metadata($section, "Title", $title);
90
91 # get the URL from the file
92 my ($url) = ($$textref =~ m/^URL=(http.+)/mg);
93 $doc_obj->add_metadata($section, "URL", $url);
94
95 # Add srclink metadata for an automatic link to the webpage
96 $doc_obj->add_utf8_metadata($section, "srclink", "<a href=\"$url\">");
97 $doc_obj->add_utf8_metadata($section, "srcicon", "_iconworld_");
98 $doc_obj->add_utf8_metadata($section, "/srclink", "</a>");
99
100 # Tidy up the favourite text to look a bit nicer
101 $$textref =~ s/^\\n/<p>/g;
102 $$textref =~ s/\[/<p><strong>/g;
103 $$textref =~ s/\]/<\/strong><p>/g;
104 $$textref =~ s/^Modified=(.+)$/<strong>Modified<\/strong>$1<p>/g;
105 $doc_obj->add_utf8_text($section, "$$textref");
106
107 $doc_obj->add_metadata($section, "FileFormat", "Favourite");
108 return 1;
109}
110
1111;
Note: See TracBrowser for help on using the repository browser.