Index: 2-extensions/pdf-box/setup.bash
===================================================================
--- /gs2-extensions/pdf-box/setup.bash	(revision 22671)
+++ 	(revision )
@@ -1,35 +1,0 @@
-
-extdesc="the PDFBox Extension"
-
-full_setup=`pwd`/${BASH_SOURCE}
-fulldir=${full_setup%/*}
-fulldir=${fulldir%/.}
-
-if [ "x$GEXT_PDFBOX" = "x" ] ; then
-  export GEXT_PDFBOX=`pwd`
-
-  if [ -d "$GEXT_PDFBOX/bin/script" ] ; then
-    export PATH=$GEXT_PDFBOX/bin/script:$PATH
-  fi
-
-  if [ -d "$GEXT_PDFBOX/lib" ] ; then
-    if [ "$GSDLOS" = "linux" ] ; then
-      export LD_LIBRARY_PATH=$GEXT_PDFBOX/lib:$LD_LIBRARY_PATH
-    elif [ "$GSDLOS" = "darwin" ] ; then
-      export DYLD_LIBRARY_PATH=$GEXT_PDFBOX/lib:$DYLD_LIBRARY_PATH
-    fi
-  fi
-
-  extdir=${GEXT_PDFBOX##*/}
-
-  if [ "x$GSDLEXTS" = "x" ] ; then
-    export GSDLEXTS=$extdir
-  else 
-    export GSDLEXTS=$GSDLEXTS:$extdir
-  fi
-
-
-  echo "+Your environment is now setup for $extdesc"
-else
-  echo "+Your environment is already setup for $extdesc"
-fi
Index: 2-extensions/pdf-box/setup.bat
===================================================================
--- /gs2-extensions/pdf-box/setup.bat	(revision 22671)
+++ 	(revision )
@@ -1,60 +1,0 @@
-@echo off
-pushd "%CD%"
-CD /D "%~dp0"
-
-set extdesc=the PDFBox Extension
-
-if "%OS%" == "Windows_NT" goto WinNT
-if "%OS%" == "" goto Win95
-if "%GSDLLANG%" == "en" echo Setup failed - your PATH has not been set
-if "%GSDLLANG%" == "es" echo No se pudo realizar la configuraci¢n - no se ha establecido la RUTA.
-if "%GSDLLANG%" == "fr" echo Echc de l'installation - votre variable PATH n'a pas t ajuste
-if "%GSDLLANG%" == "ru" echo áâ ­®¢ª  ­¥ ã€ « áì -  ­¥ ¡ë« ãáâ ­®¢«¥­
-goto End
-
-:WinNT
-set GEXT_PDFBOX=%CD%
-set PATH=%GEXT_PDFBOX%\bin\script;%PATH%
-set PATH=%GEXT_PDFBOX%\lib;%PATH%
-set GS_CP_SET=yes
-goto Success
-
-:Win95
-if "%1" == "SetEnv" goto Win95Env
-REM We'll invoke a second copy of the command processor to make
-REM sure there's enough environment space
-COMMAND /E:2048 /K %0 SetEnv
-goto End
-
-:Win95Env
-set GEXT_PDFBOX=%CD%
-set PATH="%GEXT_PDFBOX%\bin\script";"%PATH%"
-set PATH="%GEXT_PDFBOX%\lib";"%PATH%"
-set GS_CP_SET=yes
-goto Success
-
-:Success
-
-set fulldir=%~dp0
-
-:: strip off everything up to (and including) ext dir
-set extdir=%fulldir:*ext\=%
-
-:: remove trailing slash
-set extdir=%extdir:\=%
-
-if "x%GSDLEXTS%" == "x" (
-  set GSDLEXTS=%extdir%
-) else (
-  set GSDLEXTS=%GSDLEXTS%:%extdir%
-)
-
-echo +Your environment is now setup for %extdesc%
-
-:: Back to delayed expansion to avoid problems with environment
-:: variables with brackets in them, such as "Program Files (x86)"
-
-
-:End
-
-popd
Index: /gs2-extensions/pdf-box/trunk/perllib/plugins/PDFBoxConverter.pm
===================================================================
--- /gs2-extensions/pdf-box/trunk/perllib/plugins/PDFBoxConverter.pm	(revision 22672)
+++ /gs2-extensions/pdf-box/trunk/perllib/plugins/PDFBoxConverter.pm	(revision 22672)
@@ -0,0 +1,209 @@
+###########################################################################
+#
+# PDFBoxConverter - helper plugin that does pdf document conversion with PDFBox
+#
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the 
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 2010 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+package PDFBoxConverter;
+
+use BaseMediaConverter;
+
+use strict;
+no strict 'refs'; # allow filehandles to be variables and viceversa
+
+use gsprintf 'gsprintf';
+
+# these two variables mustn't be initialised here or they will get stuck 
+# at those values.
+our $pdfbox_conversion_available; 
+our $no_pdfbox_conversion_reason; 
+
+BEGIN {
+    @PDFBoxConverter::ISA = ('BaseMediaConverter');
+
+    # Check that PDFBox is installed and available on the path 
+    $pdfbox_conversion_available = 1;
+    $no_pdfbox_conversion_reason = "";
+    
+    if (!defined $ENV{'GEXT_PDFBOX'}) {
+	$pdfbox_conversion_available = 0;
+	$no_pdfbox_conversion_reason = "gextpdfboxnotinstalled";
+    }
+    else {
+	my $gextpb_home = $ENV{'GEXT_PDFBOX'};
+	my $pbajar = &util::filename_cat($gextpb_home,"lib","java","pdfbox-app.jar");
+
+	if (!-e $pbajar) {
+	    print STDERR "Failed to find $pbajar\n";
+	    $pdfbox_conversion_available = 0;
+	    $no_pdfbox_conversion_reason = "gextpdfboxjarnotinstalled";
+	}
+	else {
+	    # test to see if java is in path	 
+	    my $cmd = "java 2>&1";
+	    if ($ENV{'GSDLOS'} =~ /^windows/i) {
+		$cmd .= " >nul";
+	    }
+	    else {
+		$cmd .= " >/dev/null";
+	    }
+
+	    my $status = system($cmd);
+	    if ($status != 0) {
+		print STDERR "Testing for java\n";
+		print STDERR "Failed to run: $cmd\n";
+		print STDERR "$!\n";
+		$pdfbox_conversion_available = 0;
+		$no_pdfbox_conversion_reason = "pdfboxnotinstalled";
+	    } 
+	}
+    }
+
+}
+
+my $arguments = [ ];
+
+my $options = { 'name' => "PDFBoxConverter",
+		'desc' => "{PDFBoxConverter.desc}",
+		'abstract' => "yes",
+		'inherits' => "yes",
+		'args' => $arguments };
+
+sub new {
+    my ($class) = shift (@_);
+    my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
+    push(@$pluginlist, $class);
+
+    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
+    push(@{$hashArgOptLists->{"OptList"}},$options);
+
+    my $self = new BaseMediaConverter($pluginlist, $inputargs, $hashArgOptLists);
+
+    if ($self->{'info_only'}) {
+	# don't worry about any options etc
+	return bless $self, $class;
+    }
+    if ($pdfbox_conversion_available) {
+	my $gextpb_home = $ENV{'GEXT_PDFBOX'};
+	my $pbajar = &util::filename_cat($gextpb_home,"lib","java","pdfbox-app.jar");
+	my $launch_cmd = "java -cp $pbajar  org.apache.pdfbox.ExtractText";
+	
+	$self->{'pdfbox_launch_cmd'} = $launch_cmd;
+    }
+    else {       
+	$self->{'no_pdfbox_conversion_reason'} = $no_pdfbox_conversion_reason;
+
+	my $outhandle = $self->{'outhandle'};
+	&gsprintf($outhandle, "PDFBoxConverter: {PDFBoxConverter.noconversionavailable} ({PDFBoxConverter.$no_pdfbox_conversion_reason})\n");
+    }  
+
+    $self->{'pdfbox_conversion_available'} = $pdfbox_conversion_available;
+    
+    return bless $self, $class;
+
+}
+
+sub init {
+    my $self = shift(@_);
+    my ($verbosity, $outhandle, $failhandle) = @_;
+
+    $self->{'pbtmp_file_paths'} = ();
+}
+
+sub deinit {
+    my $self = shift(@_);
+
+    $self->clean_up_temporary_files();
+}
+
+
+sub convert {
+    my $self = shift(@_);
+    my ($source_file_full_path, $target_file_type) = @_;
+
+    return 0 unless $pdfbox_conversion_available;
+    # check the filename
+    return 0 if ( !-f $source_file_full_path);
+
+    my $source_file_no_path = &File::Basename::basename($source_file_full_path);
+    # Determine the full name and path of the output file
+    my $target_file_path;
+    if ($self->{'enable_cache'}) {
+	$self->init_cache_for_file($source_file_full_path);
+	my $cache_dir = $self->{'cached_dir'};
+	my $file_root = $self->{'cached_file_root'};
+	#$file_root .= "_$convert_id" if ($convert_id ne "");
+	my $target_file = "$file_root.$target_file_type";
+	$target_file_path = &util::filename_cat($cache_dir,$target_file);
+    }
+    else {
+	# this is in gsdl/tmp. get a tmp filename in collection instead???
+	$target_file_path = &util::get_tmp_filename($target_file_type);
+	push(@{$self->{'pbtmp_file_paths'}}, $target_file_path);
+    }
+
+    # Generate and run the convert command
+    my $convert_cmd = $self->{'launch_cmd'};
+    $convert_cmd .= " -html" if ($target_file_type eq "html");
+    my $convert_command .= " \"$source_file_full_path\" \"$target_file_path\"";
+
+    print STDERR "**** convert_command = $convert_command\n";
+
+    my $print_info = { 'message_prefix' => "PDFBox Conversion",
+		       'message' => "Converting $source_file_no_path to: $target_file_type" };
+    # $print_info->{'cache_mode'} = $cache_mode if ($cache_mode ne "");
+
+    my ($regenerated,$result,$had_error) 
+	= $self->autorun_general_cmd($convert_command,$source_file_full_path, $target_file_path,$print_info);
+    if ($had_error) {
+	return (0, $result,$target_file_path);
+    }
+    return (1, $result,$target_file_path);
+}
+
+sub convert_without_result {
+    my $self = shift(@_);
+
+    my $source_file_path = shift(@_);
+    my $target_file_type = shift(@_);
+    my $convert_options  = shift(@_) || "";
+    my $convert_id       = shift(@_) || "";
+
+    return $self->convert($source_file_path,$target_file_type,
+			  $convert_options,$convert_id,"without_result");
+}
+
+sub clean_up_temporary_files {
+    my $self = shift(@_);
+
+    foreach my $pbtmp_file_path (@{$self->{'pbtmp_file_paths'}}) {
+	if (-e $pbtmp_file_path) {
+	    &util::rm($pbtmp_file_path);
+	}
+    }
+
+    $self->{'pbtmp_file_paths'} = ();
+}
+
+
+
+1;	
Index: /gs2-extensions/pdf-box/trunk/setup.bash
===================================================================
--- /gs2-extensions/pdf-box/trunk/setup.bash	(revision 22672)
+++ /gs2-extensions/pdf-box/trunk/setup.bash	(revision 22672)
@@ -0,0 +1,35 @@
+
+extdesc="the PDFBox Extension"
+
+full_setup=`pwd`/${BASH_SOURCE}
+fulldir=${full_setup%/*}
+fulldir=${fulldir%/.}
+
+if [ "x$GEXT_PDFBOX" = "x" ] ; then
+  export GEXT_PDFBOX=`pwd`
+
+  if [ -d "$GEXT_PDFBOX/bin/script" ] ; then
+    export PATH=$GEXT_PDFBOX/bin/script:$PATH
+  fi
+
+  if [ -d "$GEXT_PDFBOX/lib" ] ; then
+    if [ "$GSDLOS" = "linux" ] ; then
+      export LD_LIBRARY_PATH=$GEXT_PDFBOX/lib:$LD_LIBRARY_PATH
+    elif [ "$GSDLOS" = "darwin" ] ; then
+      export DYLD_LIBRARY_PATH=$GEXT_PDFBOX/lib:$DYLD_LIBRARY_PATH
+    fi
+  fi
+
+  extdir=${GEXT_PDFBOX##*/}
+
+  if [ "x$GSDLEXTS" = "x" ] ; then
+    export GSDLEXTS=$extdir
+  else 
+    export GSDLEXTS=$GSDLEXTS:$extdir
+  fi
+
+
+  echo "+Your environment is now setup for $extdesc"
+else
+  echo "+Your environment is already setup for $extdesc"
+fi
Index: /gs2-extensions/pdf-box/trunk/setup.bat
===================================================================
--- /gs2-extensions/pdf-box/trunk/setup.bat	(revision 22672)
+++ /gs2-extensions/pdf-box/trunk/setup.bat	(revision 22672)
@@ -0,0 +1,60 @@
+@echo off
+pushd "%CD%"
+CD /D "%~dp0"
+
+set extdesc=the PDFBox Extension
+
+if "%OS%" == "Windows_NT" goto WinNT
+if "%OS%" == "" goto Win95
+if "%GSDLLANG%" == "en" echo Setup failed - your PATH has not been set
+if "%GSDLLANG%" == "es" echo No se pudo realizar la configuraci¢n - no se ha establecido la RUTA.
+if "%GSDLLANG%" == "fr" echo Echc de l'installation - votre variable PATH n'a pas t ajuste
+if "%GSDLLANG%" == "ru" echo áâ ­®¢ª  ­¥ ã€ « áì -  ­¥ ¡ë« ãáâ ­®¢«¥­
+goto End
+
+:WinNT
+set GEXT_PDFBOX=%CD%
+set PATH=%GEXT_PDFBOX%\bin\script;%PATH%
+set PATH=%GEXT_PDFBOX%\lib;%PATH%
+set GS_CP_SET=yes
+goto Success
+
+:Win95
+if "%1" == "SetEnv" goto Win95Env
+REM We'll invoke a second copy of the command processor to make
+REM sure there's enough environment space
+COMMAND /E:2048 /K %0 SetEnv
+goto End
+
+:Win95Env
+set GEXT_PDFBOX=%CD%
+set PATH="%GEXT_PDFBOX%\bin\script";"%PATH%"
+set PATH="%GEXT_PDFBOX%\lib";"%PATH%"
+set GS_CP_SET=yes
+goto Success
+
+:Success
+
+set fulldir=%~dp0
+
+:: strip off everything up to (and including) ext dir
+set extdir=%fulldir:*ext\=%
+
+:: remove trailing slash
+set extdir=%extdir:\=%
+
+if "x%GSDLEXTS%" == "x" (
+  set GSDLEXTS=%extdir%
+) else (
+  set GSDLEXTS=%GSDLEXTS%:%extdir%
+)
+
+echo +Your environment is now setup for %extdesc%
+
+:: Back to delayed expansion to avoid problems with environment
+:: variables with brackets in them, such as "Program Files (x86)"
+
+
+:End
+
+popd
