Delta Links
Use
The PCD provides delta link information about objects, such as whether the object is a delta link, what attributes were changed, and what attributes were erased.
Most information is derived from an IDlModificationState object that you can derive from the IPcdContext interface, as follows:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
env.put(Context.SECURITY_PRINCIPAL, request.getUser());
env.put(Constants.REQUESTED_ASPECT, IPcdAttribute.PERSISTENCY_ASPECT);
InitialContext iCtx = null;
String lookupObject = "portal_content/myFolder/myObject";
try {
iCtx = new InitialContext(env);
IPcdContext myPcdContext =(IPcdContext) iCtx.lookup(lookupObject);
IDlModificationState myDLState = myPcdContext
.getDlModificationState("");
}
If the object is not a delta link or inherited via a delta link, getDlModificationState() returns null.
Getting Delta Link Information
From an IDlModificationState object, you can perform the following tasks:
-
Get the source object of a delta link.
response.write(myDLState.getSourceUrl()); -
Get all attributes that were changed in a delta link.
Iterator myMods = myDLState.getModifiedAttributeIds(); while (myMods.hasNext()) { response.write("ID: " + myMods.next() + "<BR>"); } -
Get the changes made to a specific attribute of a delta link.
ModificationItem[] myMod = myDLState.getModifications("ForcedRequestLanguage"); for (int i=0;i<myMod.length;i++){ response.write(myMod[i].getAttribute().getID()+"<BR>"); response.write(myMod[i].getModificationOp()+"<BR>"); }The getModificationOp() method returns one of the following constants:
-
DirContext.ADD_ATTRIBUTE
-
DirContext.REMOVE_ATTRIBUTE
-
DirContext.REPLACE_ATTRIBUTE
For each attribute, a delta link stores all the changes made to the attribute, not just the final result.
-
Creating a Delta Link
The following creates a delta link:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
IPcdContext.PCD_INITIAL_CONTEXT_FACTORY);
env.put(Constants.REQUESTED_ASPECT, IPcdAttribute.PERSISTENCY_ASPECT);
env.put(Context.SECURITY_PRINCIPAL, request.getUser());
InitialContext iCtx = null;
String myFolderName = "pcd:portal_content/myFolderB";
try {
iCtx = new InitialContext(env);
IPcdContext myFolderB = (IPcdContext) iCtx.lookup(myFolderName);
myFolderB.createDeltaLink(
"myDL",null,"portal_content/myFolderA/myIView");
}
catch (Exception e) {}
The above creates a PCD object called myDL in myFolderB , which is a delta link to myIView in myFolderA .
Resetting Attributes
The following resets all attributes changed in a delta link object:
myPcdContext.removeModifications("");
The following resets a specific attribute ( ForcedRequestLanguage ) that was changed in a delta link object:
String myAttrsToDelete[] = {"ForcedRequestLanguage"};
myPcdContext.removeAttributeModifications("",myAttrsToDelete);