Search in sources :

Example 1 with DescriptorMergeStrategy

use of org.craftercms.core.xml.mergers.DescriptorMergeStrategy in project engine by craftercms.

the class TargetedContentDescriptorMergeStrategy method getDescriptors.

@Override
public List<MergeableDescriptor> getDescriptors(Context context, CachingOptions cachingOptions, String mainDescriptorUrl, Document mainDescriptorDom, boolean mainDescriptorOptional) throws XmlMergeException {
    Set<MergeableDescriptor> results = new LinkedHashSet<>();
    List<String> candidateUrls = candidateTargetedUrlsResolver.getUrls(mainDescriptorUrl);
    for (ListIterator<String> iter = candidateUrls.listIterator(candidateUrls.size()); iter.hasPrevious(); ) {
        String candidateUrl = iter.previous();
        if (!candidateUrl.equals(mainDescriptorUrl)) {
            Document descriptorDom = getDescriptorDom(context, cachingOptions, candidateUrl);
            if (descriptorDom != null) {
                DescriptorMergeStrategy mergeStrategy = mergeStrategyResolver.getStrategy(candidateUrl, descriptorDom);
                List<MergeableDescriptor> descriptors = mergeStrategy.getDescriptors(context, cachingOptions, candidateUrl, descriptorDom, true);
                results.addAll(descriptors);
            }
        }
    }
    List<MergeableDescriptor> descriptors = super.getDescriptors(context, cachingOptions, mainDescriptorUrl, mainDescriptorDom, mainDescriptorOptional);
    results.addAll(descriptors);
    return new ArrayList<>(results);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DescriptorMergeStrategy(org.craftercms.core.xml.mergers.DescriptorMergeStrategy) ArrayList(java.util.ArrayList) MergeableDescriptor(org.craftercms.core.xml.mergers.MergeableDescriptor) Document(org.dom4j.Document)

Example 2 with DescriptorMergeStrategy

use of org.craftercms.core.xml.mergers.DescriptorMergeStrategy in project engine by craftercms.

the class TargetedContentDescriptorMergeStrategyTest method createStrategyResolver.

private DescriptorMergeStrategyResolver createStrategyResolver(DescriptorMergeStrategy defaultMergeStrategy) {
    InheritLevelsMergeStrategy inheritLevelsMergeStrategy = new InheritLevelsMergeStrategy();
    inheritLevelsMergeStrategy.setLevelDescriptorFileName(LEVEL_DESCRIPTOR_FILENAME);
    Map<String, DescriptorMergeStrategy> mappings = new LinkedHashMap<>(2);
    mappings.put("/site/website/products/index.xml", inheritLevelsMergeStrategy);
    mappings.put(".*", defaultMergeStrategy);
    UrlPatternMergeStrategyResolver strategyResolver = new UrlPatternMergeStrategyResolver();
    strategyResolver.setUrlPatternToStrategyMappings(mappings);
    return strategyResolver;
}
Also used : DescriptorMergeStrategy(org.craftercms.core.xml.mergers.DescriptorMergeStrategy) UrlPatternMergeStrategyResolver(org.craftercms.core.xml.mergers.impl.resolvers.UrlPatternMergeStrategyResolver) InheritLevelsMergeStrategy(org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategy) Mockito.anyString(org.mockito.Mockito.anyString) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

DescriptorMergeStrategy (org.craftercms.core.xml.mergers.DescriptorMergeStrategy)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 MergeableDescriptor (org.craftercms.core.xml.mergers.MergeableDescriptor)1 UrlPatternMergeStrategyResolver (org.craftercms.core.xml.mergers.impl.resolvers.UrlPatternMergeStrategyResolver)1 InheritLevelsMergeStrategy (org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategy)1 Document (org.dom4j.Document)1 Mockito.anyString (org.mockito.Mockito.anyString)1