001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.servlets;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/servlets/Translator.java $
024: //$Author: Dan $
025: //$Revision: 9 $
026: //$Modtime: 8/24/04 4:28p $
027: /////////////////////////
028:
029: import java.io.*;
030:
031: import javax.servlet.ServletException;
032: import javax.servlet.http.*;
033:
034: import com.salmonllc.jsp.JspServlet;
035: import com.salmonllc.jsp.engine.JspConverter;
036: import com.salmonllc.properties.Props;
037: import com.salmonllc.util.MessageLog;
038:
039: /**
040: * This Servlet is used to translate custom tags for Dreamweaver into valid html.
041: */
042: public class Translator extends HttpServlet {
043: public void doGet(HttpServletRequest req, HttpServletResponse res)
044: throws ServletException, IOException {
045: JspServlet.setUpApplicationContext(getServletContext(), req);
046: res.setStatus(HttpServletResponse.SC_OK);
047: try {
048: String input = req.getParameter("InputFile");
049: String header = req.getParameter("HeaderLine");
050: if (header == null)
051: header = "";
052: if (input != null) {
053: FileInputStream in = new FileInputStream(input);
054: byte b[] = new byte[in.available() + header.length()];
055: in.read(b);
056: in.close();
057: String st = header + new String(b);
058: String docBase = File.separator;
059: int pos = input.lastIndexOf(File.separatorChar);
060: if (pos != -1)
061: docBase = input.substring(0, pos);
062: req.setAttribute(JspServlet.SALMON_SERVLET_KEY, this );
063: JspConverter.getInstanceVariables(
064: new ByteArrayInputStream(st.getBytes()), this ,
065: req, res, JspConverter.CONV_HTML, docBase);
066: }
067: } catch (Exception e) {
068: MessageLog.writeErrorMessage(
069: "Error in doGet of translator.", e, this );
070: }
071:
072: }
073:
074: public void doPost(HttpServletRequest req, HttpServletResponse res)
075: throws ServletException, IOException {
076: JspServlet.setUpApplicationContext(getServletContext(), req);
077: res.setStatus(HttpServletResponse.SC_OK);
078: try {
079: JspConverter.convertDocument(req.getInputStream(), this ,
080: req, res, JspConverter.CONV_DREAMWEAVER);
081:
082: Props p = Props.getSystemProps();
083: String info = "Dreamweaver Document Translated.";
084: String input = p
085: .getProperty(Props.JSP_ENGINE_DEBUG_INPUT_FILE);
086: if (input == null)
087: info += " \n Input not written to any file. Set the property \""
088: + Props.JSP_ENGINE_DEBUG_INPUT_FILE
089: + "\" in system.properties to specify a debug file for saving the Dreamweaver input.";
090: else
091: info += " \n Input written to: \"" + input + "\".";
092: String output = p
093: .getProperty(Props.JSP_ENGINE_DEBUG_OUTPUT_FILE);
094: if (output == null)
095: info += " \n Output written back to Dreamweaver stream only. Set the property \""
096: + Props.JSP_ENGINE_DEBUG_OUTPUT_FILE
097: + "\" in system.properties to specify a debug file to save the Dreamweaver output.";
098: else
099: info += " \n Output written to: \"" + output
100: + "\".";
101:
102: MessageLog.writeInfoMessage(info, this );
103: } catch (Exception e) {
104: MessageLog.writeErrorMessage(
105: "Dreamweaver Document Failed to Translate.", e,
106: this);
107: }
108:
109: }
110: }
|