sbin/res/jsdoc/app/handlers/XMLDOC/DomReader.js
author hamidouk
Fri, 23 Dec 2011 11:38:47 +0100
branchjsdoc
changeset 520 fe008e95a716
permissions -rw-r--r--
added jsdoc support, and a script to generate the docs. Also added sample documentation for the IriSP.widget base class.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
520
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
     1
LOG.inform("XMLDOC.DomReader loaded");
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
     2
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
     3
XMLDOC.DomReader = function(root) {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
     4
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
     5
   this.dom = root;
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
     6
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
     7
   /**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
     8
    * The current node the reader is on
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
     9
    */
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    10
   this.node = root;
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    11
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    12
   /**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    13
    * Get the current node the reader is on
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    14
    * @type XMLDOC.Parser.node
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    15
    */
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    16
   XMLDOC.DomReader.prototype.getNode = function() {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    17
      return this.node;
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    18
   };
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    19
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    20
   /**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    21
    * Set the node the reader should be positioned on.
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    22
    * @param node {XMLDOC.Parser.node}
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    23
    */
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    24
   XMLDOC.DomReader.prototype.setNode = function(node) {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    25
      this.node = node;
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    26
   };
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    27
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    28
   /**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    29
    * A helper method to make sure the current node will
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    30
    * never return null, unless null is passed as the root.
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    31
    * @param step {String} An expression to evaluate - should return a node or null
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    32
    */
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    33
   XMLDOC.DomReader.prototype.navigate = function(step) {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    34
      var n;
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    35
      if ((n = step) != null)
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    36
      {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    37
         this.node = n;
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    38
         return this.node;
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    39
      }
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    40
      return null;
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    41
   };
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    42
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    43
   /**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    44
    * Get the root node of the current node's document.
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    45
    */
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    46
   XMLDOC.DomReader.prototype.root = function() {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    47
      this.navigate(this.dom);
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    48
   };
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    49
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    50
   /**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    51
    * Get the parent of the current node.
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    52
    */
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    53
   XMLDOC.DomReader.prototype.parent = function() {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    54
      return this.navigate(this.node.parentNode());
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    55
   };
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    56
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    57
   /**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    58
    * Get the first child of the current node.
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    59
    */
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    60
   XMLDOC.DomReader.prototype.firstChild = function() {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    61
      return this.navigate(this.node.firstChild());
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    62
   };
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    63
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    64
   /**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    65
    * Get the last child of the current node.
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    66
    */
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    67
   XMLDOC.DomReader.prototype.lastChild = function() {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    68
      return this.navigate(this.node.lastChild());
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    69
   };
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    70
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    71
   /**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    72
    * Get the next sibling of the current node.
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    73
    */
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    74
   XMLDOC.DomReader.prototype.nextSibling = function() {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    75
      return this.navigate(this.node.nextSibling());
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    76
   };
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    77
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    78
   /**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    79
    * Get the previous sibling of the current node.
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    80
    */
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    81
   XMLDOC.DomReader.prototype.prevSibling = function() {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    82
      return this.navigate(this.node.prevSibling());
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    83
   };
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    84
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    85
   //===============================================================================================
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    86
   // Support methods
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    87
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    88
   /**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    89
    * Walk the tree starting with the current node, calling the plug-in for
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    90
    * each node visited.  Each time the plug-in is called, the DomReader
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    91
    * is passed as the only parameter.  Use the {@link XMLDOC.DomReader#getNode} method
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    92
    * to access the current node.   <i>This method uses a depth first traversal pattern.</i>
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    93
    *
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    94
    * @param srcFile {String} The source file being evaluated
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    95
    */
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    96
   XMLDOC.DomReader.prototype.getSymbols = function(srcFile)
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    97
   {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    98
      XMLDOC.DomReader.symbols = [];
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
    99
      XMLDOC.DomReader.currentFile = srcFile;
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   100
      JSDOC.Symbol.srcFile = (srcFile || "");
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   101
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   102
      if (defined(JSDOC.PluginManager)) {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   103
         JSDOC.PluginManager.run("onDomGetSymbols", this);
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   104
      }
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   105
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   106
      return XMLDOC.DomReader.symbols;
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   107
   };
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   108
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   109
   /**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   110
    * Find the node with the given name using a depth first traversal.
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   111
    * Does not modify the DomReader's current node.
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   112
    *
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   113
    * @param name {String} The name of the node to find
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   114
    * @return the node that was found, or null if not found
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   115
    */
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   116
   XMLDOC.DomReader.prototype.findNode = function(name)
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   117
   {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   118
      var findNode = null;
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   119
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   120
      // Start at the current node and move into the subtree,
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   121
      // looking for the node with the given name
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   122
      function deeper(node, find)
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   123
      {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   124
         var look = null;
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   125
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   126
         if (node) {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   127
            if (node.name == find)
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   128
            {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   129
               return node;
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   130
            }
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   131
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   132
            if (node.firstChild())
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   133
            {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   134
               look = deeper(node.firstChild(), find);
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   135
            }
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   136
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   137
            if (!look && node.nextSibling())
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   138
            {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   139
               look = deeper(node.nextSibling(), find);
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   140
            }
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   141
         }
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   142
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   143
         return look;
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   144
      }
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   145
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   146
      return deeper(this.getNode().firstChild(), name);
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   147
   };
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   148
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   149
   /**
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   150
    * Find the next node with the given name using a depth first traversal.
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   151
    *
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   152
    * @param name {String} The name of the node to find
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   153
    */
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   154
   XMLDOC.DomReader.prototype.findPreviousNode = function(name)
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   155
   {
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   156
   };
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   157
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   158
};
fe008e95a716 added jsdoc support, and a script to generate the docs.
hamidouk
parents:
diff changeset
   159