use of com.liferay.portal.kernel.repository.model.FileVersion in project liferay-ide by liferay.
the class WebServerServlet method getLastModified.
@Override
protected long getLastModified(HttpServletRequest request) {
try {
Date modifiedDate = null;
Image image = getImage(request, true);
if (image != null) {
modifiedDate = image.getModifiedDate();
} else {
String path = HttpUtil.fixPath(request.getPathInfo());
String[] pathArray = StringUtil.split(path, CharPool.SLASH);
if (pathArray.length == 0) {
return -1;
}
if (pathArray[0].equals("language")) {
return -1;
}
FileEntry fileEntry = null;
try {
fileEntry = getFileEntry(pathArray);
} catch (Exception e) {
}
if (fileEntry == null) {
return -1;
} else {
String version = ParamUtil.getString(request, "version");
if (Validator.isNotNull(version)) {
FileVersion fileVersion = fileEntry.getFileVersion(version);
modifiedDate = fileVersion.getModifiedDate();
} else {
modifiedDate = fileEntry.getModifiedDate();
}
}
}
if (modifiedDate == null) {
modifiedDate = PortalUtil.getUptime();
}
return (modifiedDate.getTime() / 1000) * 1000;
} catch (PrincipalException pe) {
if (_log.isWarnEnabled()) {
_log.warn(pe, pe);
}
} catch (Exception e) {
_log.error(e, e);
}
return -1;
}
use of com.liferay.portal.kernel.repository.model.FileVersion in project liferay-ide by liferay.
the class LiferayMediaItemService method toMediaItem.
protected MediaItem toMediaItem(FileEntry fileEntry, Set<String> fields, SecurityToken securityToken) throws Exception {
MediaItem mediaItem = new MediaItemImpl();
mediaItem.setAlbumId(String.valueOf(fileEntry.getFolderId()));
mediaItem.setCreated(String.valueOf(fileEntry.getCreateDate()));
mediaItem.setDescription(fileEntry.getDescription());
mediaItem.setId(String.valueOf(fileEntry.getFileEntryId()));
mediaItem.setLastUpdated(String.valueOf(fileEntry.getModifiedDate()));
mediaItem.setMimeType(MimeTypesUtil.getContentType(StringPool.PERIOD.concat(fileEntry.getExtension())));
mediaItem.setNumViews(String.valueOf(fileEntry.getReadCount()));
mediaItem.setTitle(fileEntry.getTitle());
mediaItem.setType(toMediaItemType(StringPool.PERIOD.concat(fileEntry.getExtension())));
String fileEntryURL = ShindigUtil.getFileEntryURL(securityToken.getDomain(), fileEntry.getFileEntryId());
mediaItem.setUrl(fileEntryURL);
FileVersion fileVersion = fileEntry.getLatestFileVersion();
SerializerUtil.copyProperties(fileVersion.getAttributes(), mediaItem, _MEDIA_ITEM_FIELDS);
return mediaItem;
}
use of com.liferay.portal.kernel.repository.model.FileVersion in project liferay-ide by liferay.
the class DLPreviewableProcessor method exportPreview.
protected void exportPreview(PortletDataContext portletDataContext, FileEntry fileEntry, Element fileEntryElement, String binPathSuffix, String previewType, int fileIndex) throws Exception {
if (portletDataContext.isPerformDirectBinaryImport()) {
return;
}
FileVersion fileVersion = fileEntry.getFileVersion();
if (!hasPreview(fileVersion, previewType)) {
if (_log.isWarnEnabled()) {
_log.warn("No preview found for file entry " + fileEntry.getFileEntryId());
}
return;
}
String binPathSegment = null;
if (fileIndex < 0) {
binPathSegment = previewType;
} else {
binPathSegment = Integer.toString(fileIndex + 1);
}
String binPath = getBinPath(portletDataContext, fileEntry, binPathSegment);
StringBundler sb = new StringBundler(4);
sb.append("bin-path-preview-");
sb.append(binPathSegment);
sb.append("-");
sb.append(binPathSuffix);
String binPathName = sb.toString();
fileEntryElement.addAttribute(binPathName, binPath);
InputStream is = null;
try {
if (fileIndex < 0) {
is = doGetPreviewAsStream(fileVersion, previewType);
} else {
is = doGetPreviewAsStream(fileVersion, fileIndex + 1, previewType);
}
exportBinary(portletDataContext, fileEntryElement, fileVersion, is, binPath, binPathName);
} finally {
StreamUtil.cleanUp(is);
}
}
use of com.liferay.portal.kernel.repository.model.FileVersion in project liferay-ide by liferay.
the class DLPreviewableProcessor method importThumbnail.
protected void importThumbnail(PortletDataContext portletDataContext, FileEntry fileEntry, FileEntry importedFileEntry, Element fileEntryElement, String binPathName, int index) throws Exception {
if (!isThumbnailEnabled(index)) {
return;
}
if (!portletDataContext.isPerformDirectBinaryImport()) {
importThumbnailFromLAR(portletDataContext, importedFileEntry, fileEntryElement, binPathName, index);
} else {
FileVersion fileVersion = fileEntry.getFileVersion();
if (!hasThumbnail(fileVersion, index)) {
return;
}
InputStream is = null;
try {
is = doGetThumbnailAsStream(fileVersion, index);
FileVersion importedFileVersion = importedFileEntry.getFileVersion();
String thumbnailFilePath = getThumbnailFilePath(importedFileVersion, getThumbnailType(importedFileVersion), index);
addFileToStore(portletDataContext.getCompanyId(), THUMBNAIL_PATH, thumbnailFilePath, is);
} finally {
StreamUtil.cleanUp(is);
}
}
}
use of com.liferay.portal.kernel.repository.model.FileVersion in project liferay-ide by liferay.
the class DLPreviewableProcessor method exportThumbnail.
protected void exportThumbnail(PortletDataContext portletDataContext, FileEntry fileEntry, Element fileEntryElement, String binPathName, int index) throws PortalException, SystemException {
if (!isThumbnailEnabled(index)) {
return;
}
FileVersion fileVersion = fileEntry.getFileVersion();
if (!hasThumbnail(fileVersion, index)) {
if (_log.isWarnEnabled()) {
_log.warn("No thumbnail found for file entry " + fileEntry.getFileEntryId());
}
return;
}
InputStream is = null;
try {
is = doGetThumbnailAsStream(fileVersion, index);
String binPath = getBinPath(portletDataContext, fileEntry, index);
fileEntryElement.addAttribute(binPathName, binPath);
exportBinary(portletDataContext, fileEntryElement, fileVersion, is, binPath, binPathName);
} finally {
StreamUtil.cleanUp(is);
}
}
Aggregations