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

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

Added Designation metadata (for the new advanced search page).

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