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

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

Jeffrey's new parsing modifications, committed approx 6 July, 15.16

  • 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 print STDERR "buttonnmae = $buttonname\n";
120 $self->{'buttonname'} = 'Collage' unless ($self->{'buttonname'});
121
122 return bless $self, $class;
123}
124
125sub init {
126 my $self = shift (@_);
127
128 $self->{'list'} = [];
129}
130
131sub classify {
132
133 my $self = shift (@_);
134 my ($doc_obj) = @_;
135
136 my $has_image_type = 0;
137
138 my @image_type_split = split(/%/,$self->{'imageType'});
139 my @image_type_ext = map { "($_)" } @image_type_split;
140 my $image_type_re = join("|",@image_type_ext);
141 $image_type_re =~ s/\./\\\./g;
142
143 my $assoc_files = $doc_obj->{'associated_files'};
144
145 foreach my $af ( @$assoc_files ) {
146 my ($real_filename, $assoc_filename, $mime_type, $section) = @$af;
147 if ($assoc_filename =~ m/$image_type_re/) {
148 $has_image_type = 1;
149 last;
150 }
151 }
152
153 if ($has_image_type) {
154 my $doc_OID = $doc_obj->get_OID();
155 push (@{$self->{'list'}}, $doc_OID);
156 }
157
158}
159
160sub get_classify_info {
161 my $self = shift (@_);
162
163 my $items_per_page = 2;
164 my $max_items_per_page = 20;
165
166 my @list = @{$self->{'list'}};
167
168 my $outhandle = $self->{'outhandle'};
169 my $verbosity = $self->{'verbosity'};
170
171 if ($verbosity>1) {
172 print $outhandle ("$self->{'buttonname'}\n");
173 }
174
175 my $collage_head = $self->get_entry ($self->{'buttonname'}, "Collage", "Invisible");
176 my $collage_curr = $self->get_entry("Collage","VList");
177 push (@{$collage_head->{'contains'}},$collage_curr);
178
179 my $global_c=1;
180 my $within_page_c=1;
181
182 foreach $oid (@list) {
183 if ($within_page_c>$items_per_page) {
184 my $title = "Items $global_c+";
185 my $nested_node = $self->get_entry($title,"VList");
186 push (@{$collage_curr->{'contains'}}, $nested_node);
187 $collage_curr = $nested_node;
188
189 $within_page_c=1;
190
191 $items_per_page++ if ($items_per_page < $max_items_per_page);
192 }
193
194 push (@{$collage_curr->{'contains'}}, {'OID'=>$oid});
195 $global_c++;
196 $within_page_c++;
197 }
198
199 return $collage_head;
200}
201
202
203sub get_entry {
204 my $self = shift (@_);
205 my ($title, $childtype, $thistype) = @_;
206
207 # organise into classification structure
208 my %classifyinfo = ('childtype'=>$childtype,
209 'Title'=>$title,
210 'parameters'=> $parameters,
211 'contains'=>[]);
212
213 $classifyinfo{'thistype'} = $thistype if (defined $thistype);
214
215 if ($childtype eq "Collage") {
216 my $geometry = $self->{'geometry'};
217 my ($x_dim,$y_dim) = ($geometry =~ m/^(.*)x(.*)$/);
218 my $verbosity = $self->{'verbosity'};
219 my $maxDepth = $self->{'maxDepth'};
220# my $maxDownloads = $self->{'maxDownloads'};
221 my $maxDisplay = $self->{'maxDisplay'};
222 my $imageType = $self->{'imageType'};
223 my $bgcolor = $self->{'bgcolor'};
224 my $refreshDelay = $self->{'refreshDelay'};
225 my $isJava2 = $self->{'isJava2'};
226 my $imageMustNotHave = $self->{'imageMustNotHave'};
227 my $caption = $self->{'caption'};
228
229 if (!defined($maxDownloads)) {
230 $maxDownloads="";
231 }
232
233 my $parameters;
234
235 $parameters = "xdim=".$x_dim;
236 $parameters .= ";ydim=".$y_dim;
237 $parameters .= ";geometry=".$self->{'geometry'};
238 $parameters .= ";verbosity=".$self->{'verbosity'};
239 $parameters .= ";maxDepth=".$self->{'maxDepth'};
240# $parameters .= ";maxDownloads=".$maxDownloads;
241 $parameters .= ";maxDisplay=".$self->{'maxDisplay'};
242 $parameters .= ";imageType=".$self->{'imageType'};
243 $parameters .= ";bgcolor=".$self->{'bgcolor'};
244 $parameters .= ";refreshDelay=".$self->{'refreshDelay'};
245 $parameters .= ";isJava2=".$self->{'isJava2'};
246 $parameters .= ";caption=".$self->{'caption'};
247
248# $parameters .= ";imageMustNotHave=".$self->{'imageMustNotHave'};
249
250
251 $classifyinfo{'parameters'} = $parameters;
252 }
253
254 return \%classifyinfo;
255}
256
2571;
Note: See TracBrowser for help on using the repository browser.