1
14
15 package com.liferay.portlet.imagegallery.webdav;
16
17 import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream;
18 import com.liferay.portal.kernel.util.MimeTypesUtil;
19 import com.liferay.portal.kernel.util.StringPool;
20 import com.liferay.portal.model.Image;
21 import com.liferay.portal.service.ImageLocalServiceUtil;
22 import com.liferay.portal.webdav.BaseResourceImpl;
23 import com.liferay.portal.webdav.WebDAVException;
24 import com.liferay.portlet.imagegallery.model.IGImage;
25
26 import java.io.InputStream;
27
28
33 public class IGImageResourceImpl extends BaseResourceImpl {
34
35 public IGImageResourceImpl(IGImage image, String parentPath, String name) {
36 super(
37 parentPath, name, image.getNameWithExtension(),
38 image.getCreateDate(), image.getModifiedDate(),
39 image.getImageSize());
40
41 setModel(image);
42 setClassName(IGImage.class.getName());
43 setPrimaryKey(image.getPrimaryKey());
44
45 _image = image;
46 }
47
48 public boolean isCollection() {
49 return false;
50 }
51
52 public String getContentType() {
53 String type = StringPool.BLANK;
54
55 try {
56 type = _image.getImageType();
57 }
58 catch (Exception e) {
59 }
60
61 return MimeTypesUtil.getContentType(type);
62 }
63
64 public InputStream getContentAsStream() throws WebDAVException {
65 try {
66 Image image = ImageLocalServiceUtil.getImage(
67 _image.getLargeImageId());
68
69 byte[] bytes = image.getTextObj();
70
71 return new UnsyncByteArrayInputStream(bytes);
72 }
73 catch (Exception e) {
74 throw new WebDAVException(e);
75 }
76 }
77
78 private IGImage _image;
79
80 }