Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * This file is part of libdom.
  3.  * Licensed under the MIT License,
  4.  *                http://www.opensource.org/licenses/mit-license.php
  5.  * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
  6.  * Copyright 2009 Bo Yang <struggleyb.nku@gmail.com>
  7.  */
  8.  
  9. #include <stdlib.h>
  10.  
  11. #include "core/document.h"
  12. #include "core/entity_ref.h"
  13. #include "core/node.h"
  14. #include "utils/utils.h"
  15.  
  16. /**
  17.  * A DOM entity reference
  18.  */
  19. struct dom_entity_reference {
  20.         dom_node_internal base;         /**< Base node */
  21. };
  22.  
  23. static struct dom_node_vtable er_vtable = {
  24.         {
  25.                 DOM_NODE_EVENT_TARGET_VTABLE
  26.         },
  27.         DOM_NODE_VTABLE
  28. };
  29.  
  30. static struct dom_node_protect_vtable er_protect_vtable = {
  31.         DOM_ER_PROTECT_VTABLE
  32. };
  33.  
  34. /**
  35.  * Create an entity reference
  36.  *
  37.  * \param doc     The owning document
  38.  * \param name    The name of the node to create
  39.  * \param value   The text content of the node
  40.  * \param result  Pointer to location to receive created node
  41.  * \return DOM_NO_ERR                on success,
  42.  *         DOM_NO_MEM_ERR            on memory exhaustion.
  43.  *
  44.  * ::doc, ::name and ::value will have their reference counts increased.
  45.  *
  46.  * The returned node will already be referenced.
  47.  */
  48. dom_exception _dom_entity_reference_create(dom_document *doc,
  49.                 dom_string *name, dom_string *value,
  50.                 dom_entity_reference **result)
  51. {
  52.         dom_entity_reference *e;
  53.         dom_exception err;
  54.  
  55.         /* Allocate the comment node */
  56.         e = malloc(sizeof(dom_entity_reference));
  57.         if (e == NULL)
  58.                 return DOM_NO_MEM_ERR;
  59.  
  60.         e->base.base.vtable = &er_vtable;
  61.         e->base.vtable = &er_protect_vtable;
  62.  
  63.         /* And initialise the node */
  64.         err = _dom_entity_reference_initialise(&e->base, doc,
  65.                         DOM_ENTITY_REFERENCE_NODE, name, value, NULL, NULL);
  66.         if (err != DOM_NO_ERR) {
  67.                 free(e);
  68.                 return err;
  69.         }
  70.  
  71.         *result = e;
  72.  
  73.         return DOM_NO_ERR;
  74. }
  75.  
  76. /**
  77.  * Destroy an entity reference
  78.  *
  79.  * \param entity  The entity reference to destroy
  80.  *
  81.  * The contents of ::entity will be destroyed and ::entity will be freed.
  82.  */
  83. void _dom_entity_reference_destroy(dom_entity_reference *entity)
  84. {
  85.         /* Finalise base class */
  86.         _dom_entity_reference_finalise(&entity->base);
  87.  
  88.         /* Destroy fragment */
  89.         free(entity);
  90. }
  91.  
  92. /**
  93.  * Get the textual representation of an EntityRererence
  94.  *
  95.  * \param entity  The entity reference to get the textual representation of
  96.  * \param result  Pointer to location to receive result
  97.  * \return DOM_NO_ERR on success.
  98.  *
  99.  * The returned string will have its reference count increased. It is
  100.  * the responsibility of the caller to unrer the string once it has
  101.  * finished with it.
  102.  */
  103. dom_exception _dom_entity_reference_get_textual_representation(
  104.                 dom_entity_reference *entity, dom_string **result)
  105. {
  106.         UNUSED(entity);
  107.         UNUSED(result);
  108.  
  109.         return DOM_NOT_SUPPORTED_ERR;
  110. }
  111.  
  112. /*-----------------------------------------------------------------------*/
  113.  
  114. /* Following comes the protected vtable  */
  115.  
  116. /* The virtual destroy function of this class */
  117. void _dom_er_destroy(dom_node_internal *node)
  118. {
  119.         _dom_entity_reference_destroy((dom_entity_reference *) node);
  120. }
  121.  
  122. /* The copy constructor of this class */
  123. dom_exception _dom_er_copy(dom_node_internal *old, dom_node_internal **copy)
  124. {
  125.         dom_entity_reference *new_er;
  126.         dom_exception err;
  127.  
  128.         new_er = malloc(sizeof(dom_entity_reference));
  129.         if (new_er == NULL)
  130.                 return DOM_NO_MEM_ERR;
  131.  
  132.         err = dom_node_copy_internal(old, new_er);
  133.         if (err != DOM_NO_ERR) {
  134.                 free(new_er);
  135.                 return err;
  136.         }
  137.  
  138.         *copy = (dom_node_internal *) new_er;
  139.  
  140.         return DOM_NO_ERR;
  141. }
  142.  
  143.