// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 10/2/2001 11:00:05
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/servlets/FlashGenerator

package com.macromedia.generator.servlets;

import com.macromedia.generator.api.*;
import com.macromedia.generator.app.*;
import com.macromedia.generator.platform.Mac;
import com.macromedia.generator.platform.Unix;
import com.macromedia.generator.utils.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class FlashGenerator extends HttpServlet
    implements FlashCommandLog
{

    public FlashGenerator()
    {
        waitCount = 0;
        m_adminLogging = true;
        admin_maxThreads = 0;
        admin_averageThreads = 0;
        admin_currentRequests = 0;
        admin_getRequests = 0;
        admin_getReleases = 0;
        admin_nSWFRequests = 0L;
        admin_nSWFAveSize = 0L;
        admin_nSWFMinSize = -1L;
        admin_nSWFMaxSize = 0L;
        admin_nSWFMinReqTime = 0L;
        admin_nSWFAveReqTime = 0L;
        admin_nSWFMaxReqTime = 0L;
        installPath = null;
        E5 = null;
        cacheProps = null;
    }

    protected synchronized void appendMessageToLogFile(String s)
    {
        try
        {
            Date date = new Date();
            String s1 = date.toString() + ": " + s + System.getProperty("line.separator", "\n");
            RandomAccessFile randomaccessfile = new RandomAccessFile(new File(getLoggingPath()), "rw");
            randomaccessfile.seek(randomaccessfile.length());
            randomaccessfile.write(s1.getBytes());
            randomaccessfile.close();
        }
        catch(IOException _ex)
        {
            log(s);
        }
    }

    protected synchronized void appendMessagesToLogFile(String s, String s1)
    {
        if(s1.length() > 0)
            try
            {
                Date date = new Date();
                String s2 = date.toString() + ": " + s + System.getProperty("line.separator", "\n");
                RandomAccessFile randomaccessfile = new RandomAccessFile(new File(getLoggingPath()), "rw");
                randomaccessfile.seek(randomaccessfile.length());
                randomaccessfile.write(s2.getBytes());
                randomaccessfile.write(s1.getBytes());
                randomaccessfile.close();
            }
            catch(IOException _ex)
            {
                log(s1);
            }
    }

    public void cleanUpMemory()
    {
        if(garbageCollectAfterJobCount > 0L)
        {
            jobCountSinceLastGC++;
            if(jobCountSinceLastGC > garbageCollectAfterJobCount)
            {
                System.runFinalization();
                System.gc();
                jobCountSinceLastGC = 0L;
            }
        }
        if(forceFinalizers)
            System.runFinalization();
        if(forceGarbageCollection)
            System.gc();
    }

    public void destroy()
    {
        if(cacheMgr != null)
        {
            cacheMgr.dispose();
            cacheMgr = null;
        }
        logStats();
        logMessage(getResString("ServletDestroy"));
        super.destroy();
    }

    public void disableRequests(boolean flag)
    {
        requestLock = flag;
    }

    public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws ServletException, IOException
    {
        if(_fld018F && processAdminRequest(httpservletrequest, httpservletresponse))
            return;
        if(requestLock)
        {
            httpservletresponse.sendError(503);
            return;
        }
        currentJobCount++;
        if(currentJobCount > maxSimultaneousRequests)
            maxSimultaneousRequests = currentJobCount;
        if((long)currentJobCount > _fld0190.maxConcurReq)
            _fld0190.maxConcurReq = currentJobCount;
        if(System.currentTimeMillis() - statStartTime > _fld019D)
            logStats();
        totalJobCount++;
        if(totalJobCount > 10000L)
            logStats();
        try
        {
            int i = getRequestType(httpservletrequest);
            switch(i)
            {
            case 1: // '\001'
                if(m_adminLogging)
                    admin_nSWFRequests++;
                doGetForFlash(httpservletrequest, httpservletresponse);
                break;

            case 2: // '\002'
                doGetForGif(httpservletrequest, httpservletresponse, false);
                break;

            case 5: // '\005'
                doGetForGif(httpservletrequest, httpservletresponse, true);
                break;

            case 3: // '\003'
                doGetForJpeg(httpservletrequest, httpservletresponse);
                break;

            case 4: // '\004'
                doGetForPng(httpservletrequest, httpservletresponse);
                break;

            case 7: // '\007'
                doGetForQTM(httpservletrequest, httpservletresponse);
                break;

            default:
                if(loggingLevel > 0)
                    logMessage(getResString("ServletInvalidType") + httpservletrequest.getRequestURI());
                doGetForFlash(httpservletrequest, httpservletresponse);
                break;

            case 6: // '\006'
                break;
            }
            currentJobCount--;
        }
        catch(Exception exception)
        {
            currentJobCount--;
            if(loggingLevel >= 1)
            {
                String s = "";
                logMessage("Exception (doGet): " + s + ": " + exception);
            }
            System.runFinalization();
            System.gc();
            httpservletresponse.sendError(500);
        }
        catch(Error error)
        {
            currentJobCount--;
            if(loggingLevel >= 1)
            {
                String s1 = "";
                logMessage("Exception (doGet): " + s1 + ": " + error);
            }
            System.runFinalization();
            System.gc();
            httpservletresponse.sendError(500);
        }
    }

    public void doGetForFlash(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws Exception, Error
    {
        long l = System.currentTimeMillis();
        int i = 0;
        File file = getRequestFile(httpservletrequest);
        if(file != null)
        {
            Buffer buffer = null;
            FlashEnvironment flashenvironment = null;
            Vector vector = getRequestParameters(httpservletrequest);
            String s = cacheMgr.makeRequestString(file.toString(), httpservletrequest.getQueryString());
            buffer = cacheMgr.getRequestBuffer(s);
            if(buffer == null)
            {
                flashenvironment = new FlashEnvironment(loggingLevel, false, serial, E5, cacheMgr);
                if(_fld018E)
                {
                    flashenvironment.getGenInfo().setRequestBuffer(httpservletrequest);
                    flashenvironment.getGenInfo().setResponseBuffer(httpservletresponse);
                    flashenvironment.getGenInfo().setServletContext(getServletContext());
                }
                if(take())
                {
                    try
                    {
                        buffer = flashenvironment.processTemplate(file, vector);
                        if(buffer != null)
                            cacheMgr.addRequest(s, buffer);
                    }
                    catch(Exception exception)
                    {
                        _mth018A(buffer, httpservletresponse, true);
                        throw exception;
                    }
                    catch(Error error)
                    {
                        _mth018A(buffer, httpservletresponse, true);
                        throw error;
                    }
                    release();
                } else
                {
                    httpservletresponse.sendError(503);
                }
            }
            if(buffer != null)
                try
                {
                    long l2 = System.currentTimeMillis();
                    httpservletresponse.setContentType("application/x-shockwave-flash");
                    i = buffer.getSize();
                    httpservletresponse.setContentLength(i);
                    if(cacheMSoftSSLFix != 1)
                    {
                        httpservletresponse.setDateHeader("Expires", l2 + cacheExpires);
                        httpservletresponse.setHeader("Cache-Control", cacheDirective);
                        httpservletresponse.setHeader("Pragma", cachePragma);
                    } else
                    {
                        httpservletresponse.setDateHeader("Expires", 0L);
                    }
                    httpservletresponse.setDateHeader("Last-modified", l2 + cacheLastModified);
                    int k = buffer.getBufferCount();
                    ServletOutputStream servletoutputstream = httpservletresponse.getOutputStream();
                    for(int i1 = 0; i1 < k; i1++)
                    {
                        byte abyte0[] = buffer.getBuffer(i1);
                        if(abyte0 != null)
                            servletoutputstream.write(abyte0);
                    }

                    servletoutputstream.close();
                    buffer.release();
                }
                catch(Exception exception1)
                {
                    _mth018A(buffer, httpservletresponse, false);
                    throw exception1;
                }
                catch(Error error1)
                {
                    _mth018A(buffer, httpservletresponse, false);
                    throw error1;
                }
            if(flashenvironment != null)
                appendMessagesToLogFile(httpservletrequest.getRequestURI(), flashenvironment.getMessages());
        } else
        {
            if(loggingLevel > 0)
                logMessage(getResString("InvalidURL") + httpservletrequest.getRequestURI());
            httpservletresponse.sendError(404);
        }
        cleanUpMemory();
        swfCnt++;
        int j = (i + 500) / 1000;
        swfTotSize += i;
        if((long)j > swfMaxSize)
            swfMaxSize = j;
        long l1 = System.currentTimeMillis() - l;
        swfTotTime += l1;
        if(l1 > swfMaxTime)
            swfMaxTime = l1;
        if(_fld0190 != null)
            synchronized(_fld0190)
            {
                _fld0190.swfCnt++;
                _fld0190.swfTotSize += i;
                if((long)j > _fld0190.swfMaxSize)
                    _fld0190.swfMaxSize = j;
                _fld0190.swfTotTime += l1;
                if(l1 > _fld0190.swfMaxTime)
                    _fld0190.swfMaxTime = l1;
            }
    }

    public void doGetForGif(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, boolean flag)
        throws Exception, Error
    {
        long l = System.currentTimeMillis();
        int i = 0;
        File file = getRequestFile(httpservletrequest);
        if(file != null)
        {
            int j = 0;
            boolean flag1 = false;
            Buffer buffer = null;
            FlashEnvironment flashenvironment = null;
            Vector vector = getRequestParameters(httpservletrequest);
            String s = cacheMgr.makeRequestString(file.toString(), httpservletrequest.getQueryString());
            buffer = cacheMgr.getRequestBuffer(s);
            if(buffer == null)
            {
                flashenvironment = new FlashEnvironment(loggingLevel, false, serial, E5, cacheMgr);
                if(_fld018E)
                {
                    flashenvironment.getGenInfo().setRequestBuffer(httpservletrequest);
                    flashenvironment.getGenInfo().setResponseBuffer(httpservletresponse);
                    flashenvironment.getGenInfo().setServletContext(getServletContext());
                }
                if(take())
                {
                    try
                    {
                        Buffer buffer1 = flashenvironment.processTemplate(file, vector);
                        if(buffer1 != null)
                        {
                            int i1 = -1;
                            int j1 = -1;
                            int k1 = 2;
                            int j2 = 0;
                            int k2 = 64;
                            int j3 = 128;
                            boolean flag2 = true;
                            boolean flag3 = false;
                            boolean flag4 = true;
                            boolean flag5 = false;
                            boolean flag6 = false;
                            boolean flag7 = false;
                            boolean flag8 = false;
                            boolean flag9 = true;
                            String s2 = "";
                            Boolean boolean1 = (Boolean)flashenvironment.get("GifInitialized");
                            if(boolean1 != null && boolean1.booleanValue())
                            {
                                i1 = ((Integer)flashenvironment.get("GifWidth")).intValue();
                                j1 = ((Integer)flashenvironment.get("GifHeight")).intValue();
                                j = ((Integer)flashenvironment.get("GifLoopCount")).intValue();
                                flag2 = ((Boolean)flashenvironment.get("GifAnimated")).booleanValue();
                                flag3 = ((Boolean)flashenvironment.get("GifDither")).booleanValue();
                                k1 = ((Integer)flashenvironment.get("GifDitherType")).intValue();
                                flag4 = ((Boolean)flashenvironment.get("GifSmooth")).booleanValue();
                                flag5 = ((Boolean)flashenvironment.get("GifInterlace")).booleanValue();
                                flag6 = ((Boolean)flashenvironment.get("GifTransparent")).booleanValue();
                                flag7 = ((Boolean)flashenvironment.get("GifTransparentSmart")).booleanValue();
                                j3 = ((Integer)flashenvironment.get("GifTransparentThreshold")).intValue();
                                flag8 = ((Boolean)flashenvironment.get("GifNoGradients")).booleanValue();
                                flag9 = ((Boolean)flashenvironment.get("GifColorOpt")).booleanValue();
                                j2 = ((Integer)flashenvironment.get("GifPaletteType")).intValue();
                                k2 = ((Integer)flashenvironment.get("GifMaxColors")).intValue();
                                s2 = (String)flashenvironment.get("GifPaletteFile");
                            }
                            GifBuilder gifbuilder = new GifBuilder();
                            gifbuilder.setSerial(serial);
                            gifbuilder.setDither(flag3);
                            gifbuilder.setSmooth(flag4);
                            gifbuilder.setInterlace(flag5);
                            gifbuilder.setTransparent(flag6);
                            gifbuilder.setTransparentSmart(flag7);
                            gifbuilder.setTransparentThreshold(j3);
                            gifbuilder.setGradient(flag8);
                            gifbuilder.setLoopCount(j);
                            gifbuilder.setDitherType(k1);
                            gifbuilder.setColorOptimization(flag9);
                            gifbuilder.setPaletteType(j2);
                            gifbuilder.setMaxColors(k2);
                            gifbuilder.setQuality(flag);
                            gifbuilder.setAnimated(flag2);
                            Mac mac = Mac.getMac();
                            if(mac != null)
                                s2 = mac.makeSystemPretty(s2);
                            gifbuilder.setFilePalette(s2);
                            if(i1 > 0 && j1 > 0)
                                gifbuilder.setDimensions(i1, j1);
                            buffer = new Buffer();
                            gifbuilder.build(buffer1, buffer);
                            buffer1.release();
                            gifbuilder.release();
                        }
                        if(buffer != null)
                            cacheMgr.addRequest(s, buffer);
                    }
                    catch(Exception exception)
                    {
                        _mth018A(buffer, httpservletresponse, true);
                        throw exception;
                    }
                    catch(Error error)
                    {
                        _mth018A(buffer, httpservletresponse, true);
                        throw error;
                    }
                    release();
                } else
                {
                    httpservletresponse.sendError(503);
                }
            }
            if(buffer != null)
                try
                {
                    long l2 = System.currentTimeMillis();
                    String s1 = httpservletrequest.getHeader("User-Agent");
                    if(s1 != null && s1.startsWith("Mozilla") && s1.indexOf("compatible") < 0)
                        flag1 = true;
                    if(flag1 && j != 1)
                    {
                        httpservletresponse.setContentType("image/gif");
                        i = buffer.getSize();
                        httpservletresponse.setContentLength(i);
                        httpservletresponse.setHeader("Cache-Control", cacheDirective);
                        if(!gifAltHeader)
                        {
                            httpservletresponse.setDateHeader("Expires", l2 + 0x493e0L + cacheExpires);
                            httpservletresponse.setDateHeader("Last-modified", l2 + cacheLastModified);
                        } else
                        {
                            Calendar calendar = Calendar.getInstance();
                            calendar.add(14, (int)gifCacheExpires);
                            httpservletresponse.setHeader("Expires", calendar.getTime().toString());
                            calendar = Calendar.getInstance();
                            calendar.add(14, (int)gifCacheLastModified);
                            httpservletresponse.setHeader("Last-modified", calendar.getTime().toString());
                        }
                    } else
                    {
                        httpservletresponse.setContentType("image/gif");
                        httpservletresponse.setContentLength(buffer.getSize());
                        httpservletresponse.setDateHeader("Last-modified", l2 + cacheLastModified);
                        httpservletresponse.setDateHeader("Expires", l2 + cacheExpires);
                        httpservletresponse.setHeader("Pragma", cachePragma);
                        httpservletresponse.setHeader("Cache-Control", cacheDirective);
                        i = buffer.getSize();
                    }
                    int i2 = buffer.getBufferCount();
                    ServletOutputStream servletoutputstream = httpservletresponse.getOutputStream();
                    for(int i3 = 0; i3 < i2; i3++)
                    {
                        byte abyte0[] = buffer.getBuffer(i3);
                        servletoutputstream.write(abyte0);
                    }

                    servletoutputstream.close();
                    buffer.release();
                }
                catch(Exception exception1)
                {
                    _mth018A(buffer, httpservletresponse, false);
                    throw exception1;
                }
                catch(Error error1)
                {
                    _mth018A(buffer, httpservletresponse, false);
                    throw error1;
                }
            if(flashenvironment != null)
                appendMessagesToLogFile(httpservletrequest.getRequestURI(), flashenvironment.getMessages());
        } else
        {
            if(loggingLevel > 0)
                logMessage(getResString("InvalidURL") + httpservletrequest.getRequestURI());
            httpservletresponse.sendError(404);
        }
        cleanUpMemory();
        if(flag)
            xgifCnt++;
        else
            gifCnt++;
        int k = (i + 500) / 1000;
        gifTotSize += i;
        if((long)k > gifMaxSize)
            gifMaxSize = k;
        long l1 = System.currentTimeMillis() - l;
        gifTotTime += l1;
        if(l1 > gifMaxTime)
            gifMaxTime = l1;
        if(_fld0190 != null)
            synchronized(_fld0190)
            {
                _fld0190.gifCnt++;
                _fld0190.gifTotSize += i;
                if((long)k > _fld0190.gifMaxSize)
                    _fld0190.gifMaxSize = k;
                _fld0190.gifTotTime += l1;
                if(l1 > _fld0190.gifMaxTime)
                    _fld0190.gifMaxTime = l1;
            }
    }

    public void doGetForJpeg(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws Exception, Error
    {
        long l = System.currentTimeMillis();
        int i = 0;
        File file = getRequestFile(httpservletrequest);
        if(file != null)
        {
            Buffer buffer = null;
            FlashEnvironment flashenvironment = null;
            Vector vector = getRequestParameters(httpservletrequest);
            String s = cacheMgr.makeRequestString(file.toString(), httpservletrequest.getQueryString());
            buffer = cacheMgr.getRequestBuffer(s);
            if(buffer == null)
            {
                flashenvironment = new FlashEnvironment(loggingLevel, false, serial, E5, cacheMgr);
                if(_fld018E)
                {
                    flashenvironment.getGenInfo().setRequestBuffer(httpservletrequest);
                    flashenvironment.getGenInfo().setResponseBuffer(httpservletresponse);
                    flashenvironment.getGenInfo().setServletContext(getServletContext());
                }
                if(take())
                {
                    try
                    {
                        Buffer buffer1 = flashenvironment.processTemplate(file, vector);
                        if(buffer1 != null)
                        {
                            int k = -1;
                            int i1 = -1;
                            int k1 = 50;
                            boolean flag = true;
                            Boolean boolean1 = (Boolean)flashenvironment.get("JPEGInitialized");
                            if(boolean1 != null && boolean1.booleanValue())
                            {
                                k = ((Integer)flashenvironment.get("JPEGWidth")).intValue();
                                i1 = ((Integer)flashenvironment.get("JPEGHeight")).intValue();
                                k1 = ((Integer)flashenvironment.get("JPEGQuality")).intValue();
                                flag = ((Boolean)flashenvironment.get("JPEGProgressive")).booleanValue();
                            }
                            JPEGBuilder jpegbuilder = new JPEGBuilder();
                            jpegbuilder.setSerial(serial);
                            if(k > 0 && i1 > 0)
                                jpegbuilder.setDimensions(k, i1);
                            jpegbuilder.setQuality(k1);
                            jpegbuilder.setProgressive(flag);
                            buffer = new Buffer();
                            jpegbuilder.build(buffer1, buffer);
                            buffer1.release();
                            jpegbuilder.release();
                        }
                        if(buffer != null)
                            cacheMgr.addRequest(s, buffer);
                    }
                    catch(Exception exception)
                    {
                        _mth018A(buffer, httpservletresponse, true);
                        throw exception;
                    }
                    catch(Error error)
                    {
                        _mth018A(buffer, httpservletresponse, true);
                        throw error;
                    }
                    release();
                } else
                {
                    httpservletresponse.sendError(503);
                }
            }
            if(buffer != null)
                try
                {
                    long l2 = System.currentTimeMillis();
                    httpservletresponse.setContentType("image/jpeg");
                    i = buffer.getSize();
                    httpservletresponse.setContentLength(i);
                    httpservletresponse.setDateHeader("Expires", l2 + cacheExpires);
                    httpservletresponse.setDateHeader("Last-modified", l2 + cacheLastModified);
                    httpservletresponse.setHeader("Pragma", cachePragma);
                    httpservletresponse.setHeader("Cache-Control", cacheDirective);
                    int j1 = buffer.getBufferCount();
                    ServletOutputStream servletoutputstream = httpservletresponse.getOutputStream();
                    for(int i2 = 0; i2 < j1; i2++)
                    {
                        byte abyte0[] = buffer.getBuffer(i2);
                        servletoutputstream.write(abyte0);
                    }

                    servletoutputstream.close();
                    buffer.release();
                }
                catch(Exception exception1)
                {
                    _mth018A(buffer, httpservletresponse, false);
                    throw exception1;
                }
                catch(Error error1)
                {
                    _mth018A(buffer, httpservletresponse, false);
                    throw error1;
                }
            if(flashenvironment != null)
                appendMessagesToLogFile(httpservletrequest.getRequestURI(), flashenvironment.getMessages());
        } else
        {
            if(loggingLevel > 0)
                logMessage(getResString("InvalidURL") + httpservletrequest.getRequestURI());
            httpservletresponse.sendError(404);
        }
        cleanUpMemory();
        jpegCnt++;
        int j = (i + 500) / 1000;
        jpegTotSize += i;
        if((long)j > jpegMaxSize)
            jpegMaxSize = j;
        long l1 = System.currentTimeMillis() - l;
        jpegTotTime += l1;
        if(l1 > jpegMaxTime)
            jpegMaxTime = l1;
        if(_fld0190 != null)
            synchronized(_fld0190)
            {
                _fld0190.jpgCnt++;
                _fld0190.jpgTotSize += i;
                if((long)j > _fld0190.jpgMaxSize)
                    _fld0190.jpgMaxSize = j;
                _fld0190.jpgTotTime += l1;
                if(l1 > _fld0190.jpgMaxTime)
                    _fld0190.jpgMaxTime = l1;
            }
    }

    public void doGetForPng(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws Exception, Error
    {
        long l = System.currentTimeMillis();
        int i = 0;
        File file = getRequestFile(httpservletrequest);
        if(file != null)
        {
            Buffer buffer = null;
            FlashEnvironment flashenvironment = null;
            Vector vector = getRequestParameters(httpservletrequest);
            String s = cacheMgr.makeRequestString(file.toString(), httpservletrequest.getQueryString());
            buffer = cacheMgr.getRequestBuffer(s);
            if(buffer == null)
            {
                flashenvironment = new FlashEnvironment(loggingLevel, false, serial, E5, cacheMgr);
                if(_fld018E)
                {
                    flashenvironment.getGenInfo().setRequestBuffer(httpservletrequest);
                    flashenvironment.getGenInfo().setResponseBuffer(httpservletresponse);
                    flashenvironment.getGenInfo().setServletContext(getServletContext());
                }
                if(take())
                {
                    try
                    {
                        Buffer buffer1 = flashenvironment.processTemplate(file, vector);
                        if(buffer1 != null)
                        {
                            int k = 0;
                            int i1 = -1;
                            int k1 = -1;
                            int i2 = 0;
                            int k2 = 0;
                            int i3 = 0;
                            int j3 = 64;
                            boolean flag = true;
                            boolean flag1 = true;
                            boolean flag2 = true;
                            boolean flag3 = false;
                            boolean flag4 = true;
                            String s1 = "";
                            Boolean boolean1 = (Boolean)flashenvironment.get("PNGInitialized");
                            if(boolean1 != null && boolean1.booleanValue())
                            {
                                k = ((Integer)flashenvironment.get("PNGType")).intValue();
                                i1 = ((Integer)flashenvironment.get("PNGWidth")).intValue();
                                k1 = ((Integer)flashenvironment.get("PNGHeight")).intValue();
                                i2 = ((Integer)flashenvironment.get("PNGOption")).intValue();
                                k2 = ((Integer)flashenvironment.get("PNGDitherType")).intValue();
                                flag = ((Boolean)flashenvironment.get("PNGInterlace")).booleanValue();
                                flag1 = ((Boolean)flashenvironment.get("PNGSmooth")).booleanValue();
                                flag2 = ((Boolean)flashenvironment.get("PNGDither")).booleanValue();
                                flag3 = ((Boolean)flashenvironment.get("PNGNoGradients")).booleanValue();
                                flag4 = ((Boolean)flashenvironment.get("PNGColorOpt")).booleanValue();
                                i3 = ((Integer)flashenvironment.get("PNGPaletteType")).intValue();
                                j3 = ((Integer)flashenvironment.get("PNGMaxColors")).intValue();
                                s1 = (String)flashenvironment.get("PNGPaletteFile");
                            }
                            PngBuilder pngbuilder = new PngBuilder();
                            pngbuilder.setSerial(serial);
                            pngbuilder.setType(k);
                            pngbuilder.setOption(i2);
                            pngbuilder.setDitherType(k2);
                            pngbuilder.setInterlace(flag);
                            pngbuilder.setSmooth(flag1);
                            pngbuilder.setDither(flag2);
                            pngbuilder.setGradient(flag3);
                            pngbuilder.setColorOptimization(flag4);
                            pngbuilder.setPaletteType(i3);
                            pngbuilder.setMaxColors(j3);
                            Mac mac = Mac.getMac();
                            if(mac != null)
                                s1 = mac.makeSystemPretty(s1);
                            pngbuilder.setFilePalette(s1);
                            if(i1 > 0 && k1 > 0)
                                pngbuilder.setDimensions(i1, k1);
                            buffer = new Buffer();
                            pngbuilder.build(buffer1, buffer);
                            buffer1.release();
                            pngbuilder.release();
                        }
                        if(buffer != null)
                            cacheMgr.addRequest(s, buffer);
                    }
                    catch(Exception exception)
                    {
                        _mth018A(buffer, httpservletresponse, true);
                        throw exception;
                    }
                    catch(Error error)
                    {
                        _mth018A(buffer, httpservletresponse, true);
                        throw error;
                    }
                    release();
                } else
                {
                    httpservletresponse.sendError(503);
                }
            }
            if(buffer != null)
                try
                {
                    long l2 = System.currentTimeMillis();
                    httpservletresponse.setContentType("image/png");
                    i = buffer.getSize();
                    httpservletresponse.setContentLength(i);
                    httpservletresponse.setDateHeader("Expires", l2 + cacheExpires);
                    httpservletresponse.setDateHeader("Last-modified", l2 + cacheLastModified);
                    httpservletresponse.setHeader("Pragma", cachePragma);
                    httpservletresponse.setHeader("Cache-Control", cacheDirective);
                    int j1 = buffer.getBufferCount();
                    ServletOutputStream servletoutputstream = httpservletresponse.getOutputStream();
                    for(int j2 = 0; j2 < j1; j2++)
                    {
                        byte abyte0[] = buffer.getBuffer(j2);
                        servletoutputstream.write(abyte0);
                    }

                    servletoutputstream.close();
                    buffer.release();
                }
                catch(Exception exception1)
                {
                    _mth018A(buffer, httpservletresponse, false);
                    throw exception1;
                }
                catch(Error error1)
                {
                    _mth018A(buffer, httpservletresponse, false);
                    throw error1;
                }
            if(flashenvironment != null)
                appendMessagesToLogFile(httpservletrequest.getRequestURI(), flashenvironment.getMessages());
        } else
        {
            if(loggingLevel > 0)
                logMessage(getResString("InvalidURL") + httpservletrequest.getRequestURI());
            httpservletresponse.sendError(404);
        }
        cleanUpMemory();
        pngCnt++;
        int j = (i + 500) / 1000;
        pngTotSize += i;
        if((long)j > pngMaxSize)
            pngMaxSize = j;
        long l1 = System.currentTimeMillis() - l;
        pngTotTime += l1;
        if(l1 > pngMaxTime)
            pngMaxTime = l1;
        if(_fld0190 != null)
            synchronized(_fld0190)
            {
                _fld0190.pngCnt++;
                _fld0190.pngTotSize += i;
                if((long)j > _fld0190.pngMaxSize)
                    _fld0190.pngMaxSize = j;
                _fld0190.pngTotTime += l1;
                if(l1 > _fld0190.pngMaxTime)
                    _fld0190.pngMaxTime = l1;
            }
    }

    public void doGetForQTM(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
        throws Exception, Error
    {
        long l = System.currentTimeMillis();
        int i = 0;
        File file = getRequestFile(httpservletrequest);
        if(file != null)
        {
            Buffer buffer = null;
            FlashEnvironment flashenvironment = null;
            Vector vector = getRequestParameters(httpservletrequest);
            String s = cacheMgr.makeRequestString(file.toString(), httpservletrequest.getQueryString());
            buffer = cacheMgr.getRequestBuffer(s);
            if(buffer == null)
            {
                flashenvironment = new FlashEnvironment(loggingLevel, false, serial, E5, cacheMgr);
                if(_fld018E)
                {
                    flashenvironment.getGenInfo().setRequestBuffer(httpservletrequest);
                    flashenvironment.getGenInfo().setResponseBuffer(httpservletresponse);
                    flashenvironment.getGenInfo().setServletContext(getServletContext());
                }
                if(take())
                {
                    try
                    {
                        buffer = flashenvironment.processTemplate(file, vector);
                        if(buffer != null)
                            cacheMgr.addRequest(s, buffer);
                    }
                    catch(Exception exception)
                    {
                        _mth018A(buffer, httpservletresponse, true);
                        throw exception;
                    }
                    catch(Error error)
                    {
                        _mth018A(buffer, httpservletresponse, true);
                        throw error;
                    }
                    release();
                } else
                {
                    httpservletresponse.sendError(503);
                }
            }
            if(buffer != null)
                try
                {
                    long l2 = System.currentTimeMillis();
                    httpservletresponse.setContentType("video/quicktime");
                    i = buffer.getSize();
                    httpservletresponse.setContentLength(i);
                    httpservletresponse.setDateHeader("Expires", l2 + cacheExpires);
                    httpservletresponse.setDateHeader("Last-modified", l2 + cacheLastModified);
                    httpservletresponse.setHeader("Pragma", cachePragma);
                    httpservletresponse.setHeader("Cache-Control", cacheDirective);
                    byte abyte0[] = {
                        83, 87, 70, 76, 116, 101, 120, 116
                    };
                    int k = buffer.getBufferCount();
                    ServletOutputStream servletoutputstream = httpservletresponse.getOutputStream();
                    servletoutputstream.write(abyte0);
                    for(int i1 = 0; i1 < k; i1++)
                    {
                        byte abyte1[] = buffer.getBuffer(i1);
                        servletoutputstream.write(abyte1);
                    }

                    servletoutputstream.close();
                    buffer.release();
                }
                catch(Exception exception1)
                {
                    _mth018A(buffer, httpservletresponse, false);
                    throw exception1;
                }
                catch(Error error1)
                {
                    _mth018A(buffer, httpservletresponse, false);
                    throw error1;
                }
            if(flashenvironment != null)
                appendMessagesToLogFile(httpservletrequest.getRequestURI(), flashenvironment.getMessages());
        } else
        {
            if(loggingLevel > 0)
                logMessage(getResString("InvalidURL") + httpservletrequest.getRequestURI());
            httpservletresponse.sendError(404);
        }
        cleanUpMemory();
        qtmCnt++;
        int j = (i + 500) / 1000;
        qtmTotSize += i;
        if((long)j > qtmMaxSize)
            qtmMaxSize = j;
        long l1 = System.currentTimeMillis() - l;
        qtmTotTime += l1;
        if(l1 > qtmMaxTime)
            qtmMaxTime = l1;
        if(_fld0190 != null)
            synchronized(_fld0190)
            {
                _fld0190.qtmCnt++;
                _fld0190.qtmTotSize += i;
                if((long)j > _fld0190.qtmMaxSize)
                    _fld0190.qtmMaxSize = j;
                _fld0190.qtmTotTime += l1;
                if(l1 > _fld0190.qtmMaxTime)
                    _fld0190.qtmMaxTime = l1;
            }
    }

    public void flushCaches()
    {
        if(cacheMgr != null)
            cacheMgr.purgeCaches();
    }

    public CacheProperties getCacheProperties(boolean flag)
    {
        if(cacheMgr != null)
            cacheProps = cacheMgr.getProperties();
        if(cacheProps == null && flag)
            cacheProps = new CacheProperties();
        return cacheProps;
    }

    protected String getCacheProperty(String s)
    {
        if(cacheProps != null)
            return cacheProps.toString(s);
        else
            return null;
    }

    public int getCurrentJobCount()
    {
        return currentJobCount;
    }

    public String getExternalFontPath()
    {
        return getSystemProperty("com.macromedia.generator.fontpath");
    }

    public long getGifAvgSize()
    {
        return gifCnt <= 0 ? 0L : ((gifTotSize + (long)(gifCnt >> 1)) / (long)gifCnt + 500L) / 1000L;
    }

    public long getGifAvgTime()
    {
        return gifCnt <= 0 ? 0L : gifTotTime / (long)gifCnt;
    }

    public int getGifCnt()
    {
        return gifCnt;
    }

    public long getGifMaxSize()
    {
        return gifMaxSize;
    }

    public long getGifMaxTime()
    {
        return gifMaxTime;
    }

    public String getInstallPath()
    {
        return installPath;
    }

    public long getJpegAvgSize()
    {
        return jpegCnt <= 0 ? 0L : ((jpegTotSize + (long)(jpegCnt >> 1)) / (long)jpegCnt + 500L) / 1000L;
    }

    public long getJpegAvgTime()
    {
        return jpegCnt <= 0 ? 0L : jpegTotTime / (long)jpegCnt;
    }

    public int getJpegCnt()
    {
        return jpegCnt;
    }

    public long getJpegMaxSize()
    {
        return jpegMaxSize;
    }

    public long getJpegMaxTime()
    {
        return jpegMaxTime;
    }

    public int getLoggingLevel()
    {
        return loggingLevel;
    }

    public String getLoggingPath()
    {
        String s = getSystemProperty("com.macromedia.generator.installpath");
        String s1 = System.getProperty("file.separator");
        return s + s1 + "logs" + s1 + "Generator.log";
    }

    public int getMaxThreads()
    {
        return maxThreads;
    }

    public long getPngAvgSize()
    {
        return pngCnt <= 0 ? 0L : ((pngTotSize + (long)(pngCnt >> 1)) / (long)pngCnt + 500L) / 1000L;
    }

    public long getPngAvgTime()
    {
        return pngCnt <= 0 ? 0L : pngTotTime / (long)pngCnt;
    }

    public int getPngCnt()
    {
        return pngCnt;
    }

    public long getPngMaxSize()
    {
        return pngMaxSize;
    }

    public long getPngMaxTime()
    {
        return pngMaxTime;
    }

    public String getPropertiesPath()
    {
        String s = System.getProperty("com.macromedia.generator.installpath");
        String s1 = System.getProperty("file.separator");
        return s + s1 + "properties" + s1 + "generator.properties";
    }

    public long getQtmAvgSize()
    {
        return qtmCnt <= 0 ? 0L : ((qtmTotSize + (long)(qtmCnt >> 1)) / (long)qtmCnt + 500L) / 1000L;
    }

    public long getQtmAvgTime()
    {
        return qtmCnt <= 0 ? 0L : qtmTotTime / (long)qtmCnt;
    }

    public int getQtmCnt()
    {
        return qtmCnt;
    }

    public long getQtmMaxSize()
    {
        return qtmMaxSize;
    }

    public long getQtmMaxTime()
    {
        return qtmMaxTime;
    }

    protected File getRequestFile(HttpServletRequest httpservletrequest)
    {
        File file = null;
        String s = null;
        String as[] = httpservletrequest.getParameterValues("templatePath");
        if(as != null && as.length != 0)
        {
            s = as[0];
            if(s.indexOf("/") != 0)
                s = httpservletrequest.getPathTranslated().substring(0, httpservletrequest.getPathTranslated().lastIndexOf("/") + 1) + s;
        } else
        if(httpservletrequest.getPathInfo() != null)
            s = httpservletrequest.getPathTranslated();
        else
            s = httpservletrequest.getRealPath(httpservletrequest.getServletPath());
        if(_fld018F)
        {
            String s1 = System.getProperty("file.separator");
            String s2 = getSystemProperty("com.macromedia.generator.installpath");
            if(s2 != null && !s2.endsWith(s1))
                s2 = s2 + s1;
            String s3 = null;
            int i = s.lastIndexOf(s1);
            if(i >= 0)
                s3 = s.substring(i + 1);
            else
                s3 = s;
            if(s3.equalsIgnoreCase("__Admin__Logon__.swt"))
                s = s2 + "admin" + s1 + "AdminLogon.swt";
            else
            if(s3.equalsIgnoreCase("__Admin__Message__.swt"))
                s = s2 + "admin" + s1 + "AdminMessage.swt";
            else
            if(s3.equalsIgnoreCase("__Admin__Service__.swt"))
                s = s2 + "admin" + s1 + "AdminService.swt";
        }
        if(s != null)
        {
            file = new File(s);
            if(file == null || !file.exists() || !file.isFile())
                file = null;
        }
        return file;
    }

    protected Vector getRequestParameters(HttpServletRequest httpservletrequest)
    {
        boolean flag = false;
        if(_fld019C && httpservletrequest.getHeader("USER_AGENT") != null && httpservletrequest.getHeader("ACCEPT_LANGUAGE") != null && httpservletrequest.getHeader("USER_AGENT").indexOf("Win") != -1 && httpservletrequest.getHeader("ACCEPT_LANGUAGE").indexOf("ja") != -1)
            flag = true;
        Vector vector = new Vector(16, 16);
        String as[];
        for(Enumeration enumeration = httpservletrequest.getParameterNames(); enumeration.hasMoreElements(); vector.addElement(as))
        {
            as = new String[2];
            as[0] = (String)enumeration.nextElement();
            as[1] = "";
            String as1[] = httpservletrequest.getParameterValues(as[0]);
            for(int i = 0; i < as1.length; i++)
                if(i == 0)
                {
                    as[1] = as1[i];
                    if(flag)
                        try
                        {
                            String s = new String(as[1].getBytes("ISO-8859-1"), "JISAutoDetect");
                            as[1] = s;
                        }
                        catch(Exception _ex) { }
                } else
                {
                    as[1] += " " + as1[i];
                }

            as[1] = GenUtils.replace(as[1], "\\r", '\r');
            as[1] = GenUtils.replace(as[1], "\\n", '\n');
        }

        return vector;
    }

    protected int getRequestType(HttpServletRequest httpservletrequest)
    {
        byte byte0 = 0;
        String s = "swf";
        for(Enumeration enumeration = httpservletrequest.getParameterNames(); enumeration.hasMoreElements();)
        {
            String s1 = (String)enumeration.nextElement();
            if(s1.equalsIgnoreCase("type"))
            {
                String as[] = httpservletrequest.getParameterValues(s1);
                s = as[0];
                break;
            }
        }

        if(s.equalsIgnoreCase("swf"))
            byte0 = 1;
        else
        if(s.equalsIgnoreCase("gif"))
            byte0 = 2;
        else
        if(s.equalsIgnoreCase("xgif"))
            byte0 = 5;
        else
        if(s.equalsIgnoreCase("jpg"))
            byte0 = 3;
        else
        if(s.equalsIgnoreCase("png"))
            byte0 = 4;
        else
        if(s.equalsIgnoreCase("admin"))
            byte0 = 6;
        else
        if(s.equalsIgnoreCase("mov"))
            byte0 = 7;
        else
            byte0 = 0;
        return byte0;
    }

    public String getResString(String s)
    {
        return resources.getString(s);
    }

    public String getSerializePath()
    {
        String s = System.getProperty("com.macromedia.generator.installpath");
        String s1 = System.getProperty("file.separator");
        return s + s1 + ".serialize";
    }

    public String getServerNumber()
    {
        if(serial != null)
            return serial.getServerNumber();
        else
            return null;
    }

    public String getServletInfo()
    {
        return getResString("ServletFlashGenerator");
    }

    public String getStartupTime()
    {
        return startupTime;
    }

    public String getStatsPath()
    {
        String s = getSystemProperty("com.macromedia.generator.installpath");
        String s1 = System.getProperty("file.separator");
        return s + s1 + "admin" + s1 + "GenStats.log";
    }

    public long getSwfAvgSize()
    {
        return swfCnt <= 0 ? 0L : ((swfTotSize + (long)(swfCnt >> 1)) / (long)swfCnt + 500L) / 1000L;
    }

    public long getSwfAvgTime()
    {
        return swfCnt <= 0 ? 0L : swfTotTime / (long)swfCnt;
    }

    public int getSwfCnt()
    {
        return swfCnt;
    }

    public long getSwfMaxSize()
    {
        return swfMaxSize;
    }

    public long getSwfMaxTime()
    {
        return swfMaxTime;
    }

    public String getSystemProperty(String s)
    {
        if(s == null)
            return null;
        Properties properties = System.getProperties();
        if(properties == null)
            return null;
        if(!s.startsWith("com.macromedia.generator."))
            s = "com.macromedia.generator." + s;
        for(Enumeration enumeration = properties.keys(); enumeration.hasMoreElements();)
        {
            String s1 = (String)enumeration.nextElement();
            if(s1.equalsIgnoreCase(s))
            {
                String s2 = (String)properties.get(s1);
                if(s2 != null)
                    s2 = s2.trim();
                return s2;
            }
        }

        return null;
    }

    public long getThreadCount()
    {
        return (long)(getMaxThreads() - semaCount);
    }

    public int getTimeout()
    {
        return timeout;
    }

    public long getXGifAvgSize()
    {
        return xgifCnt <= 0 ? 0L : ((xgifTotSize + (long)(xgifCnt >> 1)) / (long)xgifCnt + 500L) / 1000L;
    }

    public long getXGifAvgTime()
    {
        return xgifCnt <= 0 ? 0L : xgifTotTime / (long)xgifCnt;
    }

    public int getXGifCnt()
    {
        return xgifCnt;
    }

    public long getXGifMaxSize()
    {
        return xgifMaxSize;
    }

    public long getXGifMaxTime()
    {
        return xgifMaxTime;
    }

    private void _mth018A(Buffer buffer, HttpServletResponse httpservletresponse, boolean flag)
        throws IOException
    {
        if(buffer != null)
            buffer.release();
        if(flag)
            release();
    }

    public void init(ServletConfig servletconfig)
        throws ServletException
    {
        super.init(servletconfig);
        if(!initialized)
        {
            String s = servletconfig.getInitParameter("InstallPath");
            if(s == null)
                s = System.getProperty("com.macromedia.generator.installpath");
            if(s == null)
            {
                if(installPath == null)
                    s = "/";
                else
                    s = installPath;
                servletconfig.getServletContext().log("Flash Generator: Install path not found, using default: " + s);
            }
            _fld018E = false;
            String s1 = servletconfig.getInitParameter("extDataSource");
            if(s1 == null)
                s1 = System.getProperty("com.macromedia.generator.extdatasource");
            if(s1 != null && s1.equalsIgnoreCase("true"))
                _fld018E = true;
            String s3 = System.getProperty("com.macromedia.generator.nostats");
            if(s3 != null && s3.equalsIgnoreCase("true"))
                _fld0192 = true;
            _fld018F = false;
            String s5 = servletconfig.getInitParameter("parseAdminArgs");
            if(s5 == null)
                s5 = System.getProperty("com.macromedia.generator.parseAdminArgs");
            if(s5 != null && s5.equalsIgnoreCase("true"))
                _fld018F = true;
            Properties properties1 = System.getProperties();
            properties1.put("com.macromedia.generator.installpath", s);
        }
        initResources();
        initProperties();
        Properties properties = System.getProperties();
        String s2 = (String)properties.get("os.name");
        _fld019C = s2.indexOf("SunOS") != -1 || s2.indexOf("Linux") != -1 || s2.indexOf("AIX") != -1;
        String s4 = (String)properties.get("com.macromedia.generator.reportday");
        if(s4 != null)
        {
            logMessage("reportDay = " + s4);
            if(s4.equalsIgnoreCase("sec"))
                _fld019D = 1000L;
            else
            if(s4.equalsIgnoreCase("min"))
                _fld019D = 60000L;
            else
            if(s4.equalsIgnoreCase("hour"))
                _fld019D = 0x36ee80L;
            else
            if(s4.equalsIgnoreCase("day"))
                _fld019D = 0x5265c00L;
        }
        initSerialization();
        initCaches();
        if(!initialized)
        {
            if(EE)
            {
                semaCount = 1;
                _fld0196 = new Object();
                _fld0197 = new Object();
            } else
            {
                semaCount = getMaxThreads();
            }
            waitCount = 0;
        }
        E5 = getExternalFontPath();
        initialized = true;
        logMessage(getResString("ServletInit"));
        _mth018B();
    }

    private void _mth018B()
    {
        if(!_fld0191)
        {
            startupTime = Calendar.getInstance().getTime().toString();
            swfCnt = 0;
            swfTotSize = 0L;
            swfTotTime = 0L;
            swfMaxSize = 0L;
            swfMaxSize = 0L;
            gifCnt = 0;
            gifTotSize = 0L;
            gifTotTime = 0L;
            gifMaxSize = 0L;
            gifMaxSize = 0L;
            xgifCnt = 0;
            xgifTotSize = 0L;
            xgifTotTime = 0L;
            xgifMaxSize = 0L;
            xgifMaxSize = 0L;
            jpegCnt = 0;
            jpegTotSize = 0L;
            jpegTotTime = 0L;
            jpegMaxSize = 0L;
            jpegMaxSize = 0L;
            pngCnt = 0;
            pngTotSize = 0L;
            pngTotTime = 0L;
            pngMaxSize = 0L;
            pngMaxSize = 0L;
            qtmCnt = 0;
            qtmTotSize = 0L;
            qtmTotTime = 0L;
            qtmMaxSize = 0L;
            qtmMaxSize = 0L;
            _fld0191 = true;
            maxSimultaneousRequests = 0;
            _fld0190 = new GenReportFrame();
        }
        synchronized(_fld0190)
        {
            _fld0190.resetValues(startupTime);
            statStartTime = System.currentTimeMillis();
            totalJobCount = 0L;
        }
    }

    protected void initCaches()
    {
        if(!initialized)
            if(cacheProps != null)
                cacheMgr = new CacheManager(cacheProps);
            else
                cacheMgr = new CacheManager();
    }

    protected void initProperties()
    {
        if(!initialized)
        {
            Properties properties = new Properties();
            if(loggingLevel >= 3)
                log(getResString("Title") + " " + getResString("Version") + " " + " - " + getResString("BuildDate"));
            try
            {
                FileInputStream fileinputstream = new FileInputStream(getPropertiesPath());
                properties.load(fileinputstream);
                fileinputstream.close();
            }
            catch(IOException _ex)
            {
                logMessage(getResString("ServletPropertyLoadError") + getPropertiesPath());
            }
            cacheProps = new CacheProperties();
            Properties properties1 = System.getProperties();
            for(Enumeration enumeration = properties.keys(); enumeration.hasMoreElements();)
            {
                String s = (String)enumeration.nextElement();
                String s1 = (String)properties.get(s);
                s1 = s1.trim();
                if(s.equalsIgnoreCase("com.macromedia.generator.userclasspath"))
                    properties1.put("java.class.path", (String)properties1.get("java.class.path") + properties1.get("path.separator") + s1);
                else
                if(s.equalsIgnoreCase("com.macromedia.generator.garbageCollectAfterJobCount"))
                    try
                    {
                        garbageCollectAfterJobCount = (new Long(s1)).longValue();
                        logMessage("Setting garbageCollectAfterJobCount = " + s1);
                    }
                    catch(NumberFormatException _ex)
                    {
                        logMessage("Invalid setting for garbageCollectAfterJobCount " + s1);
                    }
                else
                if(s.equalsIgnoreCase("com.macromedia.generator.loggingLevel"))
                {
                    logMessage(getResString("ServletLogLevel") + s1);
                    loggingLevel = 1;
                    loggingLevel = !s1.equalsIgnoreCase("None") && !s1.equals("0") ? loggingLevel : 0;
                    loggingLevel = !s1.equalsIgnoreCase("Errors") && !s1.equals("1") ? loggingLevel : 1;
                    loggingLevel = !s1.equalsIgnoreCase("Warnings") && !s1.equals("2") ? loggingLevel : 2;
                    loggingLevel = !s1.equalsIgnoreCase("Verbose") && !s1.equals("3") ? loggingLevel : 3;
                } else
                if(s.equalsIgnoreCase("com.macromedia.generator.cacheDirective"))
                    cacheDirective = s1;
                else
                if(s.equalsIgnoreCase("com.macromedia.generator.expires"))
                    try
                    {
                        cacheExpires = (new Long(s1)).longValue();
                        logMessage("Setting cache expires to " + s1);
                    }
                    catch(NumberFormatException _ex)
                    {
                        logMessage("Invalid setting for cache Expires " + s1);
                    }
                else
                if(s.equalsIgnoreCase("com.macromedia.generator.gifAltHeader"))
                {
                    gifAltHeader = s1.equalsIgnoreCase("true");
                    logMessage("Setting gif alternate header to " + gifAltHeader);
                } else
                if(s.equalsIgnoreCase("com.macromedia.generator.gifExpires"))
                    try
                    {
                        gifCacheExpires = (new Long(s1)).longValue();
                        logMessage("Setting gif cache expires to " + s1);
                    }
                    catch(NumberFormatException _ex)
                    {
                        logMessage("Invalid setting for cache Expires " + s1);
                    }
                else
                if(s.equalsIgnoreCase("com.macromedia.generator.cachePragma"))
                {
                    cachePragma = s1;
                    logMessage("Setting cache pragma to " + cachePragma);
                } else
                if(s.equalsIgnoreCase("com.macromedia.generator.cacheMSoftSSL"))
                {
                    if(s1.equalsIgnoreCase("true"))
                    {
                        cacheMSoftSSLFix = 1;
                        logMessage("Enabling flag to disable HTTP cache settings.  This flag should be set when using IIS with");
                        logMessage("the Secure Socket Layer in order to avoid the problem of IIS not putting the resulting SWF");
                        logMessage("This was specifically to fix a bug in Micorsoft IIS.");
                    }
                } else
                if(s.equalsIgnoreCase("com.macromedia.generator.lastModified"))
                    try
                    {
                        cacheLastModified = (new Long(s1)).longValue();
                        logMessage("Setting last modified to " + s1);
                    }
                    catch(NumberFormatException _ex)
                    {
                        logMessage("Invalid setting for last modified " + s1);
                    }
                else
                if(s.equalsIgnoreCase("com.macromedia.generator.gifLastModified"))
                    try
                    {
                        gifCacheLastModified = (new Long(s1)).longValue();
                        logMessage("Setting gif last modified to " + s1);
                    }
                    catch(NumberFormatException _ex)
                    {
                        logMessage("Invalid setting for gif last modified " + s1);
                    }
                else
                if(s.equalsIgnoreCase("com.macromedia.generator.maxThreads"))
                    try
                    {
                        maxThreads = (new Integer(s1)).intValue();
                        logMessage(getResString("ServletMaxThreads") + s1);
                    }
                    catch(NumberFormatException _ex)
                    {
                        logMessage(getResString("ServletInvalidMaxThreads") + s1);
                    }
                else
                if(s.equalsIgnoreCase("com.macromedia.generator.requestTimeout"))
                    try
                    {
                        timeout = (new Integer(s1)).intValue();
                        logMessage(getResString("ServletTimeout") + s1);
                    }
                    catch(NumberFormatException _ex)
                    {
                        logMessage(getResString("ServletInvalidTimeout") + s1);
                    }
                else
                if(s.equalsIgnoreCase("com.macromedia.generator.forceFinalizers"))
                {
                    forceFinalizers = false;
                    if(s1.equalsIgnoreCase("true"))
                        forceFinalizers = true;
                } else
                if(s.equalsIgnoreCase("com.macromedia.generator.forceGarbageCollection"))
                {
                    forceGarbageCollection = false;
                    if(s1.equalsIgnoreCase("true"))
                        forceGarbageCollection = true;
                } else
                if(s.equalsIgnoreCase("com.macromedia.generator.fontpath"))
                    properties1.put(s, s1);
                else
                if(s.equalsIgnoreCase("com.macromedia.generator.qastud"))
                {
                    if(s1.equalsIgnoreCase("beauchamp"))
                    {
                        publishSerialNum = false;
                        if(serial != null)
                            serial.setPublished(false);
                    }
                } else
                if(s.equalsIgnoreCase("com.macromedia.generator.nostats"))
                {
                    if(s1.equalsIgnoreCase("true"))
                        _fld0192 = true;
                } else
                if(s.equalsIgnoreCase("com.macromedia.generator.parseadminargs"))
                {
                    if(s1.equalsIgnoreCase("true"))
                        _fld018F = true;
                } else
                if(s.equalsIgnoreCase("com.macromedia.generator.extdatasource"))
                {
                    if(s1.equalsIgnoreCase("true"))
                        _fld018E = true;
                } else
                if(s.equalsIgnoreCase("com.macromedia.generator.queueSize"))
                    try
                    {
                        int i = (new Integer(s1)).intValue();
                        if(i > 0)
                        {
                            ticketQueueSize = i;
                            logMessage(getResString("ServletQueueSize") + s1);
                        } else
                        {
                            logMessage(getResString("ServletInvalidQueueSize") + s1);
                        }
                    }
                    catch(NumberFormatException _ex)
                    {
                        logMessage(getResString("ServletInvalidQueueSize") + s1);
                    }
                else
                if(!setCacheProperty(s, s1))
                    properties1.put(s, s1);
            }

            if(loggingLevel > 2)
            {
                String s2;
                for(Enumeration enumeration1 = properties1.keys(); enumeration1.hasMoreElements(); logMessage("System Property '" + s2 + "' = '" + (String)properties1.get(s2) + "'"))
                    s2 = (String)enumeration1.nextElement();

            }
        }
    }

    protected void initResources()
    {
        resources = ResourceBundle.getBundle("com.macromedia.generator.resources.ResourceData", Locale.getDefault());
    }

    protected void initSerialization()
    {
        if(serial == null)
        {
            serial = new Serial();
            Unix unix = Unix.getUnix();
            if(unix != null)
            {
                Properties properties = new Properties();
                try
                {
                    FileInputStream fileinputstream = new FileInputStream(getSerializePath());
                    properties.load(fileinputstream);
                    fileinputstream.close();
                }
                catch(IOException _ex)
                {
                    logMessage(getResString("ServletSerializeLoadError") + getSerializePath());
                }
                serial.setFirstName((String)properties.get("FirstName"));
                serial.setMiddleName((String)properties.get("MiddleName"));
                serial.setLastName((String)properties.get("LastName"));
                serial.setOrganization((String)properties.get("Organization"));
                serial.setServerNumber((String)properties.get("ServerNumber"));
            }
            serial.setPublished(publishSerialNum);
            EE = serial.getLimited();
        }
    }

    public static boolean isLimited()
    {
        return EE;
    }

    public void logHitCounts()
    {
        if(cacheMgr != null)
            cacheMgr.logHitCounts();
    }

    public int logLevel()
    {
        return loggingLevel;
    }

    public void logMessage(String s)
    {
        appendMessageToLogFile(s);
    }

    public void logMessage(String s, String s1, String s2)
    {
        ResourceBundle resourcebundle = ResourceBundle.getBundle(s, Locale.getDefault());
        if(s2 == null)
            s2 = "";
        logMessage(resourcebundle.getString(s1) + s2);
    }

    public void logStats()
    {
        if(_fld0192)
        {
            _mth018B();
            return;
        }
        if(_fld0190 == null)
        {
            _fld0190 = new GenReportFrame();
            _fld0190.resetValues(startupTime);
            return;
        }
        synchronized(_fld0190)
        {
            if(_fld0190.isEmpty())
                return;
            String s = getStatsPath();
            try
            {
                FileOutputStream fileoutputstream = new FileOutputStream(s, true);
                PrintWriter printwriter = new PrintWriter(fileoutputstream);
                String s1 = _fld0190.getWriteString();
                printwriter.println(s1);
                printwriter.flush();
                printwriter.close();
            }
            catch(FileNotFoundException _ex) { }
            _mth018B();
        }
    }

    protected boolean processAdminRequest(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
    {
        boolean flag = false;
        boolean flag1 = false;
        boolean flag2 = false;
        boolean flag3 = false;
        boolean flag4 = false;
        boolean flag5 = false;
        String s = null;
        String s1 = null;
        String s2 = null;
        Enumeration enumeration = httpservletrequest.getParameterNames();
        if(enumeration == null)
            return false;
        while(enumeration.hasMoreElements()) 
        {
            String s3 = (String)enumeration.nextElement();
            if(s3.equalsIgnoreCase("setProp"))
            {
                String as[] = httpservletrequest.getParameterValues(s3);
                if(as != null && as.length > 0)
                {
                    s = as[0];
                    flag1 = true;
                }
            } else
            if(s3.equalsIgnoreCase("setSysProp"))
            {
                String as1[] = httpservletrequest.getParameterValues(s3);
                if(as1 != null && as1.length > 0)
                {
                    s = as1[0];
                    flag3 = true;
                }
            } else
            if(s3.equalsIgnoreCase("setCacheProp"))
            {
                String as2[] = httpservletrequest.getParameterValues(s3);
                if(as2 != null && as2.length > 0)
                {
                    s = as2[0];
                    flag5 = true;
                }
            } else
            if(s3.equalsIgnoreCase("getProp"))
            {
                String as3[] = httpservletrequest.getParameterValues(s3);
                if(as3 != null && as3.length > 0)
                {
                    s = as3[0];
                    flag = true;
                }
            } else
            if(s3.equalsIgnoreCase("getSysProp"))
            {
                String as4[] = httpservletrequest.getParameterValues(s3);
                if(as4 != null && as4.length > 0)
                {
                    s = as4[0];
                    flag2 = true;
                }
            } else
            if(s3.equalsIgnoreCase("getCacheProp"))
            {
                String as5[] = httpservletrequest.getParameterValues(s3);
                if(as5 != null && as5.length > 0)
                {
                    s = as5[0];
                    flag4 = true;
                }
            } else
            if(s3.equalsIgnoreCase("value"))
            {
                String as6[] = httpservletrequest.getParameterValues(s3);
                if(as6 != null && as6.length > 0)
                    s1 = as6[0];
            } else
            if(s3.equalsIgnoreCase("com.macromedia.generator.reportkey"))
            {
                String as7[] = httpservletrequest.getParameterValues(s3);
                if(as7 != null && as7.length > 0)
                    s2 = as7[0];
            }
        }
        boolean flag6 = flag || flag1 || flag2 || flag3 || flag4 || flag5;
        boolean flag7 = s2 != null && s2.equals(System.getProperty("com.macromedia.generator.reportkey"));
        if(flag6 && !flag7)
            logMessage(getResString("adminKeyError"));
        if(flag6 && flag7)
        {
            String s4 = null;
            if(flag2)
                s4 = getSystemProperty(s);
            else
            if(flag3)
                setSystemProperty(s, s1);
            else
            if(flag4)
                s4 = getCacheProperty(s);
            else
            if(flag5)
            {
                if(s.equalsIgnoreCase("all"))
                    updateCacheProperties();
                else
                    setCacheProperty(s, s1);
            } else
            if(s.equalsIgnoreCase("logHitCounts"))
                logHitCounts();
            else
            if(s.equalsIgnoreCase("flushCaches"))
                flushCaches();
            else
            if(s.equalsIgnoreCase("logstats"))
                logStats();
            else
            if(s.equalsIgnoreCase("loggingLevel"))
            {
                if(flag)
                    s4 = Integer.toString(getLoggingLevel());
                else
                if(s1 != null)
                    try
                    {
                        int i = Integer.parseInt(s1);
                        setLoggingLevel(i);
                    }
                    catch(NumberFormatException _ex) { }
            } else
            if(s.equalsIgnoreCase("startupTime"))
                s4 = getStartupTime();
            else
            if(s.equalsIgnoreCase("extFontPath"))
                s4 = getExternalFontPath();
            else
            if(s.equalsIgnoreCase("serial"))
                s4 = Integer.toString(serial.getPeer());
            else
            if(s.equalsIgnoreCase("serverNumber"))
                s4 = getServerNumber();
            else
            if(s.equalsIgnoreCase("propPath"))
                s4 = getPropertiesPath();
            else
            if(s.equalsIgnoreCase("swfAvgSz"))
                s4 = Long.toString(getSwfAvgSize());
            else
            if(s.equalsIgnoreCase("swfMaxSz"))
                s4 = Long.toString(getSwfMaxSize());
            else
            if(s.equalsIgnoreCase("swfAvgTime"))
                s4 = Long.toString(getSwfAvgTime());
            else
            if(s.equalsIgnoreCase("swfMaxTime"))
                s4 = Long.toString(getSwfMaxTime());
            else
            if(s.equalsIgnoreCase("swfCnt"))
                s4 = Integer.toString(getSwfCnt());
            else
            if(s.equalsIgnoreCase("pngCnt"))
                s4 = Integer.toString(getPngCnt());
            else
            if(s.equalsIgnoreCase("gifCnt"))
                s4 = Integer.toString(getGifCnt());
            else
            if(s.equalsIgnoreCase("jpgCnt"))
                s4 = Integer.toString(getJpegCnt());
            else
            if(s.equalsIgnoreCase("qtmCnt"))
                s4 = Integer.toString(getQtmCnt());
            else
            if(s.equalsIgnoreCase("pngAvgSz"))
                s4 = Long.toString(getPngAvgSize());
            else
            if(s.equalsIgnoreCase("pngMaxSz"))
                s4 = Long.toString(getPngMaxSize());
            else
            if(s.equalsIgnoreCase("pngAvgTime"))
                s4 = Long.toString(getPngAvgTime());
            else
            if(s.equalsIgnoreCase("pngMaxTime"))
                s4 = Long.toString(getPngMaxTime());
            else
            if(s.equalsIgnoreCase("jpgAvgSz"))
                s4 = Long.toString(getJpegAvgSize());
            else
            if(s.equalsIgnoreCase("jpgMaxSz"))
                s4 = Long.toString(getJpegMaxSize());
            else
            if(s.equalsIgnoreCase("jpgAvgTime"))
                s4 = Long.toString(getJpegAvgTime());
            else
            if(s.equalsIgnoreCase("jpgMaxTime"))
                s4 = Long.toString(getJpegMaxTime());
            else
            if(s.equalsIgnoreCase("gifAvgSz"))
                s4 = Long.toString(getGifAvgSize());
            else
            if(s.equalsIgnoreCase("gifMaxSz"))
                s4 = Long.toString(getGifMaxSize());
            else
            if(s.equalsIgnoreCase("gifAvgTime"))
                s4 = Long.toString(getGifAvgTime());
            else
            if(s.equalsIgnoreCase("gifMaxTime"))
                s4 = Long.toString(getGifMaxTime());
            else
            if(s.equalsIgnoreCase("qtmAvgSz"))
                s4 = Long.toString(getQtmAvgSize());
            else
            if(s.equalsIgnoreCase("qtmMaxSz"))
                s4 = Long.toString(getQtmMaxSize());
            else
            if(s.equalsIgnoreCase("qtmAvgTime"))
                s4 = Long.toString(getQtmAvgTime());
            else
            if(s.equalsIgnoreCase("qtmMaxTime"))
                s4 = Long.toString(getQtmMaxTime());
            else
            if(s.equalsIgnoreCase("threadCount"))
                s4 = Long.toString(getThreadCount());
            else
            if(s.equalsIgnoreCase("maxhreads"))
            {
                if(flag)
                    s4 = Integer.toString(getMaxThreads());
                else
                if(s1 != null)
                    try
                    {
                        int j = Integer.parseInt(s1);
                        setMaxThreads(j);
                    }
                    catch(NumberFormatException _ex) { }
            } else
            if(s.equalsIgnoreCase("timeout"))
            {
                if(flag)
                    s4 = Integer.toString(getTimeout());
                else
                if(s1 != null)
                    try
                    {
                        int k = Integer.parseInt(s1);
                        setTimeout(k);
                    }
                    catch(NumberFormatException _ex) { }
            } else
            if(s.equalsIgnoreCase("curJobCount"))
                s4 = Integer.toString(getCurrentJobCount());
            else
            if(s.equalsIgnoreCase("disableReqs"))
            {
                if(s1 != null)
                    disableRequests(s1.equalsIgnoreCase("true"));
            } else
            {
                logMessage("Invalid Admin property: " + s);
            }
            if(s4 != null)
                try
                {
                    httpservletresponse.setContentType("text/html");
                    ServletOutputStream servletoutputstream = httpservletresponse.getOutputStream();
                    servletoutputstream.print(s4);
                    servletoutputstream.close();
                }
                catch(IOException _ex) { }
        }
        return flag6;
    }

    public void release()
    {
        if(isLimited())
        {
            synchronized(_fld0197)
            {
                semaCount++;
            }
            if(waitCount > 0)
                synchronized(_fld0196)
                {
                    _fld0196.notifyAll();
                }
        } else
        {
            synchronized(this)
            {
                semaCount++;
                if(waitCount > 0)
                    notify();
            }
        }
    }

    public void setCacheProperties(CacheProperties cacheproperties)
    {
        if(cacheMgr != null && cacheproperties != null)
            cacheMgr.setProperties(cacheproperties);
    }

    protected boolean setCacheProperty(String s, String s1)
    {
        if(cacheProps != null)
            return cacheProps.set(s, s1);
        else
            return false;
    }

    public void setExternalFontPath(String s)
    {
        E5 = s;
        setSystemProperty("com.macromedia.generator.fontpath", s);
    }

    public void setInstallPath(String s)
    {
        installPath = s;
        if(s != null)
        {
            Properties properties = System.getProperties();
            properties.put("com.macromedia.generator.installpath", s);
        }
    }

    public void setLoggingLevel(int i)
    {
        if(i < 0)
            i = 0;
        if(i > 3)
            i = 3;
        loggingLevel = i;
    }

    public void setMaxThreads(int i)
    {
        if(i < 5)
            i = 5;
        else
        if(i > 1000)
            i = 1000;
        maxThreads = i;
    }

    public void setSystemProperty(String s, String s1)
    {
        if(s == null)
            return;
        Properties properties = System.getProperties();
        if(properties == null)
            return;
        if(!s.startsWith("com.macromedia.generator."))
            s = "com.macromedia.generator." + s;
        for(Enumeration enumeration = properties.keys(); enumeration.hasMoreElements();)
        {
            String s2 = (String)enumeration.nextElement();
            if(s2.equalsIgnoreCase(s))
            {
                if(s1 != null)
                {
                    s1 = s1.trim();
                    properties.put(s2, s1);
                } else
                {
                    properties.remove(s2);
                }
                return;
            }
        }

        if(s1 != null)
            properties.put(s, s1);
    }

    public void setTimeout(int i)
    {
        timeout = i;
    }

    public boolean take()
    {
        if(isLimited())
            return takeFIFO(timeout);
        else
            return take(timeout);
    }

    public synchronized boolean take(int i)
    {
        try
        {
            while(semaCount < 1) 
            {
                try
                {
                    waitCount++;
                    wait(i);
                }
                finally
                {
                    waitCount--;
                }
                if(i != 0 && semaCount < 1)
                    return false;
            }
        }
        catch(InterruptedException _ex)
        {
            return false;
        }
        semaCount--;
        return true;
    }

    public boolean takeFIFO(int i)
    {
        boolean flag = false;
        if(_fld0197 == null || _fld0196 == null)
        {
            logMessage("Error occurred in processing synchronization resources.");
            return take(i);
        }
        long l;
        synchronized(_fld0197)
        {
            if(_fld0194 - _fld0195 > (long)ticketQueueSize)
            {
                boolean flag2 = false;
                return flag2;
            }
            l = _fld0194++;
        }
        try
        {
            while(!flag) 
            {
                boolean flag1 = true;
                synchronized(_fld0197)
                {
                    if(semaCount > 0)
                    {
                        flag1 = false;
                        if(l <= _fld0195)
                        {
                            semaCount--;
                            _fld0195++;
                            flag = true;
                        }
                    }
                }
                if(flag1)
                    synchronized(_fld0196)
                    {
                        waitCount++;
                        try
                        {
                            _fld0196.wait(i);
                        }
                        finally
                        {
                            waitCount--;
                        }
                    }
            }
        }
        catch(InterruptedException _ex)
        {
            return false;
        }
        return true;
    }

    public void updateCacheProperties()
    {
        if(cacheMgr != null && cacheProps != null)
            cacheMgr.setProperties(cacheProps);
    }

    protected int waitCount;
    protected static int semaCount = 20;
    protected boolean m_adminLogging;
    protected int admin_maxThreads;
    protected int admin_averageThreads;
    protected int admin_currentRequests;
    protected int admin_getRequests;
    protected int admin_getReleases;
    protected long admin_nSWFRequests;
    protected long admin_nSWFAveSize;
    protected long admin_nSWFMinSize;
    protected long admin_nSWFMaxSize;
    protected long admin_nSWFMinReqTime;
    protected long admin_nSWFAveReqTime;
    protected long admin_nSWFMaxReqTime;
    protected ResourceBundle resources;
    protected String installPath;
    protected static String cacheDirective = "private";
    protected static String cachePragma = "no-cache";
    protected static long cacheExpires = 0L;
    protected static long cacheLastModified = 0L;
    protected static int cacheMSoftSSLFix = 0;
    protected static boolean gifAltHeader = false;
    protected static long gifCacheExpires = 0x493e0L;
    protected static long gifCacheLastModified = 0L;
    String E5;
    public static final int TYPE_UNKNOWN = 0;
    public static final int TYPE_SWF = 1;
    public static final int TYPE_GIF = 2;
    public static final int TYPE_JPG = 3;
    public static final int TYPE_PNG = 4;
    public static final int TYPE_XGIF = 5;
    public static final int TYPE_ADMIN = 6;
    public static final int TYPE_QTM = 7;
    protected static CacheManager cacheMgr = null;
    protected CacheProperties cacheProps;
    protected static int maxThreads = 20;
    protected static int timeout = 1000;
    protected static int loggingLevel = 1;
    protected static int ticketQueueSize = 5;
    protected static long jobCountSinceLastGC = 0L;
    protected static long garbageCollectAfterJobCount = 0L;
    protected static boolean forceFinalizers = false;
    protected static boolean forceGarbageCollection = false;
    protected static boolean initialized = false;
    protected static boolean publishSerialNum = true;
    protected static Serial serial = null;
    private final int _fld018A = 5;
    private final int _fld018B = 1000;
    private final boolean _fld018C = false;
    private final int _fld018D = 1;
    private static boolean _fld018E = false;
    private static boolean _fld018F = false;
    private static boolean EE = false;
    protected static int swfCnt = 0;
    protected static long swfTotSize = 0L;
    protected static long swfTotTime = 0L;
    protected static long swfMaxSize = 0L;
    protected static long swfMaxTime = 0L;
    protected static int gifCnt = 0;
    protected static long gifTotSize = 0L;
    protected static long gifTotTime = 0L;
    protected static long gifMaxSize = 0L;
    protected static long gifMaxTime = 0L;
    protected static int xgifCnt = 0;
    protected static long xgifTotSize = 0L;
    protected static long xgifTotTime = 0L;
    protected static long xgifMaxSize = 0L;
    protected static long xgifMaxTime = 0L;
    protected static int jpegCnt = 0;
    protected static long jpegTotSize = 0L;
    protected static long jpegTotTime = 0L;
    protected static long jpegMaxSize = 0L;
    protected static long jpegMaxTime = 0L;
    protected static int pngCnt = 0;
    protected static long pngTotSize = 0L;
    protected static long pngTotTime = 0L;
    protected static long pngMaxSize = 0L;
    protected static long pngMaxTime = 0L;
    protected static int qtmCnt = 0;
    protected static long qtmTotSize = 0L;
    protected static long qtmTotTime = 0L;
    protected static long qtmMaxSize = 0L;
    protected static long qtmMaxTime = 0L;
    protected static long totalJobCount = 0L;
    protected static int maxSimultaneousRequests = 0;
    protected static String startupTime = null;
    protected static long statStartTime = 0L;
    private static GenReportFrame _fld0190 = null;
    protected static int currentJobCount = 0;
    protected static boolean requestLock = false;
    private static boolean _fld0191 = false;
    private static boolean _fld0192 = false;
    private static int _fld0193 = 0;
    private static long _fld0194 = 0L;
    private static long _fld0195 = 0L;
    private static Object _fld0196;
    private static Object _fld0197;
    private static int _fld0198 = 0;
    private static int _fld0199 = 0;
    private static GenLog _fld019A = null;
    private static GenLog _fld019B = null;
    private static Runtime rt = null;
    private static boolean _fld019C = false;
    public static final String STATS_FILE_NAME = "GenStats.log";
    private static long _fld019D = 0x5265c00L;

}