Hook
From Friend2Friend Wiki
Hooks are the only resource apart from scripts that apply both clientside and serverside. Like services and displays, they are XSL-based, but they are more perform a different, more extensible function.
Contents |
Hooks as Opposed to Services/Displays
While services are general subroutines, which may have any arguments (e.g. Hello World), hooks are functions of their non-empty XML contens. Services or displays are always implemented by the same XSL transform, provided by the module which defines them. Hooks, on the other hand, may use different XSL transforms for different data items; the processing is chosen according to the namespace of the XML elements processed.
Handlers
Soft-system compilation builds a list of alternative transforms, called handlers, that may apply to the contents of a <f2f:hookreq'>. If the namespace of an element has a handler, then this XSL is used. If there is no specific handler, a wildcard XSL transform applies.
This permits modules to define how their own data should be processed. For example, by declaring a handler for the "http://friend2friend.net/modules/icon/hooks/get" icon, modules can define how their datatypes should be displayed. This may be as simple as picking a static SVG image according to the element, but could also be more complex.
Core Hooks
As well as custom hooks, some hooks are provided by F2F core:
- http://friend2friend.net/hooks/add - For adding data items
- http://friend2friend.net/hooks/delete - For deleting data items
- http://friend2friend.net/hooks/image - For returning an image representation
- http://friend2friend.net/hooks/get-resource - For returning a resource
- http://friend2friend.net/hooks/imageURI - For returning an identifier of an image representation
- http://friend2friend.net/hooks/parent - For returning the parent data item
- http://friend2friend.net/hooks/render - For transforming data items into XHTML
- http://friend2friend.net/hooks/schema - For returning the schema of data
- http://friend2friend.net/hooks/validate - For validating data