Changes to introspection generation to remove DOCTYPE and XML
[platform/core/uifw/at-spi2-atk.git] / libspi / introspect-loader.c
1 /*
2  * AT-SPI - Assistive Technology Service Provider Interface
3  * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4  *
5  * Copyright 2008 Codethink Ltd.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include <glib.h>
24 #include <accessible.h>
25
26 /*
27  * This file contains utilities for loading introspection XML
28  * from the local file system.
29  *
30  * There is an installation directory with files containing introspection xml.
31  * Each file is named after the interface it describes.
32  */
33
34 /*
35  * Provides the path for the introspection directory.
36  */
37 #if !defined ATSPI_DBUS_INTROSPECTION_DIRECTORY
38     #error "No introspection XML directory defined"
39 #endif
40
41 const char *spi_introspection_header =
42 "<?xml version=\"1.0\"?>\n";
43
44 const char *spi_introspection_node_element =
45 "<node name=\"%s\">\n";
46
47 const char *spi_introspection_footer =
48 "</node>";
49
50 void
51 spi_append_interface (GString *str, const char *interface)
52 {
53   char *filename;
54   char *contents;
55   char *introspection_directory;
56   gsize len;
57
58   GError *err = NULL;
59
60   introspection_directory = (char *) g_getenv("ATSPI_DBUS_INTROSPECTION_DIRECTORY");
61   if (introspection_directory == NULL)
62       introspection_directory = ATSPI_DBUS_INTROSPECTION_DIRECTORY;
63
64   filename = g_build_filename(introspection_directory, interface, NULL);
65
66   if (g_file_get_contents(filename, &contents, &len, &err))
67     {
68       g_string_append_len(str, contents, len);
69     }
70   else
71     {
72       g_warning("AT-SPI: Cannot find introspection XML file %s - %s",
73                 filename, err->message);
74       g_error_free(err);
75     }
76
77   g_string_append(str, "\n");
78   g_free(filename);
79   g_free(contents);
80 }