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.ImageOverlayConverterSpec;
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: * @version 1.0
043: * @author
044: */
045: public class ConvertSampleImageOverlayed extends BaseSampleServlet {
046:
047: /**
048: * serialVersionUID
049: */
050: private static final long serialVersionUID = -3697654416111319491L;
051:
052: /**
053: * The quick acces to the logo, name in the property file
054: */
055: private static final String LOGO_ACCESS = "sampleLogo1";
056:
057: /**
058: * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
059: * javax.servlet.http.HttpServletResponse)
060: * @inheritDoc
061: */
062: public void service(HttpServletRequest request,
063: HttpServletResponse response) throws ServletException {
064: try {
065:
066: MediaSampleSessionLocal session = getSession(request);
067:
068: // Query the media entity EJB instance.
069: String identity = request.getParameter("identity");
070: MediaEntityLocal mediaEntity = session
071: .getMediaFromPrimaryKey(identity);
072:
073: // name in th property file
074: MediaEntityLocal logo = null;
075:
076: try {
077: logo = session.getMediaFromRegistredName(LOGO_ACCESS);
078: } catch (MediaSampleException e) {
079: throw new MediaSampleException(
080: "(no logo in the dataBase). Please init the database.");
081:
082: }
083:
084: if (!(mediaEntity.getFormat() instanceof ImageMediaFormat)) {
085: throw new MediaSampleException(
086: "The selected media must be an image.");
087: }
088:
089: // Create a copy
090: MediaEntityLocal media = session
091: .copyMediaEntity(mediaEntity);
092: media.setDescription("Added Logo to: "
093: + mediaEntity.getName());
094:
095: // Convert the add specifed logo to the other image
096: MediaConverterSpec[] specs = new MediaConverterSpec[] { new ImageOverlayConverterSpec(
097: logo) };
098: media.convert(specs);
099: identity = (String) media.getPrimaryKey();
100:
101: // forward onto the retrieve servlet
102: request.setAttribute("identity", media.getPrimaryKey());
103: this .getServletContext().getRequestDispatcher(
104: RETRIEVE_SERVLET).forward(request, response);
105:
106: } catch (Throwable e) {
107: exceptionHandler(e, getClass(), request, response);
108: }
109: }
110: }
|