Java Code Examples for org.alfresco.repo.content.ContentStore#getReader()

The following examples show how to use org.alfresco.repo.content.ContentStore#getReader() . 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: AggregatingContentStore.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Forwards the call directly to the first store in the list of stores.
 */
public ContentReader getReader(String contentUrl) throws ContentIOException
{
    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
    {
        // get a reader from the primary store
        ContentReader primaryReader = primaryStore.getReader(contentUrl);
        
        // give it straight back if the content is there
        if (primaryReader.exists())
        {
            return primaryReader;
        }

        // the content is not in the primary reader so we have to go looking for it
        for (ContentStore store : secondaryStores)
        {
            ContentReader reader = store.getReader(contentUrl);
            if (reader.exists())
            {
                // found the content in a secondary store
                return reader;
            }
        }

        return primaryReader;
    }
    finally
    {
        readLock.unlock();
    }     
}
 
Example 2
Source File: FileWipingContentCleanerListener.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void beforeDelete(ContentStore sourceStore, String contentUrl) throws ContentIOException
{
    // First check if the content is present at all
    ContentReader reader = sourceStore.getReader(contentUrl);
    if (reader != null && reader.exists())
    {
        // Call to implementation's shred
        if (logger.isDebugEnabled())
        {
            logger.debug(
                    "About to shread: \n" +
                    "   URL:    " + contentUrl + "\n" +
                    "   Source: " + sourceStore);
        }
        try
        {
            shred(reader);
        }
        catch (Throwable e)
        {
            logger.error(
                    "Content shredding failed: \n" +
                    "   URL:    " + contentUrl + "\n" +
                    "   Source: " + sourceStore + "\n" +
                    "   Reader: " + reader,
                    e);
        }
    }
    else
    {
        logger.error(
                "Content no longer exists.  Unable to shred: \n" +
                "   URL:    " + contentUrl + "\n" +
                "   Source: " + sourceStore);
    }
}
 
Example 3
Source File: DeletedContentBackupCleanerListener.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void beforeDelete(ContentStore sourceStore, String contentUrl) throws ContentIOException
{
    if (store.isContentUrlSupported(contentUrl))
    {
        ContentContext context = new ContentContext(null, contentUrl);
        ContentReader reader = sourceStore.getReader(contentUrl);
        if (!reader.exists())
        {
            // Nothing to copy over
            return;
        }
        // write the content into the target store
        ContentWriter writer = store.getWriter(context);
        // copy across
        writer.putContent(reader);
        // done
        if (logger.isDebugEnabled())
        {
            logger.debug(
                    "Moved content before deletion: \n" +
                    "   URL:    " + contentUrl + "\n" +
                    "   Source: " + sourceStore + "\n" +
                    "   Target: " + store);
        }
    }
    else
    {
        if (logger.isDebugEnabled())
        {
            logger.debug(
                    "Content cannot be moved during deletion.  A backup will not be made: \n" +
                    "   URL:    " + contentUrl + "\n" +
                    "   Source: " + sourceStore + "\n" +
                    "   Target: " + store);
        }
    }
}
 
Example 4
Source File: MoveCapableCommonRoutingContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ContentReader getReader(final String contentUrl) throws ContentIOException
{
    final ContentReader reader;
    if (this.isContentUrlSupported(contentUrl))
    {
        final ContentStore store = this.selectReadStore(contentUrl);
        if (store != null)
        {
            LOGGER.debug("Getting reader from store: \n\tContent URL: {}\n\tStore: {}", contentUrl, store);
            reader = store.getReader(contentUrl);
        }
        else
        {
            LOGGER.debug("Getting empty reader for content URL: {}", contentUrl);
            reader = new EmptyContentReader(contentUrl);
        }
    }
    else
    {
        LOGGER.debug("Getting empty reader for unsupported content URL: {}", contentUrl);
        reader = new EmptyContentReader(contentUrl);
    }

    return reader;
}
 
Example 5
Source File: AggregatingContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 4 votes vote down vote up
@Override
public ContentReader getReader(final String contentUrl)
{
    ContentReader reader = null;
    boolean validReader = false;

    LOGGER.debug("Retrieving content reader for URL {}", contentUrl);

    if (this.primaryStore.isContentUrlSupported(contentUrl))
    {
        reader = this.primaryStore.getReader(contentUrl);
        validReader = reader != null && reader.exists();

        if (validReader)
        {
            LOGGER.debug("Content reader for URL {} retrieved from primary store", contentUrl);
        }
    }

    for (int idx = 0, max = this.secondaryStores.size(); idx < max && !validReader; idx++)
    {
        final ContentStore store = this.secondaryStores.get(idx);
        if (store.isContentUrlSupported(contentUrl))
        {
            reader = store.getReader(contentUrl);

            validReader = reader != null && reader.exists();
            if (validReader)
            {
                LOGGER.debug("Content reader for URL {} retrieved from secondary store #{}", contentUrl, idx + 1);
            }
        }
    }

    if (!validReader)
    {
        LOGGER.debug("No content reader with existing content found for URL {}", contentUrl);
    }

    return reader;
}