/* -*- indent-tabs-mode: nil; -*-
 *
 * This file is part of the Mango recipe management distribution.
 * Copyright (c) 2000-2003, Roland Jesse
 * All rights reserved.
 *
 * For license and copyright information see the file COPYRIGHT or 
 * <http://www.opensource.org/licenses/bsd-license.html>.
 *
 * $Id: RecipeMLImporter.cpp,v 1.13 2003/05/25 19:13:06 rjesse Exp $
 */

#include "RecipeMLImporter.h"
#include "RecipeMLImportHandler.h"

/*!
  Constructs an empty importer object for RecipeML documents.
  \sa apply()
*/
RecipeMLImporter::
RecipeMLImporter()
   : Importer(), QXmlSimpleReader()
{
}

RecipeModel&
RecipeMLImporter::apply()
   throw(Error)
{
   QXmlInputSource* source = new QXmlInputSource();
   if (m_type == FILE) {
      try {
         file2String( QTextStream::UnicodeUTF8);
      }
      catch (Error& e) {
         throw e;
      }
   }
   source->setData( m_rawStringL.join( " "));

   RecipeMLImportHandler handler( &m_cookbook);
   setContentHandler( &handler);
   if (!parse( source, false)) {
      switch (m_type) {
      case FILE: {
         QString s( tr( "Could not find any recipes in %1.") .arg( m_filename));
         throw Error( s);
         break;
      }
      case STRING: {
         QString s( tr( "Could not find any recipes in the given string."));
         throw Error( s);
         break;
      }
      default:
         throw Error( tr( "Undefined parse error during RecipeML import."));
         break;
      }
   }
   delete source;

   return m_cookbook;
}

/*!
  Unused as the whole document is passed at once by the RecipeMLImportHandler.
*/
void
RecipeMLImporter::readCookbookHeader() // protected
{
}

/*!
  Unused as the whole document is passed at once by the RecipeMLImportHandler.
*/
void
RecipeMLImporter::readAllRecipes() // protected
{
}

/*!
  Unused as the whole document is passed at once by the RecipeMLImportHandler.
*/
void
RecipeMLImporter::readRecipe()	// protected
{
} // readRecipe()

/*!
  Unused as the whole document is passed at once by the RecipeMLImportHandler.
*/
void
RecipeMLImporter::readRecipeHeader() // protected
{
}

/*!
  Unused as the whole document is passed at once by the RecipeMLImportHandler.
*/
void
RecipeMLImporter::readRecipeBody() // protected
{
}
