root/gs3-extensions/html-to-expeditee/trunk/src/perllib/cgiactions/HtmlToExpediteeAction.pm @ 24927

Revision 24927, 2.8 KB (checked in by davidb, 8 years ago)

More careful handling of JSON strings to work correctly with UTF8

Line 
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
26package HtmlToExpediteeAction;
27
28use strict;
29
30use cgiactions::baseaction;
31
32use JSON;
33
34
35BEGIN {
36#    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/perl-5.8");
37}
38
39
40@HtmlToExpediteeAction::ISA = ('baseaction');
41
42
43
44# c=collect and site=xxxx implicitly handled by code
45# 'c' is handled by baseaction, site is tested for only if greenstone3
46
47
48my $action_table =
49{
50    "generate-frame"     => { 'compulsory-args' => [ "fn", "json" ],
51                  'optional-args'   => [] },
52};
53
54
55sub new
56{
57    my $class = shift (@_);
58    my ($gsdl_cgi,$iis6_mode) = @_;
59
60    my $self = new baseaction($action_table,$gsdl_cgi,$iis6_mode);
61
62    return bless $self, $class;
63}
64
65
66sub generate_frame
67{
68    my $self = shift @_;
69
70    my $username  = $self->{'username'};
71    my $collect   = $self->{'collect'};
72    my $gsdl_cgi  = $self->{'gsdl_cgi'};
73    my $gsdlhome  = $self->{'gsdlhome'};
74
75    my $site = $self->{'site'};
76    my $collect_dir = $gsdl_cgi->get_collection_dir($site);
77
78    my $fn = $self->{'fn'};
79
80    # no need to lock collection (??), the operation is read only
81
82    my $json_str_unicode = $self->{'json'};
83    my $json_str_utf8 = Encode::encode("utf8",$json_str_unicode);
84    my $exp_frame_tree = decode_json $json_str_utf8;
85   
86
87    my $output_dir = &util::filename_cat($collect_dir,$collect,"export");
88
89    if (!-d $output_dir) {
90    &util::mk_dir($output_dir);
91    }
92    my $frame_filename = &util::filename_cat($output_dir,"$fn.exp");
93
94    if (open(FOUT,">$frame_filename")) {
95    binmode(FOUT,":utf8");
96
97    print FOUT $json_str_utf8;
98    close(FOUT);
99   
100    # write out next free frame num
101   
102    $gsdl_cgi->generate_message("html-to-expeditee saved frame $fn");
103    }
104    else {
105    $gsdl_cgi->generate_error("Failed to open $frame_filename for output");
106    }
107
108
109}
110
111
1121;
Note: See TracBrowser for help on using the browser.