use of org.alfresco.repo.content.UnsupportedContentUrlException 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.UnsupportedContentUrlException in project alfresco-repository by Alfresco.
the class AggregatingContentStoreTest method testGetDirectAccessUrl.
@Test
public void testGetDirectAccessUrl() {
// Create the aggregating store
AggregatingContentStore aggStore = new AggregatingContentStore();
aggStore.setPrimaryStore(primaryStoreMock);
aggStore.setSecondaryStores(List.of(secondaryStoreMock));
UnsupportedOperationException unsupportedExc = new UnsupportedOperationException();
UnsupportedContentUrlException unsupportedContentUrlExc = new UnsupportedContentUrlException(aggStore, "");
// By default it is unsupported
DirectAccessUrl directAccessUrl = aggStore.getDirectAccessUrl("url", null);
assertNull(directAccessUrl);
// Direct access not supported
try {
when(primaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedExc);
when(secondaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedExc);
aggStore.getDirectAccessUrl("urlDANotSupported", null);
fail();
} catch (UnsupportedOperationException e) {
// Expected
}
try {
when(primaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedContentUrlExc);
when(secondaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedExc);
aggStore.getDirectAccessUrl("urlDANotSupported", null);
fail();
} catch (UnsupportedOperationException e) {
// Expected
}
try {
when(primaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedExc);
when(secondaryStoreMock.getDirectAccessUrl(eq("urlDANotSupported"), any())).thenThrow(unsupportedContentUrlExc);
aggStore.getDirectAccessUrl("urlDANotSupported", null);
fail();
} catch (UnsupportedOperationException e) {
// Expected
}
// Content url not supported
try {
when(primaryStoreMock.getDirectAccessUrl(eq("urlNotSupported"), any())).thenThrow(unsupportedContentUrlExc);
when(secondaryStoreMock.getDirectAccessUrl(eq("urlNotSupported"), any())).thenThrow(unsupportedContentUrlExc);
aggStore.getDirectAccessUrl("urlNotSupported", null);
fail();
} catch (UnsupportedContentUrlException e) {
// Expected
}
when(primaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenReturn(new DirectAccessUrl());
when(secondaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenThrow(unsupportedExc);
directAccessUrl = aggStore.getDirectAccessUrl("urlPriSupported", null);
assertNotNull(directAccessUrl);
when(primaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenReturn(new DirectAccessUrl());
when(secondaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenThrow(unsupportedContentUrlExc);
directAccessUrl = aggStore.getDirectAccessUrl("urlPriSupported", null);
assertNotNull(directAccessUrl);
when(primaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenThrow(unsupportedExc);
when(secondaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenReturn(new DirectAccessUrl());
directAccessUrl = aggStore.getDirectAccessUrl("urlSecSupported", null);
assertNotNull(directAccessUrl);
when(primaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenThrow(unsupportedContentUrlExc);
when(secondaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenReturn(new DirectAccessUrl());
directAccessUrl = aggStore.getDirectAccessUrl("urlSecSupported", null);
assertNotNull(directAccessUrl);
when(primaryStoreMock.getDirectAccessUrl(eq("urlPriSupported"), any())).thenReturn(new DirectAccessUrl());
when(secondaryStoreMock.getDirectAccessUrl(eq("urlSecSupported"), any())).thenReturn(new DirectAccessUrl());
directAccessUrl = aggStore.getDirectAccessUrl("urlPriSupported", null);
assertNotNull(directAccessUrl);
directAccessUrl = aggStore.getDirectAccessUrl("urlSecSupported", null);
assertNotNull(directAccessUrl);
}
use of org.alfresco.repo.content.UnsupportedContentUrlException in project alfresco-repository by Alfresco.
the class FileContentStore method makeFile.
/**
* Creates a file from the given relative URL.
*
* @param contentUrl the content URL including the protocol prefix
* @return Returns a file representing the URL - the file may or may not
* exist
* @throws UnsupportedContentUrlException
* if the URL is invalid and doesn't support the
* {@link FileContentStore#STORE_PROTOCOL correct protocol}
*/
/*package*/
File makeFile(String contentUrl) {
// take just the part after the protocol
Pair<String, String> urlParts = super.getContentUrlParts(contentUrl);
String protocol = urlParts.getFirst();
String relativePath = urlParts.getSecond();
// Check the protocol
if (!protocol.equals(FileContentStore.STORE_PROTOCOL)) {
throw new UnsupportedContentUrlException(this, protocol + PROTOCOL_DELIMITER + relativePath);
}
// get the file
File file = new File(rootDirectory, relativePath);
ensureFileInContentStore(file);
// done
return file;
}
use of org.alfresco.repo.content.UnsupportedContentUrlException in project alfresco-repository by Alfresco.
the class AggregatingContentStore method getDirectAccessUrl.
public DirectAccessUrl getDirectAccessUrl(String contentUrl, Date expiresAt) {
if (primaryStore == null) {
throw new AlfrescoRuntimeException("ReplicatingContentStore not initialised");
}
// get a read lock so that we are sure that no replication is underway
readLock.lock();
try {
// Keep track of the unsupported state of the content URL - it might be a rubbish URL
boolean contentUrlSupported = true;
boolean directAccessUrlSupported = true;
DirectAccessUrl directAccessUrl = null;
// Check the primary store
try {
directAccessUrl = primaryStore.getDirectAccessUrl(contentUrl, expiresAt);
} catch (UnsupportedOperationException e) {
// The store does not support direct access URL
directAccessUrlSupported = false;
} catch (UnsupportedContentUrlException e) {
// The store can't handle the content URL
contentUrlSupported = false;
}
if (directAccessUrl != null) {
return directAccessUrl;
}
// the content is not in the primary store so we have to go looking for it
for (ContentStore store : secondaryStores) {
try {
directAccessUrl = store.getDirectAccessUrl(contentUrl, expiresAt);
} catch (UnsupportedOperationException e) {
// The store does not support direct access URL
directAccessUrlSupported = false;
} catch (UnsupportedContentUrlException e) {
// The store can't handle the content URL
contentUrlSupported = false;
}
if (directAccessUrl != null) {
break;
}
}
if (directAccessUrl == null) {
if (!directAccessUrlSupported) {
// The direct access URL was not supported
throw new UnsupportedOperationException("Retrieving direct access URLs is not supported by this content store.");
} else if (!contentUrlSupported) {
// The content URL was not supported
throw new UnsupportedContentUrlException(this, contentUrl);
}
}
return directAccessUrl;
} finally {
readLock.unlock();
}
}
use of org.alfresco.repo.content.UnsupportedContentUrlException in project alfresco-repository by Alfresco.
the class AggregatingContentStore method exists.
public boolean exists(String contentUrl) {
if (primaryStore == null) {
throw new AlfrescoRuntimeException("ReplicatingContentStore not initialised");
}
// get a read lock so that we are sure that no replication is underway
readLock.lock();
try {
// Keep track of the unsupported state of the content URL - it might be a rubbish URL
boolean contentUrlSupported = false;
boolean contentUrlExists = false;
// Check the primary store
try {
contentUrlExists = primaryStore.exists(contentUrl);
// At least the content URL was supported
contentUrlSupported = true;
} catch (UnsupportedContentUrlException e) {
// The store can't handle the content URL
}
if (contentUrlExists) {
return true;
}
// the content is not in the primary store so we have to go looking for it
for (ContentStore store : secondaryStores) {
contentUrlExists = false;
try {
contentUrlExists = store.exists(contentUrl);
// At least the content URL was supported
contentUrlSupported = true;
} catch (UnsupportedContentUrlException e) {
// The store can't handle the content URL
}
if (contentUrlExists) {
break;
}
}
// Check if the content URL was supported
if (!contentUrlSupported) {
throw new UnsupportedContentUrlException(this, contentUrl);
}
return contentUrlExists;
} finally {
readLock.unlock();
}
}
Aggregations