Java Code Examples for org.alfresco.repo.content.ContentStore#PROTOCOL_DELIMITER

The following examples show how to use org.alfresco.repo.content.ContentStore#PROTOCOL_DELIMITER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileContentStore.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Takes the file absolute path, strips off the root path of the store
 * and appends the store URL prefix.
 * 
 * @param file the file from which to create the URL
 * @return Returns the equivalent content URL
 */
/*package*/ String makeContentUrl(File file)
{
    String path = file.getAbsolutePath();
    // check if it belongs to this store
    if (!path.startsWith(rootAbsolutePath))
    {
        throw new AlfrescoRuntimeException(
                "File does not fall below the store's root: \n" +
                "   file: " + file + "\n" +
                "   store: " + this);
    }
    // strip off the file separator char, if present
    int index = rootAbsolutePath.length();
    if (path.charAt(index) == File.separatorChar)
    {
        index++;
    }
    // strip off the root path and adds the protocol prefix
    String url = FileContentStore.STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + path.substring(index);
    // replace '\' with '/' so that URLs are consistent across all filesystems
    url = url.replace('\\', '/');
    // done
    return url;
}
 
Example 2
Source File: FileContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 6 votes vote down vote up
/**
 * Takes the file absolute path, strips off the root path of the store and appends the store URL prefix.
 *
 * @param file
 *            the file from which to create the URL
 * @return the equivalent content URL
 */
// only needed for deprecated getUrls
@Deprecated
protected String makeContentUrl(final File file)
{
    final String path = file.getAbsolutePath();
    if (!path.startsWith(this.rootAbsolutePath))
    {
        throw new AlfrescoRuntimeException(
                "File does not fall below the store's root: \n" + "   file: " + file + "\n" + "   store: " + this);
    }
    int index = this.rootAbsolutePath.length();
    if (path.charAt(index) == File.separatorChar)
    {
        index++;
    }

    String url = this.protocol + ContentStore.PROTOCOL_DELIMITER + path.substring(index);
    url = url.replace('\\', '/');
    return url;
}
 
Example 3
Source File: FileContentStoreTest.java    From alfresco-simple-content-stores with Apache License 2.0 6 votes vote down vote up
@Test
public void predeterminedContentURL() throws Exception
{
    final FileContentStore store = this.createDefaultStore();

    store.afterPropertiesSet();

    Assert.assertTrue("Store should support write", store.isWriteSupported());

    final String testText = generateText(SEED_PRNG.nextLong());
    final String dummyContentUrl = STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + "any/path/will/do";
    final ContentWriter writer = this.testIndividualWriteAndRead(store, new ContentContext(null, dummyContentUrl), testText);

    final String contentUrl = writer.getContentUrl();
    Assert.assertEquals("Effective content URL did not match provided URL", dummyContentUrl, contentUrl);
}
 
Example 4
Source File: FileContentReader.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Constructor that builds a URL based on the absolute path of the file.
 * 
 * @param file the file for reading.  This will most likely be directly
 *      related to the content URL.
 */
public FileContentReader(File file)
{
    this(
            file,
            FileContentStore.STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + file.getAbsolutePath());
}
 
Example 5
Source File: FileContentWriter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Constructor that builds a URL based on the absolute path of the file.
 * 
 * @param file the file for writing.  This will most likely be directly
 *      related to the content URL.
 * @param existingContentReader a reader of a previous version of this content
 */
public FileContentWriter(File file, ContentReader existingContentReader)
{
    this(
            file,
            FileContentStore.STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + file.getAbsolutePath(),
            existingContentReader);
}
 
Example 6
Source File: DeduplicatingContentStoreTest.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
@Test
public void backingStoreContentURLSupportOnly()
{
    final DictionaryService dictionaryService = EasyMock.mock(DictionaryService.class);

    final DeduplicatingContentStore deduplicatingContentStore = new DeduplicatingContentStore();
    deduplicatingContentStore.setNamespaceService(PREFIX_RESOLVER);
    deduplicatingContentStore.setDictionaryService(dictionaryService);

    final FileContentStore fileContentStore = new FileContentStore();
    fileContentStore.setRootDirectory(backingStoreFolder.getAbsolutePath());
    fileContentStore.setProtocol(STORE_PROTOCOL);
    deduplicatingContentStore.setBackingStore(fileContentStore);

    final FileContentStore temporaryContentStore = new FileContentStore();
    temporaryContentStore.setRootDirectory(temporaryStoreFolder.getAbsolutePath());
    temporaryContentStore.setProtocol(TEMPORARY_STORE_PROTOCOL);
    deduplicatingContentStore.setTemporaryStore(temporaryContentStore);

    fileContentStore.afterPropertiesSet();
    temporaryContentStore.afterPropertiesSet();
    deduplicatingContentStore.afterPropertiesSet();

    final String dummyNonExistingValidContentUrl = STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + "any/path/will/do/"
            + GUID.generate();
    Assert.assertTrue("Store did not support protocol of backing content store",
            deduplicatingContentStore.isContentUrlSupported(dummyNonExistingValidContentUrl));
    Assert.assertFalse("Store reported valid dummy content URL to exist",
            deduplicatingContentStore.exists(dummyNonExistingValidContentUrl));

    final String dummyNonExistingInvalidContentUrl = TEMPORARY_STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + "any/path/will/do/"
            + GUID.generate();
    Assert.assertFalse("Store reported protocol of temporary content store to be supported",
            deduplicatingContentStore.isContentUrlSupported(dummyNonExistingInvalidContentUrl));
    this.thrown.expect(UnsupportedContentUrlException.class);
    Assert.assertFalse("Store reported invalid dummy content URL to exist",
            deduplicatingContentStore.exists(dummyNonExistingInvalidContentUrl));
}
 
Example 7
Source File: FileContentStoreTest.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
@Test
public void unconfiguredWriteReadDelete() throws Exception
{
    final FileContentStore store = this.createDefaultStore();

    store.afterPropertiesSet();

    Assert.assertTrue("Store should support write", store.isWriteSupported());

    final String testText = generateText(SEED_PRNG.nextLong());
    final Date dateBeforeWrite = new Date();
    final ContentWriter writer = this.testIndividualWriteAndRead(store, testText);

    final String contentUrl = writer.getContentUrl();
    final DateFormat df = new SimpleDateFormat("yyyy/M/d/H/m", Locale.ENGLISH);
    df.setTimeZone(TimeZone.getDefault());
    final String expectedPattern = "^" + STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + df.format(dateBeforeWrite)
            + "/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\\.bin$";
    Assert.assertTrue("Content URL did not match expected date-based pattern with UUID", contentUrl.matches(expectedPattern));

    Assert.assertTrue("Content should have been deleted", store.delete(contentUrl));
    final Path rootPath = this.storeFolder.toPath();
    final long subPathCount = TestUtilities.walk(rootPath, (stream) -> {
        return stream.filter((path) -> {
            return !path.equals(rootPath);
        }).count();
    }, FileVisitOption.FOLLOW_LINKS);
    Assert.assertEquals("Store path should not contain any elements after delete", 0, subPathCount);
}
 
Example 8
Source File: FileContentStoreTest.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
@Test
public void wildcardContentURL() throws Exception
{
    final FileContentStore store = this.createDefaultStore();

    store.afterPropertiesSet();

    Assert.assertTrue("Store should support write", store.isWriteSupported());

    final String testText = generateText(SEED_PRNG.nextLong());
    final String dummyContentUrl = StoreConstants.WILDCARD_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + "any/path/will/do";
    final String expectedContentUrl = STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + "any/path/will/do";
    final ContentWriter writer = this.testIndividualWriteAndRead(store, new ContentContext(null, dummyContentUrl), testText);

    final String contentUrl = writer.getContentUrl();
    Assert.assertEquals("Effective content URL did not match expected URL", expectedContentUrl, contentUrl);

    Assert.assertTrue("Wildcard-based content URL should have been reported as supported",
            store.isContentUrlSupported(dummyContentUrl));
    Assert.assertTrue("Wildcard-based content URL should have been reported as existing", store.exists(dummyContentUrl));

    final ContentReader reader = store.getReader(dummyContentUrl);
    Assert.assertNotNull("Wildcard-based content URL should have yielded a reader", reader);
    Assert.assertTrue("Wildcard-based content URL should have yielded a reader to existing content", reader.exists());
    final String readContent = reader.getContentString();
    Assert.assertEquals("Content read from reader for wildcard-based content URL did not match written content", testText, readContent);

    Assert.assertTrue("Content should have been deleted using wildcard-based content URL", store.delete(dummyContentUrl));
    Assert.assertFalse(
            "Content should not be reported as existing for explicit content URL after having been deleted via wildcard-based content URL",
            store.exists(contentUrl));
}
 
Example 9
Source File: FileContentStoreTest.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
@Test
public void readOnlyWrite()
{
    final FileContentStore store = this.createDefaultStore();
    store.setReadOnly(true);

    store.afterPropertiesSet();

    Assert.assertFalse("Store should not support write", store.isWriteSupported());

    final String testText = generateText(SEED_PRNG.nextLong());
    final String dummyContentUrl = STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + "any/path/will/do";
    this.thrown.expect(UnsupportedOperationException.class);
    this.testIndividualWriteAndRead(store, new ContentContext(null, dummyContentUrl), testText);
}
 
Example 10
Source File: FileContentStoreTest.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
@Test
public void readOnlyDelete()
{
    final FileContentStore store = this.createDefaultStore();
    store.setReadOnly(true);

    store.afterPropertiesSet();

    Assert.assertFalse("Store should not support write", store.isWriteSupported());

    final String dummyContentUrl = STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + "any/path/will/do";
    this.thrown.expect(UnsupportedOperationException.class);
    store.delete(dummyContentUrl);
}
 
Example 11
Source File: FileContentWriterImpl.java    From alfresco-simple-content-stores with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor that builds a URL based on the absolute path of the file.
 *
 * @param file
 *            the file for writing. This will most likely be directly
 *            related to the content URL.
 * @param existingContentReader
 *            a reader of a previous version of this content
 */
public FileContentWriterImpl(final File file, final ContentReader existingContentReader)
{
    this(file, FileContentStore.STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + file.getAbsolutePath(), existingContentReader);
}
 
Example 12
Source File: FileContentReaderImpl.java    From alfresco-simple-content-stores with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor that builds a URL based on the absolute path of the file.
 *
 * @param file
 *            the file for reading. This will most likely be directly
 *            related to the content URL.
 */
public FileContentReaderImpl(final File file)
{
    this(file, FileContentStore.STORE_PROTOCOL + ContentStore.PROTOCOL_DELIMITER + file.getAbsolutePath());
}