Changeset 28410 for gs2-extensions


Ignore:
Timestamp:
10/14/13 14:58:34 (7 years ago)
Author:
davidb
Message:

Code now runs an XSLT over the doc.xml file

Location:
gs2-extensions/apache-jena/trunk/src/perllib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/apache-jena/trunk/src/perllib/jenaTDBBuilder.pm

    r28392 r28410  
    2929use strict;
    3030no strict 'refs'; # allow filehandles to be variables and viceversa
     31
     32use util;
     33use FileUtils;
    3134
    3235use extrabuilder;
     
    6871
    6972    if (! -d $jenaTDB_dir) {
    70     &util::mk_all_dir ($jenaTDB_dir);
     73    &FileUtils::makeAllDirectories($jenaTDB_dir);
    7174    }
    7275   
  • gs2-extensions/apache-jena/trunk/src/perllib/jenaTDBBuildproc.pm

    r28392 r28410  
    3232no strict 'refs'; # allow filehandles to be variables and viceversa
    3333
     34use docprint;
    3435use util;
     36use FileUtils;
    3537
    3638use extrabuildproc;
     
    4749    my $self = new extrabuildproc (@_);
    4850
     51    my $xslt_file = "gsdom2rdf.xsl";
     52
     53    my $xslt_filename = &util::locate_config_file($xslt_file);
     54    if (!defined $xslt_filename) {
     55    print STDERR "Can not find $xslt_file, please make sure you have supplied the correct file path\n";
     56    die "\n";
     57    }
     58
     59    $self->{'xslt_file'} = $xslt_file;
     60    $self->{'xslt_filename'} = $xslt_filename;
     61
     62    # Do the following here so it doesn't keep checking (within the util.pm method)
     63    # whether it needs to create the directory or not
     64    my $tmp_dir = &util::get_collectlevel_tmp_dir();
     65    $self->{'tmp_dir'} = $tmp_dir;
     66
    4967    return bless $self, $class;
    5068}
    5169
    5270
     71
     72
     73sub open_xslt_pipe
     74{
     75    my $self = shift @_;
     76    my ($output_file_name, $xslt_file)=@_;
     77
     78    return unless defined $xslt_file and $xslt_file ne "" and &FileUtils::fileExists($xslt_file);
     79   
     80    my $apply_xslt_jar = &FileUtils::javaFilenameConcatenate($ENV{'GSDLHOME'},"bin","java","ApplyXSLT.jar");
     81    my $xalan_jar      = &FileUtils::javaFilenameConcatenate($ENV{'GSDLHOME'},"bin","java","xalan.jar");
     82
     83    my $java_class_path = &util::javapathname_cat($apply_xslt_jar,$xalan_jar);
     84
     85    $xslt_file = &util::makeFilenameJavaCygwinCompatible($xslt_file);
     86
     87    my $mapping_file_path = "";
     88
     89    my $cmd = "| java -cp \"$java_class_path\" org.nzdl.gsdl.ApplyXSLT -t \"$xslt_file\" ";
     90
     91    if (defined $self->{'mapping_file'} and $self->{'mapping_file'} ne ""){
     92    my $mapping_file_path = "\"".$self->{'mapping_file'}."\"";
     93    $cmd .= "-m $mapping_file_path";
     94    }
     95   
     96    print STDERR "*** cmd = $cmd\n";
     97
     98    open(*XMLWRITER, $cmd)
     99    or die "can't open pipe to xslt: $!";
     100
     101   
     102    $self->{'xslt_writer'} = *XMLWRITER;
     103
     104    print XMLWRITER "<?DocStart?>\n";       
     105    print XMLWRITER "$output_file_name\n";
     106 
     107  }
     108 
     109
     110sub close_xslt_pipe
     111{
     112  my $self = shift @_;
     113
     114 
     115  return unless defined $self->{'xslt_writer'} ;
     116   
     117  my $xsltwriter = $self->{'xslt_writer'};
     118 
     119  print $xsltwriter "<?DocEnd?>\n";
     120  close($xsltwriter);
     121
     122  undef $self->{'xslt_writer'};
     123
     124}
    53125
    54126
     
    60132    my $doc_oid = $doc_obj->get_OID();
    61133
     134    my $tmp_dir = $self->{'tmp_dir'};
     135    my $tmp_doc_filename = &FileUtils::filenameConcatenate($tmp_dir,"doc-$doc_oid.xml");
     136    $tmp_doc_filename    = &util::makeFilenameJavaCygwinCompatible($tmp_doc_filename);
     137
     138    my $xslt_filename = $self->{'xslt_filename'};
     139    $self->open_xslt_pipe($tmp_doc_filename, $xslt_filename); # stops with error if not able to open pipe
     140
     141    my $outhandler = $self->{'xslt_writer'};
     142    binmode($outhandler,":utf8");
     143
     144    my $section_text = &docprint::get_section_xml($doc_obj,$doc_obj->get_top_section());
     145    print $outhandler $section_text;
     146
     147    $self->close_xslt_pipe();
     148
     149
     150    # now feed to generated file to jena's (TDB) tripple store
     151
     152
     153}
     154
     155
     156sub texteditMG {
     157    my $self = shift (@_);
     158    my ($doc_obj) = @_;
     159    my $handle = $self->{'output_handle'};
     160   
     161    my $doc_oid = $doc_obj->get_OID();
     162
     163
    62164    my $doc_section = 0; # just for this document
     165
    63166
    64167    my $text = "";
Note: See TracChangeset for help on using the changeset viewer.