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

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

Much improved code for generating and maintaining the place image variants. Place images are no longer scaled larger, and it no longer rewrites all the .inf files every time the collection is imported!

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