use of org.mycore.datamodel.metadata.MCRMetaInterface in project mycore by MyCoRe-Org.
the class MCRObjectMerger method mergeMetadata.
/**
* Merges the metadata of the given source into the target object. Be aware that
* performance isn't that good when validation is activated, due checking against
* the schema each time a change is made.
*
* @param source the source which is merged into the target
* @param validate If true, every change is tracked and validated against the
* xml schema of the mycore object. When a change is invalid it will be
* canceled and the merging continues.
* When set to false the mycore object will be merged without validation.
* This can result in an invalid object.
*
* @return true if something was merged
*/
public boolean mergeMetadata(MCRObject source, boolean validate) {
MCRObjectMetadata targetMetadata = this.target.getMetadata();
boolean merged = false;
for (MCRMetaElement metaElementSource : source.getMetadata()) {
MCRMetaElement metaElementTarget = targetMetadata.getMetadataElement(metaElementSource.getTag());
if (metaElementTarget == null) {
targetMetadata.setMetadataElement(metaElementSource.clone());
if (validate && !validate(this.target)) {
targetMetadata.removeMetadataElement(metaElementSource.getTag());
} else {
merged = true;
}
} else {
for (MCRMetaInterface metaInterfaceSource : metaElementSource) {
boolean equal = false;
for (MCRMetaInterface metaInterfaceTarget : metaElementTarget) {
if (metaInterfaceSource.equals(metaInterfaceTarget)) {
equal = true;
break;
}
}
if (!equal) {
metaElementTarget.addMetaObject(metaInterfaceSource.clone());
if (validate && !validate(this.target)) {
metaElementTarget.removeMetaObject(metaInterfaceSource);
} else {
merged = true;
}
}
}
}
}
return merged;
}
use of org.mycore.datamodel.metadata.MCRMetaInterface in project mycore by MyCoRe-Org.
the class MCREditorOutValidator method checkMetaObject.
public static String checkMetaObject(Element datasubtag, Class<? extends MCRMetaInterface> metaClass, boolean keepLang) {
if (!keepLang) {
datasubtag.removeAttribute("lang", XML_NAMESPACE);
}
MCRMetaInterface test = null;
try {
test = metaClass.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new MCRException("Could not instantiate " + metaClass.getCanonicalName());
}
test.setFromDOM(datasubtag);
test.validate();
return null;
}
Aggregations