2006-09-15 [colin] 2.4.0cvs189
[claws.git] / manual / xml2pdf
1 #!/bin/sh
2
3 # pdf generation from xml and xsl
4 # $1: .xsl file 
5 # $2: .xml file
6
7 if [ $# -ne 2 ]
8 then
9         echo "usage: ${0##*/} <file.xsl> <file.xml>"
10         exit 1
11 fi
12
13 test -z "$JAVA" && \
14         JAVA=`which java`
15 test -z "$JAVA" && \
16         JAVA="$JAVA_HOME/bin/java"
17 if [ ! -x "$JAVA" ]
18 then
19         echo 'error: java not found in your $PATH or in $JAVA_HOME/bin'
20         exit 1
21 fi
22
23 test -z "$SAXON" && \
24         SAXON=`which saxon`
25 if [ -z "$SAXON" ]
26 then
27         test -z "$SAXONJAR" && \
28                 SAXONJAR='/usr/share/java/saxon.jar'
29         if [ ! -f "$SAXONJAR" ]
30         then
31                 SAXONJAR='/usr/local/share/java/saxon.jar'
32                 if [ ! -f "$SAXONJAR" ]
33                 then
34                         echo "error: neither saxon nor saxon.jar were found"
35                         exit 1
36                 fi
37         fi
38         SAXON="$JAVA -jar $SAXONJAR"
39 fi
40
41
42 if [ -n "$XML_CATALOG_FILES" ]
43 then
44         CATALOG_FILES=$XML_CATALOG_FILES
45 else
46         echo "warning: XML_CATALOG_FILES is not set or empty"
47         CATALOG_FILES="/usr/local/etc/xml/catalog /etc/xml/catalog $HOME/xml/catalog"
48 fi
49 KEY="http://docbook.sourceforge.net/release/xsl/current"
50
51 # manual base name
52 SCM=sylpheed-claws-manual
53
54 for CATALOG in $CATALOG_FILES
55 do
56         if [ -s "$CATALOG" ]
57         then
58                 DOCBOOKXSLPATH=$(xmlcatalog "$CATALOG" "$KEY/")
59                 # second chance
60                 if [ $? -ne 0 -o -z "$DOCBOOKXSLPATH" ]
61                 then
62                         DOCBOOKXSLPATH=$(xmlcatalog "$CATALOG" "$KEY")
63                         # still not found
64                         test $? -ne 0 -o -z "$DOCBOOKXSLPATH" && \
65                                 continue
66                 fi
67
68                 test "${DOCBOOKXSLPATH:0:7}" == "file://" && \
69                         DOCBOOKXSLPATH=${DOCBOOKXSLPATH:7}
70                 if [ -n "$DOCBOOKXSLPATH" ]
71                 then
72                         echo "docbook-xsl path found: $DOCBOOKXSLPATH"
73                         sed "s|@DOCBOOK_XSL_PATH@|$DOCBOOKXSLPATH|g" "$1" \
74                             > ${SCM}.xsl && \
75                                 $SAXON -o ${SCM}.fo "$2" ${SCM}.xsl && \
76                                 fop -fo ${SCM}.fo -pdf ${SCM}.pdf
77                         exit $?
78                 fi
79         fi
80 done
81 echo "couldn't find docbook-xsl path from any of the following catalog files:"
82 echo "$CATALOG_FILES"
83 exit 1