Search in sources :

Example 1 with MergeCue

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);
}
Also used : UseParentMergeCue(org.craftercms.core.xml.mergers.impl.cues.impl.UseParentMergeCue) UseParentIfNotEmptyMergeCue(org.craftercms.core.xml.mergers.impl.cues.impl.UseParentIfNotEmptyMergeCue) HashMap(java.util.HashMap) QName(org.dom4j.QName) MergeParentAndChildMergeCue(org.craftercms.core.xml.mergers.impl.cues.impl.MergeParentAndChildMergeCue) MergeCueResolverImpl(org.craftercms.core.xml.mergers.impl.cues.impl.MergeCueResolverImpl) UseChildIfNotEmptyMergeCue(org.craftercms.core.xml.mergers.impl.cues.impl.UseChildIfNotEmptyMergeCue) MergeParentAndChildMergeCue(org.craftercms.core.xml.mergers.impl.cues.impl.MergeParentAndChildMergeCue) UseParentMergeCue(org.craftercms.core.xml.mergers.impl.cues.impl.UseParentMergeCue) MergeCue(org.craftercms.core.xml.mergers.impl.cues.MergeCue) UseParentIfNotEmptyMergeCue(org.craftercms.core.xml.mergers.impl.cues.impl.UseParentIfNotEmptyMergeCue) UseChildMergeCue(org.craftercms.core.xml.mergers.impl.cues.impl.UseChildMergeCue) UseChildMergeCue(org.craftercms.core.xml.mergers.impl.cues.impl.UseChildMergeCue) ElementMergeMatcherImpl(org.craftercms.core.xml.mergers.impl.cues.impl.ElementMergeMatcherImpl) UseChildIfNotEmptyMergeCue(org.craftercms.core.xml.mergers.impl.cues.impl.UseChildIfNotEmptyMergeCue)

Example 2 with MergeCue

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);
}
Also used : HashMap(java.util.HashMap) QName(org.dom4j.QName) MergeCue(org.craftercms.core.xml.mergers.impl.cues.MergeCue)

Example 3 with MergeCue

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);
}
Also used : Attribute(org.dom4j.Attribute) MergeCueContext(org.craftercms.core.xml.mergers.impl.cues.MergeCueContext) MergeCue(org.craftercms.core.xml.mergers.impl.cues.MergeCue)

Aggregations

MergeCue (org.craftercms.core.xml.mergers.impl.cues.MergeCue)3 HashMap (java.util.HashMap)2 QName (org.dom4j.QName)2 MergeCueContext (org.craftercms.core.xml.mergers.impl.cues.MergeCueContext)1 ElementMergeMatcherImpl (org.craftercms.core.xml.mergers.impl.cues.impl.ElementMergeMatcherImpl)1 MergeCueResolverImpl (org.craftercms.core.xml.mergers.impl.cues.impl.MergeCueResolverImpl)1 MergeParentAndChildMergeCue (org.craftercms.core.xml.mergers.impl.cues.impl.MergeParentAndChildMergeCue)1 UseChildIfNotEmptyMergeCue (org.craftercms.core.xml.mergers.impl.cues.impl.UseChildIfNotEmptyMergeCue)1 UseChildMergeCue (org.craftercms.core.xml.mergers.impl.cues.impl.UseChildMergeCue)1 UseParentIfNotEmptyMergeCue (org.craftercms.core.xml.mergers.impl.cues.impl.UseParentIfNotEmptyMergeCue)1 UseParentMergeCue (org.craftercms.core.xml.mergers.impl.cues.impl.UseParentMergeCue)1 Attribute (org.dom4j.Attribute)1