Subversion Repositories bacoAlunos

Rev

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

package pt.estgp.estgweb.services.data;

import pt.estgp.estgweb.domain.Image;
import pt.estgp.estgweb.domain.ImageImpl;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.log4j.Logger;

/**
 * @author Jorge Machado
 * @date 28/Mai/2008
 * @see pt.estgp.estgweb.services.data
 */

public class ImageManager
{
    public static final 1.5.0/docs/api/java/lang/String.html">String IMAGES_RESOURCE_PATH = "/images";

    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(ImageManager.class);

    public static boolean store(ImageImpl img)
    {
        try
        {
            if(img.getId() <= 0)
                logger.error("Image arrive with out identifier: save it first");
            ResourceManager.saveResource(new 1.5.0/docs/api/java/io/ByteArrayInputStream.html">ByteArrayInputStream(img.getImage()), IMAGES_RESOURCE_PATH, img.getId());
            return true;
        }
        catch (1.5.0/docs/api/java/io/IOException.html">IOException e)
        {
            logger.error(e,e);
        }
        return false;
    }

    public static 5+0%2Fdocs%2Fapi+InputStream">InputStream load(1.5.0/docs/api/java/awt/Image.html">Image img)
    {
        try
        {
            return ResourceManager.getResource(IMAGES_RESOURCE_PATH, img.getId());
        }
        catch (1.5.0/docs/api/java/io/IOException.html">IOException e)
        {
            logger.error(e,e);
        }
        return null;
    }
}