use of com.liferay.portal.model.Image 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.model.Image in project liferay-ide by liferay.
the class WebServerServlet method service.
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
User user = null;
try {
user = _getUser(request);
PrincipalThreadLocal.setName(user.getUserId());
PrincipalThreadLocal.setPassword(PortalUtil.getUserPassword(request));
PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user, true);
PermissionThreadLocal.setPermissionChecker(permissionChecker);
if (_lastModified) {
long lastModified = getLastModified(request);
if (lastModified > 0) {
long ifModifiedSince = request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE);
if ((ifModifiedSince > 0) && (ifModifiedSince == lastModified)) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
}
if (lastModified > 0) {
response.setDateHeader(HttpHeaders.LAST_MODIFIED, lastModified);
}
}
String path = HttpUtil.fixPath(request.getPathInfo());
String[] pathArray = StringUtil.split(path, CharPool.SLASH);
if (pathArray.length == 0) {
sendGroups(response, user, request.getServletPath() + StringPool.SLASH + path);
} else {
if (_PATH_DDL.equals(pathArray[0])) {
sendDDLRecordFile(request, response, pathArray);
} else if (Validator.isNumber(pathArray[0])) {
sendFile(request, response, user, pathArray);
} else {
if (isLegacyImageGalleryImageId(request, response)) {
return;
}
Image image = getImage(request, true);
if (image != null) {
writeImage(image, request, response);
} else {
sendDocumentLibrary(request, response, user, request.getServletPath() + StringPool.SLASH + path, pathArray);
}
}
}
} catch (NoSuchFileEntryException nsfee) {
PortalUtil.sendError(HttpServletResponse.SC_NOT_FOUND, nsfee, request, response);
} catch (PrincipalException pe) {
processPrincipalException(pe, user, request, response);
} catch (Exception e) {
PortalUtil.sendError(e, request, response);
}
}
use of com.liferay.portal.model.Image in project liferay-ide by liferay.
the class WebServerServlet method convertFileEntry.
protected Image convertFileEntry(boolean smallImage, FileEntry fileEntry) throws PortalException, SystemException {
try {
Image image = new ImageImpl();
image.setModifiedDate(fileEntry.getModifiedDate());
InputStream is = null;
if (smallImage) {
is = ImageProcessorUtil.getThumbnailAsStream(fileEntry.getFileVersion(), ImageProcessorImpl.THUMBNAIL_INDEX_DEFAULT);
} else {
is = fileEntry.getContentStream();
}
byte[] bytes = FileUtil.getBytes(is);
image.setTextObj(bytes);
image.setType(fileEntry.getExtension());
return image;
} catch (PortalException pe) {
throw pe;
} catch (SystemException se) {
throw se;
} catch (Exception e) {
throw new SystemException(e);
}
}
use of com.liferay.portal.model.Image in project liferay-ide by liferay.
the class WebServerServlet method getImage.
protected Image getImage(HttpServletRequest request, boolean getDefault) throws PortalException, SystemException {
Image image = null;
long imageId = getImageId(request);
if (imageId > 0) {
image = ImageServiceUtil.getImage(imageId);
String path = GetterUtil.getString(request.getPathInfo());
if (path.startsWith("/user_female_portrait") || path.startsWith("/user_male_portrait") || path.startsWith("/user_portrait")) {
image = getUserPortraitImageResized(image, imageId);
}
} else {
String uuid = ParamUtil.getString(request, "uuid");
long groupId = ParamUtil.getLong(request, "groupId");
boolean igSmallImage = ParamUtil.getBoolean(request, "igSmallImage");
java.lang.Object[] test;
if (Validator_IW.isNotNull(test) && (groupId > 0)) {
try {
FileEntry fileEntry = DLAppServiceUtil.getFileEntryByUuidAndGroupId(uuid, groupId);
image = convertFileEntry(igSmallImage, fileEntry);
} catch (Exception e) {
}
}
}
if (getDefault) {
if (image == null) {
if (_log.isWarnEnabled()) {
_log.warn("Get a default image for " + imageId);
}
image = getDefaultImage(request, imageId);
}
}
return image;
}
Aggregations