Skip to content

Instantly share code, notes, and snippets.

robvalk /
Created October 5, 2015 01:17
XSLT Extension Functions
package com.sample.xslt;
import java.util.Random;
import net.sf.saxon.s9api.ExtensionFunction;
import net.sf.saxon.s9api.ItemType;
import net.sf.saxon.s9api.OccurrenceIndicator;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.SequenceType;
robvalk /
Last active October 29, 2019 15:22
LDAP Security in Mule
import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;
import org.mule.api.transport.PropertyScope;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class UserACLExtractor implements Callable {
private static final Logger log = LoggerFactory.getLogger(UserACLExtractor.class);
import org.mule.api.transport.OutputHandler
// store the current payload at the time the script is invoked
// (i.e. the back-end response stream/iterator)
def itr = payload;
// return a Groovy closure / lambda
return {evt, out ->
// define a stream XML builder object
robvalk /
Created December 1, 2014 01:36
Mule OutputHandler class
* Copyright (c) MuleSoft, Inc. All rights reserved.
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
package org.mule.api.transport;
import org.mule.api.MuleEvent;
robvalk / xml2map.groovy
Created December 2, 2013 09:50
Groovy data mapping from XML to Java Lists/Maps
// no need to use builder here, just raw Groovy map syntax
//get DOMCategory to get access to GPATH style operations like getNode getNodeAt etc.
//declare a java.util.Map to hold results
def result = [:]
//get input root element
def _in = payload.documentElement
use(DOMCategory) {
robvalk / map2xml.groovy
Created December 2, 2013 09:48
Groovy mapping from Java Lists / Maps to XML (w3c DOM)
//import GroovyMap to get a handle to the transformation method - toXmlDom()
//DOMCategory to get us xpath style operations eg.getNode, getAttributes while traversing through the xml
import groovy.xml.XmlUtil;
//import static codeset cross-referencing helper class, see below for lookups
return GroovyMap.toXmlDom(payload) {
robvalk / xml2xml.groovy
Created December 2, 2013 09:44
Sample XML to XML data mapping using Groovy builders. Input and output are both w3c DOM object trees.
//import the GroovyMap
//We have a customized version of DOMCategory helper class, this provides us with xpath like features to access elements
//The default version involves a slightly different syntax.
//GroovyMap's toXMLDom() method takes input as the root/documentElement of the XML tree, type @Element
//very similar to accessing the root element in Java - payload.getDocumentElement()
return GroovyMap.toXmlDom(payload.documentElement) {
//inputs is a list of input arguments
robvalk / GroovyMap.groovy
Created December 2, 2013 09:34
Simple Data Mapping utility that lets developers map between data structures and formats using Groovy Builder syntax.
import groovy.json.JsonBuilder
import groovy.xml.MarkupBuilder
import groovy.xml.NamespaceBuilder;
import groovy.xml.XmlUtil
robvalk /
Created March 6, 2012 09:15 — forked from jonseymour/type-and-null-safe-meta-data.txt
Null and type safe meta data for Java
// given
public abstract class Safely<R, V> {
public final V from(R root) {
return access(root)
} catch(NullPointerException npe) {
return null;