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: */package emb.sample.servlet;
027:
028: import java.io.IOException;
029:
030: import javax.servlet.ServletException;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletResponse;
033:
034: /**
035: * Query dispatcher to implement an MVC model
036: *
037: * @author Brice Ruzand
038: */
039: public class ActionDispatcher extends BaseSampleServlet {
040:
041: /**
042: * serialVersionUID
043: */
044: private static final long serialVersionUID = 3257285816379389239L;
045:
046: /**
047: * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
048: * javax.servlet.http.HttpServletResponse)
049: * @inheritDoc
050: */
051: public void doGet(HttpServletRequest request,
052: HttpServletResponse response) throws ServletException,
053: IOException {
054: try {
055: // get the task to perform
056: String action = request.getParameter("action");
057:
058: // Query the media entity EJB instance.
059: String identity = request.getParameter("identity");
060:
061: if (action == null) {
062: getServletContext().getRequestDispatcher("/HomeSample")
063: .forward(request, response);
064: } else if (action.equals("home")) {
065: getServletContext().getRequestDispatcher("/HomeSample")
066: .forward(request, response);
067: } else if (action.equals("load")) {
068: getServletContext().getRequestDispatcher(
069: "/LoadSampleMedia").forward(request, response);
070: } else if (action.equals("list")) {
071: getServletContext().getRequestDispatcher(
072: "/ListSampleMedia").forward(request, response);
073: } else if (action.equals("upload")) {
074: getServletContext().getRequestDispatcher(
075: "/UploadSampleMedia")
076: .forward(request, response);
077: } else {
078:
079: if (identity == null) {
080:
081: StringPrinter workspaceContent = new StringPrinter();
082:
083: // message
084: workspaceContent
085: .println("<h2>No media selected</h2>");
086: workspaceContent
087: .println("Please return to the list and select a media to process...");
088:
089: request.setAttribute("workspaceContent",
090: workspaceContent);
091: getServletConfig().getServletContext()
092: .getRequestDispatcher(TEMPLATE_JSP)
093: .forward(request, response);
094:
095: } else if (action.equals("retrieve")) {
096: getServletContext().getRequestDispatcher(
097: "/RetrieveSampleMedia").forward(request,
098: response);
099: } else if (action.equals("extractHeader")) {
100: getServletContext().getRequestDispatcher(
101: "/ExtractHeaderData").forward(request,
102: response);
103: } else if (action.equals("convertBW")) {
104: getServletContext().getRequestDispatcher(
105: "/ConvertSampleImageBW").forward(request,
106: response);
107: } else if (action.equals("convertHalfSize")) {
108: getServletContext().getRequestDispatcher(
109: "/ConvertSampleImageHalfSize").forward(
110: request, response);
111: } else if (action.equals("convertFormat")) {
112: getServletContext().getRequestDispatcher(
113: "/ConvertSampleImageFormat").forward(
114: request, response);
115: } else if (action.equals("convertChained")) {
116: getServletContext().getRequestDispatcher(
117: "/ConvertSampleImageChained").forward(
118: request, response);
119: } else if (action.equals("convertSvgToPng")) {
120: getServletContext().getRequestDispatcher(
121: "/ConvertSampleImageSvgToPng").forward(
122: request, response);
123: } else if (action.equals("convertVideoTo3GPP")) {
124: getServletContext().getRequestDispatcher(
125: "/ConvertSampleVideoTo3GPP").forward(
126: request, response);
127: } else if (action.equals("convertVideoToMpegTs")) {
128: getServletContext().getRequestDispatcher(
129: "/ConvertSampleVideoToMpegTs").forward(
130: request, response);
131: } else if (action.equals("convertVideoToMpeg")) {
132: getServletContext().getRequestDispatcher(
133: "/ConvertSampleVideoToMpeg").forward(
134: request, response);
135: } else if (action.equals("convertOverlayed")) {
136: getServletContext().getRequestDispatcher(
137: "/ConvertSampleImageOverlayed").forward(
138: request, response);
139: } else if (action.equals("convertFrame")) {
140: getServletContext().getRequestDispatcher(
141: "/ConvertSampleImageFrame").forward(
142: request, response);
143: } else {
144: throw new Exception(
145: "Invalid Action dispatecher param.");
146: }
147: }
148: } catch (Throwable e) {
149: exceptionHandler(e, getClass(), request, response);
150: }
151: }
152: }
|