cr-doc-handler.c

Go to the documentation of this file.
00001 /* -*- Mode: C; indent-tabs-mode: ni; c-basic-offset: 8 -*- */
00002 
00003 /*
00004  * This file is part of The Croco Library
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of version 2.1 of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00018  * USA
00019  * 
00020  * See COPRYRIGHTS file for copyright information.
00021  */
00022 
00023 #include <string.h>
00024 #include "cr-doc-handler.h"
00025 #include "cr-parser.h"
00026 
00027 /**
00028  *@CRDocHandler:
00029  *
00030  *The definition of the CRDocHandler class.
00031  *Contains methods to instantiate, destroy,
00032  *and initialyze instances of #CRDocHandler
00033  *to custom values.
00034  */
00035 
00036 #define PRIVATE(obj) (obj)->priv
00037 
00038 struct _CRDocHandlerPriv {
00039         /**
00040          *This pointer is to hold an application parsing context.
00041          *For example, it used by the Object Model parser to 
00042          *store it parsing context. #CRParser does not touch it, but
00043          *#CROMParser does. #CROMParser allocates this pointer at
00044          *the beginning of the css document, and frees it at the end
00045          *of the document.
00046          */
00047         gpointer context;
00048 
00049         /**
00050          *The place where #CROMParser puts the result of its parsing, if
00051          *any.
00052          */
00053         gpointer result;
00054         /**
00055          *a pointer to the parser used to parse
00056          *the current document.
00057          */
00058         CRParser *parser ;
00059 };
00060 
00061 /**
00062  * cr_doc_handler_new:
00063  *Constructor of #CRDocHandler.
00064  *
00065  *Returns the newly built instance of
00066  *#CRDocHandler
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  * cr_doc_handler_get_ctxt:
00094  *@a_this: the current instance of #CRDocHandler.
00095  *@a_ctxt: out parameter. The new parsing context.
00096  *
00097  *Gets the private parsing context associated to the document handler
00098  *The private parsing context is used by libcroco only.
00099  *
00100  *Returns CR_OK upon successfull completion, an error code otherwise.
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  * cr_doc_handler_set_ctxt:
00114  *@a_this: the current instance of #CRDocHandler
00115  *@a_ctxt: a pointer to the parsing context.
00116  *
00117  *Sets the private parsing context.
00118  *This is used by libcroco only.
00119  *Returns CR_OK upon successfull completion, an error code otherwise.
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  * cr_doc_handler_get_result:
00131  *@a_this: the current instance of #CRDocHandler
00132  *@a_result: out parameter. The returned result.
00133  *
00134  *Gets the private parsing result.
00135  *The private parsing result is used by libcroco only.
00136  *
00137  *Returns CR_OK upon successfull completion, an error code otherwise.
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  * cr_doc_handler_set_result:
00151  *@a_this: the current instance of #CRDocHandler
00152  *@a_result: the new result.
00153  *
00154  *Sets the private parsing context.
00155  *This is used by libcroco only.
00156  *
00157  *Returns CR_OK upon successfull completion, an error code otherwise.
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  *cr_doc_handler_set_default_sac_handler:
00169  *@a_this: a pointer to the current instance of #CRDocHandler.
00170  *
00171  *Sets the sac handlers contained in the current
00172  *instance of DocHandler to the default handlers.
00173  *For the time being the default handlers are
00174  *test handlers. This is expected to change in a
00175  *near future, when the libcroco gets a bit debugged.
00176  *
00177  *Returns CR_OK upon successfull completion, an error code otherwise.
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  * cr_doc_handler_ref:
00206  *@a_this: the current instance of #CRDocHandler.
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  * cr_doc_handler_unref:
00218  *@a_this: the currrent instance of #CRDocHandler.
00219  *
00220  *Decreases the ref count of the current instance of #CRDocHandler.
00221  *If the ref count reaches '0' then, destroys the instance.
00222  *
00223  *Returns TRUE if the instance as been destroyed, FALSE otherwise.
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  * cr_doc_handler_destroy:
00243  *@a_this: the instance of #CRDocHandler to
00244  *destroy.
00245  *
00246  *The destructor of the #CRDocHandler class.
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  * cr_doc_handler_associate_a_parser:
00262  *Associates a parser to the current document handler
00263  *@a_this: the current instance of document handler.
00264  *@a_parser: the parser to associate.
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 }

Generated on Thu Mar 9 19:19:08 2006 for Libcroco by  doxygen 1.4.6