use of org.craftercms.core.xml.mergers.impl.cues.MergeCue in project core by craftercms.
the class DescriptorMergerImplTest method setUpTestMerger.
private void setUpTestMerger() {
MergeCueResolverImpl mergeCueResolver = new MergeCueResolverImpl();
ElementMergeMatcherImpl elementMergeMatcher = new ElementMergeMatcherImpl();
elementMergeMatcher.setIdAttributeName(new QName(MergeParentAndChildMergeCueTest.ID_ATTR_NAME));
UseChildMergeCue overrideParentMergeCue = new UseChildMergeCue();
overrideParentMergeCue.setPriority(OVERRIDE_PARENT_MERGE_CUE_PRIORITY);
UseParentMergeCue disallowOverrideMergeCue = new UseParentMergeCue();
disallowOverrideMergeCue.setPriority(DISALLOW_OVERRIDE_MERGE_CUE_PRIORITY);
UseParentMergeCue useParentIfAvailableMergeCue = new UseParentMergeCue();
useParentIfAvailableMergeCue.setPriority(USE_PARENT_MERGE_CUE_PRIORITY);
MergeParentAndChildMergeCue mergeWithParentMergeCue = new MergeParentAndChildMergeCue();
mergeWithParentMergeCue.setPriority(MERGE_WITH_PARENT_MERGE_CUE_PRIORITY);
mergeWithParentMergeCue.setElementMergeMatcher(elementMergeMatcher);
mergeWithParentMergeCue.setMergeCueResolver(mergeCueResolver);
mergeWithParentMergeCue.setMergeOrderParamName(MergeParentAndChildMergeCueTest.MERGE_ORDER_PARAM_NAME);
mergeWithParentMergeCue.setDefaultMergeOrder(MergeParentAndChildMergeCueTest.DEFAULT_MERGE_ORDER);
MergeParentAndChildMergeCue mergeWithChildMergeCue = new MergeParentAndChildMergeCue();
mergeWithChildMergeCue.setPriority(MERGE_WITH_CHILD_MERGE_CUE_PRIORITY);
mergeWithChildMergeCue.setElementMergeMatcher(elementMergeMatcher);
mergeWithChildMergeCue.setMergeCueResolver(mergeCueResolver);
mergeWithChildMergeCue.setMergeOrderParamName(MergeParentAndChildMergeCueTest.MERGE_ORDER_PARAM_NAME);
mergeWithChildMergeCue.setDefaultMergeOrder(MergeParentAndChildMergeCueTest.DEFAULT_MERGE_ORDER);
UseParentIfNotEmptyMergeCue defaultParentMergeCue = new UseParentIfNotEmptyMergeCue();
defaultParentMergeCue.setPriority(DEFAULT_PARENT_MERGE_CUE_PRIORITY);
UseChildIfNotEmptyMergeCue defaultChildMergeCue = new UseChildIfNotEmptyMergeCue();
defaultParentMergeCue.setPriority(DEFAULT_CHILD_MERGE_CUE_PRIORITY);
Map<QName, MergeCue> parentMergeCues = new HashMap<QName, MergeCue>(2);
parentMergeCues.put(new QName(DISALLOW_OVERRIDE_MERGE_CUE_ATTR_NAME), disallowOverrideMergeCue);
parentMergeCues.put(new QName(MERGE_WITH_CHILD_MERGE_CUE_ATTR_NAME), mergeWithChildMergeCue);
Map<QName, MergeCue> childMergeCues = new HashMap<QName, MergeCue>(3);
childMergeCues.put(new QName(OVERRIDE_PARENT_MERGE_CUE_ATTR_NAME), overrideParentMergeCue);
childMergeCues.put(new QName(USE_PARENT_MERGE_CUE_ATTR_NAME), useParentIfAvailableMergeCue);
childMergeCues.put(new QName(MERGE_WITH_PARENT_MERGE_CUE_ATTR_NAME), mergeWithParentMergeCue);
mergeCueResolver.setParentMergeCues(parentMergeCues);
mergeCueResolver.setChildMergeCues(childMergeCues);
mergeCueResolver.setDefaultParentMergeCue(defaultParentMergeCue);
mergeCueResolver.setDefaultChildMergeCue(defaultChildMergeCue);
merger = new DescriptorMergerImpl();
merger.setInitialMergeCue(mergeWithChildMergeCue);
}
use of org.craftercms.core.xml.mergers.impl.cues.MergeCue in project core by craftercms.
the class MergeCueResolverImplTest method setUpTestResolver.
private void setUpTestResolver() {
Map<QName, MergeCue> parentMergeCues = new HashMap<QName, MergeCue>(2);
parentMergeCues.put(new QName("hp"), hiPriorityParentMergeCue);
parentMergeCues.put(new QName("lp"), loPriorityParentMergeCue);
Map<QName, MergeCue> childMergeCues = new HashMap<QName, MergeCue>(2);
childMergeCues.put(new QName("hp"), hiPriorityChildMergeCue);
childMergeCues.put(new QName("lp"), loPriorityChildMergeCue);
resolver = new MergeCueResolverImpl();
resolver.setParentMergeCues(parentMergeCues);
resolver.setChildMergeCues(childMergeCues);
resolver.setDefaultParentMergeCue(loPriorityParentMergeCue);
resolver.setDefaultChildMergeCue(loPriorityChildMergeCue);
}
use of org.craftercms.core.xml.mergers.impl.cues.MergeCue in project core by craftercms.
the class MergeCueResolverImpl method getMergeCue.
@Override
public MergeCueContext getMergeCue(Element parent, Element child) {
MergeCue parentMergeCue;
MergeCue childMergeCue;
Attribute parentMergeCueAttribute = getMergeCueAttribute(parent, parentMergeCues);
if (parentMergeCueAttribute != null) {
parentMergeCue = parentMergeCues.get(parentMergeCueAttribute.getQName());
} else {
parentMergeCue = defaultParentMergeCue;
}
Attribute childMergeCueAttribute = getMergeCueAttribute(child, childMergeCues);
if (childMergeCueAttribute != null) {
childMergeCue = childMergeCues.get(childMergeCueAttribute.getQName());
} else {
childMergeCue = defaultChildMergeCue;
}
MergeCue chosenMergeCue;
Map<String, String> mergeCueParams;
if (parentMergeCue.getPriority() > childMergeCue.getPriority()) {
chosenMergeCue = parentMergeCue;
if (parentMergeCueAttribute != null) {
mergeCueParams = getMergeCueParams(parent, parentMergeCueAttribute);
} else {
mergeCueParams = Collections.emptyMap();
}
} else {
chosenMergeCue = childMergeCue;
if (childMergeCueAttribute != null) {
mergeCueParams = getMergeCueParams(child, childMergeCueAttribute);
} else {
mergeCueParams = Collections.emptyMap();
}
}
return new MergeCueContext(chosenMergeCue, parent, child, mergeCueParams);
}
Aggregations