Main Page | Alphabetical List | Data Structures | Directories | 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 <string.h>
00024 #include "cr-doc-handler.h"
00025 #include "cr-parser.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 #define PRIVATE(obj) (obj)->priv
00036 
00037 struct _CRDocHandlerPriv {
00038         /**
00039          *This pointer is to hold an application parsing context.
00040          *For example, it used by the Object Model parser to 
00041          *store it parsing context. #CRParser does not touch it, but
00042          *#CROMParser does. #CROMParser allocates this pointer at
00043          *the beginning of the css document, and frees it at the end
00044          *of the document.
00045          */
00046         gpointer context;
00047 
00048         /**
00049          *The place where #CROMParser puts the result of its parsing, if
00050          *any.
00051          */
00052         gpointer result;
00053         /**
00054          *a pointer to the parser used to parse
00055          *the current document.
00056          */
00057         CRParser *parser ;
00058 };
00059 
00060 /**
00061  *Constructor of #CRDocHandler.
00062  *@return the newly built instance of
00063  *#CRDocHandler
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  *Returns the private parsing context.
00090  *The private parsing context is used by libcroco only.
00091  *@param a_this the current instance of #CRDocHandler.
00092  *@param a_ctxt out parameter. The new parsing context.
00093  *@return CR_OK upon successfull completion, an error code otherwise.
00094  *@return the parsing context, or NULL if an error occured.
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  *Sets the private parsing context.
00108  *This is used by libcroco only.
00109  *@param a_this the current instance of #CRDocHandler
00110  *@param a_ctxt a pointer to the parsing context.
00111  *@return CR_OK upon successfull completion, an error code otherwise.
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  *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, CR_BAD_PARAM_ERROR);
00132 
00133         *a_result = a_this->priv->result;
00134 
00135         return CR_OK;
00136 }
00137 
00138 /**
00139  *Sets the private parsing context.
00140  *This is used by libcroco only.
00141  *@param a_this the current instance of #CRDocHandler
00142  *@param a_result the new result.
00143  *@return CR_OK upon successfull completion, an error code otherwise.
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  *Sets the sac handlers contained in the current
00155  *instance of DocHandler to the default handlers.
00156  *For the time being the default handlers are
00157  *test handlers. This is expected to change in a
00158  *near future, when the libcroco gets a bit debugged.
00159  *
00160  *@param a_this a pointer to the current instance of #CRDocHandler.
00161  *@return CR_OK upon successfull completion, an error code otherwise.
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  *Increases the reference count of the doc handler
00190  *@param a_this the current instance of #CRDocHandler.
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  *Decreases the ref count of the current instance of #CRDocHandler.
00202  *If the ref count reaches '0' then, destroys the instance.
00203  *@param a_this the currrent instance of #CRDocHandler.
00204  *@return TRUE if the instance as been destroyed, FALSE otherwise.
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  *The destructor of the #CRDocHandler class.
00224  *@param a_this the instance of #CRDocHandler to
00225  *destroy.
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  *Associates a parser to the current document handler
00241  *@param a_this the current instance of document handler.
00242  *@param a_parser the parser to associate.
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 }

Generated on Fri Oct 29 08:29:11 2004 for Libcroco by  doxygen 1.3.9.1