// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#ifndef WFILE_RESOURCE_H_
#define WFILE_RESOURCE_H_

#include <string>
#include <Wt/WResource>

namespace Wt {

/*! \class WFileResource Wt/WFileResource Wt/WFileResource
 *  \brief A Resource which streams data from a local file
 *
 * To update the resource, either use setFileName() to point it to a new file,
 * or emit dataChanged() if only the file contents has changed, but not
 * the filename.
 */
class WT_API WFileResource : public WResource
{
public:
  /*! \brief Create a new resource with given mime-type and contents stored
   *         in filename.
   */
  WFileResource(const std::string& mimeType, const std::string& fileName);

  /*! \brief Destroy the resource.
   *
   * It is up to the user to make sure that the resource is nog longer
   * in use (by e.g. a WImage).
   */
  ~WFileResource();

  /*! \brief Set a (different) filename.
   *
   * Set the location of the file on the local filesystem which must be
   * streamed for this resource.
   */
  void setFileName(const std::string& fileName);

  /*! \brief Get the filename.
   */
  const std::string& fileName() const { return fileName_; }

  /*! \brief Get the mime-type.
   */
  const std::string& mimeType() const { return mimeType_; }

  /*! \brief Set the mime-type.
   */
  void setMimeType(const std::string& mimeType);

private:
  std::string mimeType_;
  std::string fileName_;

protected:

  /*! \brief Return the mimetype
   */
  virtual const std::string resourceMimeType() const;

  /*! \brief Stream the data for this resource.
   */
  virtual bool streamResourceData(std::ostream& stream,
				  const ArgumentMap& arguments);
};

}

#endif // WFILE_RESOURCE_H_
