@@ -13,89 +13,187 @@ import CoreFoundation
13
13
@abstract Defines the order, repetition, and allowable values for a document
14
14
*/
15
15
public class NSXMLDTD : NSXMLNode {
16
+
17
+ internal var _xmlDTD : _CFXMLDTDPtr {
18
+ return _CFXMLDTDPtr ( _xmlNode)
19
+ }
16
20
17
- public convenience init ( contentsOfURL url: NSURL , options mask: Int ) throws { NSUnimplemented ( ) }
18
- public init ( data: NSData , options mask: Int ) throws { NSUnimplemented ( ) } //primitive
21
+ public convenience init ( contentsOfURL url: NSURL , options mask: Int ) throws {
22
+ guard let urlString = url. absoluteString else {
23
+ //TODO: throw an error
24
+ fatalError ( " nil URL " )
25
+ }
26
+
27
+ let node = _CFXMLParseDTD ( urlString)
28
+ if node == nil {
29
+ //TODO: throw error
30
+ fatalError ( " parsing dtd string failed " )
31
+ }
32
+ self . init ( ptr: node)
33
+ }
34
+
35
+ public convenience init ( data: NSData , options mask: Int ) throws {
36
+ var unmanagedError : Unmanaged < CFErrorRef > ? = nil
37
+ let node = _CFXMLParseDTDFromData ( data. _cfObject, & unmanagedError)
38
+ if node == nil {
39
+ if let error = unmanagedError? . takeRetainedValue ( ) . _nsObject {
40
+ throw error
41
+ }
42
+ }
43
+
44
+ self . init ( ptr: node)
45
+ } //primitive
19
46
20
47
/*!
21
48
@method publicID
22
49
@abstract Sets the public id. This identifier should be in the default catalog in /etc/xml/catalog or in a path specified by the environment variable XML_CATALOG_FILES. When the public id is set the system id must also be set.
23
50
*/
24
- public var publicID : String ? //primitive
51
+ public var publicID : String ? {
52
+ get {
53
+ return _CFXMLDTDExternalID ( _xmlDTD) ? . _swiftObject
54
+ }
55
+
56
+ set {
57
+ if let value = newValue {
58
+ _CFXMLDTDSetExternalID ( _xmlDTD, value)
59
+ } else {
60
+ _CFXMLDTDSetExternalID ( _xmlDTD, nil )
61
+ }
62
+ }
63
+ }
25
64
26
65
/*!
27
66
@method systemID
28
67
@abstract Sets the system id. This should be a URL that points to a valid DTD.
29
68
*/
30
- public var systemID : String ? //primitive
31
-
69
+ public var systemID : String ? {
70
+ get {
71
+ return _CFXMLDTDSystemID ( _xmlDTD) ? . _swiftObject
72
+ }
73
+
74
+ set {
75
+ if let value = newValue {
76
+ _CFXMLDTDSetSystemID ( _xmlDTD, value)
77
+ } else {
78
+ _CFXMLDTDSetSystemID ( _xmlDTD, nil )
79
+ }
80
+ }
81
+ }
82
+
32
83
/*!
33
84
@method insertChild:atIndex:
34
85
@abstract Inserts a child at a particular index.
35
86
*/
36
- public func insertChild( child: NSXMLNode , atIndex index: Int ) { NSUnimplemented ( ) } //primitive
87
+ public func insertChild( child: NSXMLNode , atIndex index: Int ) {
88
+ _insertChild ( child, atIndex: index)
89
+ } //primitive
37
90
38
91
/*!
39
92
@method insertChildren:atIndex:
40
93
@abstract Insert several children at a particular index.
41
94
*/
42
- public func insertChildren( children: [ NSXMLNode ] , atIndex index: Int ) { NSUnimplemented ( ) }
95
+ public func insertChildren( children: [ NSXMLNode ] , atIndex index: Int ) {
96
+ _insertChildren ( children, atIndex: index)
97
+ }
43
98
44
99
/*!
45
100
@method removeChildAtIndex:
46
101
@abstract Removes a child at a particular index.
47
102
*/
48
- public func removeChildAtIndex( index: Int ) { NSUnimplemented ( ) } //primitive
103
+ public func removeChildAtIndex( index: Int ) {
104
+ _removeChildAtIndex ( index)
105
+ } //primitive
49
106
50
107
/*!
51
108
@method setChildren:
52
109
@abstract Removes all existing children and replaces them with the new children. Set children to nil to simply remove all children.
53
110
*/
54
- public func setChildren( children: [ NSXMLNode ] ? ) { NSUnimplemented ( ) } //primitive
111
+ public func setChildren( children: [ NSXMLNode ] ? ) {
112
+ _setChildren ( children)
113
+ } //primitive
55
114
56
115
/*!
57
116
@method addChild:
58
117
@abstract Adds a child to the end of the existing children.
59
118
*/
60
- public func addChild( child: NSXMLNode ) { NSUnimplemented ( ) }
119
+ public func addChild( child: NSXMLNode ) {
120
+ _addChild ( child)
121
+ }
61
122
62
123
/*!
63
124
@method replaceChildAtIndex:withNode:
64
125
@abstract Replaces a child at a particular index with another child.
65
126
*/
66
- public func replaceChildAtIndex( index: Int , withNode node: NSXMLNode ) { NSUnimplemented ( ) }
127
+ public func replaceChildAtIndex( index: Int , withNode node: NSXMLNode ) {
128
+ _replaceChildAtIndex ( index, withNode: node)
129
+ }
67
130
68
131
/*!
69
132
@method entityDeclarationForName:
70
133
@abstract Returns the entity declaration matching this name.
71
134
*/
72
- public func entityDeclarationForName( name: String ) -> NSXMLDTDNode ? { NSUnimplemented ( ) } //primitive
135
+ public func entityDeclarationForName( name: String ) -> NSXMLDTDNode ? {
136
+ let node = _CFXMLDTDGetEntityDesc ( _xmlDTD, name)
137
+ if node == nil {
138
+ return nil
139
+ }
140
+ return NSXMLDTDNode . _objectNodeForNode ( node)
141
+ } //primitive
73
142
74
143
/*!
75
144
@method notationDeclarationForName:
76
145
@abstract Returns the notation declaration matching this name.
77
146
*/
78
- public func notationDeclarationForName( name: String ) -> NSXMLDTDNode ? { NSUnimplemented ( ) } //primitive
147
+ public func notationDeclarationForName( name: String ) -> NSXMLDTDNode ? {
148
+ let node = _CFXMLDTDGetNotationDesc ( _xmlDTD, name)
149
+
150
+ if node == nil {
151
+ return nil
152
+ }
153
+ return NSXMLDTDNode . _objectNodeForNode ( node)
154
+ } //primitive
79
155
80
156
/*!
81
157
@method elementDeclarationForName:
82
158
@abstract Returns the element declaration matching this name.
83
159
*/
84
- public func elementDeclarationForName( name: String ) -> NSXMLDTDNode ? { NSUnimplemented ( ) } //primitive
160
+ public func elementDeclarationForName( name: String ) -> NSXMLDTDNode ? {
161
+ let node = _CFXMLDTDGetElementDesc ( _xmlDTD, name)
162
+
163
+ if node == nil {
164
+ return nil
165
+ }
166
+ return NSXMLDTDNode . _objectNodeForNode ( node)
167
+ } //primitive
85
168
86
169
/*!
87
170
@method attributeDeclarationForName:
88
171
@abstract Returns the attribute declaration matching this name.
89
172
*/
90
- public func attributeDeclarationForName( name: String , elementName: String ) -> NSXMLDTDNode ? { NSUnimplemented ( ) } //primitive
173
+ public func attributeDeclarationForName( name: String , elementName: String ) -> NSXMLDTDNode ? {
174
+ let node = _CFXMLDTDGetAttributeDesc ( _xmlDTD, elementName, name)
175
+
176
+ if node == nil {
177
+ return nil
178
+ }
179
+ return NSXMLDTDNode . _objectNodeForNode ( node)
180
+ } //primitive
91
181
92
182
/*!
93
183
@method predefinedEntityDeclarationForName:
94
184
@abstract Returns the predefined entity declaration matching this name.
95
185
@discussion The five predefined entities are
96
186
<ul><li>&lt; - <</li><li>&gt; - ></li><li>&amp; - &</li><li>&quot; - "</li><li>&apos; - &</li></ul>
97
187
*/
98
- public class func predefinedEntityDeclarationForName( name: String ) -> NSXMLDTDNode ? { NSUnimplemented ( ) }
188
+ public class func predefinedEntityDeclarationForName( name: String ) -> NSXMLDTDNode ? {
189
+ let node = _CFXMLDTDGetPredefinedEntity ( name)
190
+
191
+ if node == nil {
192
+ return nil
193
+ }
194
+
195
+ return NSXMLDTDNode . _objectNodeForNode ( node)
196
+ }
99
197
100
198
internal override class func _objectNodeForNode( node: _CFXMLNodePtr ) -> NSXMLDTD {
101
199
precondition ( _CFXMLNodeGetType ( node) == _kCFXMLTypeDTD)
0 commit comments