Search in sources :

Example 1 with ContentInfo

use of org.alfresco.rest.framework.resource.content.ContentInfo in project alfresco-remote-api by Alfresco.

the class AbstractResourceWebScript method streamResponse.

protected void streamResponse(final WebScriptRequest req, final WebScriptResponse res, BinaryResource resource) throws IOException {
    if (resource instanceof FileBinaryResource) {
        FileBinaryResource fileResource = (FileBinaryResource) resource;
        // if requested, set attachment
        boolean attach = StringUtils.isNotEmpty(fileResource.getAttachFileName());
        Map<String, Object> model = getModelForCacheDirective(fileResource.getCacheDirective());
        streamer.streamContent(req, res, fileResource.getFile(), null, attach, fileResource.getAttachFileName(), model);
    } else if (resource instanceof NodeBinaryResource) {
        NodeBinaryResource nodeResource = (NodeBinaryResource) resource;
        ContentInfo contentInfo = nodeResource.getContentInfo();
        setContentInfoOnResponse(res, contentInfo);
        // if requested, set attachment
        boolean attach = StringUtils.isNotEmpty(nodeResource.getAttachFileName());
        Map<String, Object> model = getModelForCacheDirective(nodeResource.getCacheDirective());
        streamer.streamContent(req, res, nodeResource.getNodeRef(), nodeResource.getPropertyQName(), attach, nodeResource.getAttachFileName(), model);
    }
}
Also used : NodeBinaryResource(org.alfresco.rest.framework.resource.content.NodeBinaryResource) ContentInfo(org.alfresco.rest.framework.resource.content.ContentInfo) HashMap(java.util.HashMap) Map(java.util.Map) FileBinaryResource(org.alfresco.rest.framework.resource.content.FileBinaryResource)

Example 2 with ContentInfo

use of org.alfresco.rest.framework.resource.content.ContentInfo in project alfresco-remote-api by Alfresco.

the class WithResponseTest method testSetters.

@Test
public void testSetters() throws Exception {
    WithResponse callBack = new WithResponse(Status.STATUS_OK, ResponseWriter.DEFAULT_JSON_CONTENT, ResponseWriter.CACHE_NEVER);
    callBack.setStatus(Status.STATUS_GONE);
    Cache myCache = new Cache(new Description.RequiredCache() {

        @Override
        public boolean getNeverCache() {
            return false;
        }

        @Override
        public boolean getIsPublic() {
            return true;
        }

        @Override
        public boolean getMustRevalidate() {
            return true;
        }
    });
    callBack.setCache(myCache);
    ContentInfo myContent = new ContentInfoImpl(Format.HTML.mimetype(), "UTF-16", 12, Locale.FRENCH);
    callBack.setContentInfo(myContent);
    assertEquals(Status.STATUS_GONE, callBack.getStatus());
    assertEquals(myCache, callBack.getCache());
    assertEquals(myContent, callBack.getContentInfo());
}
Also used : Description(org.springframework.extensions.webscripts.Description) WithResponse(org.alfresco.rest.framework.webscripts.WithResponse) ContentInfo(org.alfresco.rest.framework.resource.content.ContentInfo) ContentInfoImpl(org.alfresco.rest.framework.resource.content.ContentInfoImpl) Cache(org.springframework.extensions.webscripts.Cache) Test(org.junit.Test)

Aggregations

ContentInfo (org.alfresco.rest.framework.resource.content.ContentInfo)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ContentInfoImpl (org.alfresco.rest.framework.resource.content.ContentInfoImpl)1 FileBinaryResource (org.alfresco.rest.framework.resource.content.FileBinaryResource)1 NodeBinaryResource (org.alfresco.rest.framework.resource.content.NodeBinaryResource)1 WithResponse (org.alfresco.rest.framework.webscripts.WithResponse)1 Test (org.junit.Test)1 Cache (org.springframework.extensions.webscripts.Cache)1 Description (org.springframework.extensions.webscripts.Description)1