001: package com.quadcap.app.qed;
002:
003: /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.io.IOException;
042: import java.io.OutputStream;
043: import java.io.OutputStreamWriter;
044:
045: import java.util.zip.GZIPOutputStream;
046:
047: import java.sql.Connection;
048:
049: import javax.servlet.ServletConfig;
050: import javax.servlet.ServletException;
051:
052: import javax.servlet.http.HttpServlet;
053: import javax.servlet.http.HttpServletRequest;
054: import javax.servlet.http.HttpServletResponse;
055: import javax.servlet.http.HttpSession;
056:
057: import com.quadcap.sql.tools.XmlDump;
058:
059: import com.quadcap.util.Debug;
060:
061: /**
062: *
063: * @author Stan Bailes
064: */
065:
066: public class XmlDumpServlet extends HttpServlet {
067: /**
068: * Initialize this servlet
069: *
070: * @param config the servlet configuration object, containing my
071: * initialization parameters
072: * @exception ServletException if I can't initialize for some reason.
073: */
074: public void init(ServletConfig config) throws ServletException {
075: super .init(config);
076: }
077:
078: /**
079: * Handle an incoming request.
080: *
081: * @param req HttpServletRequest that encapsulates the request to
082: * the servlet
083: * @param res HttpServletResponse that encapsulates the response
084: * from the servlet
085: *
086: * @exception IOException if detected when handling the request
087: * @exception ServletException if the request could not be handled
088: */
089: protected void service(HttpServletRequest req,
090: HttpServletResponse res) throws ServletException,
091: IOException {
092: try {
093: HttpSession session = req.getSession(true);
094: if (session == null)
095: throw new ServletException("No session");
096: AdminSession admin = (AdminSession) session
097: .getValue("admin");
098: if (admin == null)
099: throw new ServletException("no admin session");
100: res.setHeader("Content-Disposition",
101: "attachment; filename=\"dumpdb.xml.gz\"");
102: String dbName = req.getParameter("dbName");
103: if (dbName == null) {
104: throw new ServletException("no dbName");
105: }
106: OutputStream w = res.getOutputStream();
107: GZIPOutputStream gz = new GZIPOutputStream(w);
108: OutputStreamWriter ow = new OutputStreamWriter(gz);
109: Connection conn = admin.getConnection(dbName);
110: XmlDump dump = new XmlDump(conn);
111: dump.dumpTables(ow);
112: gz.finish();
113: ow.flush();
114: } catch (Exception e) {
115: Debug.print(e);
116: res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
117: e.toString());
118: }
119: }
120: }
|