2 * This document is a part of the source code and related artifacts
3 * for CollectionSpace, an open source collections management system
4 * for museums and related institutions:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright 2009 University of California at Berkeley
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
16 * https://source.collectionspace.org/collection-space/LICENSE.txt
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 package org.collectionspace.services.common.publicitem;
26 import java.io.InputStream;
27 import java.lang.reflect.Method;
29 import org.collectionspace.authentication.spi.AuthNContext;
30 import org.collectionspace.services.publicitem.PublicitemsCommon;
31 import org.collectionspace.services.client.PublicItemClient;
32 import org.collectionspace.services.client.PoxPayloadIn;
33 import org.collectionspace.services.client.PoxPayloadOut;
34 import org.collectionspace.services.common.NuxeoBasedResource;
35 import org.collectionspace.services.common.ServiceMessages;
36 import org.collectionspace.services.common.blob.BlobOutput;
37 import org.collectionspace.services.common.context.RemoteServiceContext;
38 import org.collectionspace.services.common.imaging.nuxeo.NuxeoBlobUtils;
39 //import org.jboss.resteasy.core.ResourceMethod;
40 import org.jboss.resteasy.spi.HttpRequest;
41 import org.jboss.resteasy.spi.metadata.ResourceMethod;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
45 import javax.ws.rs.Consumes;
46 import javax.ws.rs.GET;
47 import javax.ws.rs.Path;
48 import javax.ws.rs.PathParam;
49 import javax.ws.rs.Produces;
50 import javax.ws.rs.core.Context;
51 import javax.ws.rs.core.Request;
52 import javax.ws.rs.core.Response;
53 import javax.ws.rs.core.UriInfo;
55 @Path(PublicItemClient.SERVICE_PATH)
56 @Consumes("application/xml")
57 @Produces("application/xml")
58 public class PublicItemResource extends NuxeoBasedResource {
60 final Logger logger = LoggerFactory.getLogger(PublicItemResource.class);
63 protected String getVersionString() {
64 final String lastChangeRevision = "$LastChangedRevision$";
65 return lastChangeRevision;
69 public String getServiceName() {
70 return PublicItemClient.SERVICE_NAME;
74 public Class<PublicitemsCommon> getCommonPartClass() {
75 return PublicitemsCommon.class;
79 public boolean allowAnonymousAccess(HttpRequest request,
85 @Path("/{csid}/{tenantId}/" + PublicItemClient.PUBLICITEMS_CONTENT_SUFFIX) // "content"
86 public Response getPublishedResource(
87 @Context Request request,
88 @Context UriInfo uriInfo,
89 @PathParam("csid") String csid,
90 @PathParam(AuthNContext.TENANT_ID_PATH_PARAM) String tenantId) {
91 Response result = null;
95 // First, extract the PublicitemsCommon instance.
97 RemoteServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = (RemoteServiceContext<PoxPayloadIn, PoxPayloadOut>) createServiceContext(uriInfo);
98 PoxPayloadOut poxPayloadOut = get(csid, ctx);
99 PublicitemsCommon publicitemsCommon = (PublicitemsCommon)poxPayloadOut.getPart(PublicItemClient.SERVICE_COMMON_PART_NAME).getBody();
101 // Get the repository blob ID and retrieve the content as a stream
103 String blobContentCsid = publicitemsCommon.getContentId();
104 StringBuffer outMimeType = new StringBuffer();
105 BlobOutput blobOutput = NuxeoBlobUtils.getBlobOutput(ctx, getRepositoryClient(ctx), blobContentCsid, outMimeType);
106 InputStream contentStream = blobOutput.getBlobInputStream();
108 // Return the content stream in the response
110 Response.ResponseBuilder responseBuilder = Response.ok(contentStream, outMimeType.toString());
111 responseBuilder = responseBuilder.header("Content-Disposition","inline;filename=\""
112 + publicitemsCommon.getContentName() +"\"");
113 result = responseBuilder.build();
114 } catch (Exception e) {
115 throw bigReThrow(e, ServiceMessages.READ_FAILED, csid);