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

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

Now shows the construction date of the places on the architect pages.

  • Property svn:keywords set to Author Date Id Revision
File size: 45.2 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_state_to_names_mapping;
234 my %institution_name_to_id_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->new_place_image($institution_doc_obj, $institution_best_place_image_location, "medium");
292 $self->new_place_image($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->new_place_image($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_name_to_id_mapping{$institution_name} = $institution_doc_obj->get_OID();
356 my $institution_state = $row_hashref->{"State"};
357 push(@{$institution_state_to_names_mapping{$institution_state}}, $institution_name);
358 }
359
360 # Write the institutions.dm macrofile
361 &write_static_browser_macrofile("institutions", \%institution_name_to_id_mapping);
362
363 # Write the states.dm macrofile
364 &write_state_browser_macrofile("states", \%institution_state_to_names_mapping, \%institution_name_to_id_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_names_mapping;
430 my %place_style_to_names_mapping;
431 my %place_date_to_names_mapping;
432 my %place_function_to_names_mapping;
433 my %place_name_to_id_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_names_mapping{$place_style}}, $place_name);
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_names_mapping{$place_time_period}}, $place_name);
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_names_mapping{$place_function}}, $place_name);
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->new_place_image($place_doc_obj, $place_image_location, "small");
593 $self->new_place_image($place_doc_obj, $place_image_location, "large");
594
595 my $place_image_name = $place_images_match_hashref->{"FileName"};
596 my $place_image_large_file_name = $place_image_name . "-large.jpg";
597 $place_image_large_file_name =~ s/ /%20/g;
598 my $place_image_large_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$place_image_large_file_name";
599 my $place_image_small_file_name = $place_image_name . "-small.jpg";
600 $place_image_small_file_name =~ s/ /%20/g;
601 my $place_image_small_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$place_image_small_file_name";
602 $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";
603 }
604
605 &new_metadata_entry($place_doc_obj, "PlaceImagesHTML", "<table>" . $place_images_html . "</table>");
606
607 $place_doc_obj->add_utf8_text($place_doc_obj->get_top_section(), "Some dummy text.");
608 $self->{'processor'}->process($place_doc_obj);
609 $self->{'num_processed'}++;
610
611 # Build mappings for creating the static macrofiles
612 $place_name_to_id_mapping{$place_name} = $place_doc_obj->get_OID();
613 push(@{$place_type_to_names_mapping{$place_type}}, $place_name);
614 }
615
616 &write_bilevel_static_browser_macrofile("types", \%place_type_to_names_mapping, \%place_name_to_id_mapping, \%place_id_to_institution_name_mapping);
617 &write_bilevel_static_browser_macrofile("styles", \%place_style_to_names_mapping, \%place_name_to_id_mapping, \%place_id_to_institution_name_mapping);
618 &write_bilevel_static_browser_macrofile("dates", \%place_date_to_names_mapping, \%place_name_to_id_mapping, \%place_id_to_institution_name_mapping);
619 &write_bilevel_static_browser_macrofile("functions", \%place_function_to_names_mapping, \%place_name_to_id_mapping, \%place_id_to_institution_name_mapping);
620}
621
622
623sub process_designers
624{
625 my $self = shift(@_);
626 my $dbh = shift(@_);
627 my $fail_log_handle = $self->{'failhandle'};
628
629 # Prepare SQL statement for getting all the Architects from the Place table
630 my $designer_sql_statement = "SELECT Architect_Name,Entry_ID FROM tblConstruction_and_dates";
631 my $designer_sql_handle = $dbh->prepare($designer_sql_statement);
632 $designer_sql_handle->{LongReadLen} = 65536;
633 $designer_sql_handle->execute() or die "Could not execute SQL statement.";
634
635 # Prepare SQL statement for getting the Place images
636 my $place_images_sql_statement = "SELECT FileName,Location FROM tblImages WHERE FileType=1 AND Entry_ID=?";
637 my $place_images_sql_handle = $dbh->prepare($place_images_sql_statement);
638 $place_images_sql_handle->{LongReadLen} = 65536;
639
640 # Prepare SQL statement for getting the Place "date of construction"
641 my $place_construction_date_sql_statement = "SELECT Date FROM tblConstruction_and_Dates WHERE Entry_ID=?";
642 my $place_construction_date_sql_handle = $dbh->prepare($place_construction_date_sql_statement);
643
644 # Get a list of all the designers, and the places they worked on
645 my %designer_name_to_place_ids_mapping;
646 my %designer_name_to_id_mapping;
647 my $designer_count = 0;
648 while (my $designer_hashref = $designer_sql_handle->fetchrow_hashref) {
649 my $designer_names_string = $designer_hashref->{"Architect_Name"};
650 next if !defined($designer_names_string);
651 foreach my $designer_name (split(/;/, $designer_names_string)) {
652 $designer_name =~ s/\(.*?\)//g;
653 $designer_name =~ s/^\s*//;
654 $designer_name =~ s/\s*$//;
655
656 if (!defined($designer_name_to_id_mapping{$designer_name})) {
657 $designer_count++;
658 $designer_name_to_id_mapping{$designer_name} = "d" . $designer_count;
659 }
660
661 push(@{$designer_name_to_place_ids_mapping{$designer_name}}, $designer_hashref->{"Entry_ID"});
662 }
663 }
664
665 # Create a document object for each designer
666 foreach my $designer_name (keys %designer_name_to_place_ids_mapping) {
667 my $designer_id = $designer_name_to_id_mapping{$designer_name};
668 # print STDERR " Designer $designer_id\n";
669 my $designer_doc_obj = new doc($self->{'filename'} . "-", "indexed_doc");
670 $designer_doc_obj->set_OID($designer_id);
671 &new_metadata_entry($designer_doc_obj, "DocumentType", "Designer");
672
673 &new_metadata_entry($designer_doc_obj, "Designer_name", $designer_name);
674
675 my $designer_places_image_html = "";
676 foreach my $designer_place_id (@{$designer_name_to_place_ids_mapping{$designer_name}}) {
677 # Get place date of construction
678 $place_construction_date_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
679 my $designer_place_construction_date_value = $place_construction_date_sql_handle->fetchrow() || "";
680
681 # Get the first image for this place
682 $place_images_sql_handle->execute($designer_place_id) or die "Could not execute SQL statement.";
683 my $designer_place_image_match_hashref = $place_images_sql_handle->fetchrow_hashref();
684 if (defined($designer_place_image_match_hashref)) {
685 my $designer_place_image_location = $designer_place_image_match_hashref->{"Location"};
686 $self->new_place_image($designer_doc_obj, $designer_place_image_location, "small");
687
688 my $designer_place_image_name = $designer_place_image_match_hashref->{"FileName"};
689 my $designer_place_image_small_file_name = $designer_place_image_name . "-small.jpg";
690 $designer_place_image_small_file_name =~ s/ /%20/g;
691 my $designer_place_image_small_file_link = "_httpcollection_/index/assoc/[assocfilepath]/$designer_place_image_small_file_name";
692 $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";
693 }
694 }
695
696 &new_metadata_entry($designer_doc_obj, "DesignerPlacesImageHTML", "<table>" . $designer_places_image_html . "</table>");
697
698 $designer_doc_obj->add_utf8_text($designer_doc_obj->get_top_section(), "Some dummy text.");
699 $self->{'processor'}->process($designer_doc_obj);
700 $self->{'num_processed'}++;
701 }
702
703 # Write the designers.dm macrofile
704 &write_static_browser_macrofile("designers", \%designer_name_to_id_mapping);
705}
706
707
708sub new_metadata_entry
709{
710 my ($doc_obj, $metadata_name, $metadata_value) = (@_);
711
712 # Don't bother with empty metadata
713 return if ($metadata_value eq "");
714
715 # Spaces aren't allowed in metadata names
716 $metadata_name =~ s/ /_/g;
717
718 # Anything from the database is ISO 8859-1 encoded, so convert to UTF-8
719 $metadata_value = &unicode::ascii2utf8(\$metadata_value);
720
721 # Remove '#' characters around links
722 if ($metadata_value =~ /\#(.*?)\#/) {
723 $metadata_value = $1;
724 }
725
726 $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), $metadata_name, $metadata_value);
727}
728
729
730sub rtf_to_html
731{
732 my $rtf_string = shift(@_);
733 $rtf_string =~ s/\{(.*?)\}//g;
734 $rtf_string =~ s/\\rquote /'/g; # ' # (for Emacs)
735 $rtf_string =~ s/\\pard//g;
736 $rtf_string =~ s/\\par/<br \/>/g;
737 $rtf_string =~ s/\\i0 /<\/i>/g;
738 $rtf_string =~ s/\\i /<i>/g;
739 $rtf_string =~ s/\\~/ /g;
740 $rtf_string =~ s/\\([A-Za-z0-9]+)//g;
741 $rtf_string =~ s/\}//g;
742
743 # Assume non-ASCII is ISO 8859-1, and convert into HTML entities
744 while ($rtf_string =~ /\\'([a-z0-9][a-z0-9])/) {
745 my $dec = hex($1);
746 $rtf_string =~ s/\\'$1/&#$dec\;/;
747 }
748
749 return $rtf_string;
750}
751
752
753sub new_place_image
754{
755 my $self = shift(@_);
756 my ($doc_obj, $place_image_location, $place_image_size) = (@_);
757 my $fail_log_handle = $self->{'failhandle'};
758
759 # Don't bother with empty values
760 return if ($place_image_location eq "");
761
762 # Convert the server location of the file into the local location of the file
763 my $place_image_file_path = $place_image_location;
764 $place_image_file_path =~ s/^[A-Z]:/$self->{'images_directory'}/;
765
766 # Create a new section for each image of the place
767 my $place_image_section = $doc_obj->insert_section($doc_obj->get_end_child($doc_obj->get_top_section()));
768 $doc_obj->add_utf8_text($place_image_section, "Some dummy text.");
769 $doc_obj->add_utf8_metadata($place_image_section, "Title", "1");
770
771 if (!-f $place_image_file_path) {
772 print STDERR "<ProcessingError n='$place_image_file_path' p='CICPlug' r='Does not exist'>\n" if ($self->{'gli'});
773 print STDERR "Error: Image $place_image_file_path does not exist.\n";
774 print $fail_log_handle "Error: Image $place_image_file_path does not exist.\n";
775 return;
776 }
777
778 my $place_image_file_name = $place_image_file_path;
779 $place_image_file_name =~ s/^.*?([^\\]+)$/$1/;
780 my ($image_file_root) = ($place_image_file_name =~ /^(.+)\./);
781
782 # Scale the original image to make the place image
783 my $image_width = $self->{$place_image_size . '_image_width'};
784 my $image_options = "-scale $image_width " . $self->{$place_image_size . '_image_options'};
785 my $image_file_name = $image_file_root . "-$place_image_size." . $self->{$place_image_size . '_image_type'};
786
787 my $original_image_file_path = $place_image_file_path;
788 my $image_type = $place_image_size;
789
790 my $original_image_file_date = (stat($original_image_file_path))[9];
791 my $image_file_path = &util::filename_cat($self->{'cache_directory'}, $image_file_name);
792 my $image_command = "convert -verbose $image_options \"$original_image_file_path\" \"$image_file_path\"";
793 my $image_height;
794
795 # Check if this image has already been generated by looking for a ".inf" file in the tmp directory
796 $image_file_name =~ /^(.*?)\.[^\.]+$/;
797 my $image_info_file_name = $1 . ".inf";
798 my $image_info_file_path = &util::filename_cat($self->{'cache_directory'}, $image_info_file_name);
799 if (-e $image_info_file_path) {
800 open(IMAGE_INFO_FILE, "<$image_info_file_path");
801 my @image_info = <IMAGE_INFO_FILE>;
802 close(IMAGE_INFO_FILE);
803
804 # Read the original image file date and image command from the file and check they match
805 my $old_original_image_file_date = $image_info[0];
806 $old_original_image_file_date =~ s/\n$//;
807 my $old_image_command = $image_info[1];
808 $old_image_command =~ s/\n$//;
809 if ($old_original_image_file_date eq $original_image_file_date && lc($old_image_command) eq lc($image_command)) {
810 # print STDERR "Already generated $image_file_name...\n";
811 $image_width = $image_info[2];
812 $image_width =~ s/\n$//;
813 $image_height = $image_info[3];
814 $image_height =~ s/\n$//;
815 }
816 }
817
818 # Generate the image if it doesn't already exist
819 if (!defined($image_width) || !defined($image_height)) {
820 print STDERR "Generating place image file: $image_file_name...\n";
821 my $outhandle = $self->{'outhandle'};
822 print $outhandle "$image_command\n" if ($self->{'verbosity'} > 2);
823 my $image_result = `$image_command` || "";
824 print $outhandle "RESULT = $image_result\n" if ($self->{'verbosity'} > 2);
825
826 # Check that the converted image exists
827 if (!-f $image_file_path) {
828 print STDERR "<ProcessingError n='$image_file_path' p='CICPlug' r='Could not be created'>\n" if ($self->{'gli'});
829 print STDERR "Error: Image $image_file_path could not be created.\n";
830 print $fail_log_handle "Error: Image $image_file_path could not be created.\n";
831 return;
832 }
833
834 # Get image dimensions
835 if ($image_command !~ /\-scale / && $image_result =~ m/([0-9]+)x([0-9]+)/) {
836 $image_width = $1;
837 $image_height = $2;
838 }
839 elsif ($image_result =~ m/[0-9]+x[0-9]+=>([0-9]+)x([0-9]+)/) {
840 $image_width = $1;
841 $image_height = $2;
842 }
843 elsif ($image_result =~ m/Image Width: (\d+) Image Length: (\d+)/) {
844 $image_width = $1;
845 $image_height = $2;
846 }
847 elsif ($image_result =~ m/JPEG (\d+)x(\d+)/) {
848 $image_width = $1;
849 $image_height = $2;
850 }
851 else {
852 print STDERR "Error: Could not parse image width and height for $original_image_file_path\n";
853 return;
854 }
855 }
856
857 # Associate the image file
858 $doc_obj->associate_file($image_file_path, $image_file_name, undef, $self->{'section'});
859
860 # Add various bits of metadata for the image
861 my $image_metadata_value = $image_file_name;
862 $image_metadata_value =~ s/ /%20/g;
863 $doc_obj->add_utf8_metadata($self->{'section'}, $image_type . "Image", $image_metadata_value);
864 $doc_obj->add_metadata($self->{'section'}, $image_type . "ImageWidth", $image_width);
865 $doc_obj->add_metadata($self->{'section'}, $image_type . "ImageHeight", $image_height);
866 $doc_obj->add_metadata($self->{'section'}, $image_type . "ImagePath", "_httpcollection_/index/assoc/[parent(Top):assocfilepath]/[${image_type}Image]");
867
868 # Write the image info file so we don't have to regenerate this exact image again in the future
869 open(IMAGE_INFO_FILE, ">$image_info_file_path");
870 print IMAGE_INFO_FILE "$original_image_file_date\n";
871 print IMAGE_INFO_FILE "$image_command\n";
872 print IMAGE_INFO_FILE "$image_width\n";
873 print IMAGE_INFO_FILE "$image_height\n";
874 close(IMAGE_INFO_FILE);
875}
876
877
878sub write_static_browser_macrofile
879{
880 my $static_browser_package_name = shift(@_);
881 my $name_to_id_mapping = shift(@_);
882
883 my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_name.dm";
884 print STDERR "Writing $static_browser_macrofile_path...\n";
885 open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
886 &write_static_browser_macros($static_browser_package_name, $name_to_id_mapping);
887 close(BROWSER_MACROFILE);
888}
889
890
891sub write_static_browser_macros
892{
893 my $static_browser_package_name = shift(@_);
894 my $name_to_id_mapping = shift(@_);
895 my $id_to_extra_mapping = shift(@_);
896
897 print BROWSER_MACROFILE "package $static_browser_package_name\n\n";
898 print BROWSER_MACROFILE "_cicstaticbrowser_ {\n";
899
900 my %letter_to_names_mapping;
901 foreach my $name (keys %$name_to_id_mapping) {
902 my ($letter) = ($name =~ /([A-Za-z0-9])/);
903 push(@{$letter_to_names_mapping{$letter}}, $name);
904 }
905
906 print BROWSER_MACROFILE "<center><b>";
907 foreach my $letter (split(//, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
908 if (defined($letter_to_names_mapping{$letter})) {
909 print BROWSER_MACROFILE "<a href=\"#$letter\">$letter</a>&nbsp;";
910 }
911 else {
912 print BROWSER_MACROFILE "$letter&nbsp;";
913 }
914 }
915 print BROWSER_MACROFILE "</b></center>\n";
916
917 print BROWSER_MACROFILE "<table cellpadding=\"0\" cellspacing=\"0\" width=\"_pagewidth_\">\n";
918 foreach my $letter (sort(keys %letter_to_names_mapping)) {
919 my @letter_names = sort(@{$letter_to_names_mapping{$letter}});
920 &write_static_browser_macros_chunk($letter, \@letter_names, $name_to_id_mapping, $id_to_extra_mapping);
921 }
922 print BROWSER_MACROFILE "</table>\n";
923
924 print BROWSER_MACROFILE "}\n";
925}
926
927
928sub write_static_browser_macros_chunk
929{
930 my $chunk_title = shift(@_);
931 my $chunk_names_ref = shift(@_);
932 my $name_to_id_mapping = shift(@_);
933 my $id_to_extra_mapping = shift(@_);
934
935 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";
936
937 my @chunk_names = @{$chunk_names_ref};
938 my $half_point = ((scalar(@chunk_names) % 2 == 0) ? scalar(@chunk_names) / 2 : (scalar(@chunk_names) + 1) / 2);
939 for (my $i = 0; $i < $half_point; $i++) {
940 print BROWSER_MACROFILE "<tr>";
941
942 my $name = $chunk_names[$i];
943 my $id = $name_to_id_mapping->{$name};
944 my $extra = "";
945 if (defined($id_to_extra_mapping)) {
946 $extra = $id_to_extra_mapping->{$id};
947 }
948 print BROWSER_MACROFILE "<td valign=\"top\"><a href=\"_gwcgi_?a=d&d=$id\">$name</a>$extra</td>";
949
950 $name = $chunk_names[$i+$half_point];
951 if (defined($name)) {
952 $id = $name_to_id_mapping->{$name};
953 $extra = "";
954 if (defined($id_to_extra_mapping)) {
955 $extra = $id_to_extra_mapping->{$id};
956 }
957 print BROWSER_MACROFILE "<td valign=\"top\"><a href=\"_gwcgi_?a=d&d=$id\">$name</a>$extra</td>";
958 }
959 else {
960 print BROWSER_MACROFILE "<td></td>";
961 }
962
963 print BROWSER_MACROFILE "</tr>\n";
964 }
965}
966
967
968sub write_bilevel_static_browser_macrofile
969{
970 my $static_browser_package_root = shift(@_);
971 my $category_to_names_mapping = shift(@_);
972 my $name_to_id_mapping = shift(@_);
973 my $id_to_extra_mapping = shift(@_);
974
975 my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_root.dm";
976 print STDERR "Writing $static_browser_macrofile_path...\n";
977 open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
978
979 foreach my $category (keys(%{$category_to_names_mapping})) {
980 my $static_browser_package_name = $static_browser_package_root . $category;
981 $static_browser_package_name =~ s/\W//g;
982
983 my %name_to_id_mapping_for_category = ();
984 foreach my $name (sort(@{$category_to_names_mapping->{$category}})) {
985 $name_to_id_mapping_for_category{$name} = $name_to_id_mapping->{$name};
986 }
987 &write_static_browser_macros($static_browser_package_name, \%name_to_id_mapping_for_category, $id_to_extra_mapping);
988 }
989
990 close(BROWSER_MACROFILE);
991}
992
993
994sub write_state_browser_macrofile
995{
996 my $static_browser_package_name = shift(@_);
997 my $state_to_names_mapping = shift(@_);
998 my $name_to_id_mapping = shift(@_);
999
1000 my $static_browser_macrofile_path = "$ENV{'GSDLHOME'}\\collect\\cic-hcap\\macros\\$static_browser_package_name.dm";
1001 print STDERR "Writing $static_browser_macrofile_path...\n";
1002 open(BROWSER_MACROFILE, ">$static_browser_macrofile_path") or die "Error: Could not write to $static_browser_macrofile_path.\n";
1003 print BROWSER_MACROFILE "package $static_browser_package_name\n\n";
1004 print BROWSER_MACROFILE "_cicstaticbrowser_ {\n";
1005
1006 print BROWSER_MACROFILE "<table cellpadding=\"0\" cellspacing=\"0\" width=\"_pagewidth_\">\n";
1007 foreach my $state (sort(keys(%{$state_to_names_mapping}))) {
1008 my @state_names = sort(@{$state_to_names_mapping->{$state}});
1009 &write_static_browser_macros_chunk($state, \@state_names, $name_to_id_mapping, undef);
1010 }
1011 print BROWSER_MACROFILE "</table>\n";
1012
1013 print BROWSER_MACROFILE "}\n";
1014 close(BROWSER_MACROFILE);
1015}
1016
1017
10181;
Note: See TracBrowser for help on using the repository browser.