source: gsdl/trunk/perllib/classify/Collage.pm@ 20828

Last change on this file since 20828 was 18455, checked in by davidb, 15 years ago

Addition of 'edit_mode' parameter to classify(). This can be either 'add' 'delete' or 'reindex' (should think about renaming the last one to something more appropriate, e.g. update).

  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1##########################################################################
2#
3# Collage.pm --
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26package Collage;
27
28use BaseClassifier;
29use sorttools;
30
31use strict;
32no strict 'refs'; # allow filehandles to be variables and viceversa
33
34sub BEGIN {
35 @Collage::ISA = ('BaseClassifier');
36}
37
38my $arguments =
39 [ { 'name' => "buttonname",
40 'desc' => "{Collage.buttonname}",
41 'type' => "string",
42 'deft' => "Collage",
43 'reqd' => "no" },
44 { 'name' => "geometry",
45 'desc' => "{Collage.geometry}",
46 'type' => "string",
47 'deft' => "600x300",
48 'reqd' => "no" },
49 { 'name' => "verbosity",
50 'desc' => "{BasClas.verbosity}",
51 'type' => "string",
52 'deft' => "5",
53 'reqd' => "no" },
54 { 'name' => "maxDepth",
55 'desc' => "{Collage.maxDepth}",
56 'type' => "string",
57 'deft' => "500"},
58# { 'name' => "maxDownloads",
59# 'desc' => "{Collage.maxDownloads}",
60# 'type' => "string",
61# 'deft' => "",
62# 'reqd' => "no" },
63 { 'name' => "maxDisplay",
64 'desc' => "{Collage.maxDisplay}",
65 'type' => "string",
66 'deft' => "25",
67 'reqd' => "no" },
68 { 'name' => "imageType",
69 'desc' => "{Collage.imageType}",
70 'type' => "string",
71 'deft' => ".jpg%%.png",
72 'reqd' => "no" },
73 { 'name' => "bgcolor",
74 'desc' => "{Collage.bgcolor}",
75 'type' => "string",
76 'deft' => "#96c29a",
77 'reqd' => "no" },
78 { 'name' => "refreshDelay",
79 'desc' => "{Collage.refreshDelay}",
80 'type' => "string",
81 'deft' => "1500",
82 'reqd' => "no" },
83 { 'name' => "isJava2",
84 'desc' => "{Collage.isJava2}",
85 'type' => "string",
86 'deft' => "auto",
87 'reqd' => "no" },
88 { 'name' => "imageMustNotHave",
89 'desc' => "{Collage.imageMustNotHave}",
90 'type' => "string",
91 'deft' => "hl=%%x=%%gt=%%gc=%%.pr",
92 'reqd' => "no" },
93 { 'name' => "caption",
94 'desc' => "{Collage.caption}",
95 'type' => "string",
96 'deft' => " ",
97 'reqd' => "no" }
98 ];
99
100
101
102
103my $options = { 'name' => "Collage",
104 'desc' => "{Collage.desc}",
105 'abstract' => "no",
106 'inherits' => "Yes",
107 'args' => $arguments };
108
109
110sub new {
111 my ($class) = shift (@_);
112 my ($classifierslist,$inputargs,$hashArgOptLists) = @_;
113 push(@$classifierslist, $class);
114
115 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
116 push(@{$hashArgOptLists->{"OptList"}},$options);
117
118 my $self = new BaseClassifier($classifierslist, $inputargs, $hashArgOptLists);
119
120 if ($self->{'info_only'}) {
121 # don't worry about any options etc
122 return bless $self, $class;
123 }
124
125 # Manually set $self parameters.
126 $self->{'list'} = {};
127 $self->{'buttonname'} = 'Collage' unless ($self->{'buttonname'});
128
129 return bless $self, $class;
130}
131
132sub init {
133 my $self = shift (@_);
134
135 $self->{'list'} = [];
136}
137
138sub classify {
139
140 my $self = shift (@_);
141 my ($doc_obj,$edit_mode) = @_;
142
143 my $has_image_type = 0;
144
145 my @image_type_split = split(/%/,$self->{'imageType'});
146 my @image_type_ext = map { "($_)" } @image_type_split;
147 my $image_type_re = join("|",@image_type_ext);
148 $image_type_re =~ s/\./\\\./g;
149
150 my $assoc_files = $doc_obj->{'associated_files'};
151
152 foreach my $af ( @$assoc_files ) {
153 my ($real_filename, $assoc_filename, $mime_type, $section) = @$af;
154 if ($assoc_filename =~ m/$image_type_re/) {
155 $has_image_type = 1;
156 last;
157 }
158 }
159
160 if ($has_image_type) {
161
162 my $doc_OID = $doc_obj->get_OID();
163
164 if ($edit_mode eq "delete") {
165 $self->oid_array_delete($doc_OID,'list');
166 }
167 else {
168 push (@{$self->{'list'}}, $doc_OID);
169 }
170 }
171
172}
173
174sub get_classify_info {
175 my $self = shift (@_);
176
177 my $items_per_page = 2;
178 my $max_items_per_page = 20;
179
180 my @list = @{$self->{'list'}};
181
182 my $outhandle = $self->{'outhandle'};
183 my $verbosity = $self->{'verbosity'};
184
185 if ($verbosity>1) {
186 print $outhandle ("$self->{'buttonname'}\n");
187 }
188
189 my $collage_head = $self->get_entry ($self->{'buttonname'}, "Collage", "Invisible");
190 my $collage_curr = $self->get_entry("Collage","VList");
191 push (@{$collage_head->{'contains'}},$collage_curr);
192
193 my $global_c=1;
194 my $within_page_c=1;
195
196 foreach my $oid (@list) {
197 if ($within_page_c>$items_per_page) {
198 my $title = "Items $global_c+";
199 my $nested_node = $self->get_entry($title,"VList");
200 push (@{$collage_curr->{'contains'}}, $nested_node);
201 $collage_curr = $nested_node;
202
203 $within_page_c=1;
204
205 $items_per_page++ if ($items_per_page < $max_items_per_page);
206 }
207
208 push (@{$collage_curr->{'contains'}}, {'OID'=>$oid});
209 $global_c++;
210 $within_page_c++;
211 }
212
213 return $collage_head;
214}
215
216
217sub get_entry {
218 my $self = shift (@_);
219 my ($title, $childtype, $thistype) = @_;
220
221 # organise into classification structure
222 my %classifyinfo = ('childtype'=>$childtype,
223 'Title'=>$title,
224 'contains'=>[]);
225
226 $classifyinfo{'thistype'} = $thistype if (defined $thistype);
227
228 if ($childtype eq "Collage") {
229 my $geometry = $self->{'geometry'};
230 my ($x_dim,$y_dim) = ($geometry =~ m/^(.*)x(.*)$/);
231 my $verbosity = $self->{'verbosity'};
232 my $maxDepth = $self->{'maxDepth'};
233# my $maxDownloads = $self->{'maxDownloads'};
234 my $maxDisplay = $self->{'maxDisplay'};
235 my $imageType = $self->{'imageType'};
236 my $bgcolor = $self->{'bgcolor'};
237 my $refreshDelay = $self->{'refreshDelay'};
238 my $isJava2 = $self->{'isJava2'};
239 my $imageMustNotHave = $self->{'imageMustNotHave'};
240 my $caption = $self->{'caption'};
241
242 #if (!defined($maxDownloads)) {
243 # $maxDownloads="";
244 #}
245
246 my $parameters;
247
248 $parameters = "xdim=".$x_dim;
249 $parameters .= ";ydim=".$y_dim;
250 $parameters .= ";geometry=".$self->{'geometry'};
251 $parameters .= ";verbosity=".$self->{'verbosity'};
252 $parameters .= ";maxDepth=".$self->{'maxDepth'};
253# $parameters .= ";maxDownloads=".$maxDownloads;
254 $parameters .= ";maxDisplay=".$self->{'maxDisplay'};
255 $parameters .= ";imageType=".$self->{'imageType'};
256 $parameters .= ";bgcolor=".$self->{'bgcolor'};
257 $parameters .= ";refreshDelay=".$self->{'refreshDelay'};
258 $parameters .= ";isJava2=".$self->{'isJava2'};
259 $parameters .= ";caption=".$self->{'caption'};
260
261# $parameters .= ";imageMustNotHave=".$self->{'imageMustNotHave'};
262
263
264 $classifyinfo{'parameters'} = $parameters;
265 }
266
267 return \%classifyinfo;
268}
269
2701;
Note: See TracBrowser for help on using the repository browser.