00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <string.h>
00024 #include "cr-doc-handler.h"
00025 #include "cr-parser.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #define PRIVATE(obj) (obj)->priv
00037
00038 struct _CRDocHandlerPriv {
00039
00040
00041
00042
00043
00044
00045
00046
00047 gpointer context;
00048
00049
00050
00051
00052
00053 gpointer result;
00054
00055
00056
00057
00058 CRParser *parser ;
00059 };
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 CRDocHandler *
00070 cr_doc_handler_new (void)
00071 {
00072 CRDocHandler *result = NULL;
00073
00074 result = g_try_malloc (sizeof (CRDocHandler));
00075
00076 g_return_val_if_fail (result, NULL);
00077
00078 memset (result, 0, sizeof (CRDocHandler));
00079
00080 result->priv = g_try_malloc (sizeof (CRDocHandlerPriv));
00081 if (!result->priv) {
00082 cr_utils_trace_info ("Out of memory exception");
00083 g_free (result);
00084 return NULL;
00085 }
00086
00087 cr_doc_handler_set_default_sac_handler (result);
00088
00089 return result;
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 enum CRStatus
00103 cr_doc_handler_get_ctxt (CRDocHandler * a_this, gpointer * a_ctxt)
00104 {
00105 g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
00106
00107 *a_ctxt = a_this->priv->context;
00108
00109 return CR_OK;
00110 }
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 enum CRStatus
00122 cr_doc_handler_set_ctxt (CRDocHandler * a_this, gpointer a_ctxt)
00123 {
00124 g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
00125 a_this->priv->context = a_ctxt;
00126 return CR_OK;
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 enum CRStatus
00140 cr_doc_handler_get_result (CRDocHandler * a_this, gpointer * a_result)
00141 {
00142 g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
00143
00144 *a_result = a_this->priv->result;
00145
00146 return CR_OK;
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 enum CRStatus
00160 cr_doc_handler_set_result (CRDocHandler * a_this, gpointer a_result)
00161 {
00162 g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
00163 a_this->priv->result = a_result;
00164 return CR_OK;
00165 }
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 enum CRStatus
00180 cr_doc_handler_set_default_sac_handler (CRDocHandler * a_this)
00181 {
00182 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00183
00184 a_this->start_document = NULL;
00185 a_this->end_document = NULL;
00186 a_this->import_style = NULL;
00187 a_this->namespace_declaration = NULL;
00188 a_this->comment = NULL;
00189 a_this->start_selector = NULL;
00190 a_this->end_selector = NULL;
00191 a_this->property = NULL;
00192 a_this->start_font_face = NULL;
00193 a_this->end_font_face = NULL;
00194 a_this->start_media = NULL;
00195 a_this->end_media = NULL;
00196 a_this->start_page = NULL;
00197 a_this->end_page = NULL;
00198 a_this->ignorable_at_rule = NULL;
00199 a_this->error = NULL;
00200 a_this->unrecoverable_error = NULL;
00201 return CR_OK;
00202 }
00203
00204
00205
00206
00207
00208 void
00209 cr_doc_handler_ref (CRDocHandler * a_this)
00210 {
00211 g_return_if_fail (a_this);
00212
00213 a_this->ref_count++;
00214 }
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 gboolean
00226 cr_doc_handler_unref (CRDocHandler * a_this)
00227 {
00228 g_return_val_if_fail (a_this, FALSE);
00229
00230 if (a_this->ref_count > 0) {
00231 a_this->ref_count--;
00232 }
00233
00234 if (a_this->ref_count == 0) {
00235 cr_doc_handler_destroy (a_this);
00236 return TRUE;
00237 }
00238 return FALSE ;
00239 }
00240
00241
00242
00243
00244
00245
00246
00247
00248 void
00249 cr_doc_handler_destroy (CRDocHandler * a_this)
00250 {
00251 g_return_if_fail (a_this);
00252
00253 if (a_this->priv) {
00254 g_free (a_this->priv);
00255 a_this->priv = NULL;
00256 }
00257 g_free (a_this);
00258 }
00259
00260
00261
00262
00263
00264
00265
00266 void
00267 cr_doc_handler_associate_a_parser (CRDocHandler *a_this,
00268 gpointer a_parser)
00269 {
00270 g_return_if_fail (a_this && PRIVATE (a_this)
00271 && a_parser) ;
00272
00273 PRIVATE (a_this)->parser = a_parser ;
00274 }