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

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

Now accepts "private residence"/"private residences" as a valid place function value.

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