~ubuntu-branches/ubuntu/saucy/ruby-xmlparser/saucy

« back to all changes in this revision

Viewing changes to lib/xml/dom2/entityreference.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-06-16 21:57:51 UTC
  • Revision ID: james.westby@ubuntu.com-20110616215751-qi0xn6fsoy0yqv1y
Tags: upstream-0.7.2
ImportĀ upstreamĀ versionĀ 0.7.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
## -*- Ruby -*-
 
2
## XML::DOM
 
3
## 1998-2001 by yoshidam
 
4
##
 
5
 
 
6
require 'xml/dom2/node'
 
7
require 'xml/dom2/domexception'
 
8
 
 
9
module XML
 
10
  module DOM
 
11
 
 
12
=begin
 
13
== Class XML::DOM::EntityReference
 
14
 
 
15
=== superclass
 
16
Node
 
17
=end
 
18
    class EntityReference<Node
 
19
 
 
20
=begin
 
21
=== Class Methods
 
22
 
 
23
    --- EntityReference.new(name, *children)
 
24
 
 
25
creates a new EntityReference.
 
26
=end
 
27
      def initialize(name, *children)
 
28
        super(*children)
 
29
        raise "parameter error" if !name
 
30
        @name = name.freeze
 
31
        @value = nil
 
32
      end
 
33
 
 
34
=begin
 
35
=== Methods
 
36
 
 
37
    --- EntityReference#nodeType
 
38
 
 
39
[DOM]
 
40
returns the nodeType.
 
41
=end
 
42
      ## [DOM]
 
43
      def nodeType
 
44
        ENTITY_REFERENCE_NODE
 
45
      end
 
46
 
 
47
=begin
 
48
    --- EntityReference#nodeName
 
49
 
 
50
[DOM]
 
51
returns  the nodeName.
 
52
=end
 
53
      ## [DOM]
 
54
      def nodeName
 
55
        @name
 
56
      end
 
57
 
 
58
=begin
 
59
    --- EntityReference#to_s
 
60
 
 
61
returns the string representation of the EntityReference.
 
62
=end
 
63
      ## reference form or expanded form?
 
64
      def to_s
 
65
        "&#{@name};"
 
66
      end
 
67
 
 
68
=begin
 
69
    --- EntityReference#dump(depth = 0)
 
70
 
 
71
dumps the EntityReference.
 
72
=end
 
73
      def dump(depth = 0)
 
74
        print ' ' * depth * 2
 
75
        print "&#{@name}{\n"
 
76
        @children.each do |child|
 
77
          child.dump(depth + 1)
 
78
        end if @children
 
79
        print ' ' * depth * 2
 
80
        print "}\n"
 
81
      end
 
82
 
 
83
=begin
 
84
    --- EntityReference#cloneNode(deep = true)
 
85
 
 
86
[DOM]
 
87
returns the copy of the EntityReference.
 
88
=end
 
89
      ## [DOM]
 
90
      def cloneNode(deep = true)
 
91
        super(deep, @name)
 
92
      end
 
93
 
 
94
      def _checkNode(node)
 
95
        unless node.nodeType == ELEMENT_NODE ||
 
96
            node.nodeType == PROCESSING_INSTRUCTION_NODE ||
 
97
            node.nodeType == COMMENT_NODE ||
 
98
            node.nodeType == TEXT_NODE ||
 
99
            node.nodeType == CDATA_SECTION_NODE ||
 
100
            node.nodeType == ENTITY_REFERENCE_NODE
 
101
          raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
 
102
        end
 
103
      end
 
104
 
 
105
    end
 
106
  end
 
107
end