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

Last change on this file since 17209 was 17209, checked in by kjdon, 16 years ago

BasClas renamed to BaseClassifier, tidied up constructors

  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 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) = @_;
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 my $doc_OID = $doc_obj->get_OID();
162 push (@{$self->{'list'}}, $doc_OID);
163 }
164
165}
166
167sub get_classify_info {
168 my $self = shift (@_);
169
170 my $items_per_page = 2;
171 my $max_items_per_page = 20;
172
173 my @list = @{$self->{'list'}};
174
175 my $outhandle = $self->{'outhandle'};
176 my $verbosity = $self->{'verbosity'};
177
178 if ($verbosity>1) {
179 print $outhandle ("$self->{'buttonname'}\n");
180 }
181
182 my $collage_head = $self->get_entry ($self->{'buttonname'}, "Collage", "Invisible");
183 my $collage_curr = $self->get_entry("Collage","VList");
184 push (@{$collage_head->{'contains'}},$collage_curr);
185
186 my $global_c=1;
187 my $within_page_c=1;
188
189 foreach my $oid (@list) {
190 if ($within_page_c>$items_per_page) {
191 my $title = "Items $global_c+";
192 my $nested_node = $self->get_entry($title,"VList");
193 push (@{$collage_curr->{'contains'}}, $nested_node);
194 $collage_curr = $nested_node;
195
196 $within_page_c=1;
197
198 $items_per_page++ if ($items_per_page < $max_items_per_page);
199 }
200
201 push (@{$collage_curr->{'contains'}}, {'OID'=>$oid});
202 $global_c++;
203 $within_page_c++;
204 }
205
206 return $collage_head;
207}
208
209
210sub get_entry {
211 my $self = shift (@_);
212 my ($title, $childtype, $thistype) = @_;
213
214 # organise into classification structure
215 my %classifyinfo = ('childtype'=>$childtype,
216 'Title'=>$title,
217 'contains'=>[]);
218
219 $classifyinfo{'thistype'} = $thistype if (defined $thistype);
220
221 if ($childtype eq "Collage") {
222 my $geometry = $self->{'geometry'};
223 my ($x_dim,$y_dim) = ($geometry =~ m/^(.*)x(.*)$/);
224 my $verbosity = $self->{'verbosity'};
225 my $maxDepth = $self->{'maxDepth'};
226# my $maxDownloads = $self->{'maxDownloads'};
227 my $maxDisplay = $self->{'maxDisplay'};
228 my $imageType = $self->{'imageType'};
229 my $bgcolor = $self->{'bgcolor'};
230 my $refreshDelay = $self->{'refreshDelay'};
231 my $isJava2 = $self->{'isJava2'};
232 my $imageMustNotHave = $self->{'imageMustNotHave'};
233 my $caption = $self->{'caption'};
234
235 #if (!defined($maxDownloads)) {
236 # $maxDownloads="";
237 #}
238
239 my $parameters;
240
241 $parameters = "xdim=".$x_dim;
242 $parameters .= ";ydim=".$y_dim;
243 $parameters .= ";geometry=".$self->{'geometry'};
244 $parameters .= ";verbosity=".$self->{'verbosity'};
245 $parameters .= ";maxDepth=".$self->{'maxDepth'};
246# $parameters .= ";maxDownloads=".$maxDownloads;
247 $parameters .= ";maxDisplay=".$self->{'maxDisplay'};
248 $parameters .= ";imageType=".$self->{'imageType'};
249 $parameters .= ";bgcolor=".$self->{'bgcolor'};
250 $parameters .= ";refreshDelay=".$self->{'refreshDelay'};
251 $parameters .= ";isJava2=".$self->{'isJava2'};
252 $parameters .= ";caption=".$self->{'caption'};
253
254# $parameters .= ";imageMustNotHave=".$self->{'imageMustNotHave'};
255
256
257 $classifyinfo{'parameters'} = $parameters;
258 }
259
260 return \%classifyinfo;
261}
262
2631;
Note: See TracBrowser for help on using the repository browser.