| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
use Getopt::Std; |
| 4 |
|
| 5 |
my $MAJOR=1; |
| 6 |
my $MINOR=2; |
| 7 |
my $DOCBOOK_BASE = "/usr/local/apps/docbook/"; |
| 8 |
#my $JAVA_HOME="/usr/local/apps/j2re1.4.1_02"; |
| 9 |
my $JAVA_HOME="/usr/local/apps/java/current/"; |
| 10 |
#my $JAVA_HOME=$ENV{JAVA_HOME}; |
| 11 |
|
| 12 |
# *************************************************************************** |
| 13 |
# Changes: |
| 14 |
# 2004-08-23: sy8 - Added "-o xml" option to output XML |
| 15 |
# 2004-11-23: sy8 - Added "-P name=value" option to pass parameters to the XSL transformation |
| 16 |
|
| 17 |
|
| 18 |
# Say hello and show received parameters! |
| 19 |
|
| 20 |
sub say_hello { |
| 21 |
|
| 22 |
my ($xml,$to,$xsl,$targetdb) = @_; |
| 23 |
|
| 24 |
print ("\ndocbookx2other: Iain's Version ".$MAJOR.".".$MINOR.".\n"); |
| 25 |
unless ($xml eq "") {print "- XML file :\t".$xml."\n";} |
| 26 |
unless ($to eq "") {print "- Convert to:\t".$to."\n";} |
| 27 |
unless ($xsl eq "") {print "- XSL to use:\t".$xsl."\n";} |
| 28 |
unless ($targetdb eq "") {print "- Target DB to generate:\t".$targetdb."\n";} |
| 29 |
print "\n\n"; |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
# Meet the options! |
| 34 |
|
| 35 |
sub usage { |
| 36 |
|
| 37 |
print ("\ndocbookx2other. Version ".$MAJOR.".".$MINOR.".\n"); |
| 38 |
print ("Usage: docbookx2other [-o format] [-t stylesheet.xsl] [-v] [-q] [-L location_string] [-S submenu_string] [-T target_database_string] docbook_file.xml\n"); |
| 39 |
print ("\t The parameters are:\n"); |
| 40 |
print ("\t -o : Which output format we want [pdf,ps,html,xml].\n"); |
| 41 |
print ("\t -t : XSL stylesheet to use. If a relative path is provided, '$DOCBOOK_BASE/docbook-xsl-ecmwf/' is assumed as base dir.\n"); |
| 42 |
print ("\t -T : Target link database to generate.\n"); |
| 43 |
print ("\t -D : Target database document to use for generating cross-references (sets target.database.document).\n"); |
| 44 |
print ("\t -C : Current document ID (sets current.docid).\n"); |
| 45 |
print ("\t -L : 'location' bar items, in HTML. 'url1\@Text1;url2\@Text2; ... ;urlN\@TextN'\n"); |
| 46 |
print ("\t -S : 'submenu' items, in HTML. 'url1\@Text1;url2\@Text2;_THIS_; ... ;urlN\@TextN'. _THIS_ will be the current document, not shown as a link.\n"); |
| 47 |
|
| 48 |
print ("\t -q : Don't output any info.\n"); |
| 49 |
print ("\t -v : Be verbose, please.\n"); |
| 50 |
print ("\t -h : Show this ;-).\n\n"); |
| 51 |
|
| 52 |
exit 0; |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
sub call_java { |
| 57 |
|
| 58 |
my ($java_home,$xml_file, $target, $xsl_to_use, $verbosity, $location, $submenu, $targetdb, $targetdoc, $currentdocid) = @_; |
| 59 |
my $endorsed="$DOCBOOK_BASE/xalan/current/bin"; |
| 60 |
#my $endorsed="/usr/local/apps/xxe-pro/current"; |
| 61 |
my $enableXinclude="-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl -Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration"; |
| 62 |
#my $enableXinclude="-Djava.xml.parsers.SAXParserFactory=com.jclark.xml.jaxp.SAXParserFactoryImpl -Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration"; |
| 63 |
|
| 64 |
my $file_no_extension = $xml_file; |
| 65 |
$file_no_extension =~ s/\.xml$//; |
| 66 |
|
| 67 |
#my $target_xsl= $target; |
| 68 |
#$target_xsl =~ s/pdf/fo/; |
| 69 |
|
| 70 |
my $basedir = get_basedir($xml_file); |
| 71 |
|
| 72 |
my $targetdbopt = ($targetdb) ? "-Dcollect.xref.targets=only -Dtargets.filename=$targetdb" : ""; |
| 73 |
my $targetdocopt = ($targetdoc) ? "-Dtarget.database.document=$targetdoc" : ""; |
| 74 |
my $currentdocidopt = ($currentdocid) ? "-Dcurrent.docid=$currentdocid" : ""; |
| 75 |
|
| 76 |
my $allow_doctypenode = "-Ddisallow.doctype=false"; |
| 77 |
|
| 78 |
|
| 79 |
if ($verbosity > 1) { |
| 80 |
print ("T: $targetdoc\n"); |
| 81 |
print ("C: $currentdocid\n"); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
# my $command = "$java_home/bin/java -Xmx128m -Djava.endorsed.dirs=$endorsed -Dbasedir=$basedir -Ddocbook.xml=$xml_file -Dout.ps=$file_no_extension.ps -Dout.pdf=$file_no_extension.pdf -Dout.fo=$file_no_extension.fo -Dout.dir=$basedir -Dout.html=$file_no_extension.html -Dout.xsl=$xsl_to_use -Dfile.noExtension=$file_no_extension -Dcollect.xref.targets=only -Decmwf.location=\"$location\" -Decmwf.submenu=\"$submenu\" $enableXinclude -classpath $DOCBOOK_BASE/bin/ant.jar:$DOCBOOK_BASE/bin/optional.jar:$DOCBOOK_BASE/docbook-xsl/current/extensions/xalan2.jar org.apache.tools.ant.Main -f $DOCBOOK_BASE/bin/build.xml $target"; |
| 86 |
my $command = "$java_home/bin/java -Xmx128m -Djava.endorsed.dirs=$endorsed -Dbasedir=$basedir -Ddocbook.xml=$xml_file -Dout.ps=$file_no_extension.ps -Dout.pdf=$file_no_extension.pdf -Dout.fo=$file_no_extension.fo -Dout.dir=$basedir -Dout.html=$file_no_extension.html -Dout.xsl=$xsl_to_use -Dfile.noExtension=$file_no_extension $targetdbopt $targetdocopt $currentdocidopt $allow_doctypenode -Decmwf.location=\"$location\" -Decmwf.submenu=\"$submenu\" $enableXinclude -classpath $DOCBOOK_BASE/bin/ant.jar:$DOCBOOK_BASE/bin/optional.jar:$DOCBOOK_BASE/docbook-xsl/current/extensions/xalan2.jar org.apache.tools.ant.Main -f tools/build.xml $target"; |
| 87 |
|
| 88 |
if ($verbosity > 1) { |
| 89 |
print "Executing: $command\n"; |
| 90 |
} |
| 91 |
return system($command); |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
sub get_basedir { |
| 96 |
|
| 97 |
my ($file) = @_; |
| 98 |
@elems = split("/",$file); |
| 99 |
pop(@elems); |
| 100 |
return join("/",@elems); |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
# *************************************************************************** |
| 106 |
|
| 107 |
# Main Thang! |
| 108 |
|
| 109 |
my $xml = ""; |
| 110 |
my $to = "pdf"; |
| 111 |
my $xsl_fo = "project_plans_fo.xsl"; |
| 112 |
my $xsl_html = "w3ec2_html.xsl"; |
| 113 |
my $xsl = $xsl_fo; |
| 114 |
my $verbosity = 1; |
| 115 |
my $location = ""; |
| 116 |
my $submenu = ""; |
| 117 |
my $targetdb = ""; |
| 118 |
my $targetdoc = ""; |
| 119 |
my $currentdocid = ""; |
| 120 |
|
| 121 |
my %options=(); |
| 122 |
getopts("s:o:t:L:S:T:C:D:qhv",\%options); |
| 123 |
|
| 124 |
if (defined($options{"h"})) { |
| 125 |
return usage(); |
| 126 |
} |
| 127 |
|
| 128 |
$xml = $ARGV[0]; |
| 129 |
if (defined($options{"o"})) { |
| 130 |
$to = $options{"o"}; |
| 131 |
if ($to eq "pdf" or $to eq "ps") { |
| 132 |
$xsl = $xsl_fo; |
| 133 |
} else { |
| 134 |
$xsl = $xsl_html; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
$xsl = $options{"t"} if (defined($options{"t"})); |
| 139 |
$verbosity = 0 if (defined($options{"q"})); |
| 140 |
$verbosity = 2 if (defined($options{"v"})); |
| 141 |
|
| 142 |
if ($xml eq "") { |
| 143 |
return usage(); |
| 144 |
} |
| 145 |
|
| 146 |
# Convert paths to absolute |
| 147 |
unless ( $xml =~ /^\// ) { |
| 148 |
my $base = `pwd`; |
| 149 |
chomp($base); |
| 150 |
$xml = $base."/".$xml; |
| 151 |
} |
| 152 |
|
| 153 |
unless ( $xsl =~ /^\// ) { |
| 154 |
$xsl = $DOCBOOK_BASE."/docbook-xsl-ecmwf/".$xsl; |
| 155 |
} |
| 156 |
|
| 157 |
if (defined($options{"T"})) { |
| 158 |
$targetdb = $options{"T"}; |
| 159 |
} |
| 160 |
|
| 161 |
if (defined($options{"D"})) { |
| 162 |
$targetdoc = $options{"D"}; |
| 163 |
} |
| 164 |
|
| 165 |
if (defined($options{"C"})) { |
| 166 |
$currentdocid = $options{"C"}; |
| 167 |
} |
| 168 |
|
| 169 |
# Be polite! |
| 170 |
if ($verbosity > 0) { |
| 171 |
say_hello($xml,$to,$xsl,$targetdb); |
| 172 |
} |
| 173 |
|
| 174 |
if (defined($options{"L"})) { |
| 175 |
$location = $options{"L"}; |
| 176 |
} |
| 177 |
if (defined($options{"S"})) { |
| 178 |
$submenu = $options{"S"}; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
exit call_java($JAVA_HOME,$xml, $to, $xsl, $verbosity, $location, $submenu, $targetdb, $targetdoc, $currentdocid); |