#ifndef __DCL_HTTP_SERVLET_EX_H__
#define __DCL_HTTP_SERVLET_EX_H__   20050530

#ifndef __DCL_BUFFER_STREAM_H__
#include <dcl/core/BufferStream.h>
#endif
#ifndef __DCL_HTTP_SERVLET_H__
#include <dcl/net/HttpServlet.h>
#endif
#ifndef __DCL_HTTP_COLLECTION_H__
#include <dcl/net/HttpCollection.h>
#endif


__DCL_BEGIN_NAMESPACE

class HttpServletEx;

class DCLNAPI HttpServletContextEx : public HttpServletContext
{
    DECLARE_CLASSINFO(HttpServletContextEx)
public:
    StringToStringMap           m_mapCookie;
    StringToStringVectorMap     m_mapQuery;
    StringToStringVectorMap     m_mapForm;
    StoredHttpFormData          m_mapFormFile;

public:
    TextBufferOutputStream& createOutputStream(
                            size_t nInitialSize = 4096,
                            size_t nGrowSize = 4096
                            );
    TextBufferOutputStream& getOutputStream();

protected:
    HttpServletContextEx(
        const DCL_HTTP_SERVER_API* pSAPI,
        const DCL_HTTP_SERVLET_CONTEXT* pContext,
        const String& strTempDir
        );
    virtual ~HttpServletContextEx();

    void initRequest(size_t nMaxContentLength) __DCL_THROWS1(FormDataException*);

    TextBufferOutputStream* m_pOutHtml;

    friend class HttpServletEx;
};

class DCLNAPI HttpServletEx : public HttpServlet
{
    DECLARE_CLASSINFO(HttpServlet)
public:
    HttpServletEx();

protected:
    size_t  m_nMaxContentLength;
    String  m_strTempDir;

#ifdef __DCL_DEBUG
    // Content-Type이 text/* 일 경우 __DCL_TRACE의 내용을 추가
    bool    m_bEnableDebugOut;
#endif

protected:
    virtual void onInitialize()
                    __DCL_THROWS1(Exception*);

    virtual void onService(
                    HttpServletContextEx& ctx
                    ) = 0 __DCL_THROWS1(Exception*);

private:
    virtual void onHttpService(
                    const DCL_HTTP_SERVLET_CONTEXT* pContext
                    ) __DCL_THROWS1(Exception*);
};

__DCL_END_NAMESPACE


#endif  // __DCL_HTTP_SERVLET_EX_H__