source: trunk/cic-hcap/perllib/plugins/CICPlug.pm@ 11917

Last change on this file since 11917 was 11917, checked in by mdewsnip, 18 years ago

Added support for PDFs as place images: these aren't converted, just associated and linked to directly.

  • Property svn:keywords set to Author Date Id Revision
File size: 49.7 KB
Line 
1###########################################################################
2#
3# CICPlug.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) 2005 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 CICPlug;
27
28
29use BasPlug;
30use DBI;
31use strict;
32no strict 'refs';
33
34
35sub BEGIN {
36 @CICPlug::ISA = ('BasPlug');
37}
38
39
40my $arguments =
41 [
42 { 'name' => "images_directory",
43 'type' => "string",
44 'deft' => "",
45 'reqd' => "yes" },
46 { 'name' => "cache_directory",
47 'type' => "string",
48 'deft' => &util::filename_cat($ENV{'GSDLHOME'}, "tmp"),
49 'reqd' => "no" },
50 { 'name' => "large_image_options",
51 'type' => "string",
52 'deft' => "",
53 'reqd' => "no" },
54 { 'name' => "large_image_type",
55 'type' => "string",
56 'deft' => "jpg",
57 'reqd' => "no" },
58 { 'name' => "large_image_width",
59 'type' => "string",
60 'deft' => "1250",
61 'reqd' => "no" },
62 { 'name' => "medium_image_options",
63 'type' => "string",
64 'deft' => "",
65 'reqd' => "no" },
66 { 'name' => "medium_image_type",
67 'type' => "string",
68 'deft' => "jpg",
69 'reqd' => "no" },
70 { 'name' => "medium_image_width",
71 'type' => "string",
72 'deft' => "375",
73 'reqd' => "no" },
74 { 'name' => "small_image_options",
75 'type' => "string",
76 'deft' => "",
77 'reqd' => "no" },
78 { 'name' => "small_image_type",
79 'type' => "string",
80 'deft' => "jpg",
81 'reqd' => "no" },
82 { 'name' => "small_image_width",
83 'type' => "string",
84 'deft' => "125",
85 'reqd' => "no" }
86 ];
87
88my $options = { 'name' => "CICPlug",
89 'desc' => "{CICPlug.desc}",
90 'abstract' => "no",
91 'inherits' => "yes" };
92
93
94sub get_default_process_exp
95{
96 return q^(?i)\.mdb$^;
97}
98
99
100sub new
101{
102 my ($class) = shift (@_);
103 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
104 push(@$pluginlist, $class);
105
106 if (defined $arguments) { push(@{$hashArgOptLists->{"ArgList"}}, @{$arguments}); }
107 if (defined $options) { push(@{$hashArgOptLists->{"OptList"}}, $options); }
108
109 my $self = (defined $hashArgOptLists) ? new BasPlug($pluginlist,$inputargs,$hashArgOptLists) : new BasPlug($pluginlist,$inputargs);
110
111 return bless $self, $class;
112}
113
114
115my $state_abbr_to_name_mapping = {
116 "AL" => "Alabama",
117 "AK" => "Alaska",
118 "AZ" => "Arizona",
119 "AR" => "Arkansas",
120 "CA" => "California",
121 "CO" => "Colorado",
122 "CT" => "Connecticut",
123 "DE" => "Delaware",
124 "FL" => "Florida",
125 "GA" => "Georgia",
126 "HI" => "Hawaii",
127 "ID" => "Idaho",
128 "IL" => "Illinois",
129 "IN" => "Indiana",
130 "IA" => "Iowa",
131 "KS" => "Kansas",
132 "KY" => "Kentucky",
133 "LA" => "Louisiana",
134 "ME" => "Maine",
135 "MD" => "Maryland",
136 "MA" => "Massachusetts",
137 "MI" => "Michigan",
138 "MN" => "Minnesota",
139 "MS" => "Mississippi",
140 "MO" => "Missouri",
141 "MT" => "Montana",
142 "NE" => "Nebraska",
143 "NV" => "Nevada",
144 "NH" => "New Hampshire",
145 "NJ" => "New Jersey",
146 "NM" => "New Mexico",
147 "NY" => "New York",
148 "NC" => "North Carolina",
149 "ND" => "North Dakota",
150 "OH" => "Ohio",
151 "OK" => "Oklahoma",
152 "OR" => "Oregon",
153 "PA" => "Pennsylvania",
154 "RI" => "Rhode Island",
155 "SC" => "South Carolina",
156 "SD" => "South Dakota",
157 "TN" => "Tennessee",
158 "TX" => "Texas",
159 "UT" => "Utah",
160 "VT" => "Vermont",
161 "VA" => "Virginia",
162 "WA" => "Washington",
163 "WV" => "West Virginia",
164 "WI" => "Wisconsin",
165 "WY" => "Wyoming"
166 };
167
168
169my $place_type_id_to_name_mapping = {
170 "1" => "Individual building",
171 "2" => "Landscape site",
172 "3" => "Campus arrangement",
173 "4" => "Building group",
174};
175
176
177sub read
178{
179 my $self = shift (@_);
180 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
181
182 $self->{'filename'} = &util::filename_cat($base_dir, $file);
183 if ($self->{'filename'} !~ /$self->{'process_exp'}/ || !-f $self->{'filename'}) {
184 return undef;
185 }
186 $self->{'processor'} = $processor;
187 $self->{'gli'} = $gli;
188
189 # Open connection to Access database
190 my $dbh = DBI->connect('dbi:ODBC:CIC-HCAP');
191
192 $self->process_institutions($dbh);
193 $self->process_places($dbh);
194 $self->process_designers($dbh);
195
196 return 1;
197}
198
199
200sub process_institutions
201{
202 my $self = shift(@_);
203 my $dbh = shift(@_);
204 my $fail_log_handle = $self->{'failhandle'};
205
206 # Prepare SQL statement for getting everything from the Institution table
207 my $institution_sql_statement = "SELECT * FROM tblInstitution"; # WHERE Institution_ID<200";
208 my $institution_sql_handle = $dbh->prepare($institution_sql_statement);
209 $institution_sql_handle->{LongReadLen} = 65536;
210 $institution_sql_handle->execute() or die "Could not execute SQL statement.";
211
212 # Prepare SQL statement for getting the Institution places
213 my $institution_places_sql_statement = "SELECT Entry_ID,Current_name FROM tblPlace WHERE PlaceType>0 AND Institution_ID=?";
214 my $institution_places_sql_handle = $dbh->prepare($institution_places_sql_statement);
215 $institution_places_sql_handle->{LongReadLen} = 65536;
216
217 # Prepare SQL statement for getting the Institution best place image location
218 my $institution_best_place_image_location_sql_statement = "SELECT Location FROM tblImages WHERE FileType=1 AND FileName=?";
219 my $institution_best_place_image_location_sql_handle = $dbh->prepare($institution_best_place_image_location_sql_statement);
220 $institution_best_place_image_location_sql_handle->{LongReadLen} = 65536;
221
222 # Prepare SQL statement for getting the Institution places images
223 my $institution_places_images_sql_statement = "SELECT FileName FROM tblImages,tblPlace WHERE tblImages.FileType=1 AND tblImages.Entry_ID=tblPlace.Entry_ID AND tblPlace.Institution_ID=?";
224 my $institution_places_images_sql_handle = $dbh->prepare($institution_places_images_sql_statement);
225 $institution_places_images_sql_handle->{LongReadLen} = 65536;
226
227 # Prepare SQL statement for getting the Institution campus plans
228 my $institution_campus_plans_sql_statement = "SELECT * FROM tblCampusMaps WHERE Electronic=1 AND Institution_ID=?";
229 my $institution_campus_plans_sql_handle = $dbh->prepare($institution_campus_plans_sql_statement);
230 $institution_campus_plans_sql_handle->{LongReadLen} = 65536;
231
232 # Create a document object for each institution
233 my %institution_id_to_name_mapping;
234 my %institution_state_to_ids_mapping;
235 while (my $row_hashref = $institution_sql_handle->fetchrow_hashref) {
236 # Skip any institutions that didn't respond
237 next if !defined($row_hashref->{"City"});
238
239 my $institution_id = $row_hashref->{"Institution_ID"};
240 # print STDERR " Institution $institution_id\n";
241 my $institution_doc_obj = new doc($self->{'filename'} . "-", "indexed_doc");
242 $institution_doc_obj->set_OID("i$institution_id");
243 &new_metadata_entry($institution_doc_obj, "DocumentType", "Institution");
244
245 # For some reason the hyphen seems to be lost from the Zip field, so add it back in
246 my $institution_zip = $row_hashref->{"Zip"};
247 if ($institution_zip =~ /^(\d\d\d\d\d)(\d\d\d\d)$/) {
248 $row_hashref->{"Zip"} = $1 . "-" . $2;
249 }
250
251 # Map state to full name
252 $row_hashref->{"State"} = $state_abbr_to_name_mapping->{$row_hashref->{"State"}};
253
254 # Get the places in this institution
255 my $institution_random_place_id;
256 my $institution_places_list_html = "";
257 $institution_places_sql_handle->execute($institution_id) or die "Could not execute SQL statement.";
258 while (my $institution_places_match_hashref = $institution_places_sql_handle->fetchrow_hashref) {
259 my $institution_place_id = $institution_places_match_hashref->{"Entry_ID"};
260 my $institution_place_name = $institution_places_match_hashref->{"Current_name"};
261 $institution_places_list_html .= "<span class=\"cictext\"><a href=\"_gwcgi_?a=d&d=p$institution_place_id\">$institution_place_name</a></span><br />\n";
262 }
263 &new_metadata_entry($institution_doc_obj, "InstitutionPlacesListHTML", $institution_places_list_html);
264
265 # Get the best place image for this institution
266 my $institution_best_place_image_name = $row_hashref->{"Best_image"};
267 if (!defined($institution_best_place_image_name) || $institution_best_place_image_name eq "") {
268 # Some institutions have no electronic images, and thus have no best image
269 $institution_places_images_sql_handle->execute($institution_id) or die "Could not execute SQL statement.";
270 if (defined($institution_places_images_sql_handle->fetchrow_hashref())) {
271 print STDERR "<ProcessingError n='Institution $institution_id' p='CICPlug' r='No best image'>\n" if ($self->{'gli'});
272 print STDERR "Error: Institution $institution_id -- No best image.\n";
273 print $fail_log_handle "Error: Institution $institution_id -- No best image.\n";
274 $self->{'num_not_processed'}++;
275 next;
276 }
277 &new_metadata_entry($institution_doc_obj, "InstitutionBestPlaceImageHTML", "");
278 }
279 else {
280 # Get the file location of the best place image for this institution
281 $institution_best_place_image_location_sql_handle->execute($institution_best_place_image_name) or die "Could not execute SQL statement.";
282 my $institution_best_place_image_location = $institution_best_place_image_location_sql_handle->fetchrow();
283 if (!defined($institution_best_place_image_location) || $institution_best_place_image_location eq "") {
284 print STDERR "<ProcessingError n='Institution $institution_id' p='CICPlug' r='Could not match best image $institution_best_place_image_name to a file'>\n" if ($self->{'gli'});
285 print STDERR "Error: Institution $institution_id -- Could not match best image $institution_best_place_image_name to a file.\n";
286 print $fail_log_handle "Error: Institution $institution_id -- Could not match best image $institution_best_place_image_name to a file.\n";
287 $self->{'num_not_processed'}++;
288 next;
289 }
290
291 # PDFs are not allowed for institution best place images
292 if ($institution_best_place_image_location =~ /.pdf$/i) {
293 print STDERR "<ProcessingError n='Institution $institution_id' p='CICPlug' r='PDF not allowed for best image'>\n" if ($self->{'gli'});
294 print STDERR "Error: Institution $institution_id -- PDF not allowed for best image.\n";
295 print $fail_log_handle "Error: Institution $institution_id -- PDF not allowed for best image.\n";
296 $self->{'num_not_processed'}++;
297 next;
298 }
299
300 $self->generate_place_image_variant($institution_doc_obj, $institution_best_place_image_location, "medium");
301 $self->generate_place_image_variant($institution_doc_obj, $institution_best_place_image_location, "large");
302
303 my $institution_best_place_image_large_file_name = $institution_best_place_image_name . "-large.jpg";
304 $institution_best_place_image_large_file_name =~ s/ /%20/g;
305 my $institution_best_place_image_large_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$institution_best_place_image_large_file_name";
306 my $institution_best_place_image_medium_file_name = $institution_best_place_image_name . "-medium.jpg";
307 $institution_best_place_image_medium_file_name =~ s/ /%20/g;
308 my $institution_best_place_image_medium_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$institution_best_place_image_medium_file_name";
309 &new_metadata_entry($institution_doc_obj, "InstitutionBestPlaceImageHTML", "<a href=\"$institution_best_place_image_large_file_link\"><img src=\"$institution_best_place_image_medium_file_link\"/><br /><span class=\"cictext\">$institution_best_place_image_name</span></a>");
310 }
311
312 # Get institution campus plans
313 my $institution_campus_plans_list_html = "";
314 $institution_campus_plans_sql_handle->execute($institution_id) or die "Could not execute SQL statement.";
315 while (my $institution_campus_plans_match_hashref = $institution_campus_plans_sql_handle->fetchrow_hashref) {
316 my $institution_campus_plan_name = $institution_campus_plans_match_hashref->{"NameAndFormat"};
317 my $institution_campus_plan_image_location = $institution_campus_plans_match_hashref->{"Location_electronic"};
318
319 # Deal with PDF files separately: don't convert, just associate
320 if ($institution_campus_plan_image_location =~ /\.pdf$/i) {
321 # Convert the server location of the file into the local location of the file
322 my $institution_campus_plan_pdf_file_path = $institution_campus_plan_image_location;
323 $institution_campus_plan_pdf_file_path =~ s/^[A-Z]:/$self->{'images_directory'}/;
324
325 if (-f $institution_campus_plan_pdf_file_path) {
326 my $institution_campus_plan_pdf_file_name = $institution_campus_plan_name . ".pdf";
327 $institution_campus_plan_pdf_file_name =~ s/ /%20/g;
328 my $institution_campus_plan_pdf_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$institution_campus_plan_pdf_file_name";
329 $institution_campus_plans_list_html .= "<a href=\"$institution_campus_plan_pdf_file_link\"><span class=\"cictext\">$institution_campus_plan_name (PDF)</span></a><br />";
330
331 $institution_doc_obj->associate_file($institution_campus_plan_pdf_file_path, $institution_campus_plan_name . ".pdf", undef, $institution_doc_obj->get_top_section());
332 }
333 else {
334 print STDERR "<ProcessingError n='$institution_campus_plan_pdf_file_path' p='CICPlug' r='Does not exist'>\n" if ($self->{'gli'});
335 print STDERR "Error: File $institution_campus_plan_pdf_file_path does not exist.\n";
336 print $fail_log_handle "Error: File $institution_campus_plan_pdf_file_path does not exist.\n";
337 }
338 }
339 else {
340 $self->generate_place_image_variant($institution_doc_obj, $institution_campus_plan_image_location, "large");
341
342 my $institution_campus_plan_image_large_file_name = $institution_campus_plan_name . "-large.jpg";
343 $institution_campus_plan_image_large_file_name =~ s/ /%20/g;
344 my $institution_campus_plan_image_large_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$institution_campus_plan_image_large_file_name";
345 $institution_campus_plans_list_html .= "<a href=\"$institution_campus_plan_image_large_file_link\"><span class=\"cictext\">$institution_campus_plan_name</span></a><br />";
346 }
347 }
348 &new_metadata_entry($institution_doc_obj, "InstitutionCampusPlansListHTML", $institution_campus_plans_list_html);
349
350 # Add each field from the table as metadata
351 foreach my $key (keys(%$row_hashref)) {
352 my $value = $row_hashref->{$key};
353 if (defined($value)) {
354 &new_metadata_entry($institution_doc_obj, $key, $value);
355 }
356 }
357
358 $institution_doc_obj->add_utf8_text($institution_doc_obj->get_top_section(), "Some dummy text.");
359 $self->{'processor'}->process($institution_doc_obj);
360 $self->{'num_processed'}++;
361
362 # Build mappings for creating the static macrofiles
363 my $institution_name = $row_hashref->{"Institution_Name"};
364 $institution_id_to_name_mapping{$institution_doc_obj->get_OID()} = $institution_name;
365 my $institution_state = $row_hashref->{"State"};
366 push(@{$institution_state_to_ids_mapping{$institution_state}}, $institution_doc_obj->get_OID());
367 }
368
369 # Write the institutions.dm macrofile
370 &write_static_browser_macrofile("institutions", \%institution_id_to_name_mapping);
371
372 # Write the states.dm macrofile
373 &write_state_browser_macrofile("states", \%institution_state_to_ids_mapping, \%institution_id_to_name_mapping);
374}
375
376
377sub process_places
378{
379 my $self = shift(@_);
380 my $dbh = shift(@_);
381 my $fail_log_handle = $self->{'failhandle'};
382
383 # Prepare SQL statement for getting everything from the Place table
384 my $place_sql_statement = "SELECT * FROM tblPlace";
385 my $place_sql_handle = $dbh->prepare($place_sql_statement);
386 $place_sql_handle->{LongReadLen} = 65536;
387 $place_sql_handle->execute() or die "Could not execute SQL statement.";
388
389 # Prepare SQL statement for getting the Place institution
390 my $place_institution_sql_statement = "SELECT Institution_Name FROM tblInstitution,tblPlace WHERE tblInstitution.Institution_ID=tblPlace.Institution_ID and tblPlace.Entry_ID=?";
391 my $place_institution_sql_handle = $dbh->prepare($place_institution_sql_statement);
392
393 # Prepare SQL statement for getting the Place "date of construction"
394 my $place_construction_date_sql_statement = "SELECT Date FROM tblConstruction_and_Dates WHERE Entry_ID=?";
395 my $place_construction_date_sql_handle = $dbh->prepare($place_construction_date_sql_statement);
396
397 # Prepare SQL statement for getting the Place images
398 my $place_images_sql_statement = "SELECT FileName,Location FROM tblImages WHERE FileType=1 AND Entry_ID=?";
399 my $place_images_sql_handle = $dbh->prepare($place_images_sql_statement);
400 $place_images_sql_handle->{LongReadLen} = 65536;
401
402 # Prepare SQL statement for getting the Place materials
403 my $place_materials_sql_statement = "SELECT * FROM tblDescription_building WHERE Entry_ID=?";
404 my $place_materials_sql_handle = $dbh->prepare($place_materials_sql_statement);
405 $place_materials_sql_handle->{LongReadLen} = 65536;
406
407 # Prepare SQL statement for getting the Place building styles
408 my $place_styles_sql_statement = "SELECT Architectural_Classification FROM tblArchTypes,jnxtblArchPlace WHERE tblArchTypes.ArchType_ID=jnxtblArchPlace.ArchType_ID AND Entry_ID=?";
409 my $place_styles_sql_handle = $dbh->prepare($place_styles_sql_statement);
410 $place_styles_sql_handle->{LongReadLen} = 65536;
411
412 # Prepare SQL statement for getting the Place functions
413 my $place_functions_sql_statement = "SELECT Function,Year,Prefix FROM tblFunction_and_dates WHERE Entry_ID=?";
414 my $place_functions_sql_handle = $dbh->prepare($place_functions_sql_statement);
415 $place_functions_sql_handle->{LongReadLen} = 65536;
416
417 # Prepare SQL statement for getting the Place significance
418 my $place_significance_sql_statement = "SELECT SigType FROM tblSigTypes,SigPlace WHERE tblSigTypes.SigTypes_ID=SigPlace.SigType_ID+1 AND SigPlace.Entry_ID=?";
419 my $place_significance_sql_handle = $dbh->prepare($place_significance_sql_statement);
420 $place_significance_sql_handle->{LongReadLen} = 65536;
421
422 # Prepare SQL statement for getting the Place references
423 my $place_references_sql_statement = "SELECT Bibliography FROM tblReferences WHERE Entry_ID=?";
424 my $place_references_sql_handle = $dbh->prepare($place_references_sql_statement);
425 $place_references_sql_handle->{LongReadLen} = 65536;
426
427 # Prepare SQL statement for getting the Place narrative
428 my $place_narrative_sql_statement = "SELECT Narrative FROM tblSignificance_Narrative WHERE Entry_ID=?";
429 my $place_narrative_sql_handle = $dbh->prepare($place_narrative_sql_statement);
430 $place_narrative_sql_handle->{LongReadLen} = 65536;
431
432 # Prepare SQL statement for getting the Place state
433 my $place_state_sql_statement = "SELECT State FROM tblInstitution,tblPlace WHERE tblInstitution.Institution_ID=tblPlace.Institution_ID AND Entry_ID=?";
434 my $place_state_sql_handle = $dbh->prepare($place_state_sql_statement);
435 $place_state_sql_handle->{LongReadLen} = 65536;
436
437 # Create a document object for each place
438 my %place_type_to_ids_mapping;
439 my %place_style_to_ids_mapping;
440 my %place_date_to_ids_mapping;
441 my %place_function_to_ids_mapping;
442 my %place_id_to_name_mapping;
443 my %place_id_to_institution_name_mapping;
444 while (my $row_hashref = $place_sql_handle->fetchrow_hashref) {
445 my $place_id = $row_hashref->{"Entry_ID"};
446 # print STDERR " Place $place_id\n";
447 my $place_doc_obj = new doc($self->{'filename'} . "-", "indexed_doc");
448 $place_doc_obj->set_OID("p$place_id");
449 &new_metadata_entry($place_doc_obj, "DocumentType", "Place");
450
451 # Convert the place type ID into a name
452 $row_hashref->{"PlaceType"} = $place_type_id_to_name_mapping->{$row_hashref->{"PlaceType"}};
453
454 # Add each field from the table as metadata
455 foreach my $key (keys(%$row_hashref)) {
456 my $value = $row_hashref->{$key};
457 if (defined($value)) {
458 &new_metadata_entry($place_doc_obj, $key, $value);
459 }
460 }
461
462 # Get place name
463 my $place_name = $row_hashref->{"Current_name"};
464 if (!defined($place_name)) {
465 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing place name'>\n" if ($self->{'gli'});
466 print STDERR "Error: Place $place_id -- Missing place name.\n";
467 print $fail_log_handle "Error: Place $place_id -- Missing place name.\n";
468 $self->{'num_not_processed'}++;
469 next;
470 }
471
472 # Get place type
473 my $place_type = $row_hashref->{"PlaceType"};
474 if (!defined($place_type)) {
475 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing place type'>\n" if ($self->{'gli'});
476 print STDERR "Error: Place $place_id -- Missing place type.\n";
477 print $fail_log_handle "Error: Place $place_id -- Missing place type.\n";
478 $self->{'num_not_processed'}++;
479 next;
480 }
481
482 # Get place date of construction, except for landscape sites which have no date
483 $place_construction_date_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
484 my $place_construction_date_value = $place_construction_date_sql_handle->fetchrow();
485 if (!defined($place_construction_date_value) && $place_type eq "Landscape site") {
486 # Landscape sites may not have a construction date
487 $place_construction_date_value = "";
488 }
489 if (!defined($place_construction_date_value)) {
490 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing construction date'>\n" if ($self->{'gli'});
491 print STDERR "Error: Place $place_id -- Missing construction date.\n";
492 print $fail_log_handle "Error: Place $place_id -- Missing construction date.\n";
493 $self->{'num_not_processed'}++;
494 next;
495 }
496 &new_metadata_entry($place_doc_obj, "Construction_date", $place_construction_date_value);
497
498 # Create place styles mapping
499 $place_styles_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
500 while (my $place_styles_match_hashref = $place_styles_sql_handle->fetchrow_hashref()) {
501 my $place_style = $place_styles_match_hashref->{"Architectural_Classification"};
502 push(@{$place_style_to_ids_mapping{$place_style}}, $place_doc_obj->get_OID());
503 &new_metadata_entry($place_doc_obj, "Style", $place_style);
504 }
505
506 # Get place institution
507 $place_institution_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
508 my $place_institution = $place_institution_sql_handle->fetchrow();
509 &new_metadata_entry($place_doc_obj, "Institution_name", $place_institution);
510 $place_id_to_institution_name_mapping{$place_doc_obj->get_OID()} = ", " . $place_institution;
511
512 # Get place state (for searching)
513 $place_state_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
514 my $place_state_abbr = $place_state_sql_handle->fetchrow();
515 &new_metadata_entry($place_doc_obj, "State", $place_state_abbr . " " . $state_abbr_to_name_mapping->{$place_state_abbr});
516
517 # Create place dates mapping
518 my $place_time_period = $place_construction_date_value;
519 if ($place_construction_date_value =~ /^(\d\d\d\d).*$/) {
520 $place_construction_date_value =~ s/^(\d\d\d\d).*$/$1/;
521 if ($place_construction_date_value < 1800) { $place_time_period = "pre-1800"; }
522 elsif ($place_construction_date_value < 1850) { $place_time_period = "1800-1850"; }
523 elsif ($place_construction_date_value < 1900) { $place_time_period = "1850-1900"; }
524 elsif ($place_construction_date_value < 1945) { $place_time_period = "1900-1945"; }
525 elsif ($place_construction_date_value < 1995) { $place_time_period = "1945-1995"; }
526 else { $place_time_period = "post-1995"; }
527 push(@{$place_date_to_ids_mapping{$place_time_period}}, $place_doc_obj->get_OID());
528 }
529 &new_metadata_entry($place_doc_obj, "Time_period", $place_time_period);
530
531 # Get place materials (individual buildings only)
532 if ($row_hashref->{"PlaceType"} eq "Individual building") {
533 $place_materials_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
534 my $place_materials_match_hashref = $place_materials_sql_handle->fetchrow_hashref();
535 &new_metadata_entry($place_doc_obj, "MaterialFoundation", $place_materials_match_hashref->{"foundation"} || "");
536 &new_metadata_entry($place_doc_obj, "MaterialRoof", $place_materials_match_hashref->{"roof"} || "");
537 &new_metadata_entry($place_doc_obj, "MaterialWalls", $place_materials_match_hashref->{"walls"} || "");
538 }
539
540 # Get place functions
541 my $place_functions = "";
542 my $place_functions_table_html = "";
543 $place_functions_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
544 while (my $place_functions_match_hashref = $place_functions_sql_handle->fetchrow_hashref()) {
545 my $place_function = $place_functions_match_hashref->{"Function"};
546 if (!defined($place_function)) {
547 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing function'>\n" if ($self->{'gli'});
548 print STDERR "Error: Place $place_id -- Missing function.\n";
549 print $fail_log_handle "Error: Place $place_id -- Missing function.\n";
550 next;
551 }
552 my $place_year = $place_functions_match_hashref->{"Year"};
553 if (!defined($place_year)) {
554 print STDERR "<ProcessingError n='Place $place_id' p='CICPlug' r='Missing function year'>\n" if ($self->{'gli'});
555 print STDERR "Error: Place $place_id -- Missing function year.\n";
556 print $fail_log_handle "Error: Place $place_id -- Missing function year.\n";
557 next;
558 }
559 my $place_year_prefix = $place_functions_match_hashref->{"Prefix"} || "";
560 $place_functions .= "$place_function ";
561 $place_functions_table_html .= "<tr><td valign=\"top\"><nobr>$place_year_prefix $place_year</nobr>&nbsp;</td><td valign=\"top\">$place_function</td></tr>";
562
563 # Create place functions mapping
564 $place_function =~ s/\(.*?\)//g;
565 $place_function =~ s/^\s*//;
566 $place_function =~ s/\s*$//;
567 next if ($place_function eq "");
568 push(@{$place_function_to_ids_mapping{$place_function}}, $place_doc_obj->get_OID());
569 }
570 &new_metadata_entry($place_doc_obj, "Functions", $place_functions);
571 &new_metadata_entry($place_doc_obj, "PlaceFunctionsTableHTML", "<table cellpadding=\"0\" cellspacing=\"0\">" . $place_functions_table_html . "</table>");
572
573 # Get place significance
574 $place_significance_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
575 while (my $place_significance_match_hashref = $place_significance_sql_handle->fetchrow_hashref()) {
576 my $place_significance = $place_significance_match_hashref->{"SigType"};
577 &new_metadata_entry($place_doc_obj, "Significance", lc($place_significance));
578 }
579
580 # Get place references
581 $place_references_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
582 my $place_references = $place_references_sql_handle->fetchrow();
583 if (defined($place_references)) {
584 &new_metadata_entry($place_doc_obj, "References", &rtf_to_html($place_references));
585 }
586
587 # Get place narrative
588 $place_narrative_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
589 my $place_narrative = $place_narrative_sql_handle->fetchrow();
590 if (defined($place_narrative)) {
591 $place_narrative = &rtf_to_html($place_narrative);
592 $place_narrative =~ s/<br \/>(\s|\n)*$//; # Remove any trailing <br /> tags
593 &new_metadata_entry($place_doc_obj, "Narrative", $place_narrative);
594 }
595
596 # Get place images
597 my $place_images_html = "";
598 $place_images_sql_handle->execute($place_id) or die "Could not execute SQL statement.";
599 while (my $place_images_match_hashref = $place_images_sql_handle->fetchrow_hashref) {
600 my $place_image_location = $place_images_match_hashref->{"Location"};
601 my $place_image_name = $place_images_match_hashref->{"FileName"};
602
603 # Deal with PDF files separately: don't convert, just associate
604 if ($place_image_location =~ /\.pdf$/i) {
605 # Convert the server location of the PDF file into the local location of the file
606 my $place_pdf_file_path = $place_image_location;
607 $place_pdf_file_path =~ s/^[A-Z]:/$self->{'images_directory'}/;
608
609 if (-f $place_pdf_file_path) {
610 my ($place_pdf_file_name) = ($place_pdf_file_path =~ /^.+\\(.+)$/);
611 $place_doc_obj->associate_file($place_pdf_file_path, $place_pdf_file_name, undef, $place_doc_obj->get_top_section());
612
613 $place_pdf_file_name =~ s/ /%20/g;
614 my $place_pdf_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$place_pdf_file_name";
615 $place_images_html .= "<tr><td align=\"right\" valign=\"top\"><a href=\"$place_pdf_file_link\">_iconpdf_</a></td><td valign=\"top\"><a href=\"$place_pdf_file_link\"><span class=\"cictext\">$place_image_name (PDF)</span></a></td></tr>\n";
616 }
617 else {
618 print STDERR "<ProcessingError n='$place_pdf_file_path' p='CICPlug' r='Does not exist'>\n" if ($self->{'gli'});
619 print STDERR "Error: File $place_pdf_file_path does not exist.\n";
620 print $fail_log_handle "Error: File $place_pdf_file_path does not exist.\n";
621 }
622 }
623 else {
624 $self->generate_place_image_variant($place_doc_obj, $place_image_location, "small");
625 $self->generate_place_image_variant($place_doc_obj, $place_image_location, "large");
626
627 if (defined($place_image_name)) {
628 my $place_image_large_file_name = $place_image_name . "-large.jpg";
629 $place_image_large_file_name =~ s/ /%20/g;
630 my $place_image_large_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$place_image_large_file_name";
631 my $place_image_small_file_name = $place_image_name . "-small.jpg";
632 $place_image_small_file_name =~ s/ /%20/g;
633 my $place_image_small_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$place_image_small_file_name";
634 $place_images_html .= "<tr><td valign=\"top\"><a href=\"$place_image_large_file_link\"><img src=\"$place_image_small_file_link\"/></a></td><td valign=\"top\"><a href=\"$place_image_large_file_link\"><span class=\"cictext\">$place_image_name</span></a></td></tr>\n";
635 }
636 else {
637 $place_images_html .= "<tr><td valign=\"top\"><img src=\"_httpcollection_/images/no_image.jpg\"/></td><td valign=\"top\"><span class=\"cictext\">&nbsp;</span></td></tr>\n";
638 }
639 }
640 }
641
642 &new_metadata_entry($place_doc_obj, "PlaceImagesHTML", "<table>" . $place_images_html . "</table>");
643
644 $place_doc_obj->add_utf8_text($place_doc_obj->get_top_section(), "Some dummy text.");
645 $self->{'processor'}->process($place_doc_obj);
646 $self->{'num_processed'}++;
647
648 # Build mappings for creating the static macrofiles
649 $place_id_to_name_mapping{$place_doc_obj->get_OID()} = $place_name;
650 push(@{$place_type_to_ids_mapping{$place_type}}, $place_doc_obj->get_OID());
651 }
652
653 &write_bilevel_static_browser_macrofile("types", \%place_type_to_ids_mapping, \%place_id_to_name_mapping, \%place_id_to_institution_name_mapping);
654 &write_bilevel_static_browser_macrofile("styles", \%place_style_to_ids_mapping, \%place_id_to_name_mapping, \%place_id_to_institution_name_mapping);
655 &write_bilevel_static_browser_macrofile("dates", \%place_date_to_ids_mapping, \%place_id_to_name_mapping, \%place_id_to_institution_name_mapping);
656 &write_bilevel_static_browser_macrofile("functions", \%place_function_to_ids_mapping, \%place_id_to_name_mapping, \%place_id_to_institution_name_mapping);
657}
658
659
660sub process_designers
661{
662 my $self = shift(@_);
663 my $dbh = shift(@_);
664 my $fail_log_handle = $self->{'failhandle'};
665
666 # Prepare SQL statement for getting all the Architects from the Place table
667 my $designer_sql_statement = "SELECT Architect_Name,Entry_ID FROM tblConstruction_and_dates";
668 my $designer_sql_handle = $dbh->prepare($designer_sql_statement);
669 $designer_sql_handle->{LongReadLen} = 65536;
670 $designer_sql_handle->execute() or die "Could not execute SQL statement.";
671
672 # Prepare SQL statement for getting the Place images
673 my $place_images_sql_statement = "SELECT FileName,Location FROM tblImages WHERE FileType=1 AND Entry_ID=?";
674 my $place_images_sql_handle = $dbh->prepare($place_images_sql_statement);
675 $place_images_sql_handle->{LongReadLen} = 65536;
676
677 # Prepare SQL statement for getting the Place "date of construction"
678 my $place_construction_date_sql_statement = "SELECT Date FROM tblConstruction_and_Dates WHERE Entry_ID=?";
679 my $place_construction_date_sql_handle = $dbh->prepare($place_construction_date_sql_statement);
680
681 # Prepare SQL statement for getting the Place name
682 my $place_name_sql_statement = "SELECT Current_name FROM tblPlace WHERE Entry_ID=?";
683 my $place_name_sql_handle = $dbh->prepare($place_name_sql_statement);
684
685 # Get a list of all the designers, and the places they worked on
686 my %designer_name_to_place_ids_mapping;
687 my %designer_name_to_id_mapping;
688 my %designer_id_to_name_mapping;
689 my $designer_count = 0;
690 while (my $designer_hashref = $designer_sql_handle->fetchrow_hashref) {
691 my $designer_names_string = $designer_hashref->{"Architect_Name"};
692 next if !defined($designer_names_string);
693 foreach my $designer_name (split(/;/, $designer_names_string)) {
694 $designer_name =~ s/\(.*?\)//g;
695 $designer_name =~ s/^\s*//;
696 $designer_name =~ s/\s*$//;
697
698 if (!defined($designer_name_to_id_mapping{$designer_name})) {
699 $designer_count++;
700 $designer_name_to_id_mapping{$designer_name} = "d" . $designer_count;
701 }
702
703 $designer_id_to_name_mapping{$designer_name_to_id_mapping{$designer_name}} = $designer_name;
704 push(@{$designer_name_to_place_ids_mapping{$designer_name}}, $designer_hashref->{"Entry_ID"});
705 }
706 }
707
708 # Create a document object for each designer
709 foreach my $designer_name (keys %designer_name_to_place_ids_mapping) {
710 my $designer_id = $designer_name_to_id_mapping{$designer_name};
711 # print STDERR " Designer $designer_id\n";
712 my $designer_doc_obj = new doc($self->{'filename'} . "-", "indexed_doc");
713 $designer_doc_obj->set_OID($designer_id);
714 &new_metadata_entry($designer_doc_obj, "DocumentType", "Designer");
715
716 &new_metadata_entry($designer_doc_obj, "Designer_name", $designer_name);
717
718 my $designer_places_image_html = "";
719 foreach my $designer_place_id (@{$designer_name_to_place_ids_mapping{$designer_name}}) {
720 # Get place date of construction
721 $place_construction_date_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
722 my $designer_place_construction_date_value = $place_construction_date_sql_handle->fetchrow() || "";
723
724 # Get the first image for this place
725 $place_images_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
726 my $designer_place_image_match_hashref = $place_images_sql_handle->fetchrow_hashref();
727 if (defined($designer_place_image_match_hashref)) {
728 my $designer_place_image_location = $designer_place_image_match_hashref->{"Location"};
729 $self->generate_place_image_variant($designer_doc_obj, $designer_place_image_location, "small");
730
731 my $designer_place_image_name = $designer_place_image_match_hashref->{"FileName"};
732 my $designer_place_image_small_file_link;
733 if (defined($designer_place_image_name)) {
734 my $designer_place_image_small_file_name = $designer_place_image_name . "-small.jpg";
735 $designer_place_image_small_file_name =~ s/ /%20/g;
736 $designer_place_image_small_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$designer_place_image_small_file_name";
737 }
738 else {
739 # Get the name of this place (since we don't have a filename)
740 $place_name_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
741 $designer_place_image_name = $place_name_sql_handle->fetchrow() || "";
742 $designer_place_image_small_file_link = "_httpcollection_/images/no_image.jpg";
743 }
744 $designer_places_image_html .= "<tr><td valign=\"top\"><a href=\"_gwcgi_?a=d&d=p$designer_place_id\"><img src=\"$designer_place_image_small_file_link\"/></a></td><td valign=\"top\"><a href=\"_gwcgi_?a=d&d=p$designer_place_id\"><span class=\"cictext\">$designer_place_image_name</span></a><br /><b>Date of construction:</b> $designer_place_construction_date_value</td></tr>\n";
745 }
746 }
747
748 &new_metadata_entry($designer_doc_obj, "DesignerPlacesImageHTML", "<table>" . $designer_places_image_html . "</table>");
749
750 $designer_doc_obj->add_utf8_text($designer_doc_obj->get_top_section(), "Some dummy text.");
751 $self->{'processor'}->process($designer_doc_obj);
752 $self->{'num_processed'}++;
753 }
754
755 # Write the designers.dm macrofile
756 &write_static_browser_macrofile("designers", \%designer_id_to_name_mapping);
757}
758
759
760sub new_metadata_entry
761{
762 my ($doc_obj, $metadata_name, $metadata_value) = (@_);
763
764 # Don't bother with empty metadata
765 return if ($metadata_value eq "");
766
767 # Spaces aren't allowed in metadata names
768 $metadata_name =~ s/ /_/g;
769
770 # Anything from the database is ISO 8859-1 encoded, so convert to UTF-8
771 $metadata_value = &unicode::ascii2utf8(\$metadata_value);
772
773 # Remove '#' characters around links
774 if ($metadata_value =~ /\#(.*?)\#/) {
775 $metadata_value = $1;
776 }
777
778 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), $metadata_name, $metadata_value);
779}
780
781
782sub rtf_to_html
783{
784 my $rtf_string = shift(@_);
785 $rtf_string =~ s/\{(.*?)\}//g;
786 $rtf_string =~ s/\\rquote /'/g; # ' # (for Emacs)
787 $rtf_string =~ s/\\pard//g;
788 $rtf_string =~ s/\\par/<br \/>/g;
789 $rtf_string =~ s/\\i0 /<\/i>/g;
790 $rtf_string =~ s/\\i /<i>/g;
791 $rtf_string =~ s/\\~/ /g;
792 $rtf_string =~ s/\\([A-Za-z0-9]+)//g;
793 $rtf_string =~ s/\}//g;
794
795 # Assume non-ASCII is ISO 8859-1, and convert into HTML entities
796 while ($rtf_string =~ /\\'([a-z0-9][a-z0-9])/) {
797 my $dec = hex($1);
798 $rtf_string =~ s/\\'$1/&#$dec\;/;
799 }
800
801 return $rtf_string;
802}
803
804
805sub get_place_image_dimensions
806{
807 my $self = shift(@_);
808 my $place_image_file_path = shift(@_);
809 my $fail_log_handle = $self->{'failhandle'};
810
811 # Make sure the place image file actually exists
812 if (!-f $place_image_file_path) {
813 print STDERR "<ProcessingError n='$place_image_file_path' p='CICPlug' r='Does not exist'>\n" if ($self->{'gli'});
814 print STDERR "Error: Image $place_image_file_path does not exist.\n";
815 print $fail_log_handle "Error: Image $place_image_file_path does not exist.\n";
816 return;
817 }
818 my $place_image_file_date = (stat($place_image_file_path))[9];
819
820 # Check if this place image has already been identified by looking for a ".info" file in the same directory
821 my $place_image_info_file_path = $place_image_file_path . ".info";
822 if (-f $place_image_info_file_path) {
823 # A ".info" file exists, so read the cached place image information from it
824 open(PLACE_IMAGE_INFO_FILE, "<$place_image_info_file_path");
825 my @place_image_info = <PLACE_IMAGE_INFO_FILE>;
826 close(PLACE_IMAGE_INFO_FILE);
827
828 # Read the cached place image file date and check that it matches
829 my $cached_place_image_file_date = $place_image_info[0];
830 $cached_place_image_file_date =~ s/\n$//;
831 if ($cached_place_image_file_date == $place_image_file_date) {
832 # It does match, so use the cached information from the ".info" file instead of re-identifying the file
833 my $place_image_width = $place_image_info[1];
834 $place_image_width =~ s/\n$//;
835 my $place_image_height = $place_image_info[2];
836 $place_image_height =~ s/\n$//;
837 return ($place_image_width, $place_image_height);
838 }
839 }
840
841 # We haven't already identified the place image, so do it now
842 print STDERR "Identifying place image $place_image_file_path...\n";
843 my $identify_command = "identify -format \"%w %h\" \"$place_image_file_path\"";
844 my $identify_result = `$identify_command`;
845 print "Identify result: $identify_result\n" if ($self->{'verbosity'} > 2);
846
847 # Check that the output is what we're expecting
848 if ($identify_result !~ /(\d+) (\d+)/) {
849 print STDERR "<ProcessingError n='$place_image_file_path' p='CICPlug' r='Could not identify'>\n" if ($self->{'gli'});
850 print STDERR "Error: Place image $place_image_file_path could not be identified.\n";
851 print $fail_log_handle "Error: Place image $place_image_file_path could not be identified.\n";
852 return;
853 }
854
855 # Parse the place image width and height from the output
856 my $place_image_width = $1;
857 my $place_image_height = $2;
858
859 # Write the place image info file so we don't have to identify this exact image again in the future
860 open(PLACE_IMAGE_INFO_FILE, ">$place_image_info_file_path");
861 print PLACE_IMAGE_INFO_FILE "$place_image_file_date\n";
862 print PLACE_IMAGE_INFO_FILE "$place_image_width\n";
863 print PLACE_IMAGE_INFO_FILE "$place_image_height\n";
864 close(PLACE_IMAGE_INFO_FILE);
865 return ($place_image_width, $place_image_height);
866}
867
868
869sub generate_place_image_variant
870{
871 my $self = shift(@_);
872 my ($doc_obj, $place_image_location, $place_image_variant_size) = (@_);
873 my $fail_log_handle = $self->{'failhandle'};
874
875 # Convert the server location of the file into the local location of the file
876 my $place_image_file_path = $place_image_location;
877 $place_image_file_path =~ s/^[A-Z]:/$self->{'images_directory'}/;
878
879 # Get the width and height of the place image
880 my ($place_image_width, $place_image_height) = $self->get_place_image_dimensions($place_image_file_path);
881 if (!defined($place_image_width) || !defined($place_image_height)) {
882 # An error has occurred (error message generated by get_place_image_dimensions())
883 return;
884 }
885 my $place_image_file_date = (stat($place_image_file_path))[9];
886
887 # Generate the path of the place image variant (in the cache directory)
888 my $place_image_variant_file_suffix = "-$place_image_variant_size." . $self->{$place_image_variant_size . '_image_type'};
889 my $place_image_variant_file_path = $place_image_location;
890 $place_image_variant_file_path =~ s/^[A-Z]:/$self->{'cache_directory'}/;
891 $place_image_variant_file_path =~ s/^(.+)(\..*)/$1$place_image_variant_file_suffix/;
892 my ($place_image_variant_file_name) = ($place_image_variant_file_path =~ /^.+\\(.+)$/);
893
894 # Only scale down the place image if it is bigger than the desired width
895 my $place_image_variant_desired_width = $self->{$place_image_variant_size . '_image_width'};
896 if ($place_image_width > $place_image_variant_desired_width) {
897 # Only generate the place image variant if it doesn't already exist, or if the place image is newer
898 if (!-f $place_image_variant_file_path || $place_image_file_date > (stat($place_image_variant_file_path))[9]) {
899 print STDERR "Generating place image variant $place_image_variant_file_path...\n";
900 my ($place_image_variant_directory) = ($place_image_variant_file_path =~ /^(.+)\\.+$/);
901 &util::mk_all_dir($place_image_variant_directory);
902 my $place_image_variant_options = "-scale $place_image_variant_desired_width " . $self->{$place_image_variant_size . '_image_options'};
903 my $convert_command = "convert $place_image_variant_options \"$place_image_file_path\" \"$place_image_variant_file_path\"";
904 my $convert_result = `$convert_command`;
905 }
906 }
907 else {
908 # The desired width is bigger than the place image, so we just use the original
909 $place_image_variant_file_path = $place_image_file_path;
910 }
911
912 my ($place_image_variant_width, $place_image_variant_height) = $self->get_place_image_dimensions($place_image_variant_file_path);
913 if (!defined($place_image_variant_width) || !defined($place_image_variant_height)) {
914 # An error has occurred (error message generated by get_place_image_dimensions())
915 return;
916 }
917
918 # Create a new section for each place image variant (!! TO DO: Check if this is really necessary)
919 my $place_image_variant_section = $doc_obj->insert_section($doc_obj->get_end_child($doc_obj->get_top_section()));
920 $doc_obj->add_utf8_text($place_image_variant_section, "Some dummy text.");
921 $doc_obj->add_utf8_metadata($place_image_variant_section, "Title", "1");
922
923 # Associate the place image variant file
924 $doc_obj->associate_file($place_image_variant_file_path, $place_image_variant_file_name, undef, $self->{'section'});
925
926 # Add various bits of metadata for the place image variant
927 my $place_image_variant_metadata_value = $place_image_variant_file_name;
928 $place_image_variant_metadata_value =~ s/ /%20/g;
929 $doc_obj->add_utf8_metadata($self->{'section'}, $place_image_variant_size . "Image", $place_image_variant_metadata_value);
930 $doc_obj->add_metadata($self->{'section'}, $place_image_variant_size . "ImageWidth", $place_image_variant_width);
931 $doc_obj->add_metadata($self->{'section'}, $place_image_variant_size . "ImageHeight", $place_image_variant_height);
932 $doc_obj->add_metadata($self->{'section'}, $place_image_variant_size . "ImagePath", "_httpcollection_/index/assoc/[parent(Top):assocfilepath]/[${place_image_variant_size}Image]");
933}
934
935
936sub write_static_browser_macrofile
937{
938 my $static_browser_package_name = shift(@_);
939 my $id_to_name_mapping = shift(@_);
940
941 my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_name.dm";
942 print STDERR "Writing $static_browser_macrofile_path...\n";
943 open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
944 &write_static_browser_macros($static_browser_package_name, $id_to_name_mapping);
945 close(BROWSER_MACROFILE);
946}
947
948
949sub write_static_browser_macros
950{
951 my $static_browser_package_name = shift(@_);
952 my $id_to_name_mapping = shift(@_);
953 my $id_to_extra_mapping = shift(@_);
954
955 print BROWSER_MACROFILE "package $static_browser_package_name\n\n";
956 print BROWSER_MACROFILE "_cicstaticbrowser_ {\n";
957
958 my %letter_to_ids_mapping;
959 foreach my $id (keys %$id_to_name_mapping) {
960 my $name = $id_to_name_mapping->{$id};
961 my ($letter) = ($name =~ /([A-Za-z0-9])/);
962 push(@{$letter_to_ids_mapping{$letter}}, $id);
963 }
964
965 print BROWSER_MACROFILE "<center><b>";
966 foreach my $letter (split(//, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
967 if (defined($letter_to_ids_mapping{$letter})) {
968 print BROWSER_MACROFILE "<a href=\"#$letter\">$letter</a>&nbsp;";
969 }
970 else {
971 print BROWSER_MACROFILE "$letter&nbsp;";
972 }
973 }
974 print BROWSER_MACROFILE "</b></center>\n";
975
976 print BROWSER_MACROFILE "<table cellpadding=\"0\" cellspacing=\"0\" width=\"_pagewidth_\">\n";
977 foreach my $letter (sort(keys %letter_to_ids_mapping)) {
978 my @letter_ids = @{$letter_to_ids_mapping{$letter}};
979 &write_static_browser_macros_chunk($letter, \@letter_ids, $id_to_name_mapping, $id_to_extra_mapping);
980 }
981 print BROWSER_MACROFILE "</table>\n";
982
983 print BROWSER_MACROFILE "}\n";
984}
985
986
987sub write_static_browser_macros_chunk
988{
989 my $chunk_title = shift(@_);
990 my $chunk_ids_ref = shift(@_);
991 my $id_to_name_mapping = shift(@_);
992 my $id_to_extra_mapping = shift(@_);
993
994 print BROWSER_MACROFILE "<tr><td width=\"50%\"><br /><a name=\"$chunk_title\"/><span style=\"color: black;\"><b>$chunk_title</b></span></td><td width=\"50%\"></td></tr>\n";
995
996 my %full_name_to_id_mapping;
997 foreach my $id (@{$chunk_ids_ref}) {
998 my $full_name = $id_to_name_mapping->{$id};
999 if (defined($id_to_extra_mapping)) {
1000 $full_name .= " " . $id_to_extra_mapping->{$id};
1001 }
1002 $full_name_to_id_mapping{$full_name} = $id;
1003 }
1004
1005 my @full_names = sort(keys(%full_name_to_id_mapping));
1006 my $half_point = ((scalar(@full_names) % 2 == 0) ? scalar(@full_names) / 2 : (scalar(@full_names) + 1) / 2);
1007 for (my $i = 0; $i < $half_point; $i++) {
1008 print BROWSER_MACROFILE "<tr>";
1009
1010 my $id = $full_name_to_id_mapping{$full_names[$i]};
1011 my $name = $id_to_name_mapping->{$id};
1012 my $extra = $id_to_extra_mapping->{$id} || "";
1013 print BROWSER_MACROFILE "<td valign=\"top\"><a href=\"_gwcgi_?a=d&d=$id\">$name</a>$extra</td>";
1014
1015 print BROWSER_MACROFILE "<td valign=\"top\">";
1016 if (defined($full_names[$i+$half_point])) {
1017 $id = $full_name_to_id_mapping{$full_names[$i+$half_point]};
1018 $name = $id_to_name_mapping->{$id};
1019 $extra = $id_to_extra_mapping->{$id} || "";
1020 print BROWSER_MACROFILE "<a href=\"_gwcgi_?a=d&d=$id\">$name</a>$extra";
1021 }
1022 print BROWSER_MACROFILE "</td>";
1023
1024 print BROWSER_MACROFILE "</tr>\n";
1025 }
1026}
1027
1028
1029sub write_bilevel_static_browser_macrofile
1030{
1031 my $static_browser_package_root = shift(@_);
1032 my $category_to_ids_mapping = shift(@_);
1033 my $id_to_name_mapping = shift(@_);
1034 my $id_to_extra_mapping = shift(@_);
1035
1036 my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_root.dm";
1037 print STDERR "Writing $static_browser_macrofile_path...\n";
1038 open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
1039
1040 foreach my $category (keys(%{$category_to_ids_mapping})) {
1041 my $static_browser_package_name = $static_browser_package_root . $category;
1042 $static_browser_package_name =~ s/\W//g;
1043
1044 my %id_to_name_mapping_for_category = ();
1045 foreach my $id (@{$category_to_ids_mapping->{$category}}) {
1046 $id_to_name_mapping_for_category{$id} = $id_to_name_mapping->{$id};
1047 }
1048 &write_static_browser_macros($static_browser_package_name, \%id_to_name_mapping_for_category, $id_to_extra_mapping);
1049 }
1050
1051 close(BROWSER_MACROFILE);
1052}
1053
1054
1055sub write_state_browser_macrofile
1056{
1057 my $static_browser_package_name = shift(@_);
1058 my $state_to_ids_mapping = shift(@_);
1059 my $id_to_name_mapping = shift(@_);
1060
1061 my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_name.dm";
1062 print STDERR "Writing $static_browser_macrofile_path...\n";
1063 open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
1064 print BROWSER_MACROFILE "package $static_browser_package_name\n\n";
1065 print BROWSER_MACROFILE "_cicstaticbrowser_ {\n";
1066
1067 print BROWSER_MACROFILE "<table cellpadding=\"0\" cellspacing=\"0\" width=\"_pagewidth_\">\n";
1068 foreach my $state (sort(keys(%{$state_to_ids_mapping}))) {
1069 my @state_ids = @{$state_to_ids_mapping->{$state}};
1070 &write_static_browser_macros_chunk($state, \@state_ids, $id_to_name_mapping, undef);
1071 }
1072 print BROWSER_MACROFILE "</table>\n";
1073
1074 print BROWSER_MACROFILE "}\n";
1075 close(BROWSER_MACROFILE);
1076}
1077
1078
10791;
Note: See TracBrowser for help on using the repository browser.