added imagesUtil
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/reports@85156 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c538f3c247
commit
f4057ee9fa
|
@ -1,3 +1,2 @@
|
|||
#Thu Jun 16 10:18:26 CEST 2011
|
||||
eclipse.preferences.version=1
|
||||
filesCopiedToWebInfLib=
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package org.gcube.portlets.user.reportgenerator.server.servlet;
|
||||
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.FolderItemType;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalImage;
|
||||
import org.gcube.common.homelibrary.home.workspace.folder.items.gcube.ImageDocument;
|
||||
|
||||
public class ImagesUtil {
|
||||
public static final String GIF = "image/gif";
|
||||
public static final String PNG = "image/png";
|
||||
public static final String JPEG = "image/jpeg";
|
||||
public static final String JPG = "image/jpg";
|
||||
public static final String TIFF = "image/tiff";
|
||||
public static final String BMP = "image/bmp";
|
||||
/**
|
||||
* return a string for the file extension given a mimetype
|
||||
*
|
||||
* @param bi the basketItem
|
||||
* @return a string for the file extension given a mimetype
|
||||
*/
|
||||
public static String getImageExtension(FolderItem bi) {
|
||||
|
||||
String mimetype = "";
|
||||
if (bi.getFolderItemType()==FolderItemType.EXTERNAL_IMAGE){
|
||||
ExternalImage image = (ExternalImage) bi;
|
||||
mimetype = image.getMimeType();
|
||||
}
|
||||
|
||||
if (bi.getFolderItemType()==FolderItemType.IMAGE_DOCUMENT){
|
||||
ImageDocument image = (ImageDocument) bi;
|
||||
mimetype = image.getMimeType();
|
||||
}
|
||||
|
||||
if (mimetype.equals(GIF))
|
||||
return "gif";
|
||||
else if (mimetype.equals(PNG))
|
||||
return "png";
|
||||
else if (mimetype.equals(JPG))
|
||||
return "jpg";
|
||||
else if (mimetype.equals(JPEG))
|
||||
return "jpg";
|
||||
else if (mimetype.equals(TIFF))
|
||||
return "png";
|
||||
else if (mimetype.equals(BMP))
|
||||
return "bmp";
|
||||
else
|
||||
return "jpg";
|
||||
}
|
||||
}
|
|
@ -100,30 +100,7 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
|
|||
private boolean withinPortal = true;
|
||||
|
||||
private static final String TEST_SCOPE = "/gcube/devsec/devVRE";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final String GIF = "image/gif";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final String PNG = "image/png";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final String JPEG = "image/jpeg";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final String JPG = "image/jpg";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final String TIFF = "image/tiff";
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final String BMP = "image/bmp";
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -731,7 +708,7 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
|
|||
if (data != null) {
|
||||
_log.debug("Encoding image in base64");
|
||||
byte[] imageBytes = IOUtils.toByteArray(data);
|
||||
String extension = getImageExtension(imageItem);
|
||||
String extension = ImagesUtil.getImageExtension(imageItem);
|
||||
String srcAttrValue = "data:image/"+extension+";base64,"+DatatypeConverter.printBase64Binary(imageBytes);
|
||||
_log.debug("Encoded image=" + srcAttrValue);
|
||||
return srcAttrValue;
|
||||
|
@ -746,71 +723,6 @@ public class ReportServiceImpl extends RemoteServiceServlet implements ReportSe
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return a string for the file extension given a mimetype
|
||||
*
|
||||
* @param bi the basketItem
|
||||
* @return a string for the file extension given a mimetype
|
||||
*/
|
||||
public static String getImageExtension(FolderItem bi) {
|
||||
|
||||
String mimetype = "";
|
||||
if (bi.getFolderItemType()==FolderItemType.EXTERNAL_IMAGE){
|
||||
ExternalImage image = (ExternalImage) bi;
|
||||
mimetype = image.getMimeType();
|
||||
}
|
||||
|
||||
if (bi.getFolderItemType()==FolderItemType.IMAGE_DOCUMENT){
|
||||
ImageDocument image = (ImageDocument) bi;
|
||||
mimetype = image.getMimeType();
|
||||
}
|
||||
|
||||
if (mimetype.equals(GIF))
|
||||
return "gif";
|
||||
else if (mimetype.equals(PNG))
|
||||
return "png";
|
||||
else if (mimetype.equals(JPG))
|
||||
return "jpg";
|
||||
else if (mimetype.equals(JPEG))
|
||||
return "jpg";
|
||||
else if (mimetype.equals(TIFF))
|
||||
return "png";
|
||||
else if (mimetype.equals(BMP))
|
||||
return "bmp";
|
||||
else
|
||||
return "jpg";
|
||||
}
|
||||
/**
|
||||
* Copies a image from fromTemplate/images/imageNameFile to toTemplate/images/imageNameFile
|
||||
* @param fromTemplate the origin template
|
||||
* @param toTemplate the target template
|
||||
* @param imageNameFile .
|
||||
* @return true if the copy went fine
|
||||
*/
|
||||
public boolean copyImage(String fromTemplate, String toTemplate, String imageNameFile) {
|
||||
ServiceUtil myUtil = new ServiceUtil(getASLSession());
|
||||
String imageFrom = myUtil.getTemplatePath(fromTemplate, getVreName(), getUsername()) + "images" + File.separator + imageNameFile;
|
||||
String imageTarget = myUtil.getTemplatePath(toTemplate, getVreName(), getUsername()) + "images" + File.separator + imageNameFile;
|
||||
|
||||
String imageNewFolder = myUtil.getTemplatePath(toTemplate, getVreName(), getUsername()) + "images" + File.separator;
|
||||
|
||||
_log.debug("Copying:" + imageFrom + "\nto: " + imageTarget);
|
||||
|
||||
File from = new File(imageFrom);
|
||||
File to = new File(imageTarget);
|
||||
|
||||
try {
|
||||
myUtil.copyFile(from, to, imageNewFolder);
|
||||
} catch (Exception e) {
|
||||
_log.error("Error While Copying: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
_log.debug("Copying Success");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param reportItemid the report itemd id in basket to store in the session
|
||||
*/
|
||||
|
|
Reference in New Issue