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 result->ref_count++;
00080
00081 result->priv = g_try_malloc (sizeof (CRDocHandlerPriv));
00082 if (!result->priv) {
00083 cr_utils_trace_info ("Out of memory exception");
00084 g_free (result);
00085 return NULL;
00086 }
00087
00088 cr_doc_handler_set_default_sac_handler (result);
00089
00090 return result;
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 enum CRStatus
00104 cr_doc_handler_get_ctxt (CRDocHandler const * a_this, gpointer * a_ctxt)
00105 {
00106 g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
00107
00108 *a_ctxt = a_this->priv->context;
00109
00110 return CR_OK;
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 enum CRStatus
00123 cr_doc_handler_set_ctxt (CRDocHandler * a_this, gpointer a_ctxt)
00124 {
00125 g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
00126 a_this->priv->context = a_ctxt;
00127 return CR_OK;
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 enum CRStatus
00141 cr_doc_handler_get_result (CRDocHandler const * a_this, gpointer * a_result)
00142 {
00143 g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
00144
00145 *a_result = a_this->priv->result;
00146
00147 return CR_OK;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 enum CRStatus
00161 cr_doc_handler_set_result (CRDocHandler * a_this, gpointer a_result)
00162 {
00163 g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR);
00164 a_this->priv->result = a_result;
00165 return CR_OK;
00166 }
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 enum CRStatus
00181 cr_doc_handler_set_default_sac_handler (CRDocHandler * a_this)
00182 {
00183 g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
00184
00185 a_this->start_document = NULL;
00186 a_this->end_document = NULL;
00187 a_this->import_style = NULL;
00188 a_this->namespace_declaration = NULL;
00189 a_this->comment = NULL;
00190 a_this->start_selector = NULL;
00191 a_this->end_selector = NULL;
00192 a_this->property = NULL;
00193 a_this->start_font_face = NULL;
00194 a_this->end_font_face = NULL;
00195 a_this->start_media = NULL;
00196 a_this->end_media = NULL;
00197 a_this->start_page = NULL;
00198 a_this->end_page = NULL;
00199 a_this->ignorable_at_rule = NULL;
00200 a_this->error = NULL;
00201 a_this->unrecoverable_error = NULL;
00202 return CR_OK;
00203 }
00204
00205
00206
00207
00208
00209 void
00210 cr_doc_handler_ref (CRDocHandler * a_this)
00211 {
00212 g_return_if_fail (a_this);
00213
00214 a_this->ref_count++;
00215 }
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 gboolean
00227 cr_doc_handler_unref (CRDocHandler * a_this)
00228 {
00229 g_return_val_if_fail (a_this, FALSE);
00230
00231 if (a_this->ref_count > 0) {
00232 a_this->ref_count--;
00233 }
00234
00235 if (a_this->ref_count == 0) {
00236 cr_doc_handler_destroy (a_this);
00237 return TRUE;
00238 }
00239 return FALSE ;
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249 void
00250 cr_doc_handler_destroy (CRDocHandler * a_this)
00251 {
00252 g_return_if_fail (a_this);
00253
00254 if (a_this->priv) {
00255 g_free (a_this->priv);
00256 a_this->priv = NULL;
00257 }
00258 g_free (a_this);
00259 }
00260
00261
00262
00263
00264
00265
00266
00267
00268 void
00269 cr_doc_handler_associate_a_parser (CRDocHandler *a_this,
00270 gpointer a_parser)
00271 {
00272 g_return_if_fail (a_this && PRIVATE (a_this)
00273 && a_parser) ;
00274
00275 PRIVATE (a_this)->parser = a_parser ;
00276 }