Package org.mycore.mods.merger
Class MCRMerger
java.lang.Object
org.mycore.mods.merger.MCRMerger
- Direct Known Subclasses:
MCRAbstractMerger
,MCRCategoryMerger
,MCRExtentMerger
,MCRIdentifierMerger
,MCRNameMerger
,MCRRelatedItemMerger
,MCRTitleInfoMerger
,MCRUniqueMerger
,MCRUniqueTypeMerger
MCRMerger is the main and default implementation for comparing
and merging MODS elements that are semantically the same.
Each MODS element is wrapped by an instance of MCRMerger or one of its subclasses.
It contains methods to decide whether the two MODS elements are equal, or probably represent the information
maybe with different granularity.
If so, the text, elements and attributes are merged so that the "better" information/representation wins.
This is done recursively for all child elements, too.
- Author:
- Frank Lützenkirchen
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Two mergers are equal if they wrap elements that are deep equals.Helper method to lookup child elements by XPath.boolean
isProbablySameAs
(MCRMerger other) Returns true, if the element wrapped by this merger probably represents the same information as the other.protected void
mergeAttributes
(MCRMerger other) Copies those attributes from the other's element into this' element that do not exist in this' element.protected void
mergeElements
(MCRMerger other) Merges all child elements of this with that from other.void
Merges the contents of the element wrapped by the other merger into the contents of the element wrapped by this merger.void
setElement
(Element element) Sets the MODS element wrapped and compared by this merger
-
Field Details
-
element
The MODS element wrapped and compared by this merger
-
-
Constructor Details
-
MCRMerger
public MCRMerger()
-
-
Method Details
-
setElement
Sets the MODS element wrapped and compared by this merger -
isProbablySameAs
Returns true, if the element wrapped by this merger probably represents the same information as the other. The default implementation returns false and may be overwritten by subclasses implementing logic for specific MODS elements. -
equals
Two mergers are equal if they wrap elements that are deep equals. -
mergeFrom
Merges the contents of the element wrapped by the other merger into the contents of the element wrapped by this merger. Should only be called if this.isProbablySameAs(other). The default implementation copies all attributes from the other into this if they do not exist in this element. Afterwards it recursively builds mergers for all child elements and compares and eventually merges them too. -
mergeAttributes
Copies those attributes from the other's element into this' element that do not exist in this' element. -
mergeElements
Merges all child elements of this with that from other. This is done by building MCRMerger instances for each child element and comparing them. -
getNodes
Helper method to lookup child elements by XPath.- Parameters:
xPath
- XPath expression relative to the element wrapped by this merger.- Returns:
- a list of elements matching the given XPath
-