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);
}
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;
}
Aggregations