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