|
From: <tr...@us...> - 2003-06-27 02:09:24
|
Update of /cvsroot/babeldoc/babeldoc/modules/web/src/com/babeldoc/web/pipeline/servlet In directory sc8-pr-cvs1:/tmp/cvs-serv32148/src/com/babeldoc/web/pipeline/servlet Modified Files: HttpPostPipelineFeeder.java Log Message: Reformatted and added new license header Index: HttpPostPipelineFeeder.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/web/src/com/babeldoc/web/pipeline/servlet/HttpPostPipelineFeeder.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** HttpPostPipelineFeeder.java 27 May 2003 03:04:57 -0000 1.4 --- HttpPostPipelineFeeder.java 27 Jun 2003 02:09:21 -0000 1.5 *************** *** 1,28 **** ! /* ! * $Header$ ! * $DateTime: 2002/07/24 18:15:55 $ * * ! * babeldoc: universal document processor * ! * This program is free software; you can redistribute it and/or ! * modify it under the terms of the GNU General Public License ! * as published by the Free Software Foundation; either version 2 ! * of the License, or (at your option) any later version. * ! * This program is distributed in the hope that it will be useful, ! * but WITHOUT ANY WARRANTY; without even the implied warranty of ! * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package com.babeldoc.web.pipeline.servlet; import com.babeldoc.core.I18n; import com.babeldoc.core.LogService; - import com.babeldoc.core.EnvironmentLoader; import com.babeldoc.core.journal.IJournalTicket; import com.babeldoc.core.journal.JournalException; --- 1,72 ---- ! /* ==================================================================== ! * The Apache Software License, Version 1.1 * + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. * ! * Redistribution and use in source and binary forms, with or without ! * modification, are permitted provided that the following conditions ! * are met: * ! * 1. Redistributions of source code must retain the above copyright ! * notice, this list of conditions and the following disclaimer. * ! * 2. Redistributions in binary form must reproduce the above copyright ! * notice, this list of conditions and the following disclaimer in ! * the documentation and/or other materials provided with the ! * distribution. ! * ! * 3. The end-user documentation included with the redistribution, ! * if any, must include the following acknowledgment: ! * "This product includes software developed by the ! * Apache Software Foundation (http://www.apache.org/)." ! * Alternately, this acknowledgment may appear in the software itself, ! * if and wherever such third-party acknowledgments normally appear. ! * ! * 4. The names "Apache" and "Apache Software Foundation" must ! * not be used to endorse or promote products derived from this ! * software without prior written permission. For written ! * permission, please contact ap...@ap.... ! * ! * 5. Products derived from this software may not be called "Apache", ! * nor may "Apache" appear in their name, without prior written ! * permission of the Apache Software Foundation. ! * ! * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ! * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ! * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ! * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ! * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ! * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ! * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ! * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ! * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ! * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ! * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! * SUCH DAMAGE. ! * ==================================================================== ! * ! * This software consists of voluntary contributions made by many ! * individuals on behalf of the Apache Software Foundation. For more ! * information on the Apache Software Foundation, please see ! * <http://www.apache.org/>. ! * ! * Portions of this software are based upon public domain software ! * originally written at the National Center for Supercomputing Applications, ! * University of Illinois, Urbana-Champaign. ! * ==================================================================== ! * ! * Babeldoc: The Universal Document Processor ! * ! * $Header$ ! * $DateTime$ ! * $Author$ * */ package com.babeldoc.web.pipeline.servlet; + import com.babeldoc.core.EnvironmentLoader; import com.babeldoc.core.I18n; import com.babeldoc.core.LogService; import com.babeldoc.core.journal.IJournalTicket; import com.babeldoc.core.journal.JournalException; *************** *** 31,43 **** import com.babeldoc.core.pipeline.feeder.*; - import javax.servlet.ServletException; - import javax.servlet.http.HttpServlet; - import javax.servlet.http.HttpServletRequest; - import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; /** * Simple Http Servlet for receiving messages. --- 75,90 ---- import com.babeldoc.core.pipeline.feeder.*; import java.io.IOException; + import java.util.Enumeration; import java.util.HashMap; import java.util.Map; + import javax.servlet.ServletException; + import javax.servlet.http.HttpServlet; + import javax.servlet.http.HttpServletRequest; + import javax.servlet.http.HttpServletResponse; + + /** * Simple Http Servlet for receiving messages. *************** *** 46,65 **** * @version 1.0 */ ! public class HttpPostPipelineFeeder ! extends HttpServlet { ! ! public final static String PIPELINE = "pipeline"; ! public final static String DOCUMENT = "document"; ! public final static String FEEDER = "feeder"; ! public final static String TOP_FORM = "top-form.html"; ! public final static String BOTTOM_FORM = "bottom-form.html"; ! ! /** ! * ! * @throws ServletException ! */ ! public void init() throws ServletException { ! EnvironmentLoader.loadEnvironment(); ! } /** --- 93,102 ---- * @version 1.0 */ ! public class HttpPostPipelineFeeder extends HttpServlet { ! public static final String PIPELINE = "pipeline"; ! public static final String DOCUMENT = "document"; ! public static final String FEEDER = "feeder"; ! public static final String TOP_FORM = "top-form.html"; ! public static final String BOTTOM_FORM = "bottom-form.html"; /** *************** *** 68,83 **** * @param request * @param response */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - response.setContentType("text/html"); String topform = com.babeldoc.core.ResourceLoader.getResourceString(TOP_FORM); String bottomform = com.babeldoc.core.ResourceLoader.getResourceString(BOTTOM_FORM); response.getWriter().write(topform); String[] pnames = PipelineFactoryFactory.getAllPipelineNames(); for (int i = 0; i < pnames.length; ++i) { response.getWriter().write("<OPTION>" + pnames[i]); } response.getWriter().write(bottomform); } --- 105,126 ---- * @param request * @param response + * + * @throws IOException DOCUMENT ME! + * @throws ServletException DOCUMENT ME! */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); + String topform = com.babeldoc.core.ResourceLoader.getResourceString(TOP_FORM); String bottomform = com.babeldoc.core.ResourceLoader.getResourceString(BOTTOM_FORM); response.getWriter().write(topform); + String[] pnames = PipelineFactoryFactory.getAllPipelineNames(); + for (int i = 0; i < pnames.length; ++i) { response.getWriter().write("<OPTION>" + pnames[i]); } + response.getWriter().write(bottomform); } *************** *** 88,91 **** --- 131,137 ---- * @param request * @param response + * + * @throws IOException DOCUMENT ME! + * @throws ServletException DOCUMENT ME! */ public void doPost(HttpServletRequest request, HttpServletResponse response) *************** *** 94,157 **** String pipeline = getPipeline(request); LogService.getInstance().logDebug("pipeline: " + pipeline); if (pipeline != null) { try { byte[] docbytes = getPipelineDocument(request); if (docbytes == null) { // Error occured LogService.getInstance().logError(I18n.get("web.101"), null); } else { ! IJournalTicket ticket = processPipelineDocument(request, docbytes, pipeline); response.setContentType("text/html"); ! response.getWriter().write("<html><body>" + I18n.get("web.105", ticket) + "</body></html>\n"); } } catch (Exception e) { LogService.getInstance().logError(e); response.setContentType("text/html"); ! response.getWriter().write("<html><body>" + I18n.get("web.102") + "</body></html>\n"); } } else { ! LogService.getInstance().logError("[HttpPostPipelineFeeder] " + I18n.get("web.103"), null); response.setContentType("text/html"); ! response.getWriter().write("<html><body>" + I18n.get("web.103") + "</body></html>\n"); } } /** ! * Get the pipeline name from the servlet request path * ! * @param request ! * @return ! * @throws javax.servlet.ServletException */ ! private String getPipeline(HttpServletRequest request) ! throws ServletException { ! return request.getParameter(PIPELINE); } /** ! * Convert the dom document and and create a pipeline document and add it to the pipeline. * * @param request ! * @param docbytes ! * @param pipeline */ ! private IJournalTicket processPipelineDocument(HttpServletRequest request, byte[] docbytes, ! String pipeline) ! throws PipelineException, JournalException { ! ! Map map = new HashMap(); ! // Apply the request parameters as document attributes ! for (Enumeration parms = request.getParameterNames(); parms.hasMoreElements();) { ! String name = (String) parms.nextElement(); ! ! if (!(name.equals(DOCUMENT) || name.equals(PIPELINE))) { ! map.put(name, request.getParameter(name)); ! } ! } ! ! // Get a ticket, add to vector and process ticket. ! FeedDocument feedDoc = new FeedDocument(pipeline, docbytes, map, false, false); ! new SynchronousFeeder().process(feedDoc); ! return feedDoc.getTicket(); } --- 140,194 ---- String pipeline = getPipeline(request); LogService.getInstance().logDebug("pipeline: " + pipeline); + if (pipeline != null) { try { byte[] docbytes = getPipelineDocument(request); + if (docbytes == null) { // Error occured LogService.getInstance().logError(I18n.get("web.101"), null); } else { ! IJournalTicket ticket = processPipelineDocument(request, docbytes, ! pipeline); response.setContentType("text/html"); ! response.getWriter().write("<html><body>" + ! I18n.get("web.105", ticket) + "</body></html>\n"); } } catch (Exception e) { LogService.getInstance().logError(e); response.setContentType("text/html"); ! response.getWriter().write("<html><body>" + I18n.get("web.102") + ! "</body></html>\n"); } } else { ! LogService.getInstance().logError("[HttpPostPipelineFeeder] " + ! I18n.get("web.103"), null); response.setContentType("text/html"); ! response.getWriter().write("<html><body>" + I18n.get("web.103") + ! "</body></html>\n"); } } /** ! * DOCUMENT ME! * ! * @throws ServletException */ ! public void init() throws ServletException { ! EnvironmentLoader.loadEnvironment(); } /** ! * Get the pipeline name from the servlet request path * * @param request ! * ! * @return ! * ! * @throws ServletException */ ! private String getPipeline(HttpServletRequest request) ! throws ServletException { ! return request.getParameter(PIPELINE); } *************** *** 160,169 **** * * @param request * @return document */ private byte[] getPipelineDocument(HttpServletRequest request) throws IOException { - String doc = request.getParameter(DOCUMENT); return doc.getBytes(); } --- 197,209 ---- * * @param request + * * @return document + * + * @throws IOException DOCUMENT ME! */ private byte[] getPipelineDocument(HttpServletRequest request) throws IOException { String doc = request.getParameter(DOCUMENT); + return doc.getBytes(); } *************** *** 180,185 **** // Traverse the HTTP headers and show them on the screen ! for (Enumeration enum = request.getHeaderNames(); ! enum.hasMoreElements();) { String header = (String) enum.nextElement(); String value = request.getHeader(header); --- 220,224 ---- // Traverse the HTTP headers and show them on the screen ! for (Enumeration enum = request.getHeaderNames(); enum.hasMoreElements();) { String header = (String) enum.nextElement(); String value = request.getHeader(header); *************** *** 189,192 **** --- 228,267 ---- System.out.println("-----------------------"); + } + + /** + * Convert the dom document and and create a pipeline document and add it to + * the pipeline. + * + * @param request + * @param docbytes + * @param pipeline + * + * @return DOCUMENT ME! + * + * @throws PipelineException DOCUMENT ME! + * @throws JournalException DOCUMENT ME! + */ + private IJournalTicket processPipelineDocument(HttpServletRequest request, + byte[] docbytes, String pipeline) + throws PipelineException, JournalException { + Map map = new HashMap(); + + // Apply the request parameters as document attributes + for (Enumeration parms = request.getParameterNames(); + parms.hasMoreElements();) { + String name = (String) parms.nextElement(); + + if (!(name.equals(DOCUMENT) || name.equals(PIPELINE))) { + map.put(name, request.getParameter(name)); + } + } + + // Get a ticket, add to vector and process ticket. + FeedDocument feedDoc = new FeedDocument(pipeline, docbytes, map, false, + false); + new SynchronousFeeder().process(feedDoc); + + return feedDoc.getTicket(); } } |