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

Last change on this file since 10223 was 10223, checked in by kjdon, 19 years ago

removed debug statements that I had forgotten about

  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 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 BasClas;
29use sorttools;
30
31sub BEGIN {
32 @ISA = ('BasClas');
33}
34
35my $arguments =
36 [ { 'name' => "buttonname",
37 'desc' => "{BasClas.buttonname}",
38 'type' => "string",
39 'deft' => "Collage",
40 'reqd' => "no" },
41 { 'name' => "geometry",
42 'desc' => "{Collage.geometry}",
43 'type' => "string",
44 'deft' => "600x300",
45 'reqd' => "no" },
46 { 'name' => "verbosity",
47 'desc' => "{BasClas.verbosity}",
48 'type' => "string",
49 'deft' => "5",
50 'reqd' => "no" },
51 { 'name' => "maxDepth",
52 'desc' => "{Collage.maxDepth}",
53 'type' => "string",
54 'deft' => "500"},
55# { 'name' => "maxDownloads",
56# 'desc' => "{BasClas.maxDownloads}",
57# 'type' => "string",
58# 'deft' => "",
59# 'reqd' => "no" },
60 { 'name' => "maxDisplay",
61 'desc' => "{Collage.maxDisplay}",
62 'type' => "string",
63 'deft' => "25",
64 'reqd' => "no" },
65 { 'name' => "imageType",
66 'desc' => "{Collage.imageType}",
67 'type' => "string",
68 'deft' => ".jpg%%.png",
69 'reqd' => "no" },
70 { 'name' => "bgcolor",
71 'desc' => "{Collage.bgcolor}",
72 'type' => "string",
73 'deft' => "#96c29a",
74 'reqd' => "no" },
75 { 'name' => "refreshDelay",
76 'desc' => "{Collage.refreshDelay}",
77 'type' => "string",
78 'deft' => "1500",
79 'reqd' => "no" },
80 { 'name' => "isJava2",
81 'desc' => "{Collage.isJava2}",
82 'type' => "string",
83 'deft' => "auto",
84 'reqd' => "no" },
85 { 'name' => "imageMustNotHave",
86 'desc' => "{Collage.imageMustNotHave}",
87 'type' => "string",
88 'deft' => "hl=%%x=%%gt=%%gc=%%.pr",
89 'reqd' => "no" },
90 { 'name' => "caption",
91 'desc' => "{Collage.caption}",
92 'type' => "string",
93 'deft' => "",
94 'reqd' => "no" }
95 ];
96
97
98
99
100my $options = { 'name' => "Collage",
101 'desc' => "{Collage.desc}",
102 'abstract' => "no",
103 'inherits' => "Yes",
104 'args' => $arguments };
105
106
107sub new {
108 my ($class) = shift (@_);
109 my ($classifierslist,$inputargs,$hashArgOptLists) = @_;
110 push(@$classifierslist, $class);
111
112 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
113 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
114
115 my $self = (defined $hashArgOptLists)? new BasClas($classifierslist,$inputargs,$hashArgOptLists): new BasClas($classifierslist,$inputargs);
116
117 # Manually set $self parameters.
118 $self->{'list'} = {};
119 $self->{'buttonname'} = 'Collage' unless ($self->{'buttonname'});
120
121 return bless $self, $class;
122}
123
124sub init {
125 my $self = shift (@_);
126
127 $self->{'list'} = [];
128}
129
130sub classify {
131
132 my $self = shift (@_);
133 my ($doc_obj) = @_;
134
135 my $has_image_type = 0;
136
137 my @image_type_split = split(/%/,$self->{'imageType'});
138 my @image_type_ext = map { "($_)" } @image_type_split;
139 my $image_type_re = join("|",@image_type_ext);
140 $image_type_re =~ s/\./\\\./g;
141
142 my $assoc_files = $doc_obj->{'associated_files'};
143
144 foreach my $af ( @$assoc_files ) {
145 my ($real_filename, $assoc_filename, $mime_type, $section) = @$af;
146 if ($assoc_filename =~ m/$image_type_re/) {
147 $has_image_type = 1;
148 last;
149 }
150 }
151
152 if ($has_image_type) {
153 my $doc_OID = $doc_obj->get_OID();
154 push (@{$self->{'list'}}, $doc_OID);
155 }
156
157}
158
159sub get_classify_info {
160 my $self = shift (@_);
161
162 my $items_per_page = 2;
163 my $max_items_per_page = 20;
164
165 my @list = @{$self->{'list'}};
166
167 my $outhandle = $self->{'outhandle'};
168 my $verbosity = $self->{'verbosity'};
169
170 if ($verbosity>1) {
171 print $outhandle ("$self->{'buttonname'}\n");
172 }
173
174 my $collage_head = $self->get_entry ($self->{'buttonname'}, "Collage", "Invisible");
175 my $collage_curr = $self->get_entry("Collage","VList");
176 push (@{$collage_head->{'contains'}},$collage_curr);
177
178 my $global_c=1;
179 my $within_page_c=1;
180
181 foreach $oid (@list) {
182 if ($within_page_c>$items_per_page) {
183 my $title = "Items $global_c+";
184 my $nested_node = $self->get_entry($title,"VList");
185 push (@{$collage_curr->{'contains'}}, $nested_node);
186 $collage_curr = $nested_node;
187
188 $within_page_c=1;
189
190 $items_per_page++ if ($items_per_page < $max_items_per_page);
191 }
192
193 push (@{$collage_curr->{'contains'}}, {'OID'=>$oid});
194 $global_c++;
195 $within_page_c++;
196 }
197
198 return $collage_head;
199}
200
201
202sub get_entry {
203 my $self = shift (@_);
204 my ($title, $childtype, $thistype) = @_;
205
206 # organise into classification structure
207 my %classifyinfo = ('childtype'=>$childtype,
208 'Title'=>$title,
209 'parameters'=> $parameters,
210 'contains'=>[]);
211
212 $classifyinfo{'thistype'} = $thistype if (defined $thistype);
213
214 if ($childtype eq "Collage") {
215 my $geometry = $self->{'geometry'};
216 my ($x_dim,$y_dim) = ($geometry =~ m/^(.*)x(.*)$/);
217 my $verbosity = $self->{'verbosity'};
218 my $maxDepth = $self->{'maxDepth'};
219# my $maxDownloads = $self->{'maxDownloads'};
220 my $maxDisplay = $self->{'maxDisplay'};
221 my $imageType = $self->{'imageType'};
222 my $bgcolor = $self->{'bgcolor'};
223 my $refreshDelay = $self->{'refreshDelay'};
224 my $isJava2 = $self->{'isJava2'};
225 my $imageMustNotHave = $self->{'imageMustNotHave'};
226 my $caption = $self->{'caption'};
227
228 if (!defined($maxDownloads)) {
229 $maxDownloads="";
230 }
231
232 my $parameters;
233
234 $parameters = "xdim=".$x_dim;
235 $parameters .= ";ydim=".$y_dim;
236 $parameters .= ";geometry=".$self->{'geometry'};
237 $parameters .= ";verbosity=".$self->{'verbosity'};
238 $parameters .= ";maxDepth=".$self->{'maxDepth'};
239# $parameters .= ";maxDownloads=".$maxDownloads;
240 $parameters .= ";maxDisplay=".$self->{'maxDisplay'};
241 $parameters .= ";imageType=".$self->{'imageType'};
242 $parameters .= ";bgcolor=".$self->{'bgcolor'};
243 $parameters .= ";refreshDelay=".$self->{'refreshDelay'};
244 $parameters .= ";isJava2=".$self->{'isJava2'};
245 $parameters .= ";caption=".$self->{'caption'};
246
247# $parameters .= ";imageMustNotHave=".$self->{'imageMustNotHave'};
248
249
250 $classifyinfo{'parameters'} = $parameters;
251 }
252
253 return \%classifyinfo;
254}
255
2561;
Note: See TracBrowser for help on using the repository browser.