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