Mobicents XML Patch Ops Reference Implementation

    Mobicents XML Patch Ops RI

     

    Mobicents provides Reference Implementation of MobicentsXMLPatchOpsAPI. The RI is based on generic DOM model. It depends on xerces implementation of standard XML APIs.

     

     

     

     

    Resources

     

    Limitations

    The RI is not sophisticated. It has been created to address Mobicents specific needs(along with demonstrating how API should be used). As such, it does not cover all corner cases of XML manipulation. Thus it has certain limitations. Here is a list of 'rules' that must be obeyed:

    • Documents must be well formed.
    • Documents which are compared end to end (document vs document) must be flat, cant contain ony 'Element' type nodes

     

     

    Still, it is fully fledged RI of API defined by MobicentsXMLPatchOpsAPI. Thus it supports all RFC mandated features and operations. 

     

     

    Example

    The documentation has fairly good set of examples. However, here is one similar to one present in API article, to show difference with RI

     

    import org.mobicents.protocols.xcap.*; //imports api and default, dom implementation

    import org.w3c.dom.*; //import dom stuff

     

    XcapDiffFactory<Document, Element, Document, Node, Node> xcapDiffFactory = new DOMXcapDiffFactory();

    XcapDiffPatchBuilder<Document, Element, Document, Node, Node> xcapDiffPatchBuilder = xcapDiffFactory.getPatchBuilder();

    DocumentPatchComponentBuilder<Element, Document, Node, Node> documentPatchComponentBuilder = xcapDiffPatchBuilder.getDocumentPatchComponentBuilder();

    XmlPatchOperationsBuilder<Document, Element, Node, Node> 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