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