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