vcdom 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +34 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +51 -0
- data/Rakefile +26 -0
- data/lib/vcdom/minidom/attr.rb +139 -0
- data/lib/vcdom/minidom/attr_ns.rb +47 -0
- data/lib/vcdom/minidom/cdata_section.rb +34 -0
- data/lib/vcdom/minidom/character_data.rb +263 -0
- data/lib/vcdom/minidom/comment.rb +34 -0
- data/lib/vcdom/minidom/document.rb +245 -0
- data/lib/vcdom/minidom/dom_exception.rb +51 -0
- data/lib/vcdom/minidom/dom_implementation.rb +214 -0
- data/lib/vcdom/minidom/element.rb +512 -0
- data/lib/vcdom/minidom/element_ns.rb +42 -0
- data/lib/vcdom/minidom/mini_parser.rb +9 -0
- data/lib/vcdom/minidom/mini_serializer.rb +118 -0
- data/lib/vcdom/minidom/minidom_standard_error.rb +9 -0
- data/lib/vcdom/minidom/mod_child_node.rb +51 -0
- data/lib/vcdom/minidom/mod_elements_getter.rb +49 -0
- data/lib/vcdom/minidom/mod_namespaceuri_manageable.rb +152 -0
- data/lib/vcdom/minidom/mod_parent_node.rb +307 -0
- data/lib/vcdom/minidom/named_node_map_attr.rb +277 -0
- data/lib/vcdom/minidom/node.rb +178 -0
- data/lib/vcdom/minidom/node_list.rb +41 -0
- data/lib/vcdom/minidom/text.rb +77 -0
- data/lib/vcdom/minidom/xml_reg_exp.rb +39 -0
- data/lib/vcdom/minidom.rb +9 -0
- data/lib/vcdom.rb +6 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/test/test_helper.rb +3 -0
- data/test/test_vcdom.rb +11 -0
- metadata +122 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
lib/vcdom.rb
|
7
|
+
lib/vcdom/minidom.rb
|
8
|
+
lib/vcdom/minidom/attr.rb
|
9
|
+
lib/vcdom/minidom/attr_ns.rb
|
10
|
+
lib/vcdom/minidom/cdata_section.rb
|
11
|
+
lib/vcdom/minidom/character_data.rb
|
12
|
+
lib/vcdom/minidom/comment.rb
|
13
|
+
lib/vcdom/minidom/document.rb
|
14
|
+
lib/vcdom/minidom/dom_exception.rb
|
15
|
+
lib/vcdom/minidom/dom_implementation.rb
|
16
|
+
lib/vcdom/minidom/element.rb
|
17
|
+
lib/vcdom/minidom/element_ns.rb
|
18
|
+
lib/vcdom/minidom/mini_parser.rb
|
19
|
+
lib/vcdom/minidom/mini_serializer.rb
|
20
|
+
lib/vcdom/minidom/minidom_standard_error.rb
|
21
|
+
lib/vcdom/minidom/mod_child_node.rb
|
22
|
+
lib/vcdom/minidom/mod_parent_node.rb
|
23
|
+
lib/vcdom/minidom/mod_elements_getter.rb
|
24
|
+
lib/vcdom/minidom/mod_namespaceuri_manageable.rb
|
25
|
+
lib/vcdom/minidom/named_node_map_attr.rb
|
26
|
+
lib/vcdom/minidom/node_list.rb
|
27
|
+
lib/vcdom/minidom/node.rb
|
28
|
+
lib/vcdom/minidom/text.rb
|
29
|
+
lib/vcdom/minidom/xml_reg_exp.rb
|
30
|
+
script/console
|
31
|
+
script/destroy
|
32
|
+
script/generate
|
33
|
+
test/test_helper.rb
|
34
|
+
test/test_vcdom.rb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
= vcdom
|
2
|
+
|
3
|
+
* http://vcdom.rubyforge.org/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This library provides DOM implementation(s).
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* list of features or problems
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
impl = VCDOM::MiniDOM.get_dom_implementation()
|
16
|
+
doc = impl.create_document( nil, "test", nil )
|
17
|
+
doc.document_element.text_content = "This is an XML for test."
|
18
|
+
$stdout << impl.mini_serializer.write_to_string( doc ) << "\n"
|
19
|
+
|
20
|
+
== REQUIREMENTS:
|
21
|
+
|
22
|
+
* list of requirements
|
23
|
+
|
24
|
+
== INSTALL:
|
25
|
+
|
26
|
+
* sudo gem install vcdom
|
27
|
+
|
28
|
+
== LICENSE:
|
29
|
+
|
30
|
+
(The MIT License)
|
31
|
+
|
32
|
+
Copyright (c) 2010 Y. NOBUOKA
|
33
|
+
|
34
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
35
|
+
a copy of this software and associated documentation files (the
|
36
|
+
'Software'), to deal in the Software without restriction, including
|
37
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
38
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
39
|
+
permit persons to whom the Software is furnished to do so, subject to
|
40
|
+
the following conditions:
|
41
|
+
|
42
|
+
The above copyright notice and this permission notice shall be
|
43
|
+
included in all copies or substantial portions of the Software.
|
44
|
+
|
45
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
46
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
47
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
48
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
49
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
50
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
51
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/vcdom'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
# Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec 'vcdom' do
|
14
|
+
self.developer 'Y. NOBUOKA', 'nobuoka@r-definition.com'
|
15
|
+
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
|
+
self.rubyforge_name = 'vcdom' # TODO this is default value
|
17
|
+
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'newgem/tasks'
|
22
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
23
|
+
|
24
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
25
|
+
# remove_task :default
|
26
|
+
# task :default => [:spec, :features]
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require "vcdom/minidom/node"
|
4
|
+
require "vcdom/minidom/mod_parent_node"
|
5
|
+
|
6
|
+
module VCDOM
|
7
|
+
module MiniDOM
|
8
|
+
class Attr < Node
|
9
|
+
|
10
|
+
module OwnerElementManageable
|
11
|
+
protected
|
12
|
+
def owner_element=( element )
|
13
|
+
@owner_element = element
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
include ModParentNode
|
18
|
+
include OwnerElementManageable
|
19
|
+
|
20
|
+
def node_type
|
21
|
+
return Node::ATTRIBUTE_NODE
|
22
|
+
end
|
23
|
+
|
24
|
+
# ===== Attributes =====
|
25
|
+
|
26
|
+
# name of type DOMString, readonly
|
27
|
+
# Returns the name of this attribute.
|
28
|
+
# If Node.localName is different from null, this attribute is a qualified name.
|
29
|
+
def name
|
30
|
+
return @name
|
31
|
+
end
|
32
|
+
alias :node_name :name
|
33
|
+
|
34
|
+
# value of type DOMString
|
35
|
+
# On retrieval, the value of the attribute is returned as a string.
|
36
|
+
# Character and general entity references are replaced with their values.
|
37
|
+
# See also the method getAttribute on the Element interface.
|
38
|
+
# On setting, this creates a Text node with the unparsed contents of the string,
|
39
|
+
# i.e. any characters that an XML processor would recognize as markup are instead
|
40
|
+
# treated as literal text.
|
41
|
+
# See also the method Element.setAttribute().
|
42
|
+
# Some specialized implementations, such as some [SVG 1.1] implementations,
|
43
|
+
# may do normalization automatically, even after mutation; in such case, the
|
44
|
+
# value on retrieval may differ from the value on setting.
|
45
|
+
#
|
46
|
+
# Exceptions on setting
|
47
|
+
# DOMException
|
48
|
+
# NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
|
49
|
+
def value
|
50
|
+
return self.text_content
|
51
|
+
end
|
52
|
+
def value=( value )
|
53
|
+
if self.is_readonly then
|
54
|
+
raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR,
|
55
|
+
'This node is readonly.' )
|
56
|
+
end
|
57
|
+
if ! value.instance_of? String then
|
58
|
+
raise TypeError.new( "The argument must be String object." )
|
59
|
+
end
|
60
|
+
self.text_content = value
|
61
|
+
end
|
62
|
+
|
63
|
+
# nodeValue of type DOMString
|
64
|
+
# The value of this node, depending on its type; see the table above.
|
65
|
+
# When it is defined to be null, setting it has no effect, including if the node is read-only.
|
66
|
+
#
|
67
|
+
# Interface nodeValue
|
68
|
+
# ------------------------------------------------------------------------------------------------
|
69
|
+
# Attr same as Attr.value
|
70
|
+
#
|
71
|
+
# Exceptions on setting
|
72
|
+
# DOMException
|
73
|
+
# NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly and
|
74
|
+
# if it is not defined to be null.
|
75
|
+
# Exceptions on retrieval
|
76
|
+
# DOMException
|
77
|
+
# DOMSTRING_SIZE_ERR: Raised when it would return more characters than
|
78
|
+
# fit in a DOMString variable on the implementation platform.
|
79
|
+
#
|
80
|
+
# Attr, PI, CharacterData ( = CDATASection, Comment, Text ) でオーバーロード
|
81
|
+
alias :node_value :value
|
82
|
+
alias :node_value= :value=
|
83
|
+
|
84
|
+
# ownerElement of type Element, readonly, introduced in DOM Level 2
|
85
|
+
# The Element node this attribute is attached to or null if this attribute is not in use.
|
86
|
+
def owner_element; return @owner_element end
|
87
|
+
|
88
|
+
# specified of type boolean, readonly
|
89
|
+
# True if this attribute was explicitly given a value in the instance document,
|
90
|
+
# false otherwise.
|
91
|
+
# #=> この属性 (specified ではなく Attr ノード) が, 文書中で明示的に値を与えられている場合は
|
92
|
+
# true, さもなければ false である.
|
93
|
+
# If the application changed the value of this attribute node (even if it ends
|
94
|
+
# up having the same value as the default value) then it is set to true.
|
95
|
+
# #=> もし, アプリケーションがこの Attr ノードの値を変化させた場合 (たとえ結果的にデフォルト値と同じ
|
96
|
+
# 値であったとしても), true になる.
|
97
|
+
# The implementation may handle attributes with default values from other schemas
|
98
|
+
# similarly but applications should use Document.normalizeDocument() to guarantee
|
99
|
+
# this information is up-to-date.
|
100
|
+
# #=> ...
|
101
|
+
def specified
|
102
|
+
return true
|
103
|
+
end
|
104
|
+
|
105
|
+
# ===== コンストラクタ =====
|
106
|
+
# Exceptions
|
107
|
+
# DOMException
|
108
|
+
# INVALID_CHARACTER_ERR: Raised if the specified name is not an XML name according to
|
109
|
+
# the XML version in use specified in the Document.xmlVersion attribute.
|
110
|
+
def initialize( owner_document, name )
|
111
|
+
if XMLRegExp::NAME !~ name then
|
112
|
+
# the specified qualified name is not an XML name
|
113
|
+
raise DOMException.new( DOMException::INVALID_CHARACTER_ERR,
|
114
|
+
'The specified name "' + name + '" is not an XML name.' )
|
115
|
+
end
|
116
|
+
super( owner_document )
|
117
|
+
init_mod_parent_node()
|
118
|
+
@name = name
|
119
|
+
end
|
120
|
+
|
121
|
+
protected
|
122
|
+
def name=( name )
|
123
|
+
@name = name
|
124
|
+
end
|
125
|
+
def check_hierarchy( new_child )
|
126
|
+
# Text, EntityReference
|
127
|
+
super( new_child, true )
|
128
|
+
case new_child.node_type
|
129
|
+
when Node::TEXT_NODE, Node::ENTITY_REFERENCE_NODE then
|
130
|
+
return true
|
131
|
+
else
|
132
|
+
raise DOMException.new( DOMException::HIERARCHY_REQUEST_ERR,
|
133
|
+
'This node is of a type that does not allow children of the type of the newChild node.' )
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require "vcdom/minidom/node"
|
4
|
+
require "vcdom/minidom/mod_parent_node"
|
5
|
+
require "vcdom/minidom/mod_namespaceuri_manageable"
|
6
|
+
|
7
|
+
module VCDOM
|
8
|
+
module MiniDOM
|
9
|
+
class AttrNS < Attr
|
10
|
+
|
11
|
+
include ModNamespaceURIManageable
|
12
|
+
|
13
|
+
# DOMException
|
14
|
+
# INVALID_CHARACTER_ERR: Raised if the specified qualifiedName is not an XML name according
|
15
|
+
# to the XML version in use specified in the Document.xmlVersion attribute.
|
16
|
+
# NAMESPACE_ERR: Raised if the qualifiedName is a malformed qualified name,
|
17
|
+
# if the qualifiedName has a prefix and the namespaceURI is null,
|
18
|
+
# if the qualifiedName has a prefix that is "xml" and the namespaceURI is different
|
19
|
+
# from "http://www.w3.org/XML/1998/namespace", if the qualifiedName or its prefix is
|
20
|
+
# "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/",
|
21
|
+
# or if the namespaceURI is "http://www.w3.org/2000/xmlns/" and
|
22
|
+
# neither the qualifiedName nor its prefix is "xmlns".
|
23
|
+
# #=> QName が奇形の場合, QName が接頭辞を持ちながら名前空間 URI が null の場合,
|
24
|
+
# QName の接頭辞が "xml" なのに名前空間 URI が
|
25
|
+
# "http://www.w3.org/XML/1998/namespace" ではない場合, QName の接頭辞が
|
26
|
+
# "xmlns" にもかかわらず名前空間 URI が "http://www.w3.org/2000/xmlns/"
|
27
|
+
# ではないとき, そして名前空間 URI が "http://www.w3.org/2000/xmlns/" なのに,
|
28
|
+
# QName または接頭辞が "xmlns" ではないとき例外発生.
|
29
|
+
# NOT_SUPPORTED_ERR: Always thrown if the current document does not support the "XML" feature,
|
30
|
+
# since namespaces were defined by XML.
|
31
|
+
def initialize( owner_document, namespace_uri, qualified_name )
|
32
|
+
begin
|
33
|
+
super( owner_document, qualified_name )
|
34
|
+
rescue DOMException => err
|
35
|
+
if err.code == DOMException::INVALID_CHARACTER_ERR then
|
36
|
+
raise DOMException.new( DOMException::INVALID_CHARACTER_ERR,
|
37
|
+
'The specified qualified name "' + qualified_name + '" is not an XML name.' )
|
38
|
+
else
|
39
|
+
raise err
|
40
|
+
end
|
41
|
+
end
|
42
|
+
init_mod_namespaceuri_manageable( namespace_uri, qualified_name )
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require "vcdom/minidom/node"
|
4
|
+
require "vcdom/minidom/character_data"
|
5
|
+
require "vcdom/minidom/mod_child_node"
|
6
|
+
require "vcdom/minidom/dom_exception"
|
7
|
+
|
8
|
+
module VCDOM
|
9
|
+
module MiniDOM
|
10
|
+
class CDATASection < CharacterData
|
11
|
+
|
12
|
+
# nodeType of type unsigned short, readonly
|
13
|
+
# A code representing the type of the underlying object, as defined above.
|
14
|
+
def node_type
|
15
|
+
return Node::CDATA_SECTION_NODE
|
16
|
+
end
|
17
|
+
|
18
|
+
# nodeName of type DOMString, readonly
|
19
|
+
# The name of this node, depending on its type; see the table above.
|
20
|
+
#
|
21
|
+
# Interface nodeName
|
22
|
+
# ------------------------------------------------------------
|
23
|
+
# CDATASection "#cdata-section"
|
24
|
+
def node_name
|
25
|
+
return "#cdata-section"
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize( owner_document, value )
|
29
|
+
super( owner_document, value )
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,263 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require "vcdom/minidom/node"
|
4
|
+
require "vcdom/minidom/mod_child_node"
|
5
|
+
require "vcdom/minidom/dom_exception"
|
6
|
+
|
7
|
+
module VCDOM
|
8
|
+
module MiniDOM
|
9
|
+
class CharacterData < Node
|
10
|
+
|
11
|
+
include ModChildNode
|
12
|
+
|
13
|
+
# data of type DOMString
|
14
|
+
#
|
15
|
+
# The character data of the node that implements this interface.
|
16
|
+
# The DOM implementation may not put arbitrary limits on the amount of
|
17
|
+
# data that may be stored in a CharacterData node.
|
18
|
+
# However, implementation limits may mean that the entirety of a node's
|
19
|
+
# data may not fit into a single DOMString.
|
20
|
+
# In such cases, the user may call substringData to retrieve the data in
|
21
|
+
# appropriately sized pieces.
|
22
|
+
#
|
23
|
+
# Exceptions on setting
|
24
|
+
# DOMException NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
|
25
|
+
# Exceptions on retrieval
|
26
|
+
# DOMException DOMSTRING_SIZE_ERR: Raised when it would return more characters than fit in a DOMString variable on the implementation platform.
|
27
|
+
def data
|
28
|
+
return @data
|
29
|
+
end
|
30
|
+
def data=( value )
|
31
|
+
if self.is_readonly then
|
32
|
+
raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR,
|
33
|
+
'This node is readonly.' )
|
34
|
+
end
|
35
|
+
@data = value
|
36
|
+
end
|
37
|
+
|
38
|
+
# nodeValue of type DOMString
|
39
|
+
# The value of this node, depending on its type; see the table above.
|
40
|
+
# When it is defined to be null, setting it has no effect, including if the node is read-only.
|
41
|
+
#
|
42
|
+
# Interface nodeValue
|
43
|
+
# ------------------------------------------------------------------------------------------------
|
44
|
+
# Text same as CharacterData.data, the content of the text node
|
45
|
+
#
|
46
|
+
# Exceptions on setting
|
47
|
+
# DOMException
|
48
|
+
# NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly and
|
49
|
+
# if it is not defined to be null.
|
50
|
+
# Exceptions on retrieval
|
51
|
+
# DOMException
|
52
|
+
# DOMSTRING_SIZE_ERR: Raised when it would return more characters than
|
53
|
+
# fit in a DOMString variable on the implementation platform.
|
54
|
+
#
|
55
|
+
# Attr, PI, CharacterData ( = CDATASection, Comment, Text ) でオーバーロード
|
56
|
+
alias :node_value :data
|
57
|
+
alias :node_value= :data=
|
58
|
+
|
59
|
+
|
60
|
+
# ===== Attributes =====
|
61
|
+
|
62
|
+
# length of type unsigned long, readonly
|
63
|
+
#
|
64
|
+
# The number of 16-bit units that are available through data and the substringData method below.
|
65
|
+
# This may have the value zero, i.e., CharacterData nodes may be empty.
|
66
|
+
def length
|
67
|
+
count = 0
|
68
|
+
while /\A.{#{count}}/mu =~ @data do
|
69
|
+
count += 1
|
70
|
+
end
|
71
|
+
count -= 1
|
72
|
+
return count
|
73
|
+
end
|
74
|
+
|
75
|
+
# ===== Methods =====
|
76
|
+
|
77
|
+
# appendData
|
78
|
+
#
|
79
|
+
# Append the string to the end of the character data of the node.
|
80
|
+
# Upon success, data provides access to the concatenation of data and the DOMString specified.
|
81
|
+
#
|
82
|
+
# Parameters
|
83
|
+
# arg of type DOMString
|
84
|
+
# The DOMString to append.
|
85
|
+
# Exceptions
|
86
|
+
# DOMException
|
87
|
+
# NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
|
88
|
+
# No Return Value
|
89
|
+
def append_data( arg )
|
90
|
+
if self.is_readonly then
|
91
|
+
raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR,
|
92
|
+
'This node is readonly.' )
|
93
|
+
end
|
94
|
+
@data = @data + arg
|
95
|
+
return nil
|
96
|
+
end
|
97
|
+
|
98
|
+
# deleteData
|
99
|
+
# Remove a range of 16-bit units from the node. Upon success, data and length
|
100
|
+
# reflect the change.
|
101
|
+
#
|
102
|
+
# Parameters
|
103
|
+
# offset of type unsigned long
|
104
|
+
# The offset from which to start removing.
|
105
|
+
# count of type unsigned long
|
106
|
+
# The number of 16-bit units to delete. If the sum of offset and count
|
107
|
+
# exceeds length then all 16-bit units from offset to the end of the data
|
108
|
+
# are deleted.
|
109
|
+
# Exceptions
|
110
|
+
# DOMException
|
111
|
+
# INDEX_SIZE_ERR: Raised if the specified offset is negative or greater
|
112
|
+
# than the number of 16-bit units in data, or if the specified
|
113
|
+
# count is negative.
|
114
|
+
# NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
|
115
|
+
# No Return Value
|
116
|
+
def delete_data( offset, count )
|
117
|
+
if self.is_readonly then
|
118
|
+
raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR,
|
119
|
+
'This node is readonly.' )
|
120
|
+
end
|
121
|
+
begin
|
122
|
+
substrs = split( offset, count )
|
123
|
+
rescue DOMException => err
|
124
|
+
raise DOMException.new( err )
|
125
|
+
end
|
126
|
+
@data = substrs[0] + substrs[2]
|
127
|
+
return nil
|
128
|
+
end
|
129
|
+
|
130
|
+
# insertData
|
131
|
+
#
|
132
|
+
# Insert a string at the specified 16-bit unit offset.
|
133
|
+
#
|
134
|
+
# Parameters
|
135
|
+
# offset of type unsigned long
|
136
|
+
# The character offset at which to insert.
|
137
|
+
# arg of type DOMString
|
138
|
+
# The DOMString to insert.
|
139
|
+
# Exceptions
|
140
|
+
# DOMException
|
141
|
+
# INDEX_SIZE_ERR: Raised if the specified offset is negative or greater
|
142
|
+
# than the number of 16-bit units in data.
|
143
|
+
# NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
|
144
|
+
# No Return Value
|
145
|
+
def insert_data( offset, arg )
|
146
|
+
if self.is_readonly then
|
147
|
+
raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR,
|
148
|
+
'This node is readonly.' )
|
149
|
+
end
|
150
|
+
begin
|
151
|
+
substrs = split( offset )
|
152
|
+
rescue DOMException => err
|
153
|
+
raise DOMException.new( err )
|
154
|
+
end
|
155
|
+
@data = substrs[0] + arg + substrs[1]
|
156
|
+
return nil
|
157
|
+
end
|
158
|
+
|
159
|
+
# replaceData
|
160
|
+
#
|
161
|
+
# Replace the characters starting at the specified 16-bit unit offset with
|
162
|
+
# the specified string.
|
163
|
+
#
|
164
|
+
# Parameters
|
165
|
+
# offset of type unsigned long
|
166
|
+
# The offset from which to start replacing.
|
167
|
+
# count of type unsigned long
|
168
|
+
# The number of 16-bit units to replace. If the sum of offset and count
|
169
|
+
# exceeds length, then all 16-bit units to the end of the data are replaced;
|
170
|
+
# (i.e., the effect is the same as a remove method call with the same range,
|
171
|
+
# followed by an append method invocation).
|
172
|
+
# arg of type DOMString
|
173
|
+
# The DOMString with which the range must be replaced.
|
174
|
+
# Exceptions
|
175
|
+
# DOMException
|
176
|
+
# INDEX_SIZE_ERR: Raised if the specified offset is negative or greater
|
177
|
+
# than the number of 16-bit units in data, or if the specified count
|
178
|
+
# is negative.
|
179
|
+
# NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
|
180
|
+
# No Return Value
|
181
|
+
def replace_data( offset, count, arg )
|
182
|
+
if self.is_readonly then
|
183
|
+
raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR,
|
184
|
+
'This node is readonly.' )
|
185
|
+
end
|
186
|
+
begin
|
187
|
+
substrs = split( offset, count )
|
188
|
+
rescue DOMException => err
|
189
|
+
raise DOMException.new( err )
|
190
|
+
end
|
191
|
+
@data = substrs[0] + arg + substrs[2]
|
192
|
+
return nil
|
193
|
+
end
|
194
|
+
|
195
|
+
# substringData
|
196
|
+
#
|
197
|
+
# Extracts a range of data from the node.
|
198
|
+
#
|
199
|
+
# Parameters
|
200
|
+
# offset of type unsigned long
|
201
|
+
# Start offset of substring to extract.
|
202
|
+
# count of type unsigned long
|
203
|
+
# The number of 16-bit units to extract.
|
204
|
+
# Return Value
|
205
|
+
# DOMString
|
206
|
+
# The specified substring. If the sum of offset and count exceeds the length,
|
207
|
+
# then all 16-bit units to the end of the data are returned.
|
208
|
+
# Exceptions
|
209
|
+
# DOMException
|
210
|
+
# INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than
|
211
|
+
# the number of 16-bit units in data, or if the specified count is
|
212
|
+
# negative.
|
213
|
+
# DOMSTRING_SIZE_ERR: Raised if the specified range of text does not fit
|
214
|
+
# into a DOMString.
|
215
|
+
def substring_data( offset, count )
|
216
|
+
begin
|
217
|
+
substrs = split( offset, count )
|
218
|
+
rescue DOMException => err
|
219
|
+
raise DOMException.new( err )
|
220
|
+
end
|
221
|
+
return substrs[1]
|
222
|
+
end
|
223
|
+
|
224
|
+
|
225
|
+
def initialize( owner_document, value )
|
226
|
+
super( owner_document )
|
227
|
+
init_mod_child_node()
|
228
|
+
@data = value
|
229
|
+
end
|
230
|
+
|
231
|
+
private
|
232
|
+
def split( offset, count = nil )
|
233
|
+
if offset < 0 then
|
234
|
+
raise DOMException.new( DOMException::INDEX_SIZE_ERR,
|
235
|
+
'The specified offset is negative.' )
|
236
|
+
end
|
237
|
+
if /\A(.{#{offset}})(.*)\Z/mu =~ @data then
|
238
|
+
substr1 = ( $1 or '' )
|
239
|
+
substr2 = ( $2 or '' )
|
240
|
+
else
|
241
|
+
raise DOMException.new( DOMException::INDEX_SIZE_ERR,
|
242
|
+
'The specified offset is greater than the number of Character data.' )
|
243
|
+
end
|
244
|
+
if count.nil? then
|
245
|
+
return [substr1, substr2]
|
246
|
+
else
|
247
|
+
if count < 0 then
|
248
|
+
raise DOMException.new( DOMException::INDEX_SIZE_ERR,
|
249
|
+
'The specified count is negative.' )
|
250
|
+
end
|
251
|
+
if /\A(.{#{count}})(.*)\Z/mu =~ substr2 then
|
252
|
+
substr2 = ( $1 or '' )
|
253
|
+
substr3 = ( $2 or '' )
|
254
|
+
else
|
255
|
+
substr3 = ''
|
256
|
+
end
|
257
|
+
return [substr1, substr2, substr3]
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require "vcdom/minidom/node"
|
4
|
+
require "vcdom/minidom/character_data"
|
5
|
+
require "vcdom/minidom/mod_child_node"
|
6
|
+
require "vcdom/minidom/dom_exception"
|
7
|
+
|
8
|
+
module VCDOM
|
9
|
+
module MiniDOM
|
10
|
+
class Comment < CharacterData
|
11
|
+
|
12
|
+
# nodeType of type unsigned short, readonly
|
13
|
+
# A code representing the type of the underlying object, as defined above.
|
14
|
+
def node_type
|
15
|
+
return Node::COMMENT_NODE
|
16
|
+
end
|
17
|
+
|
18
|
+
# nodeName of type DOMString, readonly
|
19
|
+
# The name of this node, depending on its type; see the table above.
|
20
|
+
#
|
21
|
+
# Interface nodeName
|
22
|
+
# ------------------------------------------------------------
|
23
|
+
# Comment "#comment"
|
24
|
+
def node_name
|
25
|
+
return "#comment"
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize( owner_document, value )
|
29
|
+
super( owner_document, value )
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|