2008-10-09 [colin] 3.6.0cvs20
[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
48                        /usr/local/share/xml/catalog $HOME/xml/catalog"
49 fi
50 KEY="http://docbook.sourceforge.net/release/xsl/current"
51
52 # manual base name
53 SCM=claws-mail-manual
54
55 for CATALOG in $CATALOG_FILES
56 do
57         if [ -s "$CATALOG" ]
58         then
59                 DOCBOOKXSLPATH=$(xmlcatalog "$CATALOG" "$KEY/")
60                 # second chance
61                 if [ $? -ne 0 -o -z "$DOCBOOKXSLPATH" ]
62                 then
63                         DOCBOOKXSLPATH=$(xmlcatalog "$CATALOG" "$KEY")
64                         # still not found
65                         test $? -ne 0 -o -z "$DOCBOOKXSLPATH" && \
66                                 continue
67                 fi
68
69                 test "`echo ${DOCBOOKXSLPATH} | cut -c 1-7`" = "file://" && \
70                         DOCBOOKXSLPATH=`echo ${DOCBOOKXSLPATH} | cut -c 8-`
71                 if [ -n "$DOCBOOKXSLPATH" ]
72                 then
73                         echo "docbook-xsl path found: $DOCBOOKXSLPATH"
74                         sed "s|@DOCBOOK_XSL_PATH@|$DOCBOOKXSLPATH|g" "$1" \
75                             > ${SCM}.xsl && \
76                                 $SAXON -o ${SCM}.fo "$2" ${SCM}.xsl && \
77                                 fop -fo ${SCM}.fo -pdf ${SCM}.pdf
78                         exit $?
79                 fi
80         fi
81 done
82 echo "couldn't find docbook-xsl path from any of the following catalog files:"
83 echo "$CATALOG_FILES"
84 exit 1