2 * Copyright 2011 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.server.webdav.milton;
21 import java.io.FileInputStream;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.OutputStream;
25 import java.util.Date;
28 import org.apache.commons.io.IOUtils;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 import com.bradmcevoy.common.ContentTypeUtils;
33 import com.bradmcevoy.http.Auth;
34 import com.bradmcevoy.http.CollectionResource;
35 import com.bradmcevoy.http.CopyableResource;
36 import com.bradmcevoy.http.DeletableResource;
37 import com.bradmcevoy.http.GetableResource;
38 import com.bradmcevoy.http.MoveableResource;
39 import com.bradmcevoy.http.PropFindableResource;
40 import com.bradmcevoy.http.PropPatchableResource;
41 import com.bradmcevoy.http.Range;
42 import com.bradmcevoy.http.Request;
43 import com.bradmcevoy.http.exceptions.BadRequestException;
44 import com.bradmcevoy.http.exceptions.ConflictException;
45 import com.bradmcevoy.http.exceptions.NotAuthorizedException;
46 import com.bradmcevoy.http.webdav.PropPatchHandler.Fields;
48 import gr.ebs.gss.client.exceptions.InsufficientPermissionsException;
49 import gr.ebs.gss.client.exceptions.ObjectNotFoundException;
50 import gr.ebs.gss.client.exceptions.RpcException;
51 import gr.ebs.gss.server.domain.dto.FileHeaderDTO;
52 import gr.ebs.gss.server.domain.dto.UserDTO;
59 public class GssFileResource extends GssResource implements CopyableResource, DeletableResource, GetableResource, MoveableResource, PropFindableResource, PropPatchableResource {
61 private static final Logger log = LoggerFactory.getLogger(GssFileResource.class);
67 public GssFileResource(String host, GSSResourceFactory factory, Object resource) {
68 super(host, factory, resource);
69 this.file = (FileHeaderDTO)resource;
73 public String checkRedirect(Request arg0) {
74 // TODO Auto-generated method stub
78 public Date getModifiedDate() {
79 return file.getAuditInfo().getModificationDate();
82 public String getName() {
83 return file.getName();
86 public String getUniqueId() {
87 return file.getId().toString();
90 public void moveTo(CollectionResource arg0, String arg1) throws ConflictException, NotAuthorizedException, BadRequestException {
91 // TODO Auto-generated method stub
95 public void copyTo(CollectionResource arg0, String arg1) throws NotAuthorizedException, BadRequestException, ConflictException {
96 log.info("COPY FILE:"+arg0);
100 public void delete() throws NotAuthorizedException, ConflictException, BadRequestException {
102 factory.getService().deleteFile(getCurrentUser().getId(), file.getId());
103 } catch (ObjectNotFoundException e) {
104 // TODO Auto-generated catch block
106 } catch (InsufficientPermissionsException e) {
107 // TODO Auto-generated catch block
109 } catch (RpcException e) {
110 // TODO Auto-generated catch block
116 public Long getContentLength() {
117 return file.getFileSize();
120 public String getContentType(String preferredList ) {
121 return file.getMimeType();
124 public Long getMaxAgeSeconds(Auth arg0) {
125 return factory.maxAgeSeconds( this );
128 public void sendContent(OutputStream out, Range range, Map<String, String> params, String contentType ) throws IOException {
129 InputStream in = null;
131 in = factory.getService().getFileContents(getCurrentUser().getId(), file.getId());
132 // if( range != null ) {
133 // long start = range.getStart();
134 // if( start > 0 ) in.skip(start);
135 // long finish = range.getFinish();
136 // if( finish > 0 ) {
137 // StreamToStream.readTo(in, out);
140 int bytes = IOUtils.copy( in, out );
144 } catch (ObjectNotFoundException e) {
145 // TODO Auto-generated catch block
147 } catch (InsufficientPermissionsException e) {
148 // TODO Auto-generated catch block
150 } catch (RpcException e) {
151 // TODO Auto-generated catch block
154 IOUtils.closeQuietly( in );
159 public Date getCreateDate() {
160 // TODO Auto-generated method stub
161 return file.getAuditInfo().getCreationDate();
164 public void setProperties(Fields arg0) {
165 // TODO Auto-generated method stub