示例#1
0
static enum CRStatus
cr_om_parser_init_default_sac_handler (CROMParser * a_this)
{
        CRDocHandler *sac_handler = NULL;
        gboolean free_hdlr_if_error = FALSE;
        enum CRStatus status = CR_OK;

        g_return_val_if_fail (a_this && PRIVATE (a_this)
                              && PRIVATE (a_this)->parser,
                              CR_BAD_PARAM_ERROR);

        status = cr_parser_get_sac_handler (PRIVATE (a_this)->parser,
                                            &sac_handler);
        g_return_val_if_fail (status == CR_OK, status);

        if (!sac_handler) {
                sac_handler = cr_doc_handler_new ();
                free_hdlr_if_error = TRUE;
        }

        /*
         *initialyze here the sac handler.
         */
        sac_handler->start_document = start_document;
        sac_handler->end_document = end_document;
        sac_handler->start_selector = start_selector;
        sac_handler->end_selector = end_selector;
        sac_handler->property = property;
        sac_handler->start_font_face = start_font_face;
        sac_handler->end_font_face = end_font_face;
        sac_handler->error = error;
        sac_handler->unrecoverable_error = unrecoverable_error;
        sac_handler->charset = charset;
        sac_handler->start_page = start_page;
        sac_handler->end_page = end_page;
        sac_handler->start_media = start_media;
        sac_handler->end_media = end_media;
        sac_handler->import_style = import_style;

        status = cr_parser_set_sac_handler (PRIVATE (a_this)->parser,
                                            sac_handler);
        if (status == CR_OK) {
                return CR_OK;
        }

        if (sac_handler && free_hdlr_if_error == TRUE) {
                cr_doc_handler_destroy (sac_handler);
                sac_handler = NULL;
        }

        return status;

}
示例#2
0
/**
 * cr_om_parser_parse_buf:
 *@a_this: the current instance of #CROMParser.
 *@a_buf: the in memory buffer to parse.
 *@a_len: the length of the in memory buffer in number of bytes.
 *@a_enc: the encoding of the in memory buffer.
 *@a_result: out parameter the resulting style sheet
 *
 *Parses the content of an in memory  buffer.
 *
 *Returns CR_OK upon successfull completion, an error code otherwise.
 */
enum CRStatus
cr_om_parser_parse_buf (CROMParser * a_this,
                        const guchar * a_buf,
                        gulong a_len,
                        enum CREncoding a_enc, CRStyleSheet ** a_result)
{

        enum CRStatus status = CR_OK;

        g_return_val_if_fail (a_this && a_result, CR_BAD_PARAM_ERROR);

        if (!PRIVATE (a_this)->parser) {
                PRIVATE (a_this)->parser = cr_parser_new (NULL);
        }

        status = cr_parser_parse_buf (PRIVATE (a_this)->parser,
                                      a_buf, a_len, a_enc);

        if (status == CR_OK) {
                CRStyleSheet *result = NULL;
                CRStyleSheet **resultptr = NULL;
                CRDocHandler *sac_handler = NULL;

                cr_parser_get_sac_handler (PRIVATE (a_this)->parser,
                                           &sac_handler);
                g_return_val_if_fail (sac_handler, CR_ERROR);
		resultptr = &result;
                status = cr_doc_handler_get_result (sac_handler,
                                                    (gpointer *) resultptr);
                g_return_val_if_fail (status == CR_OK, status);

                if (result)
                        *a_result = result;
        }

        return status;
}