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:
031: import javax.emb.MediaEntityLocal;
032: import javax.emb.MediaHeader;
033: import javax.servlet.ServletException;
034: import javax.servlet.http.HttpServletRequest;
035: import javax.servlet.http.HttpServletResponse;
036:
037: import emb.sample.session.MediaSampleSessionLocal;
038:
039: /**
040: * @author Brice Ruzand
041: */
042: public class ExtractHeaderData extends BaseSampleServlet {
043:
044: /**
045: * serialVersionUID
046: */
047: private static final long serialVersionUID = 3544675070548261174L;
048:
049: /**
050: * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
051: * javax.servlet.http.HttpServletResponse)
052: * @inheritDoc
053: */
054: public void service(HttpServletRequest request,
055: HttpServletResponse response) throws ServletException,
056: IOException {
057: try {
058: MediaSampleSessionLocal session = getSession(request);
059:
060: // Query the media entity EJB instance.
061: String identity = request.getParameter("identity");
062: MediaEntityLocal mediaEntity = session
063: .getMediaFromPrimaryKey(identity);
064:
065: MediaHeader header = mediaEntity.getHeader();
066: String[] fieldNames = header.getFieldNames();
067:
068: StringPrinter newMenuBox = new StringPrinter();
069: StringPrinter workspaceContent = new StringPrinter();
070:
071: newMenuBox.println("<div class=\"menu-box\">\r\n"
072: + "<h3 class=\"menu-title\">Media</h3>\r\n");
073: // add info
074: displayInfo(newMenuBox, mediaEntity);
075:
076: workspaceContent
077: .println("<h2>Header information for Media: "
078: + mediaEntity.getName() + "</h2>\n");
079: workspaceContent.println("<table>");
080: workspaceContent
081: .println("<thead><tr><th>Header tag name</th><th>Value</th></tr></thead>");
082: workspaceContent.println("<tbody>");
083:
084: if (fieldNames.length == 0) {
085: workspaceContent
086: .println("<tr><td colspan=\"2\" align=\"center\">There is no specific header for this media</td></tr>\n");
087: } else {
088:
089: for (int index = 0; index < fieldNames.length; index++) {
090: String fieldName = fieldNames[index];
091: String fieldContent = "null";
092: if (header.getField(fieldNames[index]) != null) {
093: header.getField(fieldNames[index]).toString();
094: }
095: workspaceContent
096: .println("<tr><td valign=\"top\" >");
097: workspaceContent.println(fieldName);
098: workspaceContent.println("</td><td>");
099: workspaceContent.println(fieldContent);
100: workspaceContent.println("</td></tr>\n");
101: }
102: }
103: workspaceContent.println("</tbody>");
104: workspaceContent.println("</table>\n");
105:
106: newMenuBox.println("</div>");
107:
108: request.setAttribute("newMenuBox", newMenuBox);
109: request.setAttribute("workspaceContent", workspaceContent);
110: getServletConfig().getServletContext()
111: .getRequestDispatcher(TEMPLATE_JSP).forward(
112: request, response);
113:
114: } catch (Throwable e) {
115: exceptionHandler(e, getClass(), request, response);
116: }
117: }
118:
119: }
|