01: /*
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999-2005 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * Initial developer(s): Brice Ruzand
22: *
23: * --------------------------------------------------------------------------
24: * $Id$
25: * --------------------------------------------------------------------------
26: */
27: package emb.sample.servlet;
28:
29: import javax.emb.MediaConverterSpec;
30: import javax.emb.MediaEntityLocal;
31: import javax.servlet.ServletException;
32: import javax.servlet.http.HttpServletRequest;
33: import javax.servlet.http.HttpServletResponse;
34:
35: import org.objectweb.jonas.emb.mfb.converter.image.ImageRGBtoGrayscaleConverterSpec;
36: import org.objectweb.jonas.emb.mfb.formats.image.ImageMediaFormat;
37:
38: import emb.sample.MediaSampleException;
39: import emb.sample.session.MediaSampleSessionLocal;
40:
41: /**
42: * @author Brice Ruzand
43: */
44: public class ConvertSampleImageBW extends BaseSampleServlet {
45:
46: /**
47: * serialVersionUID
48: */
49: private static final long serialVersionUID = 3687815080511141944L;
50:
51: /**
52: * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
53: * javax.servlet.http.HttpServletResponse)
54: * @inheritDoc
55: */
56: public void service(HttpServletRequest request,
57: HttpServletResponse response) throws ServletException {
58: try {
59: MediaSampleSessionLocal session = getSession(request);
60:
61: // Query the media entity EJB instance.
62: String identity = request.getParameter("identity");
63: MediaEntityLocal mediaEntity = session
64: .getMediaFromPrimaryKey(identity);
65:
66: if (!(mediaEntity.getFormat() instanceof ImageMediaFormat)) {
67: throw new MediaSampleException(
68: "The selected media must be an image.");
69: }
70:
71: MediaEntityLocal media = session
72: .copyMediaEntity(mediaEntity);
73: media.setDescription("Black and White conversion of: "
74: + mediaEntity.getName());
75:
76: // Convert the MediaEntityToBlack&White
77: MediaConverterSpec[] specs = new MediaConverterSpec[] { new ImageRGBtoGrayscaleConverterSpec() };
78: media.convert(specs);
79:
80: // forward onto the retrieve servlet
81: request.setAttribute("identity", media.getPrimaryKey());
82: this .getServletContext().getRequestDispatcher(
83: RETRIEVE_SERVLET).forward(request, response);
84:
85: } catch (Throwable e) {
86: exceptionHandler(e, getClass(), request, response);
87: }
88: }
89:
90: }
|