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.io.IOException;
030: import java.net.URL;
031:
032: import javax.emb.FormatNotFoundException;
033: import javax.emb.MediaEntityLocal;
034: import javax.emb.MediaEntityLocalHome;
035: import javax.emb.MediaFormatRegistry;
036: import javax.emb.ProtocolConstraints;
037: import javax.servlet.ServletException;
038: import javax.servlet.http.HttpServletRequest;
039: import javax.servlet.http.HttpServletResponse;
040:
041: import emb.sample.session.MediaSampleSessionLocal;
042:
043: /**
044: * @version 1.0
045: * @author
046: */
047: public class ListSampleMedia extends BaseSampleServlet {
048:
049: /**
050: * serialVersionUID
051: */
052: private static final long serialVersionUID = 3257289140767830576L;
053:
054: /**
055: * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
056: * javax.servlet.http.HttpServletResponse)
057: * @inheritDoc
058: */
059: public void doGet(HttpServletRequest request,
060: HttpServletResponse response) throws ServletException,
061: IOException {
062: try {
063:
064: MediaSampleSessionLocal session = getSession(request);
065:
066: MediaEntityLocal[] medias = session.getMediaList();
067:
068: if (medias.length > 0) {
069: try {
070: MediaFormatRegistry.SINGLETON.lookup("svg");
071: request
072: .setAttribute("drawConversion",
073: Boolean.TRUE);
074: } catch (FormatNotFoundException e) {
075: request.setAttribute("drawConversion",
076: Boolean.FALSE);
077: }
078:
079: try {
080: MediaFormatRegistry.SINGLETON.lookup("ts");
081: request.setAttribute("videoConversion",
082: Boolean.TRUE);
083: } catch (FormatNotFoundException e) {
084: request.setAttribute("videoConversion",
085: Boolean.FALSE);
086: }
087:
088: String[] proxiesUrl = new String[medias.length];
089: for (int i = 0; i < medias.length; i++) {
090: URL url = null;
091: try {
092: url = getMebHome()
093: .publishContent(
094: medias[i].getProxy(),
095: MediaEntityLocalHome.TRANSFER_TYPE_STREAM,
096: new ProtocolConstraints());
097: } catch (Throwable e) {
098: // do nothing
099: }
100:
101: proxiesUrl[i] = "";
102: if (url != null) {
103: proxiesUrl[i] = url.toExternalForm();
104: }
105: }
106:
107: request.setAttribute("samplesMedia", medias);
108: request.setAttribute("proxiesUrl", proxiesUrl);
109: this .getServletContext().getRequestDispatcher(
110: "/jsps/mediaList.jsp").forward(request,
111: response);
112:
113: } else {
114:
115: StringPrinter workspaceContent = new StringPrinter();
116:
117: // message
118: workspaceContent
119: .println("<h2>No Sample Media has been initialized.</h2>");
120:
121: request.setAttribute("workspaceContent",
122: workspaceContent);
123: getServletConfig().getServletContext()
124: .getRequestDispatcher(TEMPLATE_JSP).forward(
125: request, response);
126:
127: }
128:
129: } catch (Throwable e) {
130: exceptionHandler(e, getClass(), request, response);
131: }
132:
133: }
134: }
|