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

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

Now adds Materials metadata: a combination of MaterialsFoundation, MaterialsRoof and MaterialsWalls. For the advanced searching.

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