Subversion Repositories bacoAlunos

Rev

Rev 1306 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package pt.estgp.estgweb.web.utils;

import pt.estgp.estgweb.domain.Image;
import pt.estgp.estgweb.domain.DomainObjectFactory;
import pt.estgp.estgweb.domain.ImageImpl;
import org.apache.struts.upload.FormFile;
import org.apache.log4j.Logger;
import jomm.utils.StreamsUtils;

import java.util.Date;
import java.io.IOException;

/**
 * @author Jorge Machado
 * @date 27/Mai/2008
 * @see pt.estgp.estgweb.web.utils
 */

public class DomainUtils
{
    private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(DomainUtils.class);

    public static 1.5.0/docs/api/java/awt/Image.html">Image getNewImage(FormFile image, 1.5.0/docs/api/java/lang/String.html">String description)
    {
        byte[] bytes;
        try
        {
            bytes = StreamsUtils.readBytes(image.getInputStream());
        }
        catch (1.5.0/docs/api/java/io/IOException.html">IOException e)
        {
            logger.error(e,e);
            return null;
        }
        ImageImpl i = DomainObjectFactory.createImageImpl();
        i.setImage(bytes);
        i.setContentType(image.getContentType());
        i.setSize(image.getFileSize());
        i.setDescription(description);
        i.setName(image.getFileName());
        i.setSaveDate(new 5+0%2Fdocs%2Fapi+Date">Date());
        return i;
    }
}