source: gs3-extensions/html-to-expeditee/trunk/src/perllib/ExpediteeExportAction.pm@ 26632

Last change on this file since 26632 was 26632, checked in by davidb, 11 years ago

Adding in scripts for running Export individual GSDL documents to GlamED feature.

File size: 3.5 KB
Line 
1###########################################################################
2#
3# ExpediteeExportAction.pm --
4# Based on HTMLToExpediteeAction.pm - Used for exporting INDIVIDUAL
5# Greenstone documents to Expeditee. If you want to export an entire
6# collection, use HTMLToExpediteeAction.pm.
7#
8# A component of the Greenstone digital library software
9# from the New Zealand Digital Library Project at the
10# University of Waikato, New Zealand.
11#
12# Copyright (C) 2009 New Zealand Digital Library Project
13#
14# This program is free software; you can redistribute it and/or modify
15# it under the terms of the GNU General Public License as published by
16# the Free Software Foundation; either version 2 of the License, or
17# (at your option) any later version.
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22# GNU General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program; if not, write to the Free Software
26# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27#
28###########################################################################
29
30package ExpediteeExportAction;
31
32use strict;
33
34use cgiactions::baseaction;
35
36use ExpediteeFrameIO;
37use JSON;
38
39use Devel::Peek;
40
41BEGIN {
42# unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan/perl-5.8");
43}
44
45@ExpediteeExportAction::ISA = ('baseaction');
46
47# c=collect and site=xxxx implicitly handled by code
48# 'c' is handled by base action, site is tested for only if greenstone3.
49
50my $action_table=
51{
52 "generate-frame" => { 'compulsory-args' => [ "fn", "json" ],
53 'optional-args' => [] },
54};
55
56sub 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
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 my $json_str_unicode = $self->{'json'};
81
82 my $found = $self->{'found'};
83
84 if (!Encode::is_utf8( $json_str_unicode )) {
85 $json_str_unicode = Encode::decode_utf8( $json_str_unicode );
86 }
87
88 # decode_json expects string to convert to be raw utf8
89 my $json_str_utf8 = Encode::encode("utf8",$json_str_unicode);
90 my $exp_frame_tree = decode_json $json_str_utf8;
91
92 my $output_dir = &util::filename_cat($collect_dir,$collect,"export");
93
94 if (!-d $output_dir) {
95 &util::mk_dir($output_dir);
96 }
97
98 my $expeditee_frame_io = new ExpediteeFrameIO($output_dir,"kgas1A");
99
100 $expeditee_frame_io->buildFrame($exp_frame_tree);
101
102 if($expeditee_frame_io->saveFrame("$fn.exp")){
103 #need to determine if $fn is followed by another number or $fn is the last number in the frameset.
104
105 #if $fn is last number, write out next free frame num
106 unless($found){
107 #write out next free frame num
108 $expeditee_frame_io->saveLastFrameNumber($fn);
109 }
110
111 #otherwise just carry on.
112
113 $gsdl_cgi->generate_message("Item Exported to Expeditee $fn");
114 }else{
115 $gsdl_cgi->generate_error("Failed to save frame number $fn");
116 }
117
118
119}
120
1211;
Note: See TracBrowser for help on using the repository browser.