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 2009 Bo Yang <struggleyb.nku.com>
  6.  */
  7.  
  8. #include <stdlib.h>
  9.  
  10. #include "html/html_document.h"
  11. #include "html/html_meta_element.h"
  12.  
  13. #include "core/node.h"
  14. #include "utils/utils.h"
  15.  
  16. static struct dom_element_protected_vtable _protect_vtable = {
  17.         {
  18.                 DOM_NODE_PROTECT_VTABLE_HTML_META_ELEMENT
  19.         },
  20.         DOM_HTML_META_ELEMENT_PROTECT_VTABLE
  21. };
  22.  
  23. /**
  24.  * Create a dom_html_meta_element object
  25.  *
  26.  * \param doc  The document object
  27.  * \param ele  The returned element object
  28.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  29.  */
  30. dom_exception _dom_html_meta_element_create(struct dom_html_document *doc,
  31.                 dom_string *namespace, dom_string *prefix,
  32.                 struct dom_html_meta_element **ele)
  33. {
  34.         struct dom_node_internal *node;
  35.  
  36.         *ele = malloc(sizeof(dom_html_meta_element));
  37.         if (*ele == NULL)
  38.                 return DOM_NO_MEM_ERR;
  39.        
  40.         /* Set up vtables */
  41.         node = (struct dom_node_internal *) *ele;
  42.         node->base.vtable = &_dom_html_element_vtable;
  43.         node->vtable = &_protect_vtable;
  44.  
  45.         return _dom_html_meta_element_initialise(doc, namespace, prefix, *ele);
  46. }
  47.  
  48. /**
  49.  * Initialise a dom_html_meta_element object
  50.  *
  51.  * \param doc  The document object
  52.  * \param ele  The dom_html_meta_element object
  53.  * \return DOM_NO_ERR on success, appropriate dom_exception on failure.
  54.  */
  55. dom_exception _dom_html_meta_element_initialise(struct dom_html_document *doc,
  56.                 dom_string *namespace, dom_string *prefix,
  57.                 struct dom_html_meta_element *ele)
  58. {
  59.         return _dom_html_element_initialise(doc, &ele->base,
  60.                                             doc->memoised[hds_META],
  61.                                             namespace, prefix);
  62. }
  63.  
  64. /**
  65.  * Finalise a dom_html_meta_element object
  66.  *
  67.  * \param ele  The dom_html_meta_element object
  68.  */
  69. void _dom_html_meta_element_finalise(struct dom_html_meta_element *ele)
  70. {
  71.         _dom_html_element_finalise(&ele->base);
  72. }
  73.  
  74. /**
  75.  * Destroy a dom_html_meta_element object
  76.  *
  77.  * \param ele  The dom_html_meta_element object
  78.  */
  79. void _dom_html_meta_element_destroy(struct dom_html_meta_element *ele)
  80. {
  81.         _dom_html_meta_element_finalise(ele);
  82.         free(ele);
  83. }
  84.  
  85. /*------------------------------------------------------------------------*/
  86. /* The protected virtual functions */
  87.  
  88. /* The virtual function used to parse attribute value, see src/core/element.c
  89.  * for detail */
  90. dom_exception _dom_html_meta_element_parse_attribute(dom_element *ele,
  91.                 dom_string *name, dom_string *value,
  92.                 dom_string **parsed)
  93. {
  94.         UNUSED(ele);
  95.         UNUSED(name);
  96.  
  97.         dom_string_ref(value);
  98.         *parsed = value;
  99.  
  100.         return DOM_NO_ERR;
  101. }
  102.  
  103. /* The virtual destroy function, see src/core/node.c for detail */
  104. void _dom_virtual_html_meta_element_destroy(dom_node_internal *node)
  105. {
  106.         _dom_html_meta_element_destroy((struct dom_html_meta_element *) node);
  107. }
  108.  
  109. /* The virtual copy function, see src/core/node.c for detail */
  110. dom_exception _dom_html_meta_element_copy(dom_node_internal *old,
  111.                 dom_node_internal **copy)
  112. {
  113.         return _dom_html_element_copy(old, copy);
  114. }
  115.  
  116. /*-----------------------------------------------------------------------*/
  117. /* API functions */
  118.  
  119. #define SIMPLE_GET_SET(attr)                                            \
  120.         dom_exception dom_html_meta_element_get_##attr(                 \
  121.                 dom_html_meta_element *element,                         \
  122.                 dom_string **attr)                                      \
  123.         {                                                               \
  124.                 dom_exception ret;                                      \
  125.                 dom_string *_memo_##attr;                               \
  126.                                                                         \
  127.                 _memo_##attr =                                          \
  128.                         ((struct dom_html_document *)                   \
  129.                          ((struct dom_node_internal *)element)->owner)->\
  130.                         memoised[hds_##attr];                           \
  131.                                                                         \
  132.                 ret = dom_element_get_attribute(element, _memo_##attr, attr); \
  133.                                                                         \
  134.                 return ret;                                             \
  135.         }                                                               \
  136.                                                                         \
  137.         dom_exception dom_html_meta_element_set_##attr(                 \
  138.                 dom_html_meta_element *element,                         \
  139.                 dom_string *attr)                                       \
  140.         {                                                               \
  141.                 dom_exception ret;                                      \
  142.                 dom_string *_memo_##attr;                               \
  143.                                                                         \
  144.                 _memo_##attr =                                          \
  145.                         ((struct dom_html_document *)                   \
  146.                          ((struct dom_node_internal *)element)->owner)->\
  147.                         memoised[hds_##attr];                           \
  148.                                                                         \
  149.                 ret = dom_element_set_attribute(element, _memo_##attr, attr); \
  150.                                                                         \
  151.                 return ret;                                             \
  152.         }
  153.  
  154. SIMPLE_GET_SET(content)
  155. SIMPLE_GET_SET(http_equiv)
  156. SIMPLE_GET_SET(name)
  157. SIMPLE_GET_SET(scheme)
  158.