JBoss.orgCommunity Documentation

Mobicents xcap-diff Protocol User Guide


This manual uses several conventions to highlight certain words and phrases and draw attention to specific pieces of information.

In PDF and paper editions, this manual uses typefaces drawn from the Liberation Fonts set. The Liberation Fonts set is also used in HTML editions if the set is installed on your system. If not, alternative but equivalent typefaces are displayed. Note: Red Hat Enterprise Linux 5 and later includes the Liberation Fonts set by default.

Four typographic conventions are used to call attention to specific words and phrases. These conventions, and the circumstances they apply to, are as follows.

Mono-spaced Bold

Used to highlight system input, including shell commands, file names and paths. Also used to highlight key caps and key-combinations. For example:

The above includes a file name, a shell command and a key cap, all presented in Mono-spaced Bold and all distinguishable thanks to context.

Key-combinations can be distinguished from key caps by the hyphen connecting each part of a key-combination. For example:

The first sentence highlights the particular key cap to press. The second highlights two sets of three key caps, each set pressed simultaneously.

If source code is discussed, class names, methods, functions, variable names and returned values mentioned within a paragraph will be presented as above, in Mono-spaced Bold. For example:

Proportional Bold

This denotes words or phrases encountered on a system, including application names; dialogue box text; labelled buttons; check-box and radio button labels; menu titles and sub-menu titles. For example:

The above text includes application names; system-wide menu names and items; application-specific menu names; and buttons and text found within a GUI interface, all presented in Proportional Bold and all distinguishable by context.

Note the > shorthand used to indicate traversal through a menu and its sub-menus. This is to avoid the difficult-to-follow 'Select Mouse from the Preferences sub-menu in the System menu of the main menu bar' approach.

Mono-spaced Bold Italic or Proportional Bold Italic

Whether Mono-spaced Bold or Proportional Bold, the addition of Italics indicates replaceable or variable text. Italics denotes text you do not input literally or displayed text that changes depending on circumstance. For example:

Note the words in bold italics above username, domain.name, file-system, package, version and release. Each word is a placeholder, either for text you enter when issuing a command or for text displayed by the system.

Aside from standard usage for presenting the title of a work, italics denotes the first use of a new and important term. For example:

If you find a typographical error in this manual, or if you have thought of a way to make this manual better, we would love to hear from you! Please submit a report in the the Issue Tracker, against the product Mobicents xcap-diff Protocol, or contact the authors.

When submitting a bug report, be sure to mention the manual's identifier: XCAPDiff_Protocols_User_Guide

If you have a suggestion for improving the documentation, try to be as specific as possible when describing it. If you have found an error, please include the section number and some of the surrounding text so we can find it easily.

The xcap-diff is defined in http://tools.ietf.org/html/rfc5875 . However to understand it fully you need to have understanding of following:

XML

XPath

XPath expression are used to navigate through XML document and identify specific nodes in it. XPath is defined in this http://www.w3.org/TR/xpath20/ document.

XCAP

Minimal knowledge how XCAP interaction looks like is required. This protocol is defined in http://tools.ietf.org/html/rfc4825

XML Diff/XML Patch

XCAP Diff is an extension to XML Diff . Strong knowledge of the latter is required. This protocol is defined in http://tools.ietf.org/html/rfc5261

SIP Notification framework

http://tools.ietf.org/html/rfc3265

XCAP Diff Notification framework

http://tools.ietf.org/html/rfc5875

The xcap-diff has been divided into following components:

XML Patch instructions builder

component which is capable of creating patching instructions consistent with rfc5261 .

Attribute Patch instruction builder

component which is capable of creating xcap-diff attribute patching instructions

Element Patch instruction builder

component which is capable of creating xcap-diff element patching instructions

Document Patch instruction builder

component which is capable of creating xcap-diff document wide patch instructions(in particular aggregate instructions generated by Section 2.1, “XML Patch Instruction Builder” )

XCAP Patch builder

simple component which builds well formed document from patching operations.

XCAP Patch applier

simple component which is capable of applying patching instructions to document.

The API definition for all above components make use of Java generics. Reason for this is to make this library agnostic to specific implementation of XML manipulation library.

XML Patch instruction builder is defined as follows:



public interface XmlPatchOperationsBuilder<D,P, E, N> {
    public static final String XML_PATCH_OPS_NAMESPACE = "urn:ietf:params:xml:schema:patch-ops";
    public enum Pos {
        prepend, before, after
    }
    public enum Ws {
        before, after, both
    }
    public P addAttribute(String sel, String attrName, String attrValue,
            Map<String, String> namespaceBindings) throws BuildPatchException;
    public P addElement(String sel, E element,
            Map<String, String> namespaceBindings) throws BuildPatchException;
    public P addNode(String sel, Pos pos, N node,
            Map<String, String> namespaceBindings) throws BuildPatchException;
    public P addPrefixNamespaceDeclaration(String sel, String namespacePrefix,
            String namespaceValue, Map<String, String> namespaceBindings)
            throws BuildPatchException;
    public P replaceAttribute(String sel, String attributeValue,
            Map<String, String> namespaceBindings) throws BuildPatchException;
    public P replaceElement(String sel, E element,
            Map<String, String> namespaceBindings) throws BuildPatchException;
    public P replaceNode(String sel, N node,
            Map<String, String> namespaceBindings) throws BuildPatchException;
    public P replacePrefixNamespaceDeclaration(String sel,
            String namespaceValue, Map<String, String> namespaceBindings)
            throws BuildPatchException;
    public P removeAttribute(String sel, Map<String, String> namespaceBindings)
            throws BuildPatchException;
    public P removeElement(String sel, Ws ws,
            Map<String, String> namespaceBindings) throws BuildPatchException;
    public P removeNode(String sel, Map<String, String> namespaceBindings)
            throws BuildPatchException;
    public P removePrefixNamespaceDeclaration(String sel,
            Map<String, String> namespaceBindings) throws BuildPatchException;
    public P[] buildPatchInstructions(D originalDocument, D patchedDocument)
            throws BuildPatchException;
}
        

Above code uses following generics:

public P addAttribute(String sel, String attrName, String attrValue, Map<String, String> namespaceBindings) throws BuildPatchException;

Creates patch operation to add new attribute into document.

public P addElement(String sel, E element, Map<String, String> namespaceBindings) throws BuildPatchException;

Creates patch operation to add new element into document.

public P addNode(String sel, N node, Map<String, String> namespaceBindings) throws BuildPatchException;

Creates patch operation to add new node into document.

public P addPrefixNamespaceDeclaration(String sel, String namespacePrefix, String namespaceValue, Map<String, String> namespaceBindings) throws BuildPatchException;

Creates patch operation to insert new namespace into document.

public P replaceAttribute(String sel, String attributeValue, Map<String, String> namespaceBindings) throws BuildPatchException;

Creates patch operation to replace existing attribute.

public P replaceElement(String sel, E element, Map<String, String> namespaceBindings) throws BuildPatchException;

Creates patch operation to replace exisiting element in document.

public P replaceNode(String sel, N node, Map<String, String> namespaceBindings) throws BuildPatchException;

Creates patch operation to replace existing node in document.

public P replacePrefixNamespaceDeclaration(String sel, String namespaceValue, Map<String, String> namespaceBindings) throws BuildPatchException;

Creates patch operation to replace exisiting namespace.

public P removeAttribute(String sel, Map<String, String> namespaceBindings) throws BuildPatchException;

Creates patch operation to remove exisiting attribute from document.

public P removeElement(String sel, Ws ws, Map<String, String> namespaceBindings) throws BuildPatchException;

Creates patch operation to remove existing element from document.

public P removeNode(String sel, Map<String, String> namespaceBindings) throws BuildPatchException;

Creates patch operation to remove existing node from document.

public P removePrefixNamespaceDeclaration(String sel, Map<String, String> namespaceBindings) throws BuildPatchException;

Creates patch operation to remove existing namespace from document.

public P[] buildPatchInstructions(D originalDocument, D patchedDocument) throws BuildPatchException;

Compares two documents and creates set of patching operations that need to be applied to first document to be equal to patched one.

XCAP Document Patch instruction builder is defined as follows:



public interface DocumentPatchComponentBuilder<P, D, E, N> {
    public P buildPatchComponent(String sel, String previousETag,
            String newETag, C[] patchingInstructions)
            throws BuildPatchException;
    public P getBodyNotChangedPatchingInstruction() throws BuildPatchException;
    public XmlPatchOperationsBuilder<D,P, E, N> getXmlPatchOperationsBuilder();
}
        
        

Above code uses following generics:

XCAP Patch instruction builder is defined as follows:



public interface XcapDiffPatchBuilder<P, C, D, E, N> {
    public P buildPatch(String xcapRoot, C[] components)
            throws BuildPatchException;
    public AttributePatchComponentBuilder<C> getAttributePatchComponentBuilder();
    public ElementPatchComponentBuilder<C, E> getElementPatchComponentBuilder();
    public DocumentPatchComponentBuilder<C, D, E, N> getDocumentPatchComponentBuilder();
}
        
        

Above code uses following generics:

  1. Downloading the source code

    Use SVN to checkout a specific release source, the base URL is http://mobicents.googlecode.com/svn/tags/protocols/xcap-diff, then add the specific release version, lets consider 1.0.0.BETA1.

    [usr]$ svn co http://mobicents.googlecode.com/svn/tags/protocols/xcap-diff/xcap-diff-1.0.0.BETA1 xcap-diff-1.0.0.BETA1
  2. Building the source code

    Important

    Maven 2.0.9 (or higher) is used to build the release. Instructions for using Maven2, including install, can be found at http://maven.apache.org

    Use Maven to build the binaries.

    				    [usr]$ cd xcap-diff-1.0.0.BETA1
    				    [usr]$ mvn install
    				    

    Once the process finishes you should have the binary jar files in the target directory of module .

Similar process as for Section 3.2.1, “Release Source Code Building”, the only change is the SVN source code URL, which is http://mobicents.googlecode.com/svn/trunk/protocols/xcap-diff.

Following examples are based on current, default DOM implementation of xcap-diff library. However they are valid for any implementation honoring javadoc contracts.

Example code assumes following:



            
            import org.mobicents.protocols.xcap.*; //imports api and default, dom implementation
            import org.w3c.dom.*; //import dom  stuff
            
            DOMXcapDiffFactory xcapDiffFactory = new DOMXcapDiffFactory();
            DOMXcapDiffPatchBuilder xcapDiffPatchBuilder = xcapDiffFactory.getPatchBuilder();
            DOMDocumentPatchComponentBuilder documentPatchComponentBuilder = 
                xcapDiffPatchBuilder.getDocumentPatchComponentBuilder();
            DOMXmlPatchOperationsBuilder xmlPatchOperationsBuilder = 
                documentPatchComponentBuilder.getXmlPatchOperationsBuilder();
            //Note, no namespaces
            String xcapRoot = "http://localhost:8080/default"; //root of server
            String documentSelector = "tests/users/sip:joe@example.com/index";
            String attributeSelector = "house/room[id='main']/switch/@on"; //house status document?
            String attributeNewValue = "true";
            String oldETag = "3416134yyDFGA$v33@!";
            String newETag = "haha";
            
            Element attributeElement = xmlPatchOperationsBuilder
                .replaceAttribute(attributeSelector,attributeNewValue,null); //no namespaces
            
            Element documentElement = documentPatchComponentBuilder
                .buildPatchComponent(documentSelector,oldETag,newETag,
                    new Element[]{attributeElement});
            
            Document xcapDiffDocument = xcapDiffPatchBuilder
                .buildPatch(xcapRoot,new Element[]{documentElement}); //xcap diff patch
                
                
            
            

Example code assumes following:



            
            import org.mobicents.protocols.xcap.*; //imports api and default, dom implementation
            import org.w3c.dom.*; //import dom  stuff
            
            DOMXcapDiffFactory xcapDiffFactory = new DOMXcapDiffFactory();
            DOMXcapDiffPatchBuilder xcapDiffPatchBuilder = xcapDiffFactory.getPatchBuilder();
            DOMDocumentPatchComponentBuilder documentPatchComponentBuilder = 
                xcapDiffPatchBuilder.getDocumentPatchComponentBuilder();
            DOMXmlPatchOperationsBuilder xmlPatchOperationsBuilder = 
                documentPatchComponentBuilder.getXmlPatchOperationsBuilder();
            //Note, no namespaces
            String xcapRoot = "http://localhost:8080/default"; //root of server
            String documentSelector = "tests/users/sip:joe@example.com/index";
            String nodeSelector = "house/room[id='main']/switch"; //house status document?
            String attributeName = "serial";
            String attributeNewValue = "GID-FH56-6235-ZXOP";
            String oldETag = "3416134yyDFGA$v33@!";
            String newETag = "haha";
            
            Element attributeElement = xmlPatchOperationsBuilder
                .addAttribute(nodeSelector,attributeName,attributeNewValue,null); //no namespaces
            
            Element documentElement = documentPatchComponentBuilder
                .buildPatchComponent(documentSelector,oldETag,newETag,
                    new Element[]{attributeElement});
            
            Document xcapDiffDocument = xcapDiffPatchBuilder
                .buildPatch(xcapRoot,new Element[]{documentElement}); //xcap diff patch
                
                
            
            

Example code assumes following:



            
            import org.mobicents.protocols.xcap.*; //imports api and default, dom implementation
            import org.w3c.dom.*; //import dom  stuff
            
            DOMXcapDiffFactory xcapDiffFactory = new DOMXcapDiffFactory();
            DOMXcapDiffPatchBuilder xcapDiffPatchBuilder = xcapDiffFactory.getPatchBuilder();
            DOMAttributePatchComponentBuilder attributePatchComponentBuilder = 
                xcapDiffPatchBuilder.getAttributePatchComponentBuilder();
            //Note, no namespaces
            String xcapRoot = "http://localhost:8080/default"; //root of server
            String documentSelector = "tests/users/sip:joe@example.com/index";
            String attributeSelector = "house/room[id='main']/switch/@serial"; //house status document?
            
            String attributeNewValue = "GID-FH56-6235-ZXOP";
            
            Element attributeElement = attributePatchComponentBuilder
                .buildPatchComponent(attributeSelector,attributeNewValue,null); //no namespaces
            
            
            Document xcapDiffDocument = xcapDiffPatchBuilder
                .buildPatch(xcapRoot,new Element[]{attributeElement}); //xcap diff patch
                
                
            
            

Example code assumes following:



            
            import org.mobicents.protocols.xcap.*; //imports api and default, dom implementation
            import org.w3c.dom.*; //import dom  stuff
            
            DOMXcapDiffFactory xcapDiffFactory = new DOMXcapDiffFactory();
            DOMXcapDiffPatchBuilder xcapDiffPatchBuilder = xcapDiffFactory.getPatchBuilder();
            DOMDocumentPatchComponentBuilder documentPatchComponentBuilder = 
                xcapDiffPatchBuilder.getDocumentPatchComponentBuilder();
            DOMXmlPatchOperationsBuilder xmlPatchOperationsBuilder = 
                documentPatchComponentBuilder.getXmlPatchOperationsBuilder();
            //Note, no namespaces
            String xcapRoot = "http://localhost:8080/default"; //root of server
            String documentSelector = "tests/users/sip:joe@example.com/index";
            String nodeSelector = "house/room[id='main']/switch"; //house status document?
            Element elementNewValue = .....;
            String oldETag = "3416134yyDFGA$v33@!";
            String newETag = "haha";
            
            Element element = xmlPatchOperationsBuilder
                .replaceElement(nodeSelector,elementNewValue,null); //no namespaces
            
            Element documentElement = documentPatchComponentBuilder
                .buildPatchComponent(documentSelector,oldETag,newETag,
                    new Element[]{element});
            
            Document xcapDiffDocument = xcapDiffPatchBuilder
                .buildPatch(xcapRoot,new Element[]{documentElement}); //xcap diff patch
                
                
            
            

The XPath expressions may include namespace prefixes to identify correct resource in document. In such cases XCAP Diff requires namespace declaration its supposed to include in patch. This is required so patch consumers can properly resolve prefixes used in XPath, in order to patch locate target resource in document.

Below is example of patch generation with namespaces in XPath. Note that is similar to ???



            
            import org.mobicents.protocols.xcap.*; //imports api and default, dom implementation
            import org.w3c.dom.*; //import dom  stuff
            
            DOMXcapDiffFactory xcapDiffFactory = new DOMXcapDiffFactory();
            DOMXcapDiffPatchBuilder xcapDiffPatchBuilder = xcapDiffFactory.getPatchBuilder();
            DOMDocumentPatchComponentBuilder documentPatchComponentBuilder = 
                xcapDiffPatchBuilder.getDocumentPatchComponentBuilder();
            DOMXmlPatchOperationsBuilder xmlPatchOperationsBuilder = 
                documentPatchComponentBuilder.getXmlPatchOperationsBuilder();
            //Note, no namespaces
            String xcapRoot = "http://localhost:8080/default"; //root of server
            String documentSelector = "tests/users/sip:joe@example.com/index";
            String attributeSelector = "p:house/room[id='main']/e:switch/@on"; //house status document?
            String attributeNewValue = "true";
            String oldETag = "3416134yyDFGA$v33@!";
            String newETag = "haha";
            Map<String,String> nameSpaces = new HashMap<String,String>();
            nameSpaces.put("e","http://engineer.org/grid/electrical");
            nameSpaces.put("p","http://engineer.org/ownership/private");
            
            
            Element attributeElement = xmlPatchOperationsBuilder
                .replaceAttribute(attributeSelector,attributeNewValue,nameSpaces); //no namespaces
            
            Element documentElement = documentPatchComponentBuilder
                .buildPatchComponent(documentSelector,oldETag,newETag,
                    new Element[]{attributeElement});
            
            Document xcapDiffDocument = xcapDiffPatchBuilder
                .buildPatch(xcapRoot,new Element[]{documentElement}); //xcap diff patch
                
                
            
            

Revision History
Revision 1.0Fri June 30 2011Bartosz Baranowski
Creation of the Mobicents xcap-diff Protocol User Guide.