#!/usr/bin/perl

$filename = $uri = $ARGV[0];
$outputfile = $filename.".xml";
$uri =~ s/^backward/cic:/;
$uri =~ s/(.*),([^,]*),([^,]*)/$1#xpointer(1\/$2\/$3)/;
$uri =~ s/(.*),([^,]*)/$1#xpointer(1\/$2)/;

print "Now processing file $filename\n";

open(HEADER,">>$outputfile");
print HEADER <<EOT;
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE rdf:RDF [
        <!ENTITY rdfns 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
        <!ENTITY hthns 'http://www.cs.unibo.it/helm/schemas/schema-helmth#'>
        <!ENTITY hns 'http://www.cs.unibo.it/helm/schemas/schema-helm#'>

   ]>
<rdf:RDF xml:lang="en" xmlns:rdf="&rdfns;" xmlns:h="&hns;" xmlns:hth="&hthns;">
	<h:Object rdf:about="$uri">
EOT
close(HEADER);

$quotedfilename = $filename;
$quotedfilename =~ s/'/\\'/g;
$quotedoutputfile = $outputfile;
$quotedoutputfile =~ s/'/\\'/g;
system("cat $quotedfilename >> $quotedoutputfile");

open(FOOTER,">>$outputfile");
print FOOTER <<EOT;
	</h:Object>
</rdf:RDF>
EOT
close(FOOTER);

unlink $filename;
