xml2pdf 1.8 KB

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