static VALUE rbdom_method_DOMImplementation_saveDocToMemory (VALUE self,
                                                             VALUE rb_doc)
{
  VALUE rb_return_value = Qnil;
  GdomeException e = 0;
  GdomeDOMImplementation  * c_self = rbdom_rb2c_DOMImplementation (self);
  GdomeDocument * c_doc =  rbdom_rb2c_Document(rb_doc);
  char * mem = NULL;
  if (gdome_di_saveDocToMemory(c_self, c_doc, &mem, GDOME_SAVE_STANDARD, &e)) {
      rb_return_value = rb_str_new2(mem);
      free(mem);
  }
  if (e) rb_raise(rbdom_class_DOMException, "%d", (int)e);
  return rb_return_value;
}
static VALUE rbdom_method_DOMImplementation_parseFile(VALUE self, VALUE rb_uri)
{
    VALUE rb_return_value = Qnil;
    GdomeException e = 0;
    GdomeDOMImplementation  * c_self = rbdom_rb2c_DOMImplementation (self);
    const char * c_uri = STR2CSTR(rb_uri);
    rb_return_value =
        rbdom_c2rb_Document(gdome_di_parseFile(c_self, c_uri, &e));
    if (e) rb_raise(rbdom_class_DOMException, "%d", (int)e);
    return rb_return_value;
}
static VALUE rbdom_method_DOMImplementation_validateFile(VALUE self,
                                                         VALUE rb_uri)
{
    VALUE rb_return_value = Qnil;
    GdomeException e = 0;
    GdomeDOMImplementation  * c_self = rbdom_rb2c_DOMImplementation (self);
    const char * c_uri = STR2CSTR(rb_uri);
    rb_return_value =
        rbdom_c2rb_Document(gdome_di_validateFile(c_self, c_uri, &e));
    if (e) rb_raise(rbdom_class_DOMException, "%d", (int)e);
    return rb_return_value;
}
static VALUE rbdom_method_DOMImplementation_saveFile(VALUE self,
                                                     VALUE rb_filename,
                                                     VALUE rb_doc)
{
    VALUE rb_return_value = Qnil;
    GdomeException e = 0;
    GdomeDOMImplementation  * c_self = rbdom_rb2c_DOMImplementation (self);
    const char * c_filename = STR2CSTR(rb_filename);
    GdomeDocument * c_doc = rbdom_rb2c_Document(rb_doc);
    rb_return_value =
        gdome_di_saveFile(c_self, c_filename, c_doc, &e) ? Qtrue : Qfalse;
    if (e) rb_raise(rbdom_class_DOMException, "%d", (int)e);
    return rb_return_value;
}
static VALUE rbdom_method_DOMImplementation_saveFormatFile(VALUE self,
                                                           VALUE rb_filename,
                                                           VALUE rb_doc,
                                                           VALUE rb_format)
{
    VALUE rb_return_value = Qnil;
    GdomeException e = 0;
    GdomeDOMImplementation  * c_self = rbdom_rb2c_DOMImplementation (self);
    const char * c_filename = STR2CSTR(rb_filename);
    GdomeDocument * c_doc = rbdom_rb2c_Document(rb_doc);
    int c_format = !(rb_format == Qfalse || rb_format == Qnil);
    rb_return_value =
        gdome_di_saveFormatFile(c_self, c_filename, c_doc, c_format, &e)
        ? Qtrue : Qfalse;
    if (e) rb_raise(rbdom_class_DOMException, "%d", (int)e);
    return rb_return_value;
}
static VALUE rbdom_method_DOMImplementation_createDocFromURI(VALUE self,
                                                             VALUE rb_uri,
                                                             VALUE loadingmode)
{
    VALUE rb_return_value = Qnil;
    GdomeException e = 0;
    GdomeDOMImplementation  * c_self = rbdom_rb2c_DOMImplementation (self);
    const char * c_uri = STR2CSTR(rb_uri);
    GdomeLoadingCode c_loadingmode = NUM2INT(loadingmode);
    rb_return_value =
        rbdom_c2rb_Document(gdome_di_createDocFromURI(c_self, c_uri,
                                                      c_loadingmode, &e));
    if (e) rb_raise(rbdom_class_DOMException, "%d", (int)e);
    return rb_return_value;
}
static VALUE rbdom_method_DOMImplementation_createDocFromMemory(
                                   VALUE self,
                                   VALUE rb_buffer,
                                   VALUE loadingmode)
{
    VALUE rb_return_value = Qnil;
    GdomeException e = 0;
    GdomeDOMImplementation  * c_self = rbdom_rb2c_DOMImplementation (self);
    char * c_buffer = STR2CSTR(rb_buffer);
    GdomeLoadingCode c_loadingmode = NUM2INT(loadingmode);
    rb_return_value =
        rbdom_c2rb_Document(gdome_di_createDocFromMemory(c_self, c_buffer,
                                                         c_loadingmode, &e));
    if (e) rb_raise(rbdom_class_DOMException, "%d", (int)e);
    return rb_return_value;
}
/*
static VALUE rbdom_method_DOMImplementation_createDocFromURIWithEntityTable
          (VALUE self, VALUE rb_uri, VALUE rb_entitytable, VALUE loadingmode)
{
    VALUE rb_return_value = Qnil;
    GdomeException e = 0;
    GdomeDOMImplementation  * c_self = rbdom_rb2c_DOMImplementation (self);
    const char * c_uri = STR2CSTR(rb_uri);
    GdomeLoadingCode c_loadingmode = NUM2INT(loadingmode);
    char * c_entitytable[4];
    c_entitytable[0] = STR2CSTR(rb_ary_entry(rb_entitytable,0));
    c_entitytable[1] = STR2CSTR(rb_ary_entry(rb_entitytable,1));
    c_entitytable[2] = STR2CSTR(rb_ary_entry(rb_entitytable,2));
    c_entitytable[3] = STR2CSTR(rb_ary_entry(rb_entitytable,3));
    rb_return_value =
        rbdom_c2rb_Document(gdome_di_createDocFromURIWithEntityTable
             (c_self, c_uri, c_entitytable, c_loadingmode, &e));
    if (e) rb_raise(rbdom_class_DOMException, "%d", (int)e);
    return rb_return_value;
}
static VALUE rbdom_method_DOMImplementation_createDocFromMemoryWithEntityTable
        (VALUE self, VALUE rb_buffer, VALUE rb_entitytable, VALUE loadingmode)
{
    VALUE rb_return_value = Qnil;
    GdomeException e = 0;
    GdomeDOMImplementation  * c_self = rbdom_rb2c_DOMImplementation (self);
    const char * c_buffer = STR2CSTR(rb_buffer);
    GdomeLoadingCode c_loadingmode = NUM2INT(loadingmode);
    char * c_entitytable[4];
    c_entitytable[0] = STR2CSTR(rb_ary_entry(rb_entitytable,0));
    c_entitytable[1] = STR2CSTR(rb_ary_entry(rb_entitytable,1));
    c_entitytable[2] = STR2CSTR(rb_ary_entry(rb_entitytable,2));
    c_entitytable[3] = STR2CSTR(rb_ary_entry(rb_entitytable,3));
    rb_return_value =
        rbdom_c2rb_Document(gdome_di_createDocFromMemoryWithEntityTable(
                         c_self, c_buffer, c_entitytable, c_loadingmode, &e));
    if (e) rb_raise(rbdom_class_DOMException, "%d", (int)e);
    return rb_return_value;
}
*/
static VALUE rbdom_method_DOMImplementation_saveDocToFile(VALUE self,
                                                          VALUE rb_doc,
                                                          VALUE rb_filename,
                                                          VALUE rb_mode)
{
    VALUE rb_return_value = Qnil;
    GdomeException e = 0;
    GdomeDOMImplementation  * c_self = rbdom_rb2c_DOMImplementation (self);
    GdomeDocument * c_doc = rbdom_rb2c_Document(rb_doc);
    const char * c_filename = STR2CSTR(rb_filename);
    GdomeSavingCode c_mode = NUM2INT(rb_mode);
    rb_return_value =
        gdome_di_saveDocToFile(c_self, c_doc, c_filename, c_mode, &e)
        ? Qtrue : Qfalse;
    if (e) rb_raise(rbdom_class_DOMException, "%d", (int)e);
    return rb_return_value;
}



void libgdome_ruby_static_init(void)
{
    rb_define_method(rbdom_class_DOMImplementation, "saveDocToMemory",
                     &rbdom_method_DOMImplementation_saveDocToMemory, 1);
    rb_define_method(rbdom_class_DOMImplementation, "parseFile",
                     &rbdom_method_DOMImplementation_parseFile, 1);
    rb_define_method(rbdom_class_DOMImplementation, "validateFile",
                     &rbdom_method_DOMImplementation_validateFile, 1);
    rb_define_method(rbdom_class_DOMImplementation, "saveFile",
                     &rbdom_method_DOMImplementation_saveFile, 2);
    rb_define_method(rbdom_class_DOMImplementation, "saveFormatFile",
                     &rbdom_method_DOMImplementation_saveFormatFile, 3);
    rb_define_method(rbdom_class_DOMImplementation, "createDocFromURI",
                     &rbdom_method_DOMImplementation_createDocFromURI, 2);
    rb_define_method(rbdom_class_DOMImplementation, "createDocFromMemory",
                     &rbdom_method_DOMImplementation_createDocFromMemory, 2);
    /*
    rb_define_method(rbdom_class_DOMImplementation,
                     "createDocFromURIWithEntityTable",
               &rbdom_method_DOMImplementation_createDocFromURIWithEntityTable,
                     3);
    rb_define_method(rbdom_class_DOMImplementation,
                     "createDocFromMemoryWithEntityTable",
            &rbdom_method_DOMImplementation_createDocFromMemoryWithEntityTable,
                     3);
    */
    rb_define_method(rbdom_class_DOMImplementation, "saveDocToFile",
                     &rbdom_method_DOMImplementation_saveDocToFile, 3);

    rb_define_const (rbdom_module, "LOAD_PARSING",
                     INT2NUM (GDOME_LOAD_PARSING));
    rb_define_const (rbdom_module, "LOAD_VALIDATING",
                     INT2NUM (GDOME_LOAD_VALIDATING));
    rb_define_const (rbdom_module, "LOAD_RECOVERING",
                     INT2NUM (GDOME_LOAD_RECOVERING));
    rb_define_const (rbdom_module, "SAVE_STANDARD",
                     INT2NUM (GDOME_SAVE_STANDARD));
    rb_define_const (rbdom_module, "SAVE_LIBXML_INDENT",
                     INT2NUM (GDOME_SAVE_LIBXML_INDENT));
}
