use of org.craftercms.core.xml.mergers.MergeableDescriptor 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.MergeableDescriptor in project engine by craftercms.
the class TargetedContentDescriptorMergeStrategyTest method testGetDescriptors.
@Test
public void testGetDescriptors() throws Exception {
Item item = mock(Item.class);
when(item.getDescriptorDom()).thenReturn(mock(Document.class));
ContentStoreAdapter storeAdapter = mock(ContentStoreAdapter.class);
when(storeAdapter.findItem(any(Context.class), any(CachingOptions.class), anyString(), anyBoolean())).thenReturn(item);
Context context = mock(Context.class);
when(context.getStoreAdapter()).thenReturn(storeAdapter);
List<MergeableDescriptor> descriptors = mergeStrategy.getDescriptors(context, CachingOptions.DEFAULT_CACHING_OPTIONS, "/site/website/es_CR/products/index.xml", mock(Document.class), false);
assertNotNull(descriptors);
assertEquals(12, descriptors.size());
assertEquals("/crafter-level-descriptor.level.xml", descriptors.get(0).getUrl());
assertEquals("/site/crafter-level-descriptor.level.xml", descriptors.get(1).getUrl());
assertEquals("/site/website/crafter-level-descriptor.level.xml", descriptors.get(2).getUrl());
assertEquals("/site/website/en/crafter-level-descriptor.level.xml", descriptors.get(3).getUrl());
assertEquals("/site/website/en/products/crafter-level-descriptor.level.xml", descriptors.get(4).getUrl());
assertEquals("/site/website/en/products/index.xml", descriptors.get(5).getUrl());
assertEquals("/site/website/es/crafter-level-descriptor.level.xml", descriptors.get(6).getUrl());
assertEquals("/site/website/es/products/crafter-level-descriptor.level.xml", descriptors.get(7).getUrl());
assertEquals("/site/website/es/products/index.xml", descriptors.get(8).getUrl());
assertEquals("/site/website/es_CR/crafter-level-descriptor.level.xml", descriptors.get(9).getUrl());
assertEquals("/site/website/es_CR/products/crafter-level-descriptor.level.xml", descriptors.get(10).getUrl());
assertEquals("/site/website/es_CR/products/index.xml", descriptors.get(11).getUrl());
}
Aggregations