Document.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #import "Document.h"
  2. #import "Document+Mutable.h"
  3. #import "DOMHelperUtilities.h"
  4. #import "NodeList+Mutable.h" // needed for access to underlying array, because SVG doesnt specify how lists are made mutable
  5. #import "SVGKDefine_Private.h"
  6. @implementation Document
  7. @synthesize doctype;
  8. @synthesize implementation;
  9. @synthesize documentElement;
  10. -(Element*) createElement:(NSString*) tagName
  11. {
  12. Element* newElement = [[Element alloc] initWithLocalName:tagName attributes:nil];
  13. SVGKitLogVerbose( @"[%@] WARNING: SVG Spec, missing feature: if there are known attributes with default values, Attr nodes representing them SHOULD BE automatically created and attached to the element.", [self class] );
  14. return newElement;
  15. }
  16. -(DocumentFragment*) createDocumentFragment
  17. {
  18. return [[DocumentFragment alloc] init];
  19. }
  20. -(Text*) createTextNode:(NSString*) data
  21. {
  22. return [[Text alloc] initWithValue:data];
  23. }
  24. -(Comment*) createComment:(NSString*) data
  25. {
  26. return [[Comment alloc] initWithValue:data];
  27. }
  28. -(CDATASection*) createCDATASection:(NSString*) data
  29. {
  30. return [[CDATASection alloc] initWithValue:data];
  31. }
  32. -(ProcessingInstruction*) createProcessingInstruction:(NSString*) target data:(NSString*) data
  33. {
  34. return [[ProcessingInstruction alloc] initProcessingInstruction:target value:data];
  35. }
  36. -(Attr*) createAttribute:(NSString*) n
  37. {
  38. return [[Attr alloc] initWithName:n value:@""];
  39. }
  40. -(EntityReference*) createEntityReference:(NSString*) data
  41. {
  42. NSAssert( FALSE, @"Not implemented. According to spec: Creates an EntityReference object. In addition, if the referenced entity is known, the child list of the EntityReference node is made the same as that of the corresponding Entity node. Note: If any descendant of the Entity node has an unbound namespace prefix, the corresponding descendant of the created EntityReference node is also unbound; (its namespaceURI is null). The DOM Level 2 does not support any mechanism to resolve namespace prefixes." );
  43. return nil;
  44. }
  45. -(NodeList*) getElementsByTagName:(NSString*) data
  46. {
  47. NodeList* accumulator = [[NodeList alloc] init];
  48. [DOMHelperUtilities privateGetElementsByName:data inNamespace:nil childrenOfElement:self.documentElement addToList:accumulator];
  49. return accumulator;
  50. }
  51. // Introduced in DOM Level 2:
  52. -(Node*) importNode:(Node*) importedNode deep:(BOOL) deep
  53. {
  54. NSAssert( FALSE, @"Not implemented." );
  55. return nil;
  56. }
  57. // Introduced in DOM Level 2:
  58. -(Element*) createElementNS:(NSString*) namespaceURI qualifiedName:(NSString*) qualifiedName
  59. {
  60. Element* newElement = [[Element alloc] initWithQualifiedName:qualifiedName inNameSpaceURI:namespaceURI attributes:nil];
  61. SVGKitLogVerbose( @"[%@] WARNING: SVG Spec, missing feature: if there are known attributes with default values, Attr nodes representing them SHOULD BE automatically created and attached to the element.", [self class] );
  62. return newElement;
  63. }
  64. // Introduced in DOM Level 2:
  65. -(Attr*) createAttributeNS:(NSString*) namespaceURI qualifiedName:(NSString*) qualifiedName
  66. {
  67. NSAssert( FALSE, @"This should be re-implemented to share code with createElementNS: method above" );
  68. Attr* newAttr = [[Attr alloc] initWithNamespace:namespaceURI qualifiedName:qualifiedName value:@""];
  69. return newAttr;
  70. }
  71. // Introduced in DOM Level 2:
  72. -(NodeList*) getElementsByTagNameNS:(NSString*) namespaceURI localName:(NSString*) localName
  73. {
  74. NodeList* accumulator = [[NodeList alloc] init];
  75. [DOMHelperUtilities privateGetElementsByName:localName inNamespace:namespaceURI childrenOfElement:self.documentElement addToList:accumulator];
  76. return accumulator;
  77. }
  78. // Introduced in DOM Level 2:
  79. -(Element*) getElementById:(NSString*) elementId
  80. {
  81. return [DOMHelperUtilities privateGetElementById:elementId childrenOfElement:self.documentElement];
  82. }
  83. @end