source: gs2-extensions/parallel-building/trunk/src/perllib/plugouts/GreenstoneXMLPlugout.pm@ 26986

Last change on this file since 26986 was 26986, checked in by jmt12, 11 years ago

Commenting out some debug comments

File size: 5.0 KB
Line 
1###########################################################################
2#
3# GreenstoneXMLPlugout.pm -- the plugout module for Greenstone Archives
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) 2006 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 GreenstoneXMLPlugout;
27
28use strict;
29no strict 'refs';
30no strict 'subs';
31
32eval {require bytes};
33use util;
34use BasePlugout;
35use docprint;
36
37sub BEGIN {
38 @GreenstoneXMLPlugout::ISA = ('BasePlugout');
39}
40
41my $arguments = [];
42
43my $options = { 'name' => "GreenstoneXMLPlugout",
44 'desc' => "{GreenstoneXMLPlugout.desc}",
45 'abstract' => "no",
46 'inherits' => "yes" };
47
48sub new {
49 my ($class) = shift (@_);
50 my ($plugoutlist, $inputargs,$hashArgOptLists) = @_;
51 push(@$plugoutlist, $class);
52
53 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
54 push(@{$hashArgOptLists->{"OptList"}},$options);
55
56 my $self = new BasePlugout($plugoutlist,$inputargs,$hashArgOptLists);
57
58 return bless $self, $class;
59}
60
61sub saveas
62{
63 my $self = shift (@_);
64 my ($doc_obj,$doc_dir) = @_;
65
66 my $outhandler;
67 if ($self->{'debug'})
68 {
69 $outhandler = STDOUT;
70 # can we do the xslt and still do debug mode?
71 }
72 else
73 {
74 my $output_dir = $self->get_output_dir();
75 my $working_dir = &util::filename_cat($output_dir, $doc_dir);
76 if (!&util::dir_exists($working_dir))
77 {
78 &util::mk_all_dir($working_dir);
79 }
80 $self->process_assoc_files ($doc_obj, $doc_dir, '');
81 $self->process_metafiles_metadata ($doc_obj);
82 my $output_file = &util::filename_cat($working_dir, "doc.xml");
83 $self->open_xslt_pipe($output_file, $self->{'xslt_file'});
84 if (defined $self->{'xslt_writer'})
85 {
86 $outhandler = $self->{'xslt_writer'};
87 }
88 else
89 {
90 $outhandler = $self->get_output_handler($output_file);
91 }
92 }
93
94 binmode($outhandler,":utf8");
95
96 $self->output_xml_header($outhandler,"Archive");
97 my $section_output = &docprint::get_section_xml($doc_obj, $doc_obj->get_top_section());
98 print $outhandler $section_output;
99 $self->output_xml_footer($outhandler,"Archive");
100
101 if (!$self->{'debug'})
102 {
103 if (defined $self->{'xslt_writer'})
104 {
105 $self->close_xslt_pipe();
106 }
107 else
108 {
109 close($outhandler);
110 }
111
112 $self->{'short_doc_file'} = util::filename_cat($doc_dir, "doc.xml");
113
114 $self->store_output_info_reference($doc_obj);
115 }
116}
117# /** saveas() **/
118
119# Overriden for HDFS support
120sub get_output_handler
121{
122 my $self = shift (@_);
123 my ($output_file_name) = @_;
124 if (&util::isHDFS($output_file_name))
125 {
126 open(*OUTPUT, &util::file_openfdcommand($output_file_name, '>'));
127 return *OUTPUT;
128 }
129 else
130 {
131 return $self->SUPER::get_output_handler($output_file_name);
132 }
133}
134
135sub get_new_doc_dir
136{
137 my $self = shift (@_);
138 my ($working_info, $working_dir, $OID) = @_;
139 my $doc_dir = "";
140 my $doc_dir_rest = $OID;
141
142 ###rint "!!GreenstoneXMLPlugout::get_new_doc_dir([working_info]," . $working_dir . "," . $OID . ")\n";
143
144 # Remove any \ and / from the OID because we are about to generate a path
145 # Remove ":" too, as otherwise they get confused with the protocols / drive letters
146 $doc_dir_rest =~ s/[\:\\\/]//g;
147 my $doc_dir_num = 0;
148 my $created_directory = 0;
149 do
150 {
151 if ($doc_dir_num > 0)
152 {
153 $doc_dir .= "/";
154 }
155# if ($doc_dir_rest =~ s/^(.{1,3})//)
156 if ($doc_dir_rest =~ s/^((D|HASH)?.{1,3})//i)
157 {
158 $doc_dir .= $1;
159 $doc_dir_num++;
160 }
161 ###rint "!! - testing Path: " . $doc_dir . "\n";
162 $created_directory = &util::mk_all_dir(&util::filename_cat($working_dir, $doc_dir . '.dir'));
163 ###rint "-> result: |" . $created_directory . "|\n";
164 }
165 while ($doc_dir_rest ne "" && $doc_dir_num < 32 && !$created_directory);
166 my $i = 0;
167 my $doc_dir_base = $doc_dir;
168 while (!$created_directory && $i < 256)
169 {
170 $i++;
171 $doc_dir = $doc_dir_base . '-' . $i;
172 ###rint "!! - testing Path: " . $doc_dir . "\n";
173 $created_directory = &util::mk_all_dir(&util::filename_cat($working_dir, $doc_dir . '.dir'));
174 ###rint "-> result: |" . $created_directory . "|\n";
175 }
176 if (!$created_directory)
177 {
178 die("Error! Failed to create directory for document: " . $doc_dir_base . "\n");
179 }
180 ###rint "!! Final Path: " . $doc_dir . ".dir\n";
181 return $doc_dir . '.dir';
182}
183
1841;
185
Note: See TracBrowser for help on using the repository browser.