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