Apache FOP with Saxon

Using Saxon with Apache FOP for XSLT processing.

Apache FOP is a print formatter that uses XSL formatting objects (XSL-FO) to transform XML into a PDF for viewing or printing. We use FOP in uzERP to output documents like invoices, orders and reports. Recently, I wanted to use some XSLT2.0 features in a document that I was developing for a uzERP customer, but FOP uses Xalan as its default transformation engine and that only supports XSLT1.0.

FOP is a Java application and XML processing is pluggable using the Java API for XML Processing (JAXP), so Xalan can be replaced with an alternative processor. We are deploying our customer systems on Ubuntu 14.04 and packages are available for Saxon 6.5.5, an XSLT processor that supports new features first defined in the XSLT 1.1 working draft. This was enough for me to be able to use the format-date function and a few others in my stylesheet, but…

How to persuade FOP to use Saxon?

First of all, install the Saxon packages:

$ sudo apt-get update && apt-get install libsaxon-java libsaxonb-java

Copy the FOP command line script:

$ cp /usr/bin/fop /usr/local/bin/fop

Edit the copied script file:

#Add this before any other find_jars
find_jars saxon saxonb

#Add the saxon processor to the java_run command at the bottom of the script
run_java $HEADLESS $LOG_OPTION -Djavax.xml.transform.TransformerFactory=net.sf.saxon.TransformerFactoryImpl org.apache.fop.cli.Main "$@"

I want this script to override the standard FOP script when using the fop command, so added a system wide alias by creating a file called fop-alias.sh in /etc/profile.d with the following contents:

alias fop="/usr/local/bin/fop"

With all that done, the fop command will now load the Saxon XSLT processor, which enables access to a number of useful extensions not available in XLST1.0


Use Network Manager to Turn off auto screen-lock in Gnome Shell

Another way to control Gnome screensaver auto-lock, from NetworkManager in Linux.

A follow-up to my previous post on running a script from PAM. Here is another way to control Gnome screensaver auto-lock, from NetworkManager.

#!/bin/sh -e

# Turn off gnome auto screen-lock when connected to specific wireless networks

# USAGE
#  This script must be placed in /etc/NetworkManager/dispatcher.d
#  with an appropriate name, e.g. 95gnome-screenlock.

# Hat tip, original idea - md, http://blog.bofh.it/debian/id_444

# From NetworkManager
IFACE=$1
STATUS=$2

# Define interface, essid and user
WIRELESS_IFACE=wlan0
AUTH_ESSID=orchard
AUTH_USER=steve

# Get session users
SESSION_USERS=$(loginctl list-users|sed 's/^ *//'|cut -d' ' -f2)

# Exit if not ifup/down on target interface
case "$IFACE" in
  $WIRELESS_IFACE)
    #Do nothing
    ;;
  *)
    exit 0 ;;
esac

#exit for other users
if [[ "$SESSION_USERS" =~ $AUTH_USER ]]
then
exit 0
fi

# return the ESSID of this interface
current_essid() {
  /sbin/iwconfig $1 | sed -nre '/ESSID/s/.*ESSID:"([^"]+)".*/\1/p'
}

CURRENT_ESSID=$(current_essid $WIRELESS_IFACE)

# automatically turn off auto screen-lock when connected to this network,
# otherwise turn on auto screen-lock
case "$CURRENT_ESSID" in
  $AUTH_ESSID)
    su -c "DISPLAY=:0 dconf write /org/gnome/desktop/screensaver/lock-enabled false" $AUTH_USER
    exit 0 ;;
  *)
    su -c "DISPLAY=:0 dconf write /org/gnome/desktop/screensaver/lock-enabled true" $AUTH_USER
    exit 0 ;;
esac

exit 6

PAM Script to Turn off auto screen-lock in Gnome Shell

I’ve created a new version of this script that can be run by NetworkManager, turning Gnome screensaver auto-lock on or off as the wireless essid changes.

In Linux, we have Pluggable Authentication Modules and various applications use PAM to authenticate users. Marco Ditri posted about using PAM to run a script that would prevent xscreensaver from locking the screen on his laptop when connected to his home wireless network.

I wanted to do the same in Gnome, so I’ve modified Marco’s script to use gsettings to disable Gnome Shell auto screen-lock when authenticated to particular wireless networks and enable it everywhere else. You’ll find comments in the script on how to incorporate it in your local PAM configuration.

#!/bin/sh -e

# Turn off gnome auto screen-lock when connected to specific wireless networks

# USAGE
# Add the following to /etc/pam.d/gdm-password, just after pam_gnome_keyring.so in the auth block:
#   auth optional pam_exec.so quiet /usr/local/sbin/pam_auth_inhibit_lock

# Hat tip - md, http://blog.bofh.it/debian/id_444

WIRELESS_IFACE=wlan0
AUTH_ESSID=orchard
AUTH_USER=steve

# return the ESSID of this interface
current_essid() {
  /sbin/iwconfig $1 | sed -nre '/ESSID/s/.*ESSID:"([^"]+)".*/\1/p'
}

# automatically unlock only for these users
case "$PAM_USER" in
  "")         echo "This program must be run by pam_auth.so!"
              exit 1
              ;;

  $AUTH_USER) ;;

  *)          exit 1
              ;;
esac

CURRENT_ESSID=$(current_essid $WIRELESS_IFACE)

# automatically turn off auto screen-lock when connected to these networks,
# otherwise turn on auto screen-lock
case "$CURRENT_ESSID" in
  $AUTH_ESSID)
    su -c "DISPLAY=:0 gsettings set org.gnome.desktop.screensaver lock-enabled false" $AUTH_USER
    exit 1
    ;;
  *)
    su -c "DISPLAY=:0 gsettings set org.gnome.desktop.screensaver lock-enabled true" $AUTH_USER
    exit 1
    ;;
esac

exit 6