Search in sources :

Example 36 with Item

use of org.craftercms.core.service.Item in project core by craftercms.

the class ContentStoreRestController method getDescriptor.

@RequestMapping(value = URL_DESCRIPTOR, method = RequestMethod.GET)
public Map<String, Object> getDescriptor(WebRequest request, HttpServletResponse response, @RequestParam(REQUEST_PARAM_CONTEXT_ID) String contextId, @RequestParam(REQUEST_PARAM_URL) String url) throws InvalidContextException, StoreException, PathNotFoundException, ItemProcessingException, XmlMergeException, XmlFileParseException {
    Map<String, Object> model = getItem(request, response, contextId, url);
    if (MapUtils.isNotEmpty(model)) {
        Item item = (Item) model.remove(MODEL_ATTR_ITEM);
        model.put(MODEL_ATTR_DESCRIPTOR, item.getDescriptorDom());
    }
    return model;
}
Also used : Item(org.craftercms.core.service.Item) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with Item

use of org.craftercms.core.service.Item in project core by craftercms.

the class ContentStoreRestController method getItem.

@RequestMapping(value = URL_ITEM, method = RequestMethod.GET)
public Map<String, Object> getItem(WebRequest request, HttpServletResponse response, @RequestParam(REQUEST_PARAM_CONTEXT_ID) String contextId, @RequestParam(REQUEST_PARAM_URL) String url) throws InvalidContextException, StoreException, PathNotFoundException, ItemProcessingException, XmlMergeException, XmlFileParseException {
    Context context = storeService.getContext(contextId);
    if (context == null) {
        throw new InvalidContextException("No context found for ID " + contextId);
    }
    Item item = storeService.getItem(context, url);
    if (item.getCachingTime() != null && checkNotModified(item.getCachingTime(), request, response)) {
        return null;
    } else {
        return createMessageModel(MODEL_ATTR_ITEM, item);
    }
}
Also used : Context(org.craftercms.core.service.Context) Item(org.craftercms.core.service.Item) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 38 with Item

use of org.craftercms.core.service.Item in project core by craftercms.

the class IncludeDescriptorsProcessor method includeDescriptors.

@SuppressWarnings("unchecked")
protected void includeDescriptors(Context context, CachingOptions cachingOptions, Item item) throws ItemProcessingException {
    String descriptorUrl = item.getDescriptorUrl();
    includedItemsStack.get().push(descriptorUrl);
    try {
        Document descriptorDom = item.getDescriptorDom();
        List<Element> includeElements = descriptorDom.selectNodes(includeElementXPathQuery);
        if (CollectionUtils.isEmpty(includeElements)) {
            return;
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Processing includes of item @ " + descriptorUrl);
        }
        for (Element includeElement : includeElements) {
            String itemToIncludePath = includeElement.getTextTrim();
            if (StringUtils.isEmpty(itemToIncludePath)) {
                continue;
            }
            if (!isIncludeDisabled(includeElement)) {
                if (!includedItemsStack.get().contains(itemToIncludePath)) {
                    Item itemToInclude = getItemToInclude(context, cachingOptions, itemToIncludePath);
                    if (itemToInclude != null && itemToInclude.getDescriptorDom() != null) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Include found in " + descriptorUrl + ": " + itemToIncludePath);
                        }
                        doInclude(item, includeElement, itemToInclude);
                    } else {
                        logger.debug("No descriptor item found @ " + itemToIncludePath);
                    }
                } else {
                    logger.debug("Circular inclusion detected. Item " + itemToIncludePath + " already included");
                }
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("Ignoring include " + itemToIncludePath + ". It's currently disabled");
                }
            }
        }
    } finally {
        includedItemsStack.get().pop();
    }
}
Also used : Item(org.craftercms.core.service.Item) Element(org.dom4j.Element) Document(org.dom4j.Document)

Example 39 with Item

use of org.craftercms.core.service.Item in project core by craftercms.

the class ContentStoreServiceImplTest method testGetChildren.

@Test
public void testGetChildren() throws Exception {
    CachingAwareList<Item> children = (CachingAwareList<Item>) contentStoreService.findChildren(context, ROOT_FOLDER_PATH);
    assertRootFolderChildren(children, false, false);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    CachingAwareList<Item> cachedChildren = (CachingAwareList<Item>) contentStoreService.getChildren(context, ROOT_FOLDER_PATH);
    assertEquals(children, cachedChildren);
    assertListCaching(children, cachedChildren);
    children = (CachingAwareList<Item>) contentStoreService.findChildren(context, INVALID_PATH);
    assertNull(children);
    try {
        contentStoreService.getChildren(context, INVALID_PATH);
        fail("Expected " + PathNotFoundException.class.getName());
    } catch (PathNotFoundException e) {
    }
    ItemProcessorPipeline extractorPipeline = new ItemProcessorPipeline();
    extractorPipeline.addProcessor(new TextMetaDataCollectionExtractingProcessor("//extension"));
    extractorPipeline.addProcessor(new TextMetaDataExtractingProcessor("//size"));
    children = (CachingAwareList<Item>) contentStoreService.findChildren(context, DEFAULT_CACHING_OPTIONS, ROOT_FOLDER_PATH, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertRootFolderChildren(children, true, true);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    cachedChildren = (CachingAwareList<Item>) contentStoreService.getChildren(context, DEFAULT_CACHING_OPTIONS, ROOT_FOLDER_PATH, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertEquals(children, cachedChildren);
    assertListCaching(children, cachedChildren);
    children = (CachingAwareList<Item>) contentStoreService.findChildren(context, DEFAULT_CACHING_OPTIONS, INVALID_PATH, OnlyNonDescriptorsFilter.instance, extractorPipeline);
    assertNull(children);
    try {
        contentStoreService.getChildren(context, DEFAULT_CACHING_OPTIONS, INVALID_PATH, OnlyNonDescriptorsFilter.instance, extractorPipeline);
        assertNull(children);
        fail("Expected " + PathNotFoundException.class.getName());
    } catch (PathNotFoundException e) {
    }
}
Also used : Item(org.craftercms.core.service.Item) ItemProcessorPipeline(org.craftercms.core.processors.impl.ItemProcessorPipeline) TextMetaDataCollectionExtractingProcessor(org.craftercms.core.processors.impl.TextMetaDataCollectionExtractingProcessor) TextMetaDataExtractingProcessor(org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor) PathNotFoundException(org.craftercms.core.exception.PathNotFoundException) CachingAwareList(org.craftercms.core.util.cache.impl.CachingAwareList) Test(org.junit.Test) InheritLevelsMergeStrategyTest(org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategyTest)

Example 40 with Item

use of org.craftercms.core.service.Item in project core by craftercms.

the class ContentStoreServiceImplTest method testGetStaticAssetItem.

@Test
public void testGetStaticAssetItem() throws Exception {
    Item item = contentStoreService.findItem(context, CRAFTER_CMS_LOGO_PATH);
    assertCrafterCMSLogoItem(item, false);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    Item cachedItem = contentStoreService.getItem(context, CRAFTER_CMS_LOGO_PATH);
    assertEquals(item, cachedItem);
    assertCaching(item, cachedItem);
    TextMetaDataExtractingProcessor extractor = new TextMetaDataExtractingProcessor("//size");
    item = contentStoreService.findItem(context, DEFAULT_CACHING_OPTIONS, CRAFTER_CMS_LOGO_PATH, extractor);
    assertCrafterCMSLogoItem(item, true);
    // Sleep so that we get a different caching time in the next call if the caching is being done wrong.
    Thread.sleep(100);
    cachedItem = contentStoreService.getItem(context, DEFAULT_CACHING_OPTIONS, CRAFTER_CMS_LOGO_PATH, extractor);
    assertEquals(item, cachedItem);
    assertCaching(item, cachedItem);
}
Also used : Item(org.craftercms.core.service.Item) TextMetaDataExtractingProcessor(org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor) Test(org.junit.Test) InheritLevelsMergeStrategyTest(org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategyTest)

Aggregations

Item (org.craftercms.core.service.Item)55 Test (org.junit.Test)21 Context (org.craftercms.core.service.Context)19 CachingOptions (org.craftercms.core.service.CachingOptions)8 Document (org.dom4j.Document)8 ArrayList (java.util.ArrayList)7 ContentStoreAdapter (org.craftercms.core.store.ContentStoreAdapter)7 CachingAwareList (org.craftercms.core.util.cache.impl.CachingAwareList)5 InheritLevelsMergeStrategyTest (org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategyTest)4 DecoratedStoreAdapterContext (org.craftercms.engine.util.store.decorators.DecoratedStoreAdapterContext)4 PathNotFoundException (org.craftercms.core.exception.PathNotFoundException)3 TextMetaDataExtractingProcessor (org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor)3 Content (org.craftercms.core.service.Content)3 ContentStoreService (org.craftercms.core.service.ContentStoreService)3 Tree (org.craftercms.core.service.Tree)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 StoreException (org.craftercms.core.exception.StoreException)2 ItemProcessor (org.craftercms.core.processors.ItemProcessor)2 ItemProcessorPipeline (org.craftercms.core.processors.impl.ItemProcessorPipeline)2 TextMetaDataCollectionExtractingProcessor (org.craftercms.core.processors.impl.TextMetaDataCollectionExtractingProcessor)2