use of org.alfresco.repo.content.EmptyContentReader in project alfresco-repository by Alfresco.
the class FileContentStore method getReader.
/**
* This implementation requires that the URL start with
* {@link FileContentStore#STORE_PROTOCOL } or {@link FileContentStore#SPOOF_PROTOCOL }
*/
public ContentReader getReader(String contentUrl) {
// Handle the spoofed URL
if (contentUrl.startsWith(SPOOF_PROTOCOL)) {
return new SpoofedTextContentReader(contentUrl);
}
// else, it's a real file we are after
try {
File file = makeFile(contentUrl);
ContentReader reader = null;
if (file.exists()) {
FileContentReader fileContentReader = new FileContentReader(file, contentUrl);
fileContentReader.setAllowRandomAccess(allowRandomAccess);
reader = fileContentReader;
} else {
reader = new EmptyContentReader(contentUrl);
}
// done
if (logger.isDebugEnabled()) {
logger.debug("Created content reader: \n" + " url: " + contentUrl + "\n" + " file: " + file + "\n" + " reader: " + reader);
}
return reader;
} catch (UnsupportedContentUrlException e) {
// This can go out directly
throw e;
} catch (Throwable e) {
throw new ContentIOException("Failed to get reader for URL: " + contentUrl, e);
}
}
use of org.alfresco.repo.content.EmptyContentReader in project alfresco-repository by Alfresco.
the class ContentServiceImplTest method testTransformAndNulls.
@Test
@Deprecated
public void testTransformAndNulls() {
NodeRef versionableNode = createNewVersionableNode();
ContentReader contentReader = this.contentService.getReader(versionableNode, ContentModel.PROP_CONTENT);
ContentWriter contentWriter = this.contentService.getWriter(versionableNode, ContentModel.PROP_CONTENT, false);
// this.nodeService.setProperty(versionableNode, ContentModel.PROP_NAME, "for debugTransformers.txt");
try {
this.contentService.transform(new MimetypeMapTest.DummyContentReader(MimetypeMap.MIMETYPE_TEXT_PLAIN), new MimetypeMapTest.DummyContentWriter(MimetypeMap.MIMETYPE_IMAGE_PNG), new TransformationOptions(versionableNode, ContentModel.PROP_NAME, null, null));
} catch (NoTransformerException nte) {
nte.getMessage().contains("No transformation exists");
}
try {
this.contentService.transform(null, null, new TransformationOptions());
fail("Should throw exception");
} catch (AlfrescoRuntimeException are) {
are.getMessage().contains("The content reader must be set");
}
ContentReader empty = new EmptyContentReader("empty.txt");
try {
this.contentService.transform(empty, null, new TransformationOptions());
fail("Should throw exception");
} catch (AlfrescoRuntimeException are) {
are.getMessage().contains("The content reader mimetype must be set");
}
try {
contentWriter.setMimetype(null);
this.contentService.transform(contentReader, contentWriter, new TransformationOptions());
fail("Should throw exception");
} catch (AlfrescoRuntimeException are) {
are.getMessage().contains("The content writer mimetype must be set");
}
}
use of org.alfresco.repo.content.EmptyContentReader in project alfresco-repository by Alfresco.
the class DictionaryRepositoryBootstrap method createM2Model.
/**
* Create a M2Model from a dictionary model node
*
* @param nodeRef the dictionary model node reference
* @return the M2Model
*/
public M2Model createM2Model(NodeRef nodeRef) {
M2Model model = null;
ContentReader contentReader = this.contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
if (contentReader != null) {
if (contentReader instanceof EmptyContentReader) {
// belts-and-braces
logger.error("Failed to create model (due to EmptyContentReader): " + nodeRef);
} else {
InputStream is = null;
try {
is = contentReader.getContentInputStream();
model = M2Model.createModel(is);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
logger.error("Failed to close input stream for " + nodeRef);
}
}
}
}
}
// TODO should we inactivate the model node and put the error somewhere??
return model;
}
Aggregations