This page was generated
September  12,  2012
6:02  AM
XQuery & XSLT Built-In & Modules Function Reference

Module: Plugin

The Plugin API module contains functions that allow you to register plugins for use by MarkLogic Server.

The Plugin API is installed as the following file:

install_dir/Modules/MarkLogic/plugin/plugin.xqy

where install_dir is the directory in which MarkLogic Server is installed.

To use the plugin.xqy module in your own XQuery modules, include the following line in your XQuery prolog:

  
   import module namespace plugin = "http://marklogic.com/extension/plugin"  
      at "/MarkLogic/plugin/plugin.xqy";
  

The library uses the plugin: namespace, which is not predefined in the server.

MarkLogic recommends enabling the URI Lexicon when using Plugin; the URI lexicon will improve performance, especially when the database grows to a large number of documents.

Function Summary
plugin:capability This function returns a function pointer implementing a given capability from a particular plugin.
plugin:enumerate This function enumerates functions implementing all capabilities supported by the given plugin.
plugin:implementations This function returns a map referencing all of the plugins that implement the specified capability.
plugin:plugins This function returns unique IDs of the registered plugins that have the specified capabilities.
plugin:register This function registers the capabilities map for use by MarkLogic Server.
Function Detail
plugin:capability(
$capability as xs:string,
$uri as xs:string
)  as   xdmp:function?
Summary:

This function returns a function pointer implementing a given capability from a particular plugin. If the plugin doesn't exist an exception is thrown. If the plugin does exist but the capability isn't present, an empty sequence is returned.

Parameters:
$capability : The desired capability to match.
$uri : The unique identifier of the plugin.

Example:
  xquery version "1.0-ml"; 

  import module namespace plugin = "http://marklogic.com/extension/plugin" 
      at "/MarkLogic/plugin/plugin.xqy";

  plugin:capability(
     "http://marklogic.com/appservices/infostudio/collector/cancel", 
     "plugin:collector-filescan.xqy")

  (: Returns a pointer to the function that implements the 'cancel' capability. :)
    

plugin:enumerate(
$uri as xs:string
)  as   map:map
Summary:

This function enumerates functions implementing all capabilities supported by the given plugin. It returns a map, keyed on the capabilities.

Parameters:
$uri : The unique identifier of the plugin.

Example:

  xquery version "1.0-ml"; 

  import module namespace plugin = "http://marklogic.com/extension/plugin" 
      at "/MarkLogic/plugin/plugin.xqy";

  plugin:enumerate("plugin:collector-filescan.xqy")

  (: Returns the capabilities map for the filescan collector. :)
    

plugin:implementations(
$capability as xs:string
)  as   map:map
Summary:

This function returns a map referencing all of the plugins that implement the specified capability. If no plugins implement the given capability, returns an empty map.

Parameters:
$capability : The desired capability to match.

Example:
  xquery version "1.0-ml"; 

  import module namespace plugin = "http://marklogic.com/extension/plugin" 
      at "/MarkLogic/plugin/plugin.xqy";

  plugin:implementations(
     "http://marklogic.com/appservices/infostudio/collector/cancel")

  (: Returns a pointer to the function that implements the 'cancel' capability 
     for each plugin that implements 'cancel'. :)
    

plugin:plugins(
$capability as xs:string*
)  as   xs:string*
Summary:

This function returns unique IDs of the registered plugins that have the specified capabilities. If no matching plugins are registered, an empty sequence is returned.

Parameters:
$capability : A list of strings representing desired capabilities to match. The plugin must match all of the listed capabilities. Specify an empty sequence to return the IDs of all of the plugins.

Example:
  xquery version "1.0-ml"; 

  import module namespace plugin = "http://marklogic.com/extension/plugin" 
      at "/MarkLogic/plugin/plugin.xqy";

  plugin:plugins("http://marklogic.com/appservices/infostudio/collector/abort")

  (: Lists all collector plugins with the 'abort' capability. :)
    

plugin:register(
$capabilities as map:map,
$plugin-uri as xs:string
)  as   xs:string
Summary:

This function registers the capabilities map for use by MarkLogic Server.

Parameters:
$capabilities : The map of capabilities to be registered.
$plugin-uri : An identifier that uniquely identifies this plugin. If a plugin is added with the same identifier an existing plugin, then the newly registered plugin will be used.

Required Privilege:

http://marklogic.com/xdmp/privileges/plugin-register


Example:
  xquery version "1.0-ml"; 

  declare namespace testdoc = "http://marklogic.com/extension/plugin/testdoc";

  import module namespace plugin = "http://marklogic.com/extension/plugin" 
      at "/MarkLogic/plugin/plugin.xqy";

  declare function testdoc:capabilities() 
  as map:map
  {
    let $map := map:map()
    let $_ := map:put($map, "http://marklogic.com/appservices/infostudio/collector/model", 
                       xdmp:function(xs:QName("testdoc:model")))
    let $_ := map:put($map, "http://marklogic.com/appservices/infostudio/collector/start",  
                       xdmp:function(xs:QName("testdoc:start")))
    let $_ := map:put($map, "http://marklogic.com/appservices/infostudio/collector/config-view",  
                       xdmp:function(xs:QName("testdoc:view")))
    let $_ := map:put($map, "http://marklogic.com/appservices/infostudio/collector/cancel",  
                       xdmp:function(xs:QName("testdoc:cancel")))
    let $_ := map:put($map, "http://marklogic.com/appservices/infostudio/collector/abort",  
                       xdmp:function(xs:QName("testdoc:abort")))
    let $_ := map:put($map, "http://marklogic.com/appservices/infostudio/collector/validate",  
                       xdmp:function(xs:QName("testdoc:validate")))
    let $_ := map:put($map, "http://marklogic.com/appservices/string",  
                       xdmp:function(xs:QName("testdoc:string")))
    return $map
  };

  (: Implement the functions in the capabilities map. :)

  plugin:register(testdoc:capabilities(), "testdoc.xqy")

  (: Registers the capabilities in the map for this plugin. :)