[21205] | 1 | #!/usr/bin/perl -w
|
---|
[20983] | 2 |
|
---|
[21205] | 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 | ###########################################################################
|
---|
[20983] | 27 |
|
---|
[21205] | 28 | BEGIN {
|
---|
| 29 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
| 30 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
| 31 | die "IMAGEISHOME not set\n" unless defined $ENV{'IMAGEISHOME'};
|
---|
| 32 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
| 33 | }
|
---|
[20983] | 34 |
|
---|
| 35 |
|
---|
[21205] | 36 | use strict;
|
---|
| 37 | no strict 'refs'; # allow filehandles to be variables and vice versa
|
---|
| 38 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
[20983] | 39 |
|
---|
[21209] | 40 | use util;
|
---|
[20983] | 41 |
|
---|
[21205] | 42 | sub 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 | }
|
---|
[20983] | 53 |
|
---|
[21205] | 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 |
|
---|
| 63 | print "Generating query_id.xml\n";
|
---|
| 64 |
|
---|
| 65 | my $query_template_filename
|
---|
| 66 | = &util::filename_cat($ENV{'IMAGEISHOME'},"templates","query_id.xml");
|
---|
| 67 | my $query_this_filename = &util::filename_cat($tmp_dir,"query_id.xml");
|
---|
| 68 |
|
---|
| 69 | if (open(FIN,"<$query_template_filename")) {
|
---|
| 70 |
|
---|
| 71 | my $query_this_file_content = "";
|
---|
| 72 |
|
---|
| 73 | my $line;
|
---|
| 74 | while (defined ($line=<FIN>)) {
|
---|
| 75 | $line =~ s@\*\*docid\*\*@$docid@g;
|
---|
| 76 |
|
---|
| 77 | $query_this_file_content .= $line;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | close(FIN);
|
---|
| 81 |
|
---|
| 82 | if (open(FOUT,">$query_this_filename")) {
|
---|
| 83 | print FOUT $query_this_file_content;
|
---|
| 84 | close(FOUT);
|
---|
| 85 | }
|
---|
| 86 | else {
|
---|
| 87 | print STDERR "Error: failed to write out $query_this_filename\n";
|
---|
| 88 | print STDERR "$!\n";
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | else {
|
---|
| 92 | print STDERR "Error: failed to read $query_template_filename\n";
|
---|
| 93 | print STDERR "$!\n";
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | my $jar_filename = &util::filename_cat($ENV{'IMAGEISHOME'},"ImageIS.jar");
|
---|
| 98 | my $java_cmd = "java -jar \"$jar_filename\" \"$query_this_filename\"";
|
---|
[20983] | 99 |
|
---|
| 100 |
|
---|
[21205] | 101 | print "Querying $docid\n";
|
---|
| 102 |
|
---|
| 103 | chdir($tmp_dir);
|
---|
| 104 | my $status = system($java_cmd);
|
---|
| 105 |
|
---|
| 106 | if ($status == 0 ) {
|
---|
| 107 | &util::rm($query_this_filename);
|
---|
| 108 | }
|
---|
| 109 | else {
|
---|
| 110 | print STDERR "Error: Failed to run:\n";
|
---|
| 111 | print STDERR "$!\n";
|
---|
| 112 | exit 1;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | my $result_filename = &util::filename_cat($tmp_dir,"image_cbs_result.xml");
|
---|
| 116 |
|
---|
| 117 | if ( ! -f $result_filename ) {
|
---|
| 118 | print STDERR "\n";
|
---|
| 119 | print STDERR "Error: Failed to generate $result_filename.xml\n";
|
---|
| 120 | print STDERR " Check Tomcat's catalina.out for server-side error messages\n";
|
---|
| 121 | print STDERR "\n";
|
---|
| 122 | exit 1;
|
---|
| 123 | }
|
---|
| 124 | elsif ( -s $result_filename == 0) {
|
---|
| 125 | print STDERR "\n";
|
---|
| 126 | print STDERR "Warning: Server returned zero sized file image_cbs_result.xml\n";
|
---|
| 127 | print STDERR " Check that the doc-id used is valid\n";
|
---|
| 128 | print STDERR "\n";
|
---|
| 129 | &util::rm($result_filename);
|
---|
| 130 | }
|
---|
| 131 | else {
|
---|
| 132 |
|
---|
| 133 | if (open(FIN,"<$result_filename")) {
|
---|
| 134 |
|
---|
| 135 | my $line;
|
---|
| 136 | while (defined ($line=<FIN>)) {
|
---|
| 137 | print $line;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | close(FIN);
|
---|
| 141 | }
|
---|
| 142 | else {
|
---|
| 143 | print STDERR "Error: failed to read $result_filename\n";
|
---|
| 144 | print STDERR "$!\n";
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | print "\n";
|
---|
| 148 | &util::rm($result_filename);
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 |
|
---|
| 153 | main();
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 |
|
---|
| 157 |
|
---|