int widthUrl = -1;
Gallery gallery = null;
String namePhoto = null;
String baseUrlPhoto = null;
Photo photo = (Photo) command;
if (photo.getImage().length != 0){
image=Toolkit.getDefaultToolkit().createImage(photo.getImage());
int h=image.getHeight(null);
int w=image.getWidth(null);
long startTime = System.currentTimeMillis();
int numberPhoto=Toolkit.getDefaultToolkit().checkImage(image, w, h,null );
while(h==-1 || w==-1 || (numberPhoto < 8) )
{
h=image.getHeight(null);
w=image.getWidth(null);
numberPhoto=Toolkit.getDefaultToolkit().checkImage(image, w, h,null );
long endTime = System.currentTimeMillis();
if((endTime-startTime)>3000){
h=100;
w=100;
numberPhoto=100;
}
}
HttpSession session = null;
session = request.getSession();
ServletContext context = session.getServletContext();
String path = context.getRealPath("/");
namePhoto = java.util.UUID.randomUUID().toString();
photo.setName(namePhoto);
User user = userContainer.getUser();
int hotelId = user.getStructureId();
Structure hotel = (Structure) structureManager.get(hotelId);
ImageUtils.upload(namePhoto, path, image, hotelId, hotelId, 400, 400, "big");
baseUrlPhoto =ImageUtils.upload(namePhoto, path, image, hotelId, hotelId, 50, 50, "small");
photo.setUrl(baseUrlPhoto);
photo.setGallery(hotel.getGallery());
String locale = localeContainer.getLocale();
String photoLocale = (String) request.getParameter("locale");
if (!photoLocale.isEmpty())
{
photo.setLocale(photoLocale);
}
else
{
photo.setLocale(locale);
}
localeContainer.setLocale(photo.getLocale());
photoManager.add(photo);
localeContainer.setLocale(locale);