Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

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 "cr-doc-handler.h"
00024 #include <string.h>
00025 
00026 /**
00027  *@file
00028  *The definition of the CRDocHandler class.
00029  *Contains methods to instantiate, destroy,
00030  *and initialyze instances of #CRDocHandler
00031  *to custom values.
00032  */
00033 
00034 struct _CRDocHandlerPriv {
00035  /**
00036          *This pointer is to hold an application parsing context.
00037          *For example, it used by the Object Model parser to 
00038          *store it parsing context. #CRParser does not touch it, but
00039          *#CROMParser does. #CROMParser allocates this pointer at
00040          *the beginning of the css document, and frees it at the end
00041          *of the document.
00042          */
00043         gpointer context;
00044 
00045  /**
00046          *The place where #CROMParser puts the result of its parsing, if
00047          *any.
00048          */
00049         gpointer result;
00050 };
00051 
00052 /**
00053  *Constructor of #CRDocHandler.
00054  *@return the newly built instance of
00055  *#CRDocHandler
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  *Returns the private parsing context.
00082  *The private parsing context is used by libcroco only.
00083  *@param a_this the current instance of #CRDocHandler.
00084  *@param a_ctxt out parameter. The new parsing context.
00085  *@return CR_OK upon successfull completion, an error code otherwise.
00086  *@return the parsing context, or NULL if an error occured.
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  *Sets the private parsing context.
00100  *This is used by libcroco only.
00101  *@param a_this the current instance of #CRDocHandler
00102  *@param a_ctxt a pointer to the parsing context.
00103  *@return CR_OK upon successfull completion, an error code otherwise.
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  *Returns the private parsing result.
00115  *The private parsing result is used by libcroco only.
00116  *@param a_this the current instance of #CRDocHandler
00117  *@param a_result out parameter. The returned result.
00118  *@return CR_OK upon successfull completion, an error code otherwise.
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  *Sets the private parsing context.
00132  *This is used by libcroco only.
00133  *@param a_this the current instance of #CRDocHandler
00134  *@param a_result the new result.
00135  *@return CR_OK upon successfull completion, an error code otherwise.
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  *Sets the sac handlers contained in the current
00147  *instance of DocHandler to the default handlers.
00148  *For the time being the default handlers are
00149  *test handlers. This is expected to change in a
00150  *near future, when the libcroco gets a bit debugged.
00151  *
00152  *@param a_this a pointer to the current instance of #CRDocHandler.
00153  *@return CR_OK upon successfull completion, an error code otherwise.
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  *Increases the reference count of the doc handler
00182  *@param a_this the current instance of #CRDocHandler.
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  *Decreases the ref count of the current instance of #CRDocHandler.
00194  *If the ref count reaches '0' then, destroys the instance.
00195  *@param a_this the currrent instance of #CRDocHandler.
00196  *@return TRUE if the instance as been destroyed, FALSE otherwise.
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  *The destructor of the #CRDocHandler class.
00217  *@param a_this the instance of #CRDocHandler to
00218  *destroy.
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 }

Generated on Sat Mar 20 02:38:42 2004 for Libcroco by doxygen 1.3.5