source: gs3-extensions/pharos-imageis/trunk/bin/script/pharos-imageis-query.pl@ 21339

Last change on this file since 21339 was 21339, checked in by kjdon, 14 years ago

make the tmp directory if it doesn't exist

File size: 4.3 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# pharos-imageis-query.pl --
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# Copyright (C) 1999 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28BEGIN {
29 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
30 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
31 die "PHAROSIS_SRC_HOME not set\n" unless defined $ENV{'PHAROSIS_SRC_HOME'};
32 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
33}
34
35
36use strict;
37no strict 'refs'; # allow filehandles to be variables and vice versa
38no strict 'subs'; # allow barewords (eg STDERR) as function arguments
39
40use util;
41
42sub main
43{
44
45 my $ARGC = scalar(@ARGV);
46
47
48 if ($ARGC != 2) {
49 my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
50 print STDERR "Usage: $progname collection doc-id\n";
51 exit 1;
52 }
53
54 my ($col,$id) = @ARGV;
55
56 my $docid = $id;
57 if ( $col ne "" ) {
58 $docid="$col:$docid";
59 }
60
61 my $tmp_dir = &util::get_toplevel_tmp_dir();
62 $tmp_dir = &util::filename_cat($tmp_dir,"pharos-imageis");
63 if (! -d $tmp_dir) {
64 &util::mk_all_dir($tmp_dir);
65 }
66
67 print "Generating query_id.xml\n";
68
69 my $query_template_filename
70 = &util::filename_cat($ENV{'PHAROSIS_SRC_HOME'},"resources","templates","query_id.xml");
71 my $query_this_filename = &util::filename_cat($tmp_dir,"query_id.xml");
72
73 if (open(FIN,"<$query_template_filename")) {
74
75 my $query_this_file_content = "";
76
77 my $line;
78 while (defined ($line=<FIN>)) {
79 $line =~ s@\*\*docid\*\*@$docid@g;
80
81 $query_this_file_content .= $line;
82 }
83
84 close(FIN);
85
86 if (open(FOUT,">$query_this_filename")) {
87 print FOUT $query_this_file_content;
88 close(FOUT);
89 }
90 else {
91 print STDERR "Error: failed to write out $query_this_filename\n";
92 print STDERR "$!\n";
93 }
94 }
95 else {
96 print STDERR "Error: failed to read $query_template_filename\n";
97 print STDERR "$!\n";
98 }
99
100
101 my $jar_filename = &util::filename_cat($ENV{'PHAROSIS_SRC_HOME'},"pharos-imageis.jar");
102
103 my $prop_dir = &util::filename_cat($ENV{'PHAROSIS_SRC_HOME'},"classes");
104
105 &util::envvar_append("CLASSPATH",$prop_dir);
106 &util::envvar_append("CLASSPATH",$jar_filename);
107
108 my $java_cmd = "java imageis.ImageIS \"$query_this_filename\"";
109
110 # print STDERR "java_cmd = $java_cmd\n";
111
112 print "Querying $docid\n";
113
114 chdir($tmp_dir);
115 my $status = system($java_cmd);
116
117 if ($status == 0 ) {
118 #&util::rm($query_this_filename);
119 }
120 else {
121 print STDERR "Error: Failed to run:\n";
122 print STDERR "$!\n";
123 exit 1;
124 }
125
126 my $result_filename = &util::filename_cat($tmp_dir,"image_cbs_result.xml");
127
128 if ( ! -f $result_filename ) {
129 print STDERR "\n";
130 print STDERR "Error: Failed to generate $result_filename.xml\n";
131 print STDERR " Check Tomcat's catalina.out for server-side error messages\n";
132 print STDERR "\n";
133 exit 1;
134 }
135 elsif ( -s $result_filename == 0) {
136 print STDERR "\n";
137 print STDERR "Warning: Server returned zero sized file image_cbs_result.xml\n";
138 print STDERR " Check that the doc-id used is valid\n";
139 print STDERR "\n";
140 &util::rm($result_filename);
141 }
142 else {
143
144 if (open(FIN,"<$result_filename")) {
145
146 my $line;
147 while (defined ($line=<FIN>)) {
148 print $line;
149 }
150
151 close(FIN);
152 }
153 else {
154 print STDERR "Error: failed to read $result_filename\n";
155 print STDERR "$!\n";
156 }
157
158 print "\n";
159 &util::rm($result_filename);
160 }
161}
162
163
164main();
165
166
167
168
Note: See TracBrowser for help on using the repository browser.