vcdom 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. data/lib/vcdom/attr.rb +70 -0
  2. data/lib/vcdom/attr_node_map.rb +30 -0
  3. data/lib/vcdom/attr_ns.rb +38 -0
  4. data/lib/vcdom/character_data.rb +22 -0
  5. data/lib/vcdom/child.rb +53 -0
  6. data/lib/vcdom/document.rb +126 -0
  7. data/lib/vcdom/element.rb +332 -0
  8. data/lib/vcdom/element_ns.rb +44 -0
  9. data/lib/vcdom/node.rb +278 -0
  10. data/lib/vcdom/node_list.rb +32 -0
  11. data/lib/vcdom/parent.rb +126 -0
  12. data/lib/vcdom/text.rb +23 -0
  13. data/lib/vcdom/xml_parser.rb +368 -0
  14. data/lib/vcdom/xml_serializer.rb +55 -0
  15. metadata +48 -81
  16. data/History.txt +0 -4
  17. data/Manifest.txt +0 -34
  18. data/PostInstall.txt +0 -7
  19. data/README.rdoc +0 -51
  20. data/Rakefile +0 -26
  21. data/lib/vcdom/minidom/attr.rb +0 -139
  22. data/lib/vcdom/minidom/attr_ns.rb +0 -47
  23. data/lib/vcdom/minidom/cdata_section.rb +0 -34
  24. data/lib/vcdom/minidom/character_data.rb +0 -263
  25. data/lib/vcdom/minidom/comment.rb +0 -34
  26. data/lib/vcdom/minidom/document.rb +0 -245
  27. data/lib/vcdom/minidom/dom_exception.rb +0 -51
  28. data/lib/vcdom/minidom/dom_implementation.rb +0 -214
  29. data/lib/vcdom/minidom/element.rb +0 -512
  30. data/lib/vcdom/minidom/element_ns.rb +0 -42
  31. data/lib/vcdom/minidom/mini_parser.rb +0 -9
  32. data/lib/vcdom/minidom/mini_serializer.rb +0 -118
  33. data/lib/vcdom/minidom/minidom_standard_error.rb +0 -9
  34. data/lib/vcdom/minidom/mod_child_node.rb +0 -51
  35. data/lib/vcdom/minidom/mod_elements_getter.rb +0 -49
  36. data/lib/vcdom/minidom/mod_namespaceuri_manageable.rb +0 -152
  37. data/lib/vcdom/minidom/mod_parent_node.rb +0 -307
  38. data/lib/vcdom/minidom/named_node_map_attr.rb +0 -277
  39. data/lib/vcdom/minidom/node.rb +0 -178
  40. data/lib/vcdom/minidom/node_list.rb +0 -41
  41. data/lib/vcdom/minidom/text.rb +0 -77
  42. data/lib/vcdom/minidom/xml_reg_exp.rb +0 -39
  43. data/lib/vcdom/minidom.rb +0 -9
  44. data/lib/vcdom.rb +0 -6
  45. data/script/console +0 -10
  46. data/script/destroy +0 -14
  47. data/script/generate +0 -14
  48. data/test/test_helper.rb +0 -3
  49. data/test/test_vcdom.rb +0 -11
@@ -1,245 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # ソースコードのエンコーディング指定
3
-
4
- require "vcdom/minidom/node"
5
- require "vcdom/minidom/text"
6
- require "vcdom/minidom/element"
7
- require "vcdom/minidom/element_ns"
8
- require "vcdom/minidom/attr"
9
- require "vcdom/minidom/attr_ns"
10
- require "vcdom/minidom/comment"
11
- require "vcdom/minidom/cdata_section"
12
- require "vcdom/minidom/mod_parent_node"
13
- require "vcdom/minidom/mod_elements_getter"
14
-
15
- module VCDOM
16
- module MiniDOM
17
- class Document < Node
18
-
19
- include ModParentNode
20
- include ModElementsGetter
21
- #include Const
22
-
23
- def node_type; return Node::DOCUMENT_NODE end
24
- def node_name; return "#document" end
25
- def text_content; return nil end
26
- def text_content=( value ); end
27
- def implementation; return DOMImplementation.get_instance() end
28
-
29
- # documentElement of type Element, readonly
30
- # This is a convenience attribute that allows direct access to the child node
31
- # that is the document element of the document.
32
- def document_element; return @document_element end
33
-
34
- def append_child( new_child )
35
- super( new_child )
36
- case new_child.node_type
37
- when Node::ELEMENT_NODE then
38
- @document_element = new_child
39
- when Node::DOCUMENT_TYPE_NODE then
40
- @doctype = new_child
41
- end
42
- end
43
- def remove_child( old_child )
44
- super( old_child )
45
- case old_child.node_type
46
- when Node::ELEMENT_NODE then
47
- @document_element = nil
48
- when Node::DOCUMENT_TYPE_NODE then
49
- @doctype = nil
50
- end
51
- end
52
-
53
- def create_element( tagname )
54
- return Element.new( self, tagname )
55
- end
56
-
57
- # createElementNS introduced in DOM Level 2
58
- # Creates an element of the given qualified name and namespace URI.
59
- # Per [XML Namespaces], applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.
60
- #
61
- # Parameters
62
- # namespaceURI of type DOMString : The namespace URI of the element to create.
63
- # qualifiedName of type DOMString : The qualified name of the element type to instantiate.
64
- # Return Value
65
- # Element :
66
- # A new Element object with the following attributes:
67
- # Attribute Value
68
- # ----------------------------------------
69
- # Node.nodeName qualifiedName
70
- # Node.namespaceURI namespaceURI
71
- # Node.prefix prefix, extracted from qualifiedName, or null if there is no prefix
72
- # Node.localName local name, extracted from qualifiedName
73
- # Element.tagName qualifiedName
74
- # Exceptions
75
- # DOMException
76
- # INVALID_CHARACTER_ERR: Raised if the specified qualifiedName is not an
77
- # XML name according to the XML version in use specified in
78
- # the Document.xmlVersion attribute.
79
- # NAMESPACE_ERR: Raised if the qualifiedName is a malformed qualified name,
80
- # if the qualifiedName has a prefix and the namespaceURI is null,
81
- # or if the qualifiedName has a prefix that is "xml" and the
82
- # namespaceURI is different from
83
- # "http://www.w3.org/XML/1998/namespace" [XML Namespaces], or
84
- # if the qualifiedName or its prefix is "xmlns" and the
85
- # namespaceURI is different from "http://www.w3.org/2000/xmlns/",
86
- # or if the namespaceURI is "http://www.w3.org/2000/xmlns/" and
87
- # neither the qualifiedName nor its prefix is "xmlns".
88
- # NOT_SUPPORTED_ERR: Always thrown if the current document does not support
89
- # the "XML" feature, since namespaces were defined by XML.
90
- def create_element_ns( namespace_uri, qualified_name )
91
- return ElementNS.new( self, namespace_uri, qualified_name )
92
- end
93
-
94
- # createAttribute
95
- # Creates an Attr of the given name. Note that the Attr instance can then be set on an Element
96
- # using the setAttributeNode method.
97
- # To create an attribute with a qualified name and namespace URI, use the createAttributeNS method.
98
- #
99
- # Parameters
100
- # name of type DOMString
101
- # The name of the attribute.
102
- # Return Value
103
- # Attr
104
- # A new Attr object with the nodeName attribute set to name, and localName, prefix,
105
- # and namespaceURI set to null. The value of the attribute is the empty string.
106
- # Exceptions
107
- # DOMException
108
- # INVALID_CHARACTER_ERR: Raised if the specified name is not an XML name
109
- # according to the XML version in use specified in the Document.xmlVersion attribute.
110
- def create_attribute( name )
111
- return Attr.new( self, name )
112
- end
113
-
114
- # createAttributeNS introduced in DOM Level 2
115
- #
116
- # Creates an attribute of the given qualified name and namespace URI.
117
- # Per [XML Namespaces], applications must use the value null as the namespaceURI parameter
118
- # for methods if they wish to have no namespace.
119
- #
120
- # Parameters
121
- # namespaceURI of type DOMString
122
- # The namespace URI of the attribute to create.
123
- # qualifiedName of type DOMString
124
- # The qualified name of the attribute to instantiate.
125
- # Return Value
126
- # Attr
127
- # A new Attr object with the following attributes:
128
- # Attribute Value
129
- # ---------------------------------------------------------------
130
- # Node.nodeName qualifiedName
131
- # Node.namespaceURI namespaceURI
132
- # Node.prefix prefix, extracted from qualifiedName, or null if there is no prefix
133
- # Node.localName local name, extracted from qualifiedName
134
- # Attr.name qualifiedName
135
- # Node.nodeValue the empty string
136
- # Exceptions
137
- # DOMException
138
- # INVALID_CHARACTER_ERR: Raised if the specified qualifiedName is not an XML name according
139
- # to the XML version in use specified in the Document.xmlVersion attribute.
140
- # NAMESPACE_ERR: Raised if the qualifiedName is a malformed qualified name,
141
- # if the qualifiedName has a prefix and the namespaceURI is null,
142
- # if the qualifiedName has a prefix that is "xml" and the namespaceURI is different
143
- # from "http://www.w3.org/XML/1998/namespace", if the qualifiedName or its prefix is
144
- # "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/",
145
- # or if the namespaceURI is "http://www.w3.org/2000/xmlns/" and
146
- # neither the qualifiedName nor its prefix is "xmlns".
147
- # #=> QName が奇形の場合, QName が接頭辞を持ちながら名前空間 URI が null の場合, QName の接頭辞が
148
- # #=> "xml" なのに名前空間 URI が "http://www.w3.org/XML/1998/namespace" ではない場合,
149
- # #=> QName の接頭辞が "xmlns" にもかかわらず名前空間 URI が "http://www.w3.org/2000/xmlns/"
150
- # #=> ではないとき, そして名前空間 URI が "http://www.w3.org/2000/xmlns/" なのに, QName または接頭辞が
151
- # #=> "xmlns" ではないとき例外発生.
152
- # NOT_SUPPORTED_ERR: Always thrown if the current document does not support the "XML" feature,
153
- # since namespaces were defined by XML.
154
- def create_attribute_ns( namespace_uri, qualified_name )
155
- return AttrNS.new( self, namespace_uri, qualified_name )
156
- end
157
-
158
- # createTextNode
159
- # Creates a Text node given the specified string.
160
- #
161
- # Parameters
162
- # data of type DOMString
163
- # The data for the node.
164
- # Return Value
165
- # Text
166
- # The new Text object.
167
- # No Exceptions
168
- def create_text_node( data )
169
- return Text.new( self, data )
170
- end
171
-
172
- # createCDATASection
173
- #
174
- # Creates a CDATASection node whose value is the specified string.
175
- #
176
- # Parameters
177
- # data of type DOMString
178
- # The data for the CDATASection contents.
179
- # Return Value
180
- # CDATASection
181
- # The new CDATASection object.
182
- # Exceptions
183
- # DOMException
184
- # NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
185
- def create_cdata_section( data )
186
- return CDATASection.new( self, data )
187
- end
188
-
189
- # createComment
190
- #
191
- # Creates a Comment node given the specified string.
192
- #
193
- # Parameters
194
- # data of type DOMString
195
- # The data for the node.
196
- # Return Value
197
- # Comment
198
- # The new Comment object.
199
- # No Exceptions
200
- def create_comment( data )
201
- return Comment.new( self, data )
202
- end
203
-
204
- # ===== コンストラクタ =====
205
-
206
- #def initialize( aDOMImplementation, aNamespaceURI, aQualifiedName, aDoctype )
207
- def initialize()
208
- super(nil)
209
- init_mod_parent_node()
210
- @doctype = nil
211
- @document_element = nil
212
- end
213
-
214
- private
215
- def check_hierarchy( new_child )
216
- # Element (maximum of one), ProcessingInstruction, Comment, DocumentType (maximum of one)
217
- super( new_child, true )
218
- case new_child.node_type
219
- when Node::ELEMENT_NODE then
220
- if @document_element.nil? or @document_element.equal? new_child then
221
- return true
222
- else
223
- raise DOMException.new( DOMException::HIERARCHY_REQUEST_ERR,
224
- 'This Document node already has an Element node. A second Element node can\'t be appended to a Document node.' )
225
- end
226
- when Node::DOCUMENT_TYPE_NODE then
227
- if @doctype.nil? or @doctype.equal? new_child then
228
- return true
229
- else
230
- raise DOMException.new( DOMException::HIERARCHY_REQUEST_ERR,
231
- 'This Document node already has an DocumentType node. A second DocumentType node can\'t be appended to a Document node.' )
232
- end
233
- when Node::COMMENT_NODE then
234
- return true
235
- when Node::PROCESSING_INSTRUCTION_NODE then
236
- return true
237
- else
238
- raise DOMException.new( DOMException::HIERARCHY_REQUEST_ERR,
239
- 'This node is of a type that does not allow children of the type of the newChild node.' )
240
- end
241
- end
242
-
243
- end
244
- end
245
- end
@@ -1,51 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # ソースコードのエンコーディング指定
3
-
4
- #require "vcdom/const"
5
- require "vcdom/minidom/minidom_standard_error"
6
-
7
- module VCDOM
8
- module MiniDOM
9
- class DOMException < MiniDOMStandardError
10
-
11
- #include Const::DOMException
12
- # ExceptionCode
13
- INDEX_SIZE_ERR = 1;
14
- DOMSTRING_SIZE_ERR = 2;
15
- HIERARCHY_REQUEST_ERR = 3;
16
- WRONG_DOCUMENT_ERR = 4;
17
- INVALID_CHARACTER_ERR = 5;
18
- NO_DATA_ALLOWED_ERR = 6;
19
- NO_MODIFICATION_ALLOWED_ERR = 7;
20
- NOT_FOUND_ERR = 8;
21
- NOT_SUPPORTED_ERR = 9;
22
- INUSE_ATTRIBUTE_ERR = 10;
23
- INVALID_STATE_ERR = 11;
24
- SYNTAX_ERR = 12;
25
- INVALID_MODIFICATION_ERR = 13;
26
- NAMESPACE_ERR = 14;
27
- INVALID_ACCESS_ERR = 15;
28
- VALIDATION_ERR = 16;
29
- TYPE_MISMATCH_ERR = 17;
30
-
31
- # ===== インスタンス変数 =====
32
- def code; return @code end
33
-
34
- # ===== コンストラクタ =====
35
-
36
- def initialize( err_code, err_message = '' )
37
- if err_code.is_a? DOMException then
38
- err_message = err_code.message
39
- err_code = err_code.code
40
- end
41
- super( err_message )
42
- @code = err_code
43
- end
44
-
45
- # ===== 内部メソッド =====
46
-
47
- # ===== 上書き =====
48
-
49
- end
50
- end
51
- end
@@ -1,214 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require "vcdom/minidom/document"
4
- #require "vcdom/minidom/document_type"
5
- require "vcdom/minidom/dom_exception"
6
-
7
- require "vcdom/minidom/mini_parser"
8
- require "vcdom/minidom/mini_serializer"
9
- require "vcdom/minidom/xml_reg_exp"
10
-
11
- =begin
12
- Interface DOMImplementation
13
-
14
- The DOMImplementation interface provides a number of methods for performing
15
- operations that are independent of any particular instance of the document object model.
16
-
17
- IDL Definition
18
-
19
- interface DOMImplementation {
20
- boolean hasFeature(in DOMString feature,
21
- in DOMString version);
22
- // Introduced in DOM Level 2:
23
- DocumentType createDocumentType(in DOMString qualifiedName,
24
- in DOMString publicId,
25
- in DOMString systemId)
26
- raises(DOMException);
27
- // Introduced in DOM Level 2:
28
- Document createDocument(in DOMString namespaceURI,
29
- in DOMString qualifiedName,
30
- in DocumentType doctype)
31
- raises(DOMException);
32
- // Introduced in DOM Level 3:
33
- DOMObject getFeature(in DOMString feature,
34
- in DOMString version);
35
- };
36
-
37
- =end
38
-
39
- module VCDOM
40
- module MiniDOM
41
- class DOMImplementation
42
-
43
- @@instance = nil
44
-
45
- def mini_parser
46
- return @mini_parser
47
- end
48
- def mini_serializer
49
- return @mini_serializer
50
- end
51
-
52
- # ===== Methods =====
53
-
54
- # createDocument introduced in DOM Level 2
55
- #
56
- # Creates a DOM Document object of the specified type with its document element.
57
- # Note that based on the DocumentType given to create the document,
58
- # the implementation may instantiate specialized Document objects that support
59
- # additional features than the "Core", such as "HTML" [DOM Level 2 HTML].
60
- # On the other hand, setting the DocumentType after the document was
61
- # created makes this very unlikely to happen.
62
- # Alternatively, specialized Document creation methods, such as createHTMLDocument
63
- # [DOM Level 2 HTML], can be used to obtain specific types of Document objects.
64
- #
65
- # Parameters
66
- # namespaceURI of type DOMString
67
- # The namespace URI of the document element to create or null.
68
- # qualifiedName of type DOMString
69
- # The qualified name of the document element to be created or null.
70
- # doctype of type DocumentType
71
- # The type of document to be created or null.
72
- # When doctype is not null, its Node.ownerDocument attribute is set to
73
- # the document being created.
74
- # Return Value
75
- # Document
76
- # A new Document object with its document element.
77
- # If the NamespaceURI, qualifiedName, and doctype are null, the returned
78
- # Document is empty with no document element.
79
- # Exceptions
80
- # DOMException
81
- # INVALID_CHARACTER_ERR: Raised if the specified qualified name is not an
82
- # XML name according to [XML 1.0].
83
- # NAMESPACE_ERR: Raised if the qualifiedName is malformed, if the
84
- # qualifiedName has a prefix and the namespaceURI is null,
85
- # or if the qualifiedName is null and the namespaceURI is
86
- # different from null, or if the qualifiedName has a prefix
87
- # that is "xml" and the namespaceURI is different from
88
- # "http://www.w3.org/XML/1998/namespace" [XML Namespaces],
89
- # or if the DOM implementation does not support the "XML" feature
90
- # but a non-null namespace URI was provided, since namespaces were
91
- # defined by XML.
92
- # WRONG_DOCUMENT_ERR: Raised if doctype has already been used with a different
93
- # document or was created from a different implementation.
94
- # NOT_SUPPORTED_ERR: May be raised if the implementation does not support
95
- # the feature "XML" and the language exposed through the Document
96
- # does not support XML Namespaces (such as [HTML 4.01]).
97
- def create_document( namespace_uri, qualified_name, doctype = nil )
98
- # 第 3 引数が nil でなければエラー
99
- if ! doctype.nil? then
100
- raise TypeError.new( 'This DOM implementation does not support a Doctype, so the third argument must be null.' )
101
- end
102
- doc = Document.new()
103
- if qualified_name.nil? and ! namespace_uri.nil? then
104
- # the qualified name is null, but namespace URI is different from null
105
- raise DOMException.new( DOMException::NAMESPACE_ERR,
106
- 'The qualified name is null, but namespace URI is different from null.' )
107
- end
108
- if ! qualified_name.nil? then
109
- doc.append_child( doc.create_element_ns( namespace_uri, qualified_name ) )
110
- end
111
- #doc._set_document_type( doctype )
112
- #doc._set_document_element( doc.create_element_ns( namespace_uri, qualified_name ) )
113
- # doctype の ownerDocument を設定
114
- #aDoctype._setOwnerDocument( doc ) if ( aDoctype != nil )
115
- return doc
116
- end
117
- #alias :createDocument :create_document
118
-
119
- # createDocumentType introduced in DOM Level 2
120
- #
121
- # Creates an empty DocumentType node.
122
- # Entity declarations and notations are not made available.
123
- # Entity reference expansions and default attribute additions do not occur..
124
- #
125
- # Parameters
126
- # qualifiedName of type DOMString
127
- # The qualified name of the document type to be created.
128
- # publicId of type DOMString
129
- # The external subset public identifier.
130
- # systemId of type DOMString
131
- # The external subset system identifier.
132
- # Return Value
133
- # DocumentType
134
- # A new DocumentType node with Node.ownerDocument set to null.
135
- # Exceptions
136
- # DOMException
137
- # INVALID_CHARACTER_ERR: Raised if the specified qualified name is not
138
- # an XML name according to [XML 1.0].
139
- # NAMESPACE_ERR: Raised if the qualifiedName is malformed.
140
- # NOT_SUPPORTED_ERR: May be raised if the implementation does not support
141
- # the feature "XML" and the language exposed through the Document
142
- # does not support XML Namespaces (such as [HTML 4.01]).
143
- #def create_document_type( qualified_name, public_id, system_id )
144
- #return DocumentType.new( qualified_name, public_id, system_id )
145
- #end
146
- #alias :createDocumentType :create_document_type
147
-
148
- =begin
149
-
150
- # getFeature introduced in DOM Level 3
151
- #
152
- # This method returns a specialized object which implements the specialized
153
- # APIs of the specified feature and version, as specified in DOM Features.
154
- # The specialized object may also be obtained by using binding-specific
155
- # casting methods but is not necessarily expected to, as discussed in Mixed
156
- # DOM Implementations.
157
- # This method also allow the implementation to provide specialized objects
158
- # which do not support the DOMImplementation interface.
159
- #
160
- # Parameters
161
- # feature of type DOMString
162
- # The name of the feature requested.
163
- # Note that any plus sign "+" prepended to the name of the feature will
164
- # be ignored since it is not significant in the context of this method.
165
- # version of type DOMString
166
- # This is the version number of the feature to test.
167
- # Return Value
168
- # DOMObject
169
- # Returns an object which implements the specialized APIs of the specified
170
- # feature and version, if any, or null if there is no object which implements
171
- # interfaces associated with that feature.
172
- # If the DOMObject returned by this method implements the DOMImplementation
173
- # interface, it must delegate to the primary core DOMImplementation and not
174
- # return results inconsistent with the primary core DOMImplementation such
175
- # as hasFeature, getFeature, etc.
176
- # No Exceptions
177
-
178
- # hasFeature
179
- #
180
- # Test if the DOM implementation implements a specific feature and version,
181
- # as specified in DOM Features.
182
- #
183
- # Parameters
184
- # feature of type DOMString
185
- # The name of the feature to test.
186
- # version of type DOMString
187
- # This is the version number of the feature to test.
188
- # Return Value
189
- # boolean
190
- # true if the feature is implemented in the specified version, false otherwise.
191
- # No Exceptions
192
-
193
- =end
194
-
195
- def initialize()
196
- if ! @@instance.nil? then
197
- raise "既にインスタンス化されています"
198
- end
199
- @@instance = self
200
- @mini_parser = MiniParser.new()
201
- @mini_serializer = MiniSerializer.new()
202
- end
203
-
204
- def self.get_instance()
205
- if @@instance.nil? then
206
- return self.new()
207
- else
208
- return @@instance
209
- end
210
- end
211
-
212
- end
213
- end
214
- end