Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-9591

Support Saxon integrated extension functions

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 2.17.0
    • camel-xslt
    • None
    • Unknown

    Description

      Since Saxon 9.2, writing extension functions has been supplemented by a new mechanism, referred to as integrated extension functions.

      To use such an extension function, user writes a custom class which extends net.sf.saxon.lib.ExtensionFunctionDefinition an registers it in the Saxon transformer factory. It works fine. Only problem is that there's no convenient support in Camel to pass such an extension function reference to camel-xslt.

      Current way:

          // Define my extension functions (note: Saxon requires a class for each function)
          List<ExtensionFunctionDefinition> extensionFunctions = new ArrayList<ExtensionFunctionDefinition>();
          extensionFunctions.add(new MyExtensionFunction1());
          extensionFunctions.add(new MyExtensionFunction2());
          
          // Register extension functions
          TransformerFactoryImpl extendedSaxonTransformerFactory = new TransformerFactoryImpl();
          Configuration configuration = extendedSaxonTransformerFactory.getConfiguration();
          for ( ExtensionFunctionDefinition func : extensionFunctions ) {
              configuration.registerExtensionFunction(func);
          }
      
          // Enable secure processing (note: secure processing allows use of Saxon integrated extension functions as opposed to reflective extension functions)  
          extendedSaxonTransformerFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
      
          // Register transformer factory on Camel
          SimpleRegistry registry = new SimpleRegistry();
          registry.put("extendedSaxonTransformerFactory", extendedSaxonTransformerFactory);
          CamelContext context = new DefaultCamelContext(registry);
      
          // Define Route
          context.addRoutes(new RouteBuilder() {
              @Override
              public void configure() throws Exception {
                  from("direct:start")
                      .to("xslt:transformation/myStyleSheet.xslt?transformerFactory=#extendedSaxonTransformerFactory");
              }
          });
      

      Proposed way:

          // Define my extension functions (note: Saxon requires a class for each function)
          List<ExtensionFunctionDefinition> extensionFunctions = new ArrayList<ExtensionFunctionDefinition>();
          extensionFunctions.add(new MyExtensionFunction1());
          extensionFunctions.add(new MyExtensionFunction2());
      
          // Register extension functions with Camel
          SimpleRegistry registry = new SimpleRegistry();
          registry.put("extensionFunctions", extensionFunctions);
          CamelContext context = new DefaultCamelContext(registry);
      
          // Define Route
          context.addRoutes(new RouteBuilder() {
              @Override
              public void configure() throws Exception {
                  from("direct:start")
                      .to("xslt:transformation/myStyleSheet.xslt?saxon=true&saxonExtensionFunctions=#extensionFunctions&secureProcessing=true");
              }
          });
      

      Attachments

        Activity

          People

            lb Luca Burgazzoli
            lb Luca Burgazzoli
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: