Search in sources :

Example 6 with CachingOptions

use of org.craftercms.core.service.CachingOptions in project engine by craftercms.

the class TargetedContentStoreAdapterDecoratorTest method testFindItems.

@Test
public void testFindItems() throws Exception {
    Context context = new DecoratedStoreAdapterContext(mock(Context.class), storeAdapter);
    CachingOptions cachingOptions = CachingOptions.DEFAULT_CACHING_OPTIONS;
    List<Item> items = storeAdapter.findItems(context, cachingOptions, "/site/website/en");
    assertNotNull(items);
    assertEquals(2, items.size());
    assertEquals("index.xml", items.get(0).getName());
    assertEquals("/site/website/en/index.xml", items.get(0).getUrl());
    assertEquals("about-us", items.get(1).getName());
    assertEquals("/site/website/en/about-us", items.get(1).getUrl());
    items = storeAdapter.findItems(context, cachingOptions, "/site/website/ja_jp_jp");
    assertNotNull(items);
    assertEquals(2, items.size());
    assertEquals("index.xml", items.get(0).getName());
    assertEquals("/site/website/ja/index.xml", items.get(0).getUrl());
    assertEquals("about-us", items.get(1).getName());
    assertEquals("/site/website/en/about-us", items.get(1).getUrl());
    config.setProperty(SiteProperties.MERGE_FOLDERS_CONFIG_KEY, false);
    items = storeAdapter.findItems(context, cachingOptions, "/site/website/ja_jp_jp");
    assertNotNull(items);
    assertEquals(1, items.size());
    assertEquals("index.xml", items.get(0).getName());
    assertEquals("/site/website/ja/index.xml", items.get(0).getUrl());
}
Also used : DecoratedStoreAdapterContext(org.craftercms.engine.util.store.decorators.DecoratedStoreAdapterContext) Context(org.craftercms.core.service.Context) Item(org.craftercms.core.service.Item) CachingOptions(org.craftercms.core.service.CachingOptions) DecoratedStoreAdapterContext(org.craftercms.engine.util.store.decorators.DecoratedStoreAdapterContext) Test(org.junit.Test)

Example 7 with CachingOptions

use of org.craftercms.core.service.CachingOptions in project engine by craftercms.

the class UrlTransformationServiceImpl method transform.

public String transform(String transformerName, String url, boolean cache) {
    SiteContext siteContext = SiteContext.getCurrent();
    if (siteContext != null) {
        CachingOptions cachingOptions = new CachingOptions();
        cachingOptions.setDoCaching(cache);
        return siteContext.getUrlTransformationEngine().transformUrl(siteContext.getContext(), cachingOptions, transformerName, url);
    } else {
        return url;
    }
}
Also used : CachingOptions(org.craftercms.core.service.CachingOptions) SiteContext(org.craftercms.engine.service.context.SiteContext)

Example 8 with CachingOptions

use of org.craftercms.core.service.CachingOptions in project engine by craftercms.

the class TargetedContentStoreAdapterTest method testFindItem.

@Test
public void testFindItem() throws Exception {
    Context context = new TargetedContentStoreAdapter.ContextWrapper(storeAdapter, mock(Context.class));
    CachingOptions cachingOptions = CachingOptions.DEFAULT_CACHING_OPTIONS;
    Item item = storeAdapter.findItem(context, cachingOptions, "/site/website/en", true);
    assertNotNull(item);
    assertEquals("en", item.getName());
    assertEquals("/site/website/en", item.getUrl());
    item = storeAdapter.findItem(context, cachingOptions, "/site/website/ja_jp_jp", true);
    assertNotNull(item);
    assertEquals("en", item.getName());
    assertEquals("/site/website/en", item.getUrl());
    item = storeAdapter.findItem(context, cachingOptions, "/site/website/ja_jp_jp/index.xml", true);
    assertNotNull(item);
    assertEquals("index.xml", item.getName());
    assertEquals("/site/website/en/index.xml", item.getUrl());
    item = storeAdapter.findItem(context, cachingOptions, "/site/website/index.xml", true);
    assertNotNull(item);
    assertEquals("index.xml", item.getName());
    assertEquals("/site/website/index.xml", item.getUrl());
    item = storeAdapter.findItem(context, cachingOptions, "/static-assets/css/main.css", true);
    assertNotNull(item);
    assertEquals("main.css", item.getName());
    assertEquals("/static-assets/css/main.css", item.getUrl());
}
Also used : Context(org.craftercms.core.service.Context) Item(org.craftercms.core.service.Item) CachingOptions(org.craftercms.core.service.CachingOptions) Test(org.junit.Test)

Example 9 with CachingOptions

use of org.craftercms.core.service.CachingOptions in project engine by craftercms.

the class TargetedContentStoreAdapterTest method testFindItems.

@Test
public void testFindItems() throws Exception {
    Context context = new TargetedContentStoreAdapter.ContextWrapper(storeAdapter, mock(Context.class));
    CachingOptions cachingOptions = CachingOptions.DEFAULT_CACHING_OPTIONS;
    List<Item> items = storeAdapter.findItems(context, cachingOptions, "/site/website/en", true);
    assertNotNull(items);
    assertEquals(2, items.size());
    assertEquals("index.xml", items.get(0).getName());
    assertEquals("/site/website/en/index.xml", items.get(0).getUrl());
    assertEquals("about-us", items.get(1).getName());
    assertEquals("/site/website/en/about-us", items.get(1).getUrl());
    items = storeAdapter.findItems(context, cachingOptions, "/site/website/ja_jp_jp", true);
    assertNotNull(items);
    assertEquals(2, items.size());
    assertEquals("index.xml", items.get(0).getName());
    assertEquals("/site/website/ja/index.xml", items.get(0).getUrl());
    assertEquals("about-us", items.get(1).getName());
    assertEquals("/site/website/en/about-us", items.get(1).getUrl());
    config.setProperty(SiteProperties.MERGE_FOLDERS_CONFIG_KEY, false);
    items = storeAdapter.findItems(context, cachingOptions, "/site/website/ja_jp_jp", true);
    assertNotNull(items);
    assertEquals(1, items.size());
    assertEquals("index.xml", items.get(0).getName());
    assertEquals("/site/website/ja/index.xml", items.get(0).getUrl());
}
Also used : Context(org.craftercms.core.service.Context) Item(org.craftercms.core.service.Item) CachingOptions(org.craftercms.core.service.CachingOptions) Test(org.junit.Test)

Example 10 with CachingOptions

use of org.craftercms.core.service.CachingOptions in project search by craftercms.

the class InheritedDescriptorsItemProcessor method process.

@Override
public Item process(final Context context, final CachingOptions cachingOptions, final Item item) throws ItemProcessingException {
    if (item.getDescriptorDom() != null) {
        DescriptorMergeStrategy mergeStrategy = mergeStrategyResolver.getStrategy(item.getDescriptorUrl(), item.getDescriptorDom());
        if (mergeStrategy != null) {
            List<MergeableDescriptor> inheritedDescriptors = mergeStrategy.getDescriptors(context, cachingOptions, item.getDescriptorUrl(), item.getDescriptorDom());
            if (CollectionUtils.isNotEmpty(inheritedDescriptors)) {
                inheritedDescriptors.stream().filter(descriptor -> !StringUtils.equals(descriptor.getUrl(), item.getDescriptorUrl())).forEach(descriptor -> {
                    Element inheritedFromElement = DocumentHelper.createElement(inheritsFromElementName);
                    inheritedFromElement.setText(descriptor.getUrl());
                    item.getDescriptorDom().getRootElement().add(inheritedFromElement);
                });
            }
        }
    }
    return item;
}
Also used : Item(org.craftercms.core.service.Item) CachingOptions(org.craftercms.core.service.CachingOptions) DescriptorMergeStrategyResolver(org.craftercms.core.xml.mergers.DescriptorMergeStrategyResolver) DocumentHelper(org.dom4j.DocumentHelper) StringUtils(org.apache.commons.lang3.StringUtils) Context(org.craftercms.core.service.Context) List(java.util.List) CollectionUtils(org.apache.commons.collections.CollectionUtils) MergeableDescriptor(org.craftercms.core.xml.mergers.MergeableDescriptor) ItemProcessingException(org.craftercms.core.exception.ItemProcessingException) Element(org.dom4j.Element) DescriptorMergeStrategy(org.craftercms.core.xml.mergers.DescriptorMergeStrategy) ItemProcessor(org.craftercms.core.processors.ItemProcessor) DescriptorMergeStrategy(org.craftercms.core.xml.mergers.DescriptorMergeStrategy) Element(org.dom4j.Element) MergeableDescriptor(org.craftercms.core.xml.mergers.MergeableDescriptor)

Aggregations

CachingOptions (org.craftercms.core.service.CachingOptions)10 Context (org.craftercms.core.service.Context)9 Test (org.junit.Test)7 Item (org.craftercms.core.service.Item)5 DecoratedStoreAdapterContext (org.craftercms.engine.util.store.decorators.DecoratedStoreAdapterContext)4 Content (org.craftercms.core.service.Content)3 SiteContext (org.craftercms.engine.service.context.SiteContext)2 InputStreamReader (java.io.InputStreamReader)1 List (java.util.List)1 Properties (java.util.Properties)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 ItemProcessingException (org.craftercms.core.exception.ItemProcessingException)1 ItemProcessor (org.craftercms.core.processors.ItemProcessor)1 ContentStoreService (org.craftercms.core.service.ContentStoreService)1 DescriptorMergeStrategy (org.craftercms.core.xml.mergers.DescriptorMergeStrategy)1 DescriptorMergeStrategyResolver (org.craftercms.core.xml.mergers.DescriptorMergeStrategyResolver)1 MergeableDescriptor (org.craftercms.core.xml.mergers.MergeableDescriptor)1 DocumentHelper (org.dom4j.DocumentHelper)1 Element (org.dom4j.Element)1