[24924] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # HtmlToExpediteeAction.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) 2009 New Zealand Digital Library Project
|
---|
| 9 | #
|
---|
| 10 | # This program is free software; you can redistr te 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 |
|
---|
| 26 | package HtmlToExpediteeAction;
|
---|
| 27 |
|
---|
| 28 | use strict;
|
---|
| 29 |
|
---|
| 30 | use cgiactions::baseaction;
|
---|
| 31 |
|
---|
[24934] | 32 | use ExpediteeFrameIO;
|
---|
[24924] | 33 | use JSON;
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | BEGIN {
|
---|
| 37 | # unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/perl-5.8");
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | @HtmlToExpediteeAction::ISA = ('baseaction');
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | # c=collect and site=xxxx implicitly handled by code
|
---|
| 46 | # 'c' is handled by baseaction, site is tested for only if greenstone3
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | my $action_table =
|
---|
| 50 | {
|
---|
[24927] | 51 | "generate-frame" => { 'compulsory-args' => [ "fn", "json" ],
|
---|
[26731] | 52 | 'optional-args' => ["assoc", "compute-font"] },
|
---|
[24924] | 53 | };
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | sub new
|
---|
| 57 | {
|
---|
| 58 | my $class = shift (@_);
|
---|
| 59 | my ($gsdl_cgi,$iis6_mode) = @_;
|
---|
| 60 |
|
---|
| 61 | my $self = new baseaction($action_table,$gsdl_cgi,$iis6_mode);
|
---|
| 62 |
|
---|
| 63 | return bless $self, $class;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[26752] | 66 | ##
|
---|
| 67 | # Subroutine for writing a collection.inf file -
|
---|
| 68 | # this is just so that when we load GlamED, it will
|
---|
| 69 | # only try to process framesets containing this file.
|
---|
| 70 | ##
|
---|
| 71 | sub write_collection_info
|
---|
| 72 | {
|
---|
| 73 | my ($output_dir,$collect) = @_;
|
---|
| 74 |
|
---|
| 75 | my $filename = &util::filename_cat($output_dir,"collection.inf");
|
---|
| 76 | my $status = undef;
|
---|
| 77 |
|
---|
| 78 | if(open(FNOUT,">$filename")){
|
---|
| 79 | binmode(FNOUT,":utf8");
|
---|
| 80 |
|
---|
| 81 | print FNOUT "$collect";
|
---|
| 82 | close(FNOUT);
|
---|
| 83 | $status =1;
|
---|
| 84 | }else{
|
---|
| 85 | print STDERR "Failed to open $filename for outputting collection info\n";
|
---|
| 86 |
|
---|
| 87 | $status = 0;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | return $status;
|
---|
| 91 | }
|
---|
[24924] | 92 |
|
---|
| 93 | sub generate_frame
|
---|
| 94 | {
|
---|
| 95 | my $self = shift @_;
|
---|
| 96 |
|
---|
| 97 | my $username = $self->{'username'};
|
---|
| 98 | my $collect = $self->{'collect'};
|
---|
| 99 | my $gsdl_cgi = $self->{'gsdl_cgi'};
|
---|
| 100 | my $gsdlhome = $self->{'gsdlhome'};
|
---|
| 101 |
|
---|
| 102 | my $site = $self->{'site'};
|
---|
| 103 | my $collect_dir = $gsdl_cgi->get_collection_dir($site);
|
---|
| 104 |
|
---|
| 105 | my $fn = $self->{'fn'};
|
---|
[26596] | 106 |
|
---|
| 107 | my $assoc = $self->{'assoc'};
|
---|
[26731] | 108 |
|
---|
| 109 | my $compute_font = $self->{'compute-font'};
|
---|
| 110 | print STDERR "Wil send compute_font... $compute_font\n\n";
|
---|
| 111 |
|
---|
[24924] | 112 | # no need to lock collection (??), the operation is read only
|
---|
| 113 |
|
---|
[24927] | 114 | my $json_str_unicode = $self->{'json'};
|
---|
| 115 | my $json_str_utf8 = Encode::encode("utf8",$json_str_unicode);
|
---|
| 116 | my $exp_frame_tree = decode_json $json_str_utf8;
|
---|
[26760] | 117 |
|
---|
| 118 | #if (!-d $output_dir) {
|
---|
| 119 | #&util::mk_dir($output_dir);
|
---|
| 120 | #}
|
---|
[24924] | 121 |
|
---|
[26760] | 122 | #Check for export directory. If it doesn't exist, create it.
|
---|
| 123 | my $export_dir = &util::filename_cat($collect_dir,$collect,"export");
|
---|
| 124 |
|
---|
| 125 | if(!-d $export_dir){
|
---|
| 126 | &util::mk_dir($export_dir);
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | #create output subdirectory within export directory.
|
---|
[26752] | 130 | my $output_dir = &util::filename_cat($collect_dir,$collect,"export",$collect);
|
---|
[26760] | 131 |
|
---|
| 132 | if(!-d $output_dir){
|
---|
| 133 | &util::mk_dir($output_dir);
|
---|
| 134 | }
|
---|
[24924] | 135 |
|
---|
[24938] | 136 | my $expeditee_frame_io = new ExpediteeFrameIO($output_dir);
|
---|
[24934] | 137 |
|
---|
[26731] | 138 | $expeditee_frame_io->buildFrame($exp_frame_tree,$compute_font);
|
---|
[24927] | 139 |
|
---|
[26596] | 140 | if ($expeditee_frame_io->saveFrame("$fn.exp",$assoc)) {
|
---|
[24924] | 141 |
|
---|
| 142 | # write out next free frame num
|
---|
[26597] | 143 | $expeditee_frame_io->saveLastFrameNumber($fn,$collect);
|
---|
[26752] | 144 |
|
---|
| 145 | # TODO: Have a parameter so that this file is only written out if requested.
|
---|
| 146 | write_collection_info($output_dir,$collect);
|
---|
| 147 |
|
---|
[24924] | 148 | $gsdl_cgi->generate_message("html-to-expeditee saved frame $fn");
|
---|
| 149 | }
|
---|
| 150 | else {
|
---|
[24938] | 151 | $gsdl_cgi->generate_error("Failed to save frame number $fn");
|
---|
[24924] | 152 | }
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 | 1;
|
---|