source: gs2-extensions/parallel-building/trunk/src/perllib/classify/Collage.pm@ 24626

Last change on this file since 24626 was 24626, checked in by jmt12, 13 years ago

An (almost) complete copy of the perllib directory from a (circa SEP2011) head checkout from Greenstone 2 trunk - in order to try and make merging in this extension a little easier later on (as there have been some major changes to buildcol.pl commited in the main trunk but not in the x64 branch)

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