001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999-2005 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s): Brice Ruzand
022: *
023: * --------------------------------------------------------------------------
024: * $Id$
025: * --------------------------------------------------------------------------
026: */
027: package emb.sample.servlet;
028:
029: import javax.emb.MediaConverterSpec;
030: import javax.emb.MediaEntityLocal;
031: import javax.servlet.ServletException;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import org.objectweb.jonas.emb.mfb.converter.image.ImageFrameConverterSpec;
036: import org.objectweb.jonas.emb.mfb.formats.image.ImageMediaFormat;
037:
038: import emb.sample.MediaSampleException;
039: import emb.sample.session.MediaSampleSessionLocal;
040:
041: /**
042: * @author Brice Ruzand
043: */
044: public class ConvertSampleImageFrame extends BaseSampleServlet {
045:
046: /**
047: * serialVersionUID
048: */
049: private static final long serialVersionUID = -3697654416111319491L;
050:
051: /**
052: * The quick acces to the frame, name in the property file
053: */
054: private static final String FRAME_ACCESS = "sampleFrame1";
055:
056: /**
057: * The quick acces to the mask, name in the property file
058: */
059: private static final String MASK_ACCESS = "sampleMask1";
060:
061: /**
062: * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
063: * javax.servlet.http.HttpServletResponse)
064: * @inheritDoc
065: */
066: public void service(HttpServletRequest request,
067: HttpServletResponse response) throws ServletException {
068: try {
069: MediaSampleSessionLocal session = getSession(request);
070:
071: // Query the media entity EJB instance.
072: String identity = request.getParameter("identity");
073: MediaEntityLocal mediaEntity = session
074: .getMediaFromPrimaryKey(identity);
075:
076: // name in th property file
077: MediaEntityLocal frame = null;
078: MediaEntityLocal mask = null;
079:
080: try {
081: frame = session.getMediaFromRegistredName(FRAME_ACCESS);
082: mask = session.getMediaFromRegistredName(MASK_ACCESS);
083: } catch (MediaSampleException e) {
084: throw new MediaSampleException(
085: "(no mask and frame in the dataBase). Please init the database.");
086:
087: }
088:
089: if (!(mediaEntity.getFormat() instanceof ImageMediaFormat)) {
090: throw new MediaSampleException(
091: "The selected media must be an image.");
092: }
093:
094: // Create a copy
095: MediaEntityLocal media = session
096: .copyMediaEntity(mediaEntity);
097: media.setDescription("Added frame to: "
098: + mediaEntity.getName());
099:
100: // Convert the add specifed frame to the other image
101:
102: // well know position offset
103: final int posX = 50;
104: final int posY = 58;
105:
106: MediaConverterSpec[] specs = new MediaConverterSpec[] { new ImageFrameConverterSpec(
107: frame, mask, posX, posY) };
108: media.convert(specs);
109: identity = (String) media.getPrimaryKey();
110:
111: // forward onto the retrieve servlet
112: request.setAttribute("identity", media.getPrimaryKey());
113: this .getServletContext().getRequestDispatcher(
114: RETRIEVE_SERVLET).forward(request, response);
115:
116: } catch (Throwable e) {
117: exceptionHandler(e, getClass(), request, response);
118: }
119: }
120: }
|