Java Code Examples for org.alfresco.service.cmr.repository.ContentReader#setLocale()

The following examples show how to use org.alfresco.service.cmr.repository.ContentReader#setLocale() . 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: AbstractContentWriter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Performs checks and copies required reader attributes
 */
public final ContentReader getReader() throws ContentIOException
{
    String contentUrl = getContentUrl();
    if (!isClosed())
    {
        return new EmptyContentReader(contentUrl);
    }
    ContentReader reader = createReader();
    if (reader == null)
    {
        throw new AlfrescoRuntimeException("ContentReader failed to create new reader: \n" +
                "   writer: " + this);
    }
    else if (reader.getContentUrl() == null || !reader.getContentUrl().equals(contentUrl))
    {
        throw new AlfrescoRuntimeException("ContentReader has different URL: \n" +
                "   writer: " + this + "\n" +
                "   new reader: " + reader);
    }
    // copy across common attributes
    reader.setMimetype(this.getMimetype());
    reader.setEncoding(this.getEncoding());
    reader.setLocale(this.getLocale());
    // done
    if (logger.isDebugEnabled())
    {
        logger.debug("Writer spawned new reader: \n" +
                "   writer: " + this + "\n" +
                "   new reader: " + reader);
    }
    return reader;
}
 
Example 2
Source File: AbstractContentReader.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Performs checks and copies required reader attributes
 */
public final ContentReader getReader() throws ContentIOException
{
    ContentReader reader = createReader();
    if (reader == null)
    {
        throw new AlfrescoRuntimeException("ContentReader failed to create new reader: \n" +
                "   reader: " + this);
    }
    else if (reader.getContentUrl() == null || !reader.getContentUrl().equals(getContentUrl()))
    {
        throw new AlfrescoRuntimeException("ContentReader has different URL: \n" +
                "   reader: " + this + "\n" +
                "   new reader: " + reader);
    }
    // copy across common attributes
    reader.setMimetype(this.getMimetype());
    reader.setEncoding(this.getEncoding());
    reader.setLocale(this.getLocale());
    // done
    if (logger.isDebugEnabled())
    {
        logger.debug("Reader spawned new reader: \n" +
                "   reader: " + this + "\n" +
                "   new reader: " + reader);
    }
    return reader;
}
 
Example 3
Source File: ContentServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** {@inheritDoc} */
public ContentReader getRawReader(String contentUrl)
{
    ContentReader reader = null;
    try
    {
        reader = store.getReader(contentUrl);
    }
    catch (UnsupportedContentUrlException e)
    {
        // The URL is not supported, so we spoof it
        reader = new EmptyContentReader(contentUrl);
    }
    if (reader == null)
    {
        throw new AlfrescoRuntimeException("ContentStore implementations may not return null ContentReaders");
    }
    // set extra data on the reader
    reader.setMimetype(MimetypeMap.MIMETYPE_BINARY);
    reader.setEncoding("UTF-8");
    reader.setLocale(I18NUtil.getLocale());
    
    // Done
    if (logger.isDebugEnabled())
    {
        logger.debug(
                "Direct request for reader: \n" +
                "   Content URL: " + contentUrl + "\n" +
                "   Reader:      " + reader);
    }
    return reader;
}
 
Example 4
Source File: ContentServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private ContentReader getReader(NodeRef nodeRef, QName propertyQName, boolean fireContentReadPolicy)
{
    ContentData contentData = getContentData(nodeRef, propertyQName);

    // check that the URL is available
    if (contentData == null || contentData.getContentUrl() == null)
    {
        // there is no URL - the interface specifies that this is not an error condition
        return null;                                
    }
    String contentUrl = contentData.getContentUrl();
    
    // The context of the read is entirely described by the URL
    ContentReader reader = store.getReader(contentUrl);
    if (reader == null)
    {
        throw new AlfrescoRuntimeException("ContentStore implementations may not return null ContentReaders");
    }
    
    // set extra data on the reader
    reader.setMimetype(contentData.getMimetype());
    reader.setEncoding(contentData.getEncoding());
    reader.setLocale(contentData.getLocale());
    
    // Fire the content read policy
    if (reader != null && fireContentReadPolicy == true)
    {
        // Fire the content update policy
        Set<QName> types = new HashSet<QName>(this.nodeService.getAspects(nodeRef));
        types.add(this.nodeService.getType(nodeRef));
        OnContentReadPolicy policy = this.onContentReadDelegate.get(nodeRef, types);
        policy.onContentRead(nodeRef);
    }
    
    // we don't listen for anything
    // result may be null - but interface contract says we may return null
    return reader;
}