This page was generated
March  13,  2012
4:49  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.

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:flush-scope This function unloads all application plugins from a given scope.
plugin:implementations This function returns a map referencing all of the plugins that implement the specified capability.
plugin:initialize-scope This function ensures the availability of all plugins from a given scope.
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,
[$scope 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.
$scope (optional): A scope identifier. This must be a "dotted" package-style path, which will be resolved relative to the marklogic-dir/Assets/plugins directory. For example, a $scope value of my-plugin-scope is resolved to the marklogic-dir/Assets/plugins/myplugin-scope directory and a $scope value of my.plugin.scope is resolved to the marklogic-dir/Assets/plugins/my/plugin/scope directory.

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,
[$scope 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.
$scope (optional): A scope identifier. This must be a "dotted" package-style path, which will be resolved relative to the marklogic-dir/Assets/plugins directory. For example, a $scope value of my-plugin-scope is resolved to the marklogic-dir/Assets/plugins/myplugin-scope directory and a $scope value of my.plugin.scope is resolved to the marklogic-dir/Assets/plugins/my/plugin/scope directory.

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:flush-scope(
$scope as xs:string
)  as   empty-sequence()
Summary:

This function unloads all application plugins from a given scope. Note that system plugins are unaffected by this function. Like plugin:initialize-scope, this function requires the application-plugin-registrar role.

Parameters:
$scope : A scope identifier. This must be a "dotted" package-style path, which will be resolved relative to the marklogic-dir/Assets/plugins directory. For example, a $scope value of my-plugin-scope is resolved to the marklogic-dir/Assets/plugins/myplugin-scope directory and a $scope value of my.plugin.scope is resolved to the marklogic-dir/Assets/plugins/my/plugin/scope directory.

Required Privilege:

This function requires the privileges in the application-plugin-registrar role, and the best practice is to put plugin:flush-scope in a function that is amped to the application-plugin-registrar role.

Example:
xquery version "1.0-ml"; 
 
import module namespace plugin = "http://marklogic.com/xdmp/plugin" 
    at "/MarkLogic/plugin.xqy";

plugin:flush-scope("my-plugin-scope")

plugin:implementations(
$capability as xs:string,
[$scope 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.
$scope (optional): A scope identifier. This must be a "dotted" package-style path, which will be resolved relative to the marklogic-dir/Assets/plugins directory. For example, a $scope value of my-plugin-scope is resolved to the marklogic-dir/Assets/plugins/myplugin-scope directory and a $scope value of my.plugin.scope is resolved to the marklogic-dir/Assets/plugins/my/plugin/scope directory.

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:initialize-scope(
$scope as xs:string
)  as   xs:integer
Summary:

This function ensures the availability of all plugins from a given scope. A scope is a directory relative to marklogic-dir/Assets/plugins. Attempting to reload the System scope (with an empty string for $scope) has no effect (and hence returns 0). Any application that calls this function must do so through a function amped to the application-plugin-registrar role.

This function MUST be called by an application before querying or enumerating plugins (or else see an empty set of available plugins). Even if called on every request, this function will only load from the directory on the first call. This function checks the global debug flag, and if true, forces a reload on every request.


Parameters:
$scope : A scope identifier. This must be a "dotted" package-style path, which will be resolved relative to the marklogic-dir/Assets/plugins directory. For example, a $scope value of my-plugin-scope is resolved to the marklogic-dir/Assets/plugins/myplugin-scope directory and a $scope value of my.plugin.scope is resolved to the marklogic-dir/Assets/plugins/my/plugin/scope directory.

Required Privilege:

This function requires the privileges in the application-plugin-registrar role, and the best practice is to put plugin:initialize-scope in a a function that is amped to the application-plugin-registrar role.


Example:
xquery version "1.0-ml"; 
 
import module namespace plugin = "http://marklogic.com/xdmp/plugin" 
    at "/MarkLogic/plugin.xqy";

plugin:initialize-scope("my-plugin-scope")
 

plugin:plugins(
$capability as xs:string*,
[$scope 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.
$scope (optional): A scope identifier. This must be a "dotted" package-style path, which will be resolved relative to the marklogic-dir/Assets/plugins directory. For example, a $scope value of my-plugin-scope is resolved to the marklogic-dir/Assets/plugins/myplugin-scope directory and a $scope value of my.plugin.scope is resolved to the marklogic-dir/Assets/plugins/my/plugin/scope directory.

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. It returns the URI of the plugin.

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 as 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. :)