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.formats.draw.DrawMediaFormat;
36:
37: import emb.sample.MediaSampleException;
38: import emb.sample.session.MediaSampleSessionLocal;
39:
40: /**
41: * @author Brice Ruzand
42: */
43: public class ConvertSampleImageSvgToPng extends BaseSampleServlet {
44:
45: /**
46: * serialVersionUID
47: */
48: private static final long serialVersionUID = 3688503298940548148L;
49:
50: /**
51: * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
52: * javax.servlet.http.HttpServletResponse)
53: * @inheritDoc
54: */
55: public void service(HttpServletRequest request,
56: HttpServletResponse response) throws ServletException {
57: try {
58: MediaSampleSessionLocal session = getSession(request);
59:
60: // Query the media entity EJB instance.
61: String identity = request.getParameter("identity");
62: MediaEntityLocal mediaEntity = session
63: .getMediaFromPrimaryKey(identity);
64:
65: if (!(mediaEntity.getFormat() instanceof DrawMediaFormat)) {
66: throw new MediaSampleException(
67: "The selected media must be a drawing.");
68: }
69:
70: // Create a copy
71: MediaEntityLocal media = session
72: .copyMediaEntity(mediaEntity);
73: media.setDescription("PNG conversion using batik of: "
74: + mediaEntity.getName());
75:
76: // Convert the convert SVG to PNG
77: Class converterSpecClass = getClass()
78: .getClassLoader()
79: .loadClass(
80: "org.objectweb.jonas.emb.mfb.plugins.svg.batik.Svg2PngConverterSpec");
81: MediaConverterSpec converterSpec = (MediaConverterSpec) converterSpecClass
82: .newInstance();
83: MediaConverterSpec[] specs = new MediaConverterSpec[] { converterSpec };
84: media.convert(specs);
85:
86: identity = (String) media.getPrimaryKey();
87:
88: // forward onto the retrieve servlet
89: request.setAttribute("identity", media.getPrimaryKey());
90: this .getServletContext().getRequestDispatcher(
91: RETRIEVE_SERVLET).forward(request, response);
92:
93: } catch (Throwable e) {
94: exceptionHandler(e, getClass(), request, response);
95: }
96: }
97:
98: }
|