}
Map originalProfile;
Map baseProfile;
String baseType, baseRole, baseID, rootElementName;
DocumentFragment originalFragment;
DocumentFragment delta;
SessionContext context = this.getContext(true);
originalProfile = this.retrieveProfile(this.getProfileID(type, role, id, adminProfile));
if (originalProfile == null) {
throw new ProcessingException("buildProfileDelta: no profile found for " +
type + " - " + role + " - " + id + ".");
}
if (type.equals(PortalManager.BUILDTYPE_VALUE_ID) == true) {
baseType = PortalManager.BUILDTYPE_VALUE_ROLE;
baseRole = role;
baseID = null;
rootElementName = "user-delta";
} else if (type.equals(PortalManager.BUILDTYPE_VALUE_ROLE) == true) {
baseType = PortalManager.BUILDTYPE_VALUE_GLOBAL;
baseRole = null;
baseID = null;
rootElementName = "role-delta";
} else if (type.equals(PortalManager.BUILDTYPE_VALUE_GLOBAL) == true) {
baseType = PortalManager.BUILDTYPE_VALUE_BASIC;
baseRole = null;
baseID = null;
rootElementName = "global-delta";
} else {
throw new ProcessingException("buildProfileDelta: type '"+type+"' not allowed.");
}
// the profile is created as we dont want to use any memory representation!
this.createProfile(context, baseType, baseRole, baseID, adminProfile);
baseProfile = this.retrieveProfile(this.getProfileID(baseType, baseRole, baseID, adminProfile));
if (baseProfile == null) {
throw new ProcessingException("buildProfileDelta: no baseProfile found.");
}
originalFragment = (DocumentFragment)originalProfile.get(PortalConstants.PROFILE_PROFILE);
delta = originalFragment.getOwnerDocument().createDocumentFragment();
delta.appendChild(delta.getOwnerDocument().createElementNS(null, rootElementName));
// Copy portal content
Node profileDelta = DOMUtil.getFirstNodeFromPath(originalFragment, new String[] {"profile","portal-profile"}, false).cloneNode(true);
delta.getFirstChild().appendChild(profileDelta);
// Diff layout profile, coplet profile, personal profile but not status profile!
this.diff(originalFragment,
(DocumentFragment)baseProfile.get(PortalConstants.PROFILE_PROFILE),
"profile/layout-profile",
(Element)delta.getFirstChild());
this.diff(originalFragment,
(DocumentFragment)baseProfile.get(PortalConstants.PROFILE_PROFILE),
"profile/coplets-profile",
(Element)delta.getFirstChild());
if (type.equals(PortalManager.BUILDTYPE_VALUE_GLOBAL) == true) {
profileDelta = DOMUtil.getFirstNodeFromPath(originalFragment, new String[] {"profile","personal-profile"}, false).cloneNode(true);
delta.getFirstChild().appendChild(profileDelta);
} else {
this.diff(originalFragment,
(DocumentFragment)baseProfile.get(PortalConstants.PROFILE_PROFILE),
"profile/personal-profile",
(Element)delta.getFirstChild());
}
// check for the highes coplet number
Node[] miscNodes = (Node[])originalProfile.get(PortalConstants.PROFILE_MISC_POINTER);
Element lastCoplet = (Element)miscNodes[PortalConstants.PROFILE_MISC_LAST_COPLET_NODE];