use of org.craftercms.core.exception.XmlFileParseException 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;
}
Aggregations