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  * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of version 2.1 of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00020  * USA
00021  */
00022 
00023 
00024 #include "cr-doc-handler.h"
00025 #include <string.h>
00026 
00027 /**
00028  *@file
00029  *The definition of the CRDocHandler class.
00030  *Contains methods to instantiate, destroy,
00031  *and initialyze instances of #CRDocHandler
00032  *to custom values.
00033  */
00034 
00035 struct _CRDocHandlerPriv
00036 {
00037         /**
00038          *This pointer is to hold an application parsing context.
00039          *For example, it used by the Object Model parser to 
00040          *store it parsing context. #CRParser does not touch it, but
00041          *#CROMParser does. #CROMParser allocates this pointer at
00042          *the beginning of the css document, and frees it at the end
00043          *of the document.
00044          */
00045         gpointer context ;
00046 
00047         /**
00048          *The place where #CROMParser puts the result of its parsing, if
00049          *any.
00050          */
00051         gpointer result ;
00052 } ;
00053 
00054 
00055 /**
00056  *Constructor of #CRDocHandler.
00057  *@return the newly built instance of
00058  *#CRDocHandler
00059  */
00060 CRDocHandler * 
00061 cr_doc_handler_new (void)
00062 {
00063         CRDocHandler * result = NULL ;
00064 
00065         result = g_try_malloc (sizeof (CRDocHandler)) ;
00066 
00067         g_return_val_if_fail (result, NULL) ;
00068 
00069         memset (result, 0, sizeof (CRDocHandler)) ;
00070 
00071         result->priv = g_try_malloc (sizeof (CRDocHandlerPriv)) ;
00072         if (!result->priv)
00073         {
00074                 cr_utils_trace_info ("Out of memory exception") ;
00075                 g_free (result) ;
00076                 return NULL ;
00077         }
00078         
00079         cr_doc_handler_ref (result) ;
00080         cr_doc_handler_set_default_sac_handler (result) ;
00081 
00082         return result ;
00083 }
00084 
00085 
00086 /**
00087  *Returns the private parsing context.
00088  *The private parsing context is used by libcroco only.
00089  *@param a_this the current instance of #CRDocHandler.
00090  *@param a_ctxt out parameter. The new parsing context.
00091  *@return CR_OK upon successfull completion, an error code otherwise.
00092  *@return the parsing context, or NULL if an error occured.
00093  */
00094 enum CRStatus
00095 cr_doc_handler_get_ctxt (CRDocHandler *a_this, gpointer * a_ctxt)
00096 {
00097         g_return_val_if_fail (a_this && a_this->priv,
00098                               CR_BAD_PARAM_ERROR) ;
00099 
00100         *a_ctxt = a_this->priv->context ;
00101 
00102         return CR_OK ;
00103 }
00104 
00105 /**
00106  *Sets the private parsing context.
00107  *This is used by libcroco only.
00108  *@param a_this the current instance of #CRDocHandler
00109  *@param a_ctxt a pointer to the parsing context.
00110  *@return CR_OK upon successfull completion, an error code otherwise.
00111  */
00112 enum CRStatus
00113 cr_doc_handler_set_ctxt (CRDocHandler *a_this, gpointer a_ctxt)
00114 {
00115         g_return_val_if_fail (a_this && a_this->priv,
00116                               CR_BAD_PARAM_ERROR) ;
00117         a_this->priv->context = a_ctxt ;
00118         return CR_OK ;
00119 }
00120 
00121 /**
00122  *Returns the private parsing result.
00123  *The private parsing result is used by libcroco only.
00124  *@param a_this the current instance of #CRDocHandler
00125  *@param a_result out parameter. The returned result.
00126  *@return CR_OK upon successfull completion, an error code otherwise.
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,
00132                               CR_BAD_PARAM_ERROR) ;
00133 
00134         *a_result = a_this->priv->result ;
00135 
00136         return CR_OK ;
00137 }
00138 
00139 /**
00140  *Sets the private parsing context.
00141  *This is used by libcroco only.
00142  *@param a_this the current instance of #CRDocHandler
00143  *@param a_result the new result.
00144  *@return CR_OK upon successfull completion, an error code otherwise.
00145  */
00146 enum CRStatus
00147 cr_doc_handler_set_result (CRDocHandler *a_this, gpointer a_result)
00148 {
00149         g_return_val_if_fail (a_this && a_this->priv,
00150                               CR_BAD_PARAM_ERROR) ;
00151         a_this->priv->result = a_result ;
00152         return CR_OK ;
00153 }
00154 
00155 /**
00156  *Sets the sac handlers contained in the current
00157  *instance of DocHandler to the default handlers.
00158  *For the time being the default handlers are
00159  *test handlers. This is expected to change in a
00160  *near future, when the libcroco gets a bit debugged.
00161  *
00162  *@param a_this a pointer to the current instance of #CRDocHandler.
00163  *@return CR_OK upon successfull completion, an error code otherwise.
00164  */
00165 enum CRStatus
00166 cr_doc_handler_set_default_sac_handler (CRDocHandler *a_this)
00167 {
00168         g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
00169 
00170         a_this->start_document = NULL;
00171         a_this->end_document = NULL ;
00172         a_this->import_style = NULL ;
00173         a_this->namespace_declaration = NULL ;
00174         a_this->comment = NULL ;
00175         a_this->start_selector = NULL ;
00176         a_this->end_selector = NULL ;
00177         a_this->property = NULL ;
00178         a_this->start_font_face = NULL ;
00179         a_this->end_font_face = NULL ;
00180         a_this->start_media = NULL ;
00181         a_this->end_media = NULL ;
00182         a_this->start_page = NULL ;
00183         a_this->end_page = NULL ;
00184         a_this->ignorable_at_rule = NULL ;
00185         a_this->error = NULL ;
00186         a_this->unrecoverable_error = NULL ;
00187         return CR_OK ;
00188 }
00189 
00190 /**
00191  *Increases the reference count of the doc handler
00192  *@param a_this the current instance of #CRDocHandler.
00193  */
00194 void 
00195 cr_doc_handler_ref (CRDocHandler *a_this)
00196 {
00197         g_return_if_fail (a_this) ;
00198 
00199         a_this->ref_count++ ;
00200 }
00201 
00202 /**
00203  *Decreases the ref count of the current instance of #CRDocHandler.
00204  *If the ref count reaches '0' then, destroys the instance.
00205  *@param a_this the currrent instance of #CRDocHandler.
00206  *@return TRUE if the instance as been destroyed, FALSE otherwise.
00207  */
00208 gboolean
00209 cr_doc_handler_unref (CRDocHandler *a_this)
00210 {
00211         g_return_val_if_fail (a_this, FALSE) ;
00212 
00213         if (a_this->ref_count > 0)
00214         {
00215                 a_this->ref_count -- ;
00216         }
00217 
00218         if (a_this->ref_count == 0)
00219         {
00220                 cr_doc_handler_destroy (a_this) ;
00221                 return TRUE ;
00222         }
00223 
00224         return FALSE ;
00225 }
00226 
00227 
00228 /**
00229  *The destructor of the #CRDocHandler class.
00230  *@param a_this the instance of #CRDocHandler to
00231  *destroy.
00232  */
00233 void
00234 cr_doc_handler_destroy (CRDocHandler *a_this)
00235 {
00236         g_return_if_fail (a_this) ;
00237 
00238         if (a_this->priv)
00239         {
00240                 g_free (a_this->priv) ;
00241                 a_this->priv = NULL ;
00242         }
00243         g_free (a_this) ;
00244 }

Generated on Wed Oct 1 01:36:45 2003 for Libcroco by doxygen 1.3.3