rubysl-rexml 1.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/lib/rexml/attlistdecl.rb +56 -56
  4. data/lib/rexml/attribute.rb +155 -149
  5. data/lib/rexml/cdata.rb +48 -48
  6. data/lib/rexml/child.rb +82 -82
  7. data/lib/rexml/comment.rb +59 -59
  8. data/lib/rexml/doctype.rb +22 -24
  9. data/lib/rexml/document.rb +185 -129
  10. data/lib/rexml/dtd/attlistdecl.rb +7 -7
  11. data/lib/rexml/dtd/dtd.rb +41 -41
  12. data/lib/rexml/dtd/elementdecl.rb +13 -13
  13. data/lib/rexml/dtd/entitydecl.rb +49 -49
  14. data/lib/rexml/dtd/notationdecl.rb +32 -32
  15. data/lib/rexml/element.rb +122 -107
  16. data/lib/rexml/encoding.rb +37 -58
  17. data/lib/rexml/entity.rb +144 -144
  18. data/lib/rexml/formatters/default.rb +6 -4
  19. data/lib/rexml/formatters/pretty.rb +11 -8
  20. data/lib/rexml/formatters/transitive.rb +4 -3
  21. data/lib/rexml/functions.rb +33 -21
  22. data/lib/rexml/instruction.rb +49 -49
  23. data/lib/rexml/light/node.rb +190 -191
  24. data/lib/rexml/namespace.rb +39 -39
  25. data/lib/rexml/node.rb +38 -38
  26. data/lib/rexml/output.rb +17 -12
  27. data/lib/rexml/parent.rb +26 -25
  28. data/lib/rexml/parseexception.rb +4 -4
  29. data/lib/rexml/parsers/baseparser.rb +90 -61
  30. data/lib/rexml/parsers/lightparser.rb +41 -43
  31. data/lib/rexml/parsers/pullparser.rb +1 -1
  32. data/lib/rexml/parsers/sax2parser.rb +233 -198
  33. data/lib/rexml/parsers/streamparser.rb +6 -2
  34. data/lib/rexml/parsers/treeparser.rb +9 -6
  35. data/lib/rexml/parsers/ultralightparser.rb +40 -40
  36. data/lib/rexml/parsers/xpathparser.rb +51 -52
  37. data/lib/rexml/quickpath.rb +247 -248
  38. data/lib/rexml/rexml.rb +9 -10
  39. data/lib/rexml/sax2listener.rb +92 -92
  40. data/lib/rexml/security.rb +27 -0
  41. data/lib/rexml/source.rb +95 -50
  42. data/lib/rexml/streamlistener.rb +90 -90
  43. data/lib/rexml/syncenumerator.rb +3 -4
  44. data/lib/rexml/text.rb +157 -76
  45. data/lib/rexml/validation/relaxng.rb +18 -18
  46. data/lib/rexml/validation/validation.rb +5 -5
  47. data/lib/rexml/xmldecl.rb +59 -63
  48. data/lib/rexml/xmltokens.rb +14 -14
  49. data/lib/rexml/xpath.rb +67 -53
  50. data/lib/rexml/xpath_parser.rb +49 -38
  51. data/lib/rubysl/rexml.rb +1 -0
  52. data/lib/rubysl/rexml/version.rb +1 -1
  53. data/rubysl-rexml.gemspec +3 -1
  54. metadata +19 -28
  55. data/lib/rexml/encodings/CP-1252.rb +0 -103
  56. data/lib/rexml/encodings/EUC-JP.rb +0 -35
  57. data/lib/rexml/encodings/ICONV.rb +0 -22
  58. data/lib/rexml/encodings/ISO-8859-1.rb +0 -7
  59. data/lib/rexml/encodings/ISO-8859-15.rb +0 -72
  60. data/lib/rexml/encodings/SHIFT-JIS.rb +0 -37
  61. data/lib/rexml/encodings/SHIFT_JIS.rb +0 -1
  62. data/lib/rexml/encodings/UNILE.rb +0 -34
  63. data/lib/rexml/encodings/US-ASCII.rb +0 -30
  64. data/lib/rexml/encodings/UTF-16.rb +0 -35
  65. data/lib/rexml/encodings/UTF-8.rb +0 -18
data/lib/rexml/cdata.rb CHANGED
@@ -1,39 +1,39 @@
1
1
  require "rexml/text"
2
2
 
3
3
  module REXML
4
- class CData < Text
5
- START = '<![CDATA['
6
- STOP = ']]>'
7
- ILLEGAL = /(\]\]>)/
4
+ class CData < Text
5
+ START = '<![CDATA['
6
+ STOP = ']]>'
7
+ ILLEGAL = /(\]\]>)/
8
8
 
9
- # Constructor. CData is data between <![CDATA[ ... ]]>
10
- #
11
- # _Examples_
12
- # CData.new( source )
13
- # CData.new( "Here is some CDATA" )
14
- # CData.new( "Some unprocessed data", respect_whitespace_TF, parent_element )
15
- def initialize( first, whitespace=true, parent=nil )
16
- super( first, whitespace, parent, true, true, ILLEGAL )
17
- end
9
+ # Constructor. CData is data between <![CDATA[ ... ]]>
10
+ #
11
+ # _Examples_
12
+ # CData.new( source )
13
+ # CData.new( "Here is some CDATA" )
14
+ # CData.new( "Some unprocessed data", respect_whitespace_TF, parent_element )
15
+ def initialize( first, whitespace=true, parent=nil )
16
+ super( first, whitespace, parent, false, true, ILLEGAL )
17
+ end
18
18
 
19
- # Make a copy of this object
20
- #
21
- # _Examples_
22
- # c = CData.new( "Some text" )
23
- # d = c.clone
24
- # d.to_s # -> "Some text"
25
- def clone
26
- CData.new self
27
- end
19
+ # Make a copy of this object
20
+ #
21
+ # _Examples_
22
+ # c = CData.new( "Some text" )
23
+ # d = c.clone
24
+ # d.to_s # -> "Some text"
25
+ def clone
26
+ CData.new self
27
+ end
28
28
 
29
- # Returns the content of this CData object
30
- #
31
- # _Examples_
32
- # c = CData.new( "Some text" )
33
- # c.to_s # -> "Some text"
34
- def to_s
35
- @string
36
- end
29
+ # Returns the content of this CData object
30
+ #
31
+ # _Examples_
32
+ # c = CData.new( "Some text" )
33
+ # c.to_s # -> "Some text"
34
+ def to_s
35
+ @string
36
+ end
37
37
 
38
38
  def value
39
39
  @string
@@ -42,26 +42,26 @@ module REXML
42
42
  # == DEPRECATED
43
43
  # See the rexml/formatters package
44
44
  #
45
- # Generates XML output of this object
46
- #
47
- # output::
48
- # Where to write the string. Defaults to $stdout
49
- # indent::
45
+ # Generates XML output of this object
46
+ #
47
+ # output::
48
+ # Where to write the string. Defaults to $stdout
49
+ # indent::
50
50
  # The amount to indent this node by
51
- # transitive::
51
+ # transitive::
52
52
  # Ignored
53
- # ie_hack::
53
+ # ie_hack::
54
54
  # Ignored
55
- #
56
- # _Examples_
57
- # c = CData.new( " Some text " )
58
- # c.write( $stdout ) #-> <![CDATA[ Some text ]]>
59
- def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
55
+ #
56
+ # _Examples_
57
+ # c = CData.new( " Some text " )
58
+ # c.write( $stdout ) #-> <![CDATA[ Some text ]]>
59
+ def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
60
60
  Kernel.warn( "#{self.class.name}.write is deprecated" )
61
- indent( output, indent )
62
- output << START
63
- output << @string
64
- output << STOP
65
- end
66
- end
61
+ indent( output, indent )
62
+ output << START
63
+ output << @string
64
+ output << STOP
65
+ end
66
+ end
67
67
  end
data/lib/rexml/child.rb CHANGED
@@ -1,96 +1,96 @@
1
1
  require "rexml/node"
2
2
 
3
3
  module REXML
4
- ##
5
- # A Child object is something contained by a parent, and this class
6
- # contains methods to support that. Most user code will not use this
7
- # class directly.
8
- class Child
9
- include Node
10
- attr_reader :parent # The Parent of this object
4
+ ##
5
+ # A Child object is something contained by a parent, and this class
6
+ # contains methods to support that. Most user code will not use this
7
+ # class directly.
8
+ class Child
9
+ include Node
10
+ attr_reader :parent # The Parent of this object
11
11
 
12
- # Constructor. Any inheritors of this class should call super to make
13
- # sure this method is called.
14
- # parent::
15
- # if supplied, the parent of this child will be set to the
16
- # supplied value, and self will be added to the parent
17
- def initialize( parent = nil )
18
- @parent = nil
19
- # Declare @parent, but don't define it. The next line sets the
20
- # parent.
21
- parent.add( self ) if parent
22
- end
12
+ # Constructor. Any inheritors of this class should call super to make
13
+ # sure this method is called.
14
+ # parent::
15
+ # if supplied, the parent of this child will be set to the
16
+ # supplied value, and self will be added to the parent
17
+ def initialize( parent = nil )
18
+ @parent = nil
19
+ # Declare @parent, but don't define it. The next line sets the
20
+ # parent.
21
+ parent.add( self ) if parent
22
+ end
23
23
 
24
- # Replaces this object with another object. Basically, calls
25
- # Parent.replace_child
26
- #
27
- # Returns:: self
28
- def replace_with( child )
29
- @parent.replace_child( self, child )
30
- self
31
- end
24
+ # Replaces this object with another object. Basically, calls
25
+ # Parent.replace_child
26
+ #
27
+ # Returns:: self
28
+ def replace_with( child )
29
+ @parent.replace_child( self, child )
30
+ self
31
+ end
32
32
 
33
- # Removes this child from the parent.
34
- #
35
- # Returns:: self
36
- def remove
37
- unless @parent.nil?
38
- @parent.delete self
39
- end
40
- self
41
- end
33
+ # Removes this child from the parent.
34
+ #
35
+ # Returns:: self
36
+ def remove
37
+ unless @parent.nil?
38
+ @parent.delete self
39
+ end
40
+ self
41
+ end
42
42
 
43
- # Sets the parent of this child to the supplied argument.
44
- #
45
- # other::
46
- # Must be a Parent object. If this object is the same object as the
47
- # existing parent of this child, no action is taken. Otherwise, this
48
- # child is removed from the current parent (if one exists), and is added
49
- # to the new parent.
50
- # Returns:: The parent added
51
- def parent=( other )
52
- return @parent if @parent == other
53
- @parent.delete self if defined? @parent and @parent
54
- @parent = other
55
- end
43
+ # Sets the parent of this child to the supplied argument.
44
+ #
45
+ # other::
46
+ # Must be a Parent object. If this object is the same object as the
47
+ # existing parent of this child, no action is taken. Otherwise, this
48
+ # child is removed from the current parent (if one exists), and is added
49
+ # to the new parent.
50
+ # Returns:: The parent added
51
+ def parent=( other )
52
+ return @parent if @parent == other
53
+ @parent.delete self if defined? @parent and @parent
54
+ @parent = other
55
+ end
56
56
 
57
- alias :next_sibling :next_sibling_node
58
- alias :previous_sibling :previous_sibling_node
57
+ alias :next_sibling :next_sibling_node
58
+ alias :previous_sibling :previous_sibling_node
59
59
 
60
- # Sets the next sibling of this child. This can be used to insert a child
61
- # after some other child.
62
- # a = Element.new("a")
63
- # b = a.add_element("b")
64
- # c = Element.new("c")
65
- # b.next_sibling = c
66
- # # => <a><b/><c/></a>
67
- def next_sibling=( other )
68
- parent.insert_after self, other
69
- end
60
+ # Sets the next sibling of this child. This can be used to insert a child
61
+ # after some other child.
62
+ # a = Element.new("a")
63
+ # b = a.add_element("b")
64
+ # c = Element.new("c")
65
+ # b.next_sibling = c
66
+ # # => <a><b/><c/></a>
67
+ def next_sibling=( other )
68
+ parent.insert_after self, other
69
+ end
70
70
 
71
- # Sets the previous sibling of this child. This can be used to insert a
72
- # child before some other child.
73
- # a = Element.new("a")
74
- # b = a.add_element("b")
75
- # c = Element.new("c")
76
- # b.previous_sibling = c
77
- # # => <a><b/><c/></a>
78
- def previous_sibling=(other)
79
- parent.insert_before self, other
80
- end
71
+ # Sets the previous sibling of this child. This can be used to insert a
72
+ # child before some other child.
73
+ # a = Element.new("a")
74
+ # b = a.add_element("b")
75
+ # c = Element.new("c")
76
+ # b.previous_sibling = c
77
+ # # => <a><b/><c/></a>
78
+ def previous_sibling=(other)
79
+ parent.insert_before self, other
80
+ end
81
81
 
82
- # Returns:: the document this child belongs to, or nil if this child
83
- # belongs to no document
84
- def document
85
- return parent.document unless parent.nil?
86
- nil
87
- end
82
+ # Returns:: the document this child belongs to, or nil if this child
83
+ # belongs to no document
84
+ def document
85
+ return parent.document unless parent.nil?
86
+ nil
87
+ end
88
88
 
89
- # This doesn't yet handle encodings
90
- def bytes
91
- encoding = document.encoding
89
+ # This doesn't yet handle encodings
90
+ def bytes
91
+ document.encoding
92
92
 
93
- to_s
94
- end
95
- end
93
+ to_s
94
+ end
95
+ end
96
96
  end
data/lib/rexml/comment.rb CHANGED
@@ -1,80 +1,80 @@
1
1
  require "rexml/child"
2
2
 
3
3
  module REXML
4
- ##
5
- # Represents an XML comment; that is, text between \<!-- ... -->
6
- class Comment < Child
7
- include Comparable
8
- START = "<!--"
9
- STOP = "-->"
4
+ ##
5
+ # Represents an XML comment; that is, text between \<!-- ... -->
6
+ class Comment < Child
7
+ include Comparable
8
+ START = "<!--"
9
+ STOP = "-->"
10
10
 
11
- # The content text
11
+ # The content text
12
12
 
13
- attr_accessor :string
13
+ attr_accessor :string
14
14
 
15
- ##
16
- # Constructor. The first argument can be one of three types:
17
- # @param first If String, the contents of this comment are set to the
18
- # argument. If Comment, the argument is duplicated. If
19
- # Source, the argument is scanned for a comment.
20
- # @param second If the first argument is a Source, this argument
21
- # should be nil, not supplied, or a Parent to be set as the parent
22
- # of this object
23
- def initialize( first, second = nil )
24
- #puts "IN COMMENT CONSTRUCTOR; SECOND IS #{second.type}"
25
- super(second)
26
- if first.kind_of? String
27
- @string = first
28
- elsif first.kind_of? Comment
29
- @string = first.string
30
- end
31
- end
15
+ ##
16
+ # Constructor. The first argument can be one of three types:
17
+ # @param first If String, the contents of this comment are set to the
18
+ # argument. If Comment, the argument is duplicated. If
19
+ # Source, the argument is scanned for a comment.
20
+ # @param second If the first argument is a Source, this argument
21
+ # should be nil, not supplied, or a Parent to be set as the parent
22
+ # of this object
23
+ def initialize( first, second = nil )
24
+ #puts "IN COMMENT CONSTRUCTOR; SECOND IS #{second.type}"
25
+ super(second)
26
+ if first.kind_of? String
27
+ @string = first
28
+ elsif first.kind_of? Comment
29
+ @string = first.string
30
+ end
31
+ end
32
32
 
33
- def clone
34
- Comment.new self
35
- end
33
+ def clone
34
+ Comment.new self
35
+ end
36
36
 
37
37
  # == DEPRECATED
38
38
  # See REXML::Formatters
39
39
  #
40
- # output::
41
- # Where to write the string
42
- # indent::
43
- # An integer. If -1, no indenting will be used; otherwise, the
44
- # indentation will be this number of spaces, and children will be
45
- # indented an additional amount.
46
- # transitive::
47
- # Ignored by this class. The contents of comments are never modified.
48
- # ie_hack::
49
- # Needed for conformity to the child API, but not used by this class.
50
- def write( output, indent=-1, transitive=false, ie_hack=false )
40
+ # output::
41
+ # Where to write the string
42
+ # indent::
43
+ # An integer. If -1, no indenting will be used; otherwise, the
44
+ # indentation will be this number of spaces, and children will be
45
+ # indented an additional amount.
46
+ # transitive::
47
+ # Ignored by this class. The contents of comments are never modified.
48
+ # ie_hack::
49
+ # Needed for conformity to the child API, but not used by this class.
50
+ def write( output, indent=-1, transitive=false, ie_hack=false )
51
51
  Kernel.warn("Comment.write is deprecated. See REXML::Formatters")
52
- indent( output, indent )
53
- output << START
54
- output << @string
55
- output << STOP
56
- end
52
+ indent( output, indent )
53
+ output << START
54
+ output << @string
55
+ output << STOP
56
+ end
57
57
 
58
- alias :to_s :string
58
+ alias :to_s :string
59
59
 
60
- ##
61
- # Compares this Comment to another; the contents of the comment are used
62
- # in the comparison.
63
- def <=>(other)
64
- other.to_s <=> @string
65
- end
60
+ ##
61
+ # Compares this Comment to another; the contents of the comment are used
62
+ # in the comparison.
63
+ def <=>(other)
64
+ other.to_s <=> @string
65
+ end
66
66
 
67
- ##
68
- # Compares this Comment to another; the contents of the comment are used
69
- # in the comparison.
70
- def ==( other )
71
- other.kind_of? Comment and
72
- (other <=> self) == 0
73
- end
67
+ ##
68
+ # Compares this Comment to another; the contents of the comment are used
69
+ # in the comparison.
70
+ def ==( other )
71
+ other.kind_of? Comment and
72
+ (other <=> self) == 0
73
+ end
74
74
 
75
75
  def node_type
76
76
  :comment
77
77
  end
78
- end
78
+ end
79
79
  end
80
80
  #vim:ts=2 sw=2 noexpandtab:
data/lib/rexml/doctype.rb CHANGED
@@ -15,11 +15,11 @@ module REXML
15
15
  STOP = ">"
16
16
  SYSTEM = "SYSTEM"
17
17
  PUBLIC = "PUBLIC"
18
- DEFAULT_ENTITIES = {
19
- 'gt'=>EntityConst::GT,
20
- 'lt'=>EntityConst::LT,
21
- 'quot'=>EntityConst::QUOT,
22
- "apos"=>EntityConst::APOS
18
+ DEFAULT_ENTITIES = {
19
+ 'gt'=>EntityConst::GT,
20
+ 'lt'=>EntityConst::LT,
21
+ 'quot'=>EntityConst::QUOT,
22
+ "apos"=>EntityConst::APOS
23
23
  }
24
24
 
25
25
  # name is the name of the doctype
@@ -33,7 +33,7 @@ module REXML
33
33
  # dt = DocType.new( doctype_to_clone )
34
34
  # # Incomplete. Shallow clone of doctype
35
35
  #
36
- # +Note+ that the constructor:
36
+ # +Note+ that the constructor:
37
37
  #
38
38
  # Doctype.new( Source.new( "<!DOCTYPE foo 'bar'>" ) )
39
39
  #
@@ -115,9 +115,7 @@ module REXML
115
115
  output << " #{@long_name.inspect}" if @long_name
116
116
  output << " #{@uri.inspect}" if @uri
117
117
  unless @children.empty?
118
- next_indent = indent + 1
119
118
  output << ' ['
120
- child = nil # speed
121
119
  @children.each { |child|
122
120
  output << "\n"
123
121
  f.write( child, output )
@@ -140,8 +138,8 @@ module REXML
140
138
  @entities = DEFAULT_ENTITIES.clone if @entities == DEFAULT_ENTITIES
141
139
  @entities[ child.name ] = child if child.kind_of? Entity
142
140
  end
143
-
144
- # This method retrieves the public identifier identifying the document's
141
+
142
+ # This method retrieves the public identifier identifying the document's
145
143
  # DTD.
146
144
  #
147
145
  # Method contributed by Henrik Martensson
@@ -153,7 +151,7 @@ module REXML
153
151
  strip_quotes(@long_name)
154
152
  end
155
153
  end
156
-
154
+
157
155
  # This method retrieves the system identifier identifying the document's DTD
158
156
  #
159
157
  # Method contributed by Henrik Martensson
@@ -165,16 +163,16 @@ module REXML
165
163
  @uri.kind_of?(String) ? strip_quotes(@uri) : nil
166
164
  end
167
165
  end
168
-
166
+
169
167
  # This method returns a list of notations that have been declared in the
170
- # _internal_ DTD subset. Notations in the external DTD subset are not
168
+ # _internal_ DTD subset. Notations in the external DTD subset are not
171
169
  # listed.
172
170
  #
173
171
  # Method contributed by Henrik Martensson
174
172
  def notations
175
173
  children().select {|node| node.kind_of?(REXML::NotationDecl)}
176
174
  end
177
-
175
+
178
176
  # Retrieves a named notation. Only notations declared in the internal
179
177
  # DTD subset can be retrieved.
180
178
  #
@@ -184,12 +182,12 @@ module REXML
184
182
  notation_decl.name == name
185
183
  }
186
184
  end
187
-
185
+
188
186
  private
189
-
187
+
190
188
  # Method contributed by Henrik Martensson
191
189
  def strip_quotes(quoted_string)
192
- quoted_string =~ /^[\'\"].*[\´\"]$/ ?
190
+ quoted_string =~ /^[\'\"].*[\'\"]$/ ?
193
191
  quoted_string[1, quoted_string.length-2] :
194
192
  quoted_string
195
193
  end
@@ -218,7 +216,7 @@ module REXML
218
216
  output << to_s
219
217
  end
220
218
  end
221
-
219
+
222
220
  public
223
221
  class ElementDecl < Declaration
224
222
  def initialize( src )
@@ -250,17 +248,17 @@ module REXML
250
248
  end
251
249
 
252
250
  def to_s
253
- "<!NOTATION #@name #@middle#{
254
- @public ? ' ' + public.inspect : ''
255
- }#{
256
- @system ? ' ' +@system.inspect : ''
257
- }>"
251
+ notation = "<!NOTATION #{@name} #{@middle}"
252
+ notation << " #{@public.inspect}" if @public
253
+ notation << " #{@system.inspect}" if @system
254
+ notation << ">"
255
+ notation
258
256
  end
259
257
 
260
258
  def write( output, indent=-1 )
261
259
  output << to_s
262
260
  end
263
-
261
+
264
262
  # This method retrieves the name of the notation.
265
263
  #
266
264
  # Method contributed by Henrik Martensson