diff --git a/distro/changelog.xml b/distro/changelog.xml index 75d89ff..007e722 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,9 +1,16 @@ - - updated opengraph checkURL for getting images in case of HTTP redirect permanently is encountered + + Removed asl session dependency + Thumbnails are no longer stored on the FTP server. Storage + service is used + + + updated opengraph checkURL for getting images in case of HTTP + redirect permanently is encountered + - Updated to Liferay 6.2.5 @@ -24,7 +31,8 @@ made notification to members option configurable as default, - see Feature #121 + see Feature #121 + diff --git a/pom.xml b/pom.xml index d50a4b8..fff83d5 100644 --- a/pom.xml +++ b/pom.xml @@ -97,7 +97,7 @@ org.gcube.core common-scope-maps - compile + provided org.gcube.portlets.widgets @@ -232,10 +232,12 @@ org.slf4j slf4j-log4j12 + provided org.slf4j slf4j-api + provided diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/FilePreviewer.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/FilePreviewer.java index fe5fbd0..22824cf 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/FilePreviewer.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/FilePreviewer.java @@ -8,20 +8,27 @@ import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.RandomAccessFile; +import java.net.HttpURLConnection; +import java.net.URL; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; +import java.util.UUID; import javax.imageio.ImageIO; import javax.imageio.ImageReader; import javax.imageio.stream.ImageInputStream; +import javax.servlet.ServletContext; import net.coobird.thumbnailator.Thumbnails; +import org.apache.commons.fileupload.util.Streams; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.util.PDFTextStripper; import org.apache.tika.config.TikaConfig; @@ -29,8 +36,7 @@ import org.apache.tika.detect.Detector; import org.apache.tika.io.TikaInputStream; import org.apache.tika.metadata.Metadata; import org.apache.tika.mime.MediaType; -import org.gcube.applicationsupportlayer.social.storage.FTPManager; -import org.gcube.portal.databook.shared.ImageType; +import org.gcube.contentmanagement.blobstorage.service.IClient; import org.gcube.portlets.user.shareupdates.shared.LinkPreview; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,35 +45,36 @@ import com.sun.pdfview.PDFFile; import com.sun.pdfview.PDFPage; import com.sun.pdfview.PDFParseException; /** - * - * @author Massimiliano Assante, ISTI-CNR - * * Parse files and returns an image preview plus description - * + * @author Massimiliano Assante, ISTI-CNR */ public class FilePreviewer { - private static Logger _log = LoggerFactory.getLogger(FilePreviewer.class); - private static final String PDF_DEFAULT_IMAGE = "default/pdf.png"; - private static final String GENERICFILE_DEFAULT_IMAGE = "default/default_generic.png"; + private static final Logger _log = LoggerFactory.getLogger(FilePreviewer.class); + private static final String UPLOAD_LOCATION_LOCAL = System.getProperty("java.io.tmpdir"); + public static final String DIR_STORAGE_DEFAULT_ICONS = "default-icons-directory"; // to be append to UPLOAD_DIR + /** * these are the extension for which I have an icon image preview */ private static final String[] handledextensionImages = {"css", "csv", "doc", "docx", "java", "mdb", "mp3", "pdf", "ppt", "pptx", "psd", "rar", "tex", "txt", "xls", "xlsx", "zip"}; - private static FTPManager getFTPManager() { - return FTPManager.getInstance(); - } - /** * * @param fileNameLabel thename of the file * @param path2Pdf the path of the pdf file * @param httpUrl the http url where the file is reachable at + * @param storageClient * @return * @throws Exception */ - protected static LinkPreview getPdfPreview(String fileName, String path2Pdf, String httpUrl, String mimeType) throws Exception { + protected static LinkPreview getPdfPreview( + String fileName, + String path2Pdf, + String httpUrl, + String mimeType, + IClient sClient, + ServletContext sContext) throws Exception { ArrayList imagesUrl = new ArrayList(); //description String desc = null; @@ -90,8 +97,7 @@ public class FilePreviewer { } catch (PDFParseException ex) { raf.close(); _log.error("PDF Parse exception, returning default pdf image"); - - imagesUrl.add(getFTPManager().getBaseURL()+PDF_DEFAULT_IMAGE); + imagesUrl.add(getDefaultIconUrl(sClient, IconFileNames.PDF.getFileName(), sContext)); return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl); } PDFPage page = pdf.getPage(0); @@ -104,11 +110,8 @@ public class FilePreviewer { // create the image Rectangle rect = new Rectangle(0, 0, width, height); - BufferedImage bufferedImage = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_RGB); - Image image = page.getImage(scaledWidth, scaledHeight, rect, null, true, true); - Graphics2D bufImageGraphics = bufferedImage.createGraphics(); bufImageGraphics.drawImage(image, 0, 0, scaledWidth, scaledHeight, null); @@ -118,9 +121,14 @@ public class FilePreviewer { raf.close(); if (result) { - String httpLink = getFTPManager().uploadImageOnFTPServer(new ByteArrayInputStream(out.toByteArray()), ImageType.JPG); - _log.debug("PDF thumbnail available at: " + httpLink); - imagesUrl.add(httpLink); + try{ + String storagehttpLink = syncUploadThumbnailStorage(new ByteArrayInputStream(out.toByteArray()), sClient, "thumbnail_" + fileName); + imagesUrl.add(storagehttpLink); + _log.debug("PDF thumbnail available at: " + storagehttpLink); + }catch(Exception e){ + _log.error("Failed to create a thumbnail for the preview ..."); + imagesUrl.add(getDefaultIconUrl(sClient, IconFileNames.PDF.getFileName(), sContext)); + } return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl); } else @@ -134,7 +142,7 @@ public class FilePreviewer { * @return * @throws Exception */ - protected static LinkPreview getImagePreview(String fileName, String path2Image, String httpUrl, String mimeType) { + protected static LinkPreview getImagePreview(String fileName, String path2Image, String httpUrl, String mimeType, IClient sClient, ServletContext sContext) { ArrayList imagesUrl = new ArrayList(); Dimension dim; @@ -152,13 +160,15 @@ public class FilePreviewer { .width(80) .outputFormat("jpg") .toOutputStream(out); + + String storagehttpLink = syncUploadThumbnailStorage(new ByteArrayInputStream(out.toByteArray()), sClient, "thumbnail_" + fileName); + _log.debug("Image thumbnail available at: " + storagehttpLink); + imagesUrl.add(storagehttpLink); + }catch (IOException e) { + _log.error("Failed to get a preview... Using generic image"); + imagesUrl.add(getDefaultIconUrl(sClient, IconFileNames.IMAGE_GENERIC.getFileName(), sContext)); } - catch (IOException e) { - e.printStackTrace(); - } - String httpLink = getFTPManager().uploadImageOnFTPServer(new ByteArrayInputStream(out.toByteArray()), ImageType.JPG); - _log.debug("\nFlushed, Image thumbnail available at: " + httpLink); - imagesUrl.add(httpLink); + return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl); } @@ -170,20 +180,26 @@ public class FilePreviewer { * @return * @throws Exception */ - protected static LinkPreview getUnhandledTypePreview(String fileName, String path2Pdf, String httpUrl, String mimeType) throws Exception { + protected static LinkPreview getUnhandledTypePreview( + String fileName, + String path2Pdf, + String httpUrl, + String mimeType, + IClient sClient, + ServletContext sContext) throws Exception { ArrayList imagesUrl = new ArrayList(); String extension = getExtension(fileName); //no description String desc = ""; if (extension == null) - imagesUrl.add(getFTPManager().getBaseURL()+GENERICFILE_DEFAULT_IMAGE); + imagesUrl.add(getDefaultIconUrl(sClient, IconFileNames.GENERIC.getFileName(), sContext)); else { int foundIndex = Arrays.binarySearch(handledextensionImages, extension); if (foundIndex < 0) - imagesUrl.add(getFTPManager().getBaseURL()+GENERICFILE_DEFAULT_IMAGE); + imagesUrl.add(getDefaultIconUrl(sClient, IconFileNames.GENERIC.getFileName(), sContext)); else - imagesUrl.add(getFTPManager().getBaseURL()+"default/"+extension+".png"); + imagesUrl.add(getDefaultIconUrl(sClient, extension+".png", sContext)); } return new LinkPreview(fileName, desc, httpUrl, mimeType, imagesUrl); } @@ -254,4 +270,148 @@ public class FilePreviewer { MediaType mediaType = detector.detect(stream, metadata); return mediaType.getBaseType().toString(); } + + /** + * Same as above, but having as input an inputstream object + * @param is + * @param filenameWithExtension + * @return + * @throws IOException + */ + protected static String getMimeType(InputStream is, String filenameWithExtension) throws IOException { + TikaConfig config = TikaConfig.getDefaultConfig(); + Detector detector = config.getDetector(); + TikaInputStream stream = TikaInputStream.get(is); + Metadata metadata = new Metadata(); + metadata.add(Metadata.RESOURCE_NAME_KEY, filenameWithExtension); + MediaType mediaType = detector.detect(stream, metadata); + return mediaType.getBaseType().toString(); + } + + /** + * Upload a thumbnail on the storage and returns the http url. The operation is synchronous + * @param sClient + * @param byteArrayInputStream + * @return http url of the thumbnail + */ + protected static String syncUploadThumbnailStorage(ByteArrayInputStream byteArrayInputStream, IClient sClient, String thumbnailFileName){ + try{ + // a random remote folder/file on the storage for the thumbnail + String randomUploadFolderName = UUID.randomUUID().toString(); + String remoteFilePath = ShareUpdateServiceImpl.UPLOAD_DIR + "/" + randomUploadFolderName + "/" + thumbnailFileName; + String thumbnailMime = getMimeType(byteArrayInputStream, null); + sClient.put(true, thumbnailMime).LFile(byteArrayInputStream).RFile(remoteFilePath); + return sClient.getHttpUrl(true).RFile(remoteFilePath); + }catch(Exception e){ + _log.error("Failed to upload thumbnail on storage..."); + return null; + } + } + + /** + * Check if a resource at a given url exists or not. If it exists, create a file in the temp dir + * of the tomcat. Files and folers are deleted on exit. + * @param urlThumbnail + * @return + */ + public static File storeAndGetFile(String urlThumbnail){ + try { + HttpURLConnection.setFollowRedirects(true); + HttpURLConnection con = + (HttpURLConnection) new URL(urlThumbnail).openConnection(); + con.setRequestMethod("HEAD"); // body is not needed yet + if(con.getResponseCode() == HttpURLConnection.HTTP_OK){ + + //generate the random dir + File theRandomDir = new File(UPLOAD_LOCATION_LOCAL + File.separator + UUID.randomUUID().toString()); + theRandomDir.mkdir(); + theRandomDir.deleteOnExit(); + _log.debug("Created temp upload directory in: " + theRandomDir); + + // generate a random file name and create it under the randomDir + File file = new File(theRandomDir, UUID.randomUUID().toString().substring(0, 10)); + file.deleteOnExit(); + + //Get the inputstream and copy there + URL url = new URL(urlThumbnail); + Streams.copy(url.openStream(), new FileOutputStream(file), true); + _log.debug("File is at " + file.getAbsolutePath()); + + return file; + }else + return null; + } + catch (Exception e) { + _log.error("The resource at url " + urlThumbnail + " doesn't exist"); + return null; + } + } + + /** + * When a link preview needs to be saved, the method save the thumbnail on the storage no longer using the external url + * @param urlThumbnail + * @return the url of the thumbnail saved on the storage or null in case of error + */ + public static String getThumbnailFromUrl(String urlThumbnail, IClient sClient, ServletContext sContext) { + File localFile; + if((localFile = storeAndGetFile(urlThumbnail)) != null){ + String mimeType = null; + try { + mimeType = FilePreviewer.getMimeType(localFile, localFile.getName()); + String thumbnailUrlStorage = null; + switch(mimeType){ + case "image/png": + case "image/gif": + case "image/tiff": + case "image/jpg": + case "image/jpeg": + case "image/bmp": + thumbnailUrlStorage = getImagePreview(localFile.getName(), localFile.getAbsolutePath(), null, mimeType, sClient, sContext).getImageUrls().get(0); + break; + default: break; + } + return thumbnailUrlStorage; + } catch (IOException e) { + _log.error("Error while saving thumbnail on ftp", e); + } + + }else + _log.warn("the file at url " + urlThumbnail + " doesn't exist"); + + return null; + } + + /** + * When the preview methods fail to create a thumbnail and one of the "default icons" needs to be used, + * the method retrieve the url of these files from the storage. In case the icon is missing, it upload the file too on the storage + * before returning. + * @param storage + * @return + */ + private static String getDefaultIconUrl(IClient sClient, String iconFile, ServletContext sContext){ + + try{ + //TODO do I need to download the whole stream?! + String iconPathOnStorage = ShareUpdateServiceImpl.UPLOAD_DIR + "/" + FilePreviewer.DIR_STORAGE_DEFAULT_ICONS + "/" + iconFile; + _log.debug("looking for remote file at relative url " + iconPathOnStorage); + + InputStream inputStream = sClient.get().RFileAsInputStream(iconPathOnStorage); + if(inputStream == null){ + _log.info("Ok, the default icon was not on the storage.. going to put it there"); + InputStream localInputStream = sContext.getResourceAsStream("/images/default/" + iconFile); + if(localInputStream != null){ + sClient.put(true).LFile(localInputStream).RFile(iconPathOnStorage); + _log.info("Request for upload started for file " + iconPathOnStorage + ", trying to get the http url"); + return sClient.getHttpUrl(true).RFile(iconPathOnStorage); + }else{ + _log.warn("Failed to get the inputstream of the icon " + iconFile + " form the subpath /images/default/"); + return null; + } + }else + return sClient.getHttpUrl(true).RFile(iconPathOnStorage); + }catch(Exception e){ + _log.error("Something went wrong with the storage for the default image.. returning null", e); + } + return null; + } } diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/IconFileNames.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/IconFileNames.java new file mode 100644 index 0000000..83d9d87 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/IconFileNames.java @@ -0,0 +1,38 @@ +package org.gcube.portlets.user.shareupdates.server; + +/** + * Icons type + * @author Costantino Perciante at ISTI-CNR + * (costantino.perciante@isti.cnr.it) + */ +public enum IconFileNames { + + GENERIC("default_generic.png"), + IMAGE_GENERIC("default_image.png"), + DOCX("docx.png"), + PPTX("pptx.png"), + PDF("pdf.png"), + RAR("rar.png"), + ZIP("zip.png"), + XLS("xls.png"), + CSS("css.png"), + CSV("csv.png"), + DOC("doc.png"), + JAVA("java.png"), + MDB("mdb.png"), + MP3("mp3.png"), + PSD("psd.png"), + TEX("tex.png"), + PPT("ppt.png"), + XLSX("xlsx.png"); + + private String fileName; + + IconFileNames(String fileName){ + this.fileName = fileName; + } + + public String getFileName(){ + return this.fileName; + } +} diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java index e6406c4..85f9198 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java @@ -1,7 +1,6 @@ package org.gcube.portlets.user.shareupdates.server; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.net.HttpURLConnection; import java.net.MalformedURLException; @@ -19,7 +18,6 @@ import java.util.UUID; import javax.net.ssl.HttpsURLConnection; -import org.apache.commons.fileupload.util.Streams; import org.apache.commons.validator.routines.UrlValidator; import org.gcube.applicationsupportlayer.social.ApplicationNotificationsManager; import org.gcube.applicationsupportlayer.social.NotificationsManager; @@ -84,12 +82,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar private static final String STORAGE_OWNER = "gCubeSocialFramework"; public static final String UPLOAD_DIR = "/social-framework-uploads"; private static final String NEWS_FEED_PORTLET_CLASSNAME = "org.gcube.portlets.user.newsfeed.server.NewsServiceImpl"; - private static String UPLOAD_LOCATION_LOCAL = System.getProperty("java.io.tmpdir"); - - /** - * - */ - private static Logger _log = LoggerFactory.getLogger(ShareUpdateServiceImpl.class); + private static final Logger _log = LoggerFactory.getLogger(ShareUpdateServiceImpl.class); private DatabookStore store; /** @@ -146,7 +139,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar String username = currUser.getUsername(); String email = currUser.getEmail(); String fullName = currUser.getFullname(); - String thumbnailAvatarURL = currUser.getUserAvatarId(); + String thumbnailAvatarURL = currUser.getUserAvatarURL(); // get data from the preview of the link String linkTitle = preview.getTitle(); @@ -156,7 +149,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar if (urlThumbnail == null) urlThumbnail = "null"; else - urlThumbnail = saveThumbnailOnFTPAndGetUrl(urlThumbnail); + urlThumbnail = FilePreviewer.getThumbnailFromUrl(urlThumbnail, getStorage(), getServletContext()); Date feedDate = new Date(); @@ -192,7 +185,6 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar }//save the feed _log.trace("Success writing onto " + vreScope); } - } //share on a single VRE Timeline //receives a VreId(groupId) get the scope from the groupId @@ -228,80 +220,6 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar } - /** - * Check if a resource at a given url exists or not. If it exists, create a file in the temp dir - * of the tomcat - * @param urlThumbnail - * @return - */ - private File storeAndGetFile(String urlThumbnail){ - try { - HttpURLConnection.setFollowRedirects(true); - HttpURLConnection con = - (HttpURLConnection) new URL(urlThumbnail).openConnection(); - con.setRequestMethod("HEAD"); // body is not needed yet - if(con.getResponseCode() == HttpURLConnection.HTTP_OK){ - - //generate the random dir - File theRandomDir = new File(UPLOAD_LOCATION_LOCAL + File.separator + UUID.randomUUID().toString()); - theRandomDir.mkdir(); - theRandomDir.deleteOnExit(); - _log.debug("Created temp upload directory in: " + theRandomDir); - - // generate a random file name and create it under the randomDir - File file = new File(theRandomDir, UUID.randomUUID().toString().substring(0, 10)); - file.deleteOnExit(); - - //Get the inputstream and copy there - URL url = new URL(urlThumbnail); - Streams.copy(url.openStream(), new FileOutputStream(file), true); - _log.debug("File is at " + file.getAbsolutePath()); - - return file; - }else - return null; - } - catch (Exception e) { - _log.error("The resource at url " + urlThumbnail + " doesn't exist"); - return null; - } - } - - /** - * When a link preview needs to be saved, the method save the thumbnail on the storage no longer using the external url - * @param urlThumbnail - * @return the url of the thumbnail saved on the storage or null in case of error - */ - private String saveThumbnailOnFTPAndGetUrl(String urlThumbnail) { - File localFile; - if((localFile = storeAndGetFile(urlThumbnail)) != null){ - String mimeType = null; - if (isWithinPortal()) { - try { - mimeType = FilePreviewer.getMimeType(localFile, localFile.getName()); - String thumbnailUrlFTP = null; - switch(mimeType){ - case "image/png": - case "image/gif": - case "image/tiff": - case "image/jpg": - case "image/jpeg": - case "image/bmp": - thumbnailUrlFTP = FilePreviewer.getImagePreview(localFile.getName(), localFile.getAbsolutePath(), null, mimeType).getImageUrls().get(0); - break; - default: break; - } - return thumbnailUrlFTP; - } catch (IOException e) { - _log.error("Error while saving thumbnail on ftp", e); - } - } - }else - _log.warn("the file at url " + urlThumbnail + " doesn't exist"); - - return null; - } - /** * Share a post with at least one attachment. */ @@ -331,7 +249,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar String username = currUser.getUsername(); String email = currUser.getEmail(); String fullName = currUser.getFullname(); - String thumbnailAvatarURL = currUser.getUserAvatarId(); + String thumbnailAvatarURL = currUser.getUserAvatarURL(); // Managing attachments: the first one will use the same fields of a link preview. // If more than one attachments are present, they will be saved as Attachment objects. @@ -664,17 +582,14 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar @Override public LinkPreview checkUploadedFile(String fileName, String fileabsolutePathOnServer) { - PortalContext context = PortalContext.getConfiguration(); - LinkPreview toReturn = null; + // a random remote folder/file on the storage for the payload String randomUploadFolderName = UUID.randomUUID().toString(); String remoteFilePath = UPLOAD_DIR + "/" + randomUploadFolderName + "/" + fileName; + //get the Storage Client - String currScope = ScopeProvider.instance.get(); - ScopeProvider.instance.set(context.getCurrentScope(getThreadLocalRequest())); - IClient storageClient = new StorageClient(STORAGE_OWNER, AccessType.SHARED, MemoryType.PERSISTENT).getClient(); - ScopeProvider.instance.set(currScope); + IClient storageClient = getStorage(); String httpURL = ""; String smpURI = ""; @@ -692,49 +607,44 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar } Thread thread = new Thread(new UploadToStorageThread(storageClient, fileName, fileabsolutePathOnServer, remoteFilePath, mimeType)); thread.start(); - } - try { - //get the url to show (though it could not be ready for download at this stage) - httpURL = smpURI; - - switch (mimeType) { - case "application/pdf": - toReturn = FilePreviewer.getPdfPreview(fileName, fileabsolutePathOnServer, httpURL, mimeType); - break; - case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": - mimeType = "application/wordprocessor"; - return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType); - case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": - mimeType = "application/spreadsheet"; - return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType); - case "application/vnd.openxmlformats-officedocument.presentationml.presentation": - mimeType = "application/presentation"; - return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType); - case "image/png": - case "image/gif": - case "image/tiff": - case "image/jpg": - case "image/jpeg": - case "image/bmp": - toReturn = FilePreviewer.getImagePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType); - break; - default: - return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType); - - } - - } catch (Exception e) { - _log.error("Error while resolving or previewing file"); - e.printStackTrace(); try { - return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, "Error During upload on Server!"); - } catch (Exception e1) { - e1.printStackTrace(); - } - - } + //get the url to show (though it could not be ready for download at this stage) + httpURL = smpURI; + switch (mimeType) { + case "application/pdf": + toReturn = FilePreviewer.getPdfPreview(fileName, fileabsolutePathOnServer, httpURL, mimeType, storageClient, getServletContext()); + break; + case "application/vnd.openxmlformats-officedocument.wordprocessingml.document": + mimeType = "application/wordprocessor"; + return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType, storageClient, getServletContext()); + case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": + mimeType = "application/spreadsheet"; + return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType, storageClient, getServletContext()); + case "application/vnd.openxmlformats-officedocument.presentationml.presentation": + mimeType = "application/presentation"; + return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType, storageClient, getServletContext()); + case "image/png": + case "image/gif": + case "image/tiff": + case "image/jpg": + case "image/jpeg": + case "image/bmp": + toReturn = FilePreviewer.getImagePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType, storageClient, getServletContext()); + break; + default: + return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, mimeType, storageClient, getServletContext()); + } + } catch (Exception e) { + _log.error("Error while resolving or previewing file", e); + try { + return FilePreviewer.getUnhandledTypePreview(fileName, fileabsolutePathOnServer, httpURL, "Error During upload on Server!", storageClient, getServletContext()); + } catch (Exception e1) { + _log.error("Unable to extract a preview ...", e1); + } + } + } _log.debug("smpURI=" + smpURI); _log.debug("Returning httpURL=" + httpURL); return toReturn; @@ -944,4 +854,20 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar } return toReturn; } + + /** + * Return the storage client object + * @return + */ + private IClient getStorage(){ + + String currScope = ScopeProvider.instance.get(); + PortalContext context = PortalContext.getConfiguration(); + ScopeProvider.instance.set(context.getCurrentScope(getThreadLocalRequest())); + IClient storageClient = new StorageClient(STORAGE_OWNER, AccessType.SHARED, MemoryType.PERSISTENT).getClient(); + ScopeProvider.instance.set(currScope); + return storageClient; + + } + } diff --git a/src/main/webapp/images/default/css.png b/src/main/webapp/images/default/css.png new file mode 100644 index 0000000..6c26e3f Binary files /dev/null and b/src/main/webapp/images/default/css.png differ diff --git a/src/main/webapp/images/default/csv.png b/src/main/webapp/images/default/csv.png new file mode 100644 index 0000000..020086a Binary files /dev/null and b/src/main/webapp/images/default/csv.png differ diff --git a/src/main/webapp/images/default/default_generic.png b/src/main/webapp/images/default/default_generic.png new file mode 100644 index 0000000..b0e0695 Binary files /dev/null and b/src/main/webapp/images/default/default_generic.png differ diff --git a/src/main/webapp/images/default/default_image.png b/src/main/webapp/images/default/default_image.png new file mode 100644 index 0000000..e87b145 Binary files /dev/null and b/src/main/webapp/images/default/default_image.png differ diff --git a/src/main/webapp/images/default/doc.png b/src/main/webapp/images/default/doc.png new file mode 100644 index 0000000..f623068 Binary files /dev/null and b/src/main/webapp/images/default/doc.png differ diff --git a/src/main/webapp/images/default/docx.png b/src/main/webapp/images/default/docx.png new file mode 100644 index 0000000..f623068 Binary files /dev/null and b/src/main/webapp/images/default/docx.png differ diff --git a/src/main/webapp/images/default/java.png b/src/main/webapp/images/default/java.png new file mode 100644 index 0000000..423897f Binary files /dev/null and b/src/main/webapp/images/default/java.png differ diff --git a/src/main/webapp/images/default/mdb.png b/src/main/webapp/images/default/mdb.png new file mode 100644 index 0000000..b880b0a Binary files /dev/null and b/src/main/webapp/images/default/mdb.png differ diff --git a/src/main/webapp/images/default/mp3.png b/src/main/webapp/images/default/mp3.png new file mode 100644 index 0000000..9be93fd Binary files /dev/null and b/src/main/webapp/images/default/mp3.png differ diff --git a/src/main/webapp/images/default/pdf.png b/src/main/webapp/images/default/pdf.png new file mode 100644 index 0000000..1ca2749 Binary files /dev/null and b/src/main/webapp/images/default/pdf.png differ diff --git a/src/main/webapp/images/default/ppt.png b/src/main/webapp/images/default/ppt.png new file mode 100644 index 0000000..4c17759 Binary files /dev/null and b/src/main/webapp/images/default/ppt.png differ diff --git a/src/main/webapp/images/default/pptx.png b/src/main/webapp/images/default/pptx.png new file mode 100644 index 0000000..4c17759 Binary files /dev/null and b/src/main/webapp/images/default/pptx.png differ diff --git a/src/main/webapp/images/default/psd.png b/src/main/webapp/images/default/psd.png new file mode 100644 index 0000000..5c4247e Binary files /dev/null and b/src/main/webapp/images/default/psd.png differ diff --git a/src/main/webapp/images/default/rar.png b/src/main/webapp/images/default/rar.png new file mode 100644 index 0000000..45f7ed0 Binary files /dev/null and b/src/main/webapp/images/default/rar.png differ diff --git a/src/main/webapp/images/default/tex.png b/src/main/webapp/images/default/tex.png new file mode 100644 index 0000000..1a4090e Binary files /dev/null and b/src/main/webapp/images/default/tex.png differ diff --git a/src/main/webapp/images/default/txt.png b/src/main/webapp/images/default/txt.png new file mode 100644 index 0000000..17b572f Binary files /dev/null and b/src/main/webapp/images/default/txt.png differ diff --git a/src/main/webapp/images/default/xls.png b/src/main/webapp/images/default/xls.png new file mode 100644 index 0000000..cceb362 Binary files /dev/null and b/src/main/webapp/images/default/xls.png differ diff --git a/src/main/webapp/images/default/xlsx.png b/src/main/webapp/images/default/xlsx.png new file mode 100644 index 0000000..cceb362 Binary files /dev/null and b/src/main/webapp/images/default/xlsx.png differ diff --git a/src/main/webapp/images/default/zip.png b/src/main/webapp/images/default/zip.png new file mode 100644 index 0000000..ded6b41 Binary files /dev/null and b/src/main/webapp/images/default/zip.png differ