use of org.craftercms.core.exception.StoreException in project core by craftercms.
the class ContentStoreServiceImpl method createContext.
/**
* {@inheritDoc}
*/
@Override
public Context createContext(String storeType, String storeServerUrl, String username, String password, String rootFolderPath, boolean mergingOn, boolean cacheOn, int maxAllowedItemsInCache, boolean ignoreHiddenFiles) throws InvalidStoreTypeException, RootFolderNotFoundException, StoreException, AuthenticationException {
String id = createContextId(storeType, storeServerUrl, username, password, rootFolderPath, cacheOn, maxAllowedItemsInCache, ignoreHiddenFiles);
if (!contexts.containsKey(id)) {
ContentStoreAdapter storeAdapter = storeAdapterRegistry.get(storeType);
if (storeAdapter == null) {
throw new InvalidStoreTypeException("No registered content store adapter for store type " + storeType);
}
Context context = storeAdapter.createContext(id, storeServerUrl, username, password, rootFolderPath, mergingOn, cacheOn, maxAllowedItemsInCache, ignoreHiddenFiles);
cacheTemplate.getCacheService().addScope(context);
contexts.put(id, context);
return context;
} else {
throw new StoreException("A context for id '" + id + "' already exists");
}
}
use of org.craftercms.core.exception.StoreException in project engine by craftercms.
the class S3ContentStoreAdapter method getContent.
@Override
protected Content getContent(Context context, CachingOptions cachingOptions, File file) throws InvalidContextException, StoreException {
S3Context s3Context = (S3Context) context;
String key = ((S3File) file).getKey();
logger.debug("Getting content for key {}", key);
try {
GetObjectRequest request = new GetObjectRequest(s3Context.getBucket(), key);
S3Object object = client.getObject(request);
return new S3Content(object);
} catch (AmazonS3Exception e) {
if (e.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
throw new StoreException("No item found for key " + key);
} else {
throw new StoreException("Error getting item for key " + key, e);
}
}
}
use of org.craftercms.core.exception.StoreException in project core by craftercms.
the class AbstractFileBasedContentStoreAdapter method doFindItem.
@Override
protected Item doFindItem(Context context, CachingOptions cachingOptions, String path, boolean withDescriptor) throws InvalidContextException, PathNotFoundException, XmlFileParseException, StoreException {
path = normalizePath(path);
File file = findFile(context, path);
if (file == null) {
return null;
}
Item item = new Item();
item.setName(file.getName());
item.setUrl(path);
item.setFolder(file.isDirectory());
if (withDescriptor) {
File descriptorFile;
// a DOM.
if (file.isFile() && item.getName().endsWith(descriptorFileExtension)) {
item.setDescriptorUrl(path);
descriptorFile = file;
// If it's not a file (a dir) or is not a descriptor (a static asset, like an image), locate the file's
// descriptor by appending a metadata file extension to the file name. If the file exists, load it as
// a DOM.
} else {
String descriptorPath = FilenameUtils.removeExtension(path) + metadataFileExtension;
item.setDescriptorUrl(descriptorPath);
descriptorFile = findFile(context, descriptorPath);
if (descriptorFile != null && !descriptorFile.isFile()) {
throw new StoreException("Descriptor file at " + descriptorFile + " is not really a file");
}
}
if (descriptorFile != null) {
try {
InputStream fileInputStream = new BufferedInputStream(descriptorFile.getInputStream());
Reader fileReader = new InputStreamReader(fileInputStream, charset);
try {
item.setDescriptorDom(createXmlReader().read(fileReader));
} finally {
IOUtils.closeQuietly(fileReader);
}
} catch (IOException e) {
throw new StoreException("Unable to open input stream for descriptor file at " + descriptorFile, e);
} catch (DocumentException e) {
throw new XmlFileParseException("Error while parsing xml document at " + descriptorFile, e);
}
}
}
return item;
}
use of org.craftercms.core.exception.StoreException in project core by craftercms.
the class AbstractFileBasedContentStoreAdapter method doFindItems.
@Override
protected List<Item> doFindItems(Context context, CachingOptions cachingOptions, String path, boolean withDescriptor) throws InvalidContextException, PathNotFoundException, XmlFileParseException, StoreException {
path = normalizePath(path);
File dir = findFile(context, path);
if (dir == null) {
return null;
}
if (!dir.isDirectory()) {
throw new StoreException("The path " + dir + " doesn't correspond to a dir");
}
List<File> children = getChildren(context, dir);
CachingAwareList<Item> items = new CachingAwareList<>(children.size());
if (CollectionUtils.isNotEmpty(children)) {
for (File child : children) {
// items.
if (!child.isFile() || !child.getName().endsWith(metadataFileExtension)) {
String fileRelPath = path + (!path.equals("/") ? "/" : "") + child.getName();
Item item = findItem(context, cachingOptions, fileRelPath, withDescriptor);
if (item != null) {
items.add(item);
items.addDependencyKey(item.getKey());
}
}
}
}
return items;
}
use of org.craftercms.core.exception.StoreException in project core by craftercms.
the class FileSystemContentStoreAdapter method createContext.
@Override
public Context createContext(String id, String storeServerUrl, String username, String password, String rootFolderPath, boolean mergingOn, boolean cacheOn, int maxAllowedItemsInCache, boolean ignoreHiddenFiles) throws RootFolderNotFoundException, StoreException, AuthenticationException {
Resource rootFolderResource = resourceLoader.getResource(rootFolderPath);
if (!rootFolderResource.exists()) {
throw new RootFolderNotFoundException("Root folder " + rootFolderPath + " not found (make sure that it has a valid URL " + "prefix (e.g. file:))");
}
FileSystemFile rootFolder;
try {
rootFolder = new FileSystemFile(rootFolderResource.getFile());
} catch (IOException e) {
throw new StoreException("Unable to retrieve file handle for root folder " + rootFolderPath, e);
}
return new FileSystemContext(id, this, null, rootFolderPath, rootFolder, mergingOn, cacheOn, maxAllowedItemsInCache, ignoreHiddenFiles);
}
Aggregations