<commit_before>/******************************************************************************
 * ResponderSOURCE.java
 * ****************************************************************************/

/* J_LZ_COPYRIGHT_BEGIN *******************************************************
* Copyright 2001-2004 Laszlo Systems, Inc.  All Rights Reserved.              *
* Use is subject to license terms.                                            *
* J_LZ_COPYRIGHT_END *********************************************************/

package org.openlaszlo.servlets.responders;

import java.io.*;
import java.net.URL;
import java.util.Properties;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.openlaszlo.utils.FileUtils;
import org.openlaszlo.utils.StringUtils;
import org.openlaszlo.xml.internal.XMLUtils;
import org.apache.log4j.Logger;

public final class ResponderSOURCE extends ResponderCompile
{
    private static Logger mLogger = Logger.getLogger(ResponderSOURCE.class);

    /**
     * Overridden method from ReponseCompile.
     *
     * @param req unused
     */
    protected long getLastModified(String fileName, HttpServletRequest req)
    {
        // We don't care about other dependencies since all we show is the
        // top-level LZX file.
        return new File(fileName).lastModified();
    }

    /**
     * @param fileName Full pathname to file from request.
     */
    protected void respondImpl(String fileName, HttpServletRequest req, 
                               HttpServletResponse res)
        throws IOException
    {
        mLogger.info(
/* (non-Javadoc)
 * @i18n.test
 * @org-mes="Responding with SOURCE for " + p[0]
 */
                        org.openlaszlo.i18n.LaszloMessages.getMessage(
                                ResponderSOURCE.class.getName(),"051018-53", new Object[] {fileName})
);
        if (fileName.endsWith(".lzo")) {
            fileName = StringUtils.setCharAt(fileName, fileName.length() - 1, 'x');
        }
    
        ServletOutputStream  out = res.getOutputStream();

        try {
            res.setContentType ("text/html");
            writeHeader(out, null);
            writeText(out, FileUtils.readFileString(new File(fileName)));
            writeFooter(out);
        } finally {
            FileUtils.close(out);
        }
    }

    /**
     * Writes the Text entry 
     * @param out A PrintWriter
     * @param text A <tt>String</tt> containing the .lzx text
     * @param message Message(s) generated during the compilation process
     */
    private void writeText(ServletOutputStream out, String text)
        throws IOException {
        out.println ("<pre class=\"code\">");
        // TODO: [2003-04-03 bloch] should rename SWFHTML to HTML
        // since that's a better description.
        out.println (XMLUtils.escapeXmlForSWFHTML(text));
        out.println ("</pre>");
    }


    public int getMimeType()
    {
        return MIME_TYPE_HTML;
    }
}
<commit_msg>Change 20080903-hqm-3 by <EMAIL> on 2008-09-03 12:27:06 EDT     in /Users/hqm/openlaszlo/trunk     for http://svn.openlaszlo.org/openlaszlo/trunk<commit_after>/******************************************************************************
 * ResponderSOURCE.java
 * ****************************************************************************/

/* J_LZ_COPYRIGHT_BEGIN *******************************************************
* Copyright 2001-2004, 2008 Laszlo Systems, Inc.  All Rights Reserved.              *
* Use is subject to license terms.                                            *
* J_LZ_COPYRIGHT_END *********************************************************/

package org.openlaszlo.servlets.responders;

import java.io.*;
import java.net.URL;
import java.util.Properties;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.openlaszlo.utils.FileUtils;
import org.openlaszlo.utils.StringUtils;
import org.openlaszlo.xml.internal.XMLUtils;
import org.apache.log4j.Logger;

public final class ResponderSOURCE extends ResponderCompile
{
    private static Logger mLogger = Logger.getLogger(ResponderSOURCE.class);

    /**
     * Overridden method from ReponseCompile.
     *
     * @param req unused
     */
    protected long getLastModified(String fileName, HttpServletRequest req)
    {
        // We don't care about other dependencies since all we show is the
        // top-level LZX file.
        return new File(fileName).lastModified();
    }

    /**
     * @param fileName Full pathname to file from request.
     */
    protected void respondImpl(String fileName, HttpServletRequest req, 
                               HttpServletResponse res)
        throws IOException
    {
        mLogger.info(
/* (non-Javadoc)
 * @i18n.test
 * @org-mes="Responding with SOURCE for " + p[0]
 */
                        org.openlaszlo.i18n.LaszloMessages.getMessage(
                                ResponderSOURCE.class.getName(),"051018-53", new Object[] {fileName})
);
        ServletOutputStream  out = res.getOutputStream();

        try {
            res.setContentType ("text/html; charset=utf-8");
            writeHeader(out, null);
            writeText(out, FileUtils.readFileString(new File(fileName)));
            writeFooter(out);
        } finally {
            FileUtils.close(out);
        }
    }

    /**
     * Writes the Text entry 
     * @param out A PrintWriter
     * @param text A <tt>String</tt> containing the .lzx text
     * @param message Message(s) generated during the compilation process
     */
    private void writeText(ServletOutputStream out, String text)
        throws IOException {
        out.println ("<pre class=\"code\">");
        // TODO: [2003-04-03 bloch] should rename SWFHTML to HTML
        // since that's a better description.
        out.println (XMLUtils.escapeXmlForSWFHTML(text));
        out.println ("</pre>");
    }


    public int getMimeType()
    {
        return MIME_TYPE_HTML;
    }
}

{'fraction_non_alphanumeric': 0.17777777777777778, 'fraction_numerical': 0.014228617106314949, 'mean_word_length': 2.7149643705463182, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6205531', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1645, 'n_words': 396}