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 java.net.URL;
030:
031: import javax.emb.MediaEntityLocal;
032: import javax.emb.MediaEntityLocalHome;
033: import javax.emb.MediaFormatRegistry;
034: import javax.emb.ProtocolConstraints;
035: import javax.servlet.ServletException;
036: import javax.servlet.http.HttpServletRequest;
037: import javax.servlet.http.HttpServletResponse;
038:
039: import org.objectweb.jonas.emb.mfb.formats.image.ImageMediaFormat;
040:
041: import emb.sample.session.MediaSampleSessionLocal;
042:
043: /**
044: * Generate an HTML web page to present the media
045: *
046: * @author Brice Ruzand
047: */
048: public class RetrieveSampleMedia extends BaseSampleServlet {
049:
050: /**
051: * serialVersionUID
052: */
053: private static final long serialVersionUID = 3762250859580634161L;
054:
055: /**
056: * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
057: * javax.servlet.http.HttpServletResponse)
058: * @inheritDoc
059: */
060: public void service(HttpServletRequest request,
061: HttpServletResponse response) throws ServletException {
062: try {
063:
064: // Query the media entity EJB instance.
065: String identity = (String) request.getAttribute("identity");
066: if (identity == null) {
067: identity = request.getParameter("identity");
068: }
069:
070: MediaSampleSessionLocal session = getSession(request);
071:
072: // Query the media entity EJB instance.
073: MediaEntityLocal mediaEntity = session
074: .getMediaFromPrimaryKey(identity);
075:
076: // publish it
077: URL url = null;
078:
079: if (mediaEntity.getFormat().equals(
080: MediaFormatRegistry.SINGLETON.lookup("mp4"))) {
081: url = getMebHome().publishContent(mediaEntity,
082: MediaEntityLocalHome.TRANSFER_TYPE_STREAM,
083: new ProtocolConstraints());
084: } else {
085: url = getMebHome().publishContent(mediaEntity,
086: MediaEntityLocalHome.TRANSFER_TYPE_BURST,
087: new ProtocolConstraints());
088: }
089:
090: StringPrinter newMenuBox = new StringPrinter();
091: StringPrinter workspaceContent = new StringPrinter();
092:
093: newMenuBox.println("<div class=\"menu-box\">\r\n"
094: + "<h3 class=\"menu-title\">Media</h3>\r\n");
095:
096: workspaceContent.println("<h2>Media content : "
097: + mediaEntity.getName() + "</h2>");
098:
099: workspaceContent.println("<span class=\"url\"> URL : "
100: + url + "</span><br/>");
101:
102: if (mediaEntity.getFormat() instanceof ImageMediaFormat) {
103: newMenuBox.println("<h2>Image</h2>");
104: workspaceContent.println("<div class=media><img src=\""
105: + url + "\" alt=\"" + mediaEntity.getName()
106: + "\" /></div>");
107: } else {
108: newMenuBox.println("<h2>Standard Object</h2>");
109: workspaceContent
110: .println("<div class=\"media\"><object data=\""
111: + url
112: + "\" type=\""
113: + mediaEntity.getMimeType()
114: + "\" width=\"500\" height=\"350\" standby=\"Loading in progress...\">"
115: + "Unfortunately your browser cannot display this media !!</object></div>");
116: }
117:
118: // add info in menu
119: displayInfo(newMenuBox, mediaEntity);
120:
121: newMenuBox
122: .println("<span>If your browser can not display this media, please select the link below for accessing the media.... ");
123: newMenuBox.println("<a href=\"" + url + "\" >"
124: + mediaEntity.getName() + "</a></span>");
125:
126: newMenuBox.println("</div>");
127:
128: request.setAttribute("newMenuBox", newMenuBox);
129: request.setAttribute("workspaceContent", workspaceContent);
130: getServletConfig().getServletContext()
131: .getRequestDispatcher(TEMPLATE_JSP).forward(
132: request, response);
133:
134: } catch (Throwable e) {
135: exceptionHandler(e, getClass(), request, response);
136: }
137: }
138:
139: }
|