Index: gs2-extensions/apache-jena/trunk/src/perllib/jenaTDBBuildproc.pm
===================================================================
--- gs2-extensions/apache-jena/trunk/src/perllib/jenaTDBBuildproc.pm	(revision 28410)
+++ gs2-extensions/apache-jena/trunk/src/perllib/jenaTDBBuildproc.pm	(revision 28468)
@@ -49,15 +49,4 @@
     my $self = new extrabuildproc (@_);
 
-    my $xslt_file = "gsdom2rdf.xsl";
-
-    my $xslt_filename = &util::locate_config_file($xslt_file);
-    if (!defined $xslt_filename) {
-	print STDERR "Can not find $xslt_file, please make sure you have supplied the correct file path\n";
-	die "\n";
-    }
-
-    $self->{'xslt_file'} = $xslt_file;
-    $self->{'xslt_filename'} = $xslt_filename;
-
     # Do the following here so it doesn't keep checking (within the util.pm method)
     # whether it needs to create the directory or not
@@ -65,8 +54,76 @@
     $self->{'tmp_dir'} = $tmp_dir;
 
+
+    my $xslt_file_in = "gsdom2rdf.xsl";
+
+    my $xslt_filename_in = &util::locate_config_file($xslt_file_in);
+    if (!defined $xslt_filename_in) {
+	print STDERR "Can not find $xslt_file_in, please make sure you have supplied the correct file path\n";
+	die "\n";
+    }
+
+    my $xslt_filename_out = &FileUtils::filenameConcatenate($tmp_dir,$xslt_file_in);
+
+    my $collection = $self->{'collection'};
+
+    my $url_prefix = &util::get_full_greenstone_url_prefix();
+
+    my $property_hashmap = { 'libraryurl' => $url_prefix,
+			     'collect'    => $collection };
+
+    file_copy_with_property_sub($xslt_filename_in,$xslt_filename_out,$property_hashmap);
+
+    $self->{'xslt_file'} = $xslt_file_in;
+    $self->{'xslt_filename'} = $xslt_filename_out;
+
     return bless $self, $class;
 }
 
 
+sub property_lookup
+{
+    my ($hashmap,$value) = @_;
+    
+    print STDERR "*** checking value = '$value'\n";
+
+    print STDERR "*** lookup = ", $hashmap->{$value}, "\n";
+
+    my $lookup = (defined $hashmap->{$value}) ? $hashmap->{$value} : "\@$value\@";
+
+    return $lookup;
+}
+
+
+# Performs a text file copy, substituding substings of the form
+# @xxx@ in the input file with the values set in hashmap
+# passed in 
+
+sub file_copy_with_property_sub
+{
+    my ($filename_in,$filename_out,$property_hashmap) = @_;
+
+    if (!open(FIN, "<$filename_in")) {
+	print STDERR "util::file_substitute_at_properteis failed to open $filename_in\n  $!\n";
+	return;
+    }
+    binmode(FIN,":utf8");
+
+    if (!open(FOUT, ">$filename_out")) {
+	print STDERR "util::file_substitute_at_properteis failed to open $filename_out\n  $!\n";
+	return;
+    }
+    binmode(FOUT,":utf8");
+
+    my $line;
+    while (defined($line = <FIN>)) {
+	
+	$line =~ s/\@([^@ ]+)\@/&property_lookup($property_hashmap,$1)/ige;
+
+	print FOUT $line;
+    }
+
+    close(FIN);
+    close(FOUT);	    
+}
 
 
@@ -88,4 +145,5 @@
 
     my $cmd = "| java -cp \"$java_class_path\" org.nzdl.gsdl.ApplyXSLT -t \"$xslt_file\" "; 
+
 
     if (defined $self->{'mapping_file'} and $self->{'mapping_file'} ne ""){
@@ -94,9 +152,6 @@
     }
     
-    print STDERR "*** cmd = $cmd\n";
-
     open(*XMLWRITER, $cmd)
 	or die "can't open pipe to xslt: $!";
-
     
     $self->{'xslt_writer'} = *XMLWRITER;
@@ -133,9 +188,9 @@
 
     my $tmp_dir = $self->{'tmp_dir'};
-    my $tmp_doc_filename = &FileUtils::filenameConcatenate($tmp_dir,"doc-$doc_oid.xml");
-    $tmp_doc_filename    = &util::makeFilenameJavaCygwinCompatible($tmp_doc_filename);
+    my $tmp_doc_filename = &FileUtils::filenameConcatenate($tmp_dir,"doc-$doc_oid.ttl");
+    my $tmp_doc_filename_cc    = &util::makeFilenameJavaCygwinCompatible($tmp_doc_filename);
 
     my $xslt_filename = $self->{'xslt_filename'};
-    $self->open_xslt_pipe($tmp_doc_filename, $xslt_filename); # stops with error if not able to open pipe
+    $self->open_xslt_pipe($tmp_doc_filename_cc, $xslt_filename); # stops with error if not able to open pipe
 
     my $outhandler = $self->{'xslt_writer'};
@@ -147,99 +202,28 @@
     $self->close_xslt_pipe();
 
-
     # now feed to generated file to jena's (TDB) tripple store
 
-
-}
-
-
-sub texteditMG {
-    my $self = shift (@_);
-    my ($doc_obj) = @_;
-    my $handle = $self->{'output_handle'};
-    
-    my $doc_oid = $doc_obj->get_OID();
-
-
-    my $doc_section = 0; # just for this document
-
-
-    my $text = "";
-    my $text_extra = "";
-
-    # get the text for this document
-    my $section = $doc_obj->get_top_section();
-    while (defined $section) {
-	# update a few statistics
-	$doc_section++;
-
-	my $title = $doc_obj->get_metadata_element($section, "Title");
-
-	if (defined $title && ($title =~ m/\S/)) {
-	    print "$doc_oid: Title = $title\n";
-	}
-
-	my $dc_title = $doc_obj->get_metadata_element($section, "dc.Title");
-
-	if (defined $dc_title && ($dc_title =~ m/\S/)) {
-	    print "$doc_oid: dc.Title = $dc_title\n";
-	}
-
-
-	my $id3_title = $doc_obj->get_metadata_element($section, "ex.ID3.Title");
-
-	if (defined $id3_title && ($id3_title =~ m/\S/)) {
-	    print "$doc_oid: id3.Title = $id3_title\n";
+    my $outhandle = $self->{'outhandle'};
+    print $outhandle "  Inserting tripples for $doc_oid\n";
+
+    my $collection = $self->{'collection'};
+
+    if (-f $tmp_doc_filename) {
+
+	my $cmd = "gs-triplestore-add $collection \"$tmp_doc_filename\"";
+	
+	my $status = system($cmd);
+	if ($status != 0) {
+	    print STDERR "Error: failed to run:\n  $cmd\n$!\n";
 	}
 	
-	$section = $doc_obj->get_next_section($section);
-    }
-
-    print $handle "$text$text_extra";
-}
-
-
-
-sub texteditADB {
-    my $self = shift (@_);
-    my ($doc_obj,$file,$mode) = @_;
-
-    # Code written on the assumption that that jenaTDB does a replace
-    # operation when presented with a docid that already extis.
-    # => don't need to do anything special to distinguish between
-    #    a mode of "add" and "update"
-
-    my $outhandle = $self->{'outhandle'};
-
-
-    my $source_dir = $self->{'source_dir'}; # typically the archives dir
-    my $build_dir  = $self->{'build_dir'};
-
-    # full path to adb database
-    my $adb_filename 
-	= &util::filename_cat($build_dir, "jenaTDB", "lsh-features.adb");
-
-    # get doc id
-    my $doc_oid = $doc_obj->get_OID();
-
-    # map to assoc dir
-    my $top_section = $doc_obj->get_top_section();
-    my $assoc_file
-	= $doc_obj->get_metadata_element ($top_section,"assocfilepath");
-    my $assoc_filename = &util::filename_cat($source_dir,$assoc_file);
-
-    my $chr12_filename = &util::filename_cat($assoc_filename,"doc.chr12");
-    my $powerlog_filename = &util::filename_cat($assoc_filename,"doc.power");
-
-    print $outhandle "  Inserting tripples for $doc_oid\n";
-
-#    my $cmd = "jenaTDB -d \"$adb_filename\" -I -k \"$doc_oid\" -f \"$chr12_filename\" -w \"$powerlog_filename\"";
-
-#    my $status = system($cmd);
-#    if ($status != 0) {
-#	print STDERR "Error: failed to run:\n  $cmd\n$!\n";
-#    }
-
-}
+	unlink $tmp_doc_filename;
+    }
+    else {
+	print STDERR "*** Failed to generate: $tmp_doc_filename\n";
+    }
+
+}
+
 
 sub text {
