JBoss.orgCommunity Documentation
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:
Client subscribed to document/element
Attribute has been replaced in document or in child element to which client subscribed
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:
Client subscribed to document/element
Attribute has been added in document or in child element to which client subscribed
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:
Client subscribed to attribute
Attribute has been added
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
Note difference between this code above and Section 4.2, “Attribute Add Patch” Similar rules apply to element changes.
Example code assumes following:
Client subscribed to document/element
Attribute has been replaced in document or in child element to which client subscribed
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