[PATCH] Finish XML refactoring

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Finish XML refactoring

Paolo Bonzini
This patch finishes the refactoring of the XML package in five different
packages.  It is now possible to load XML-XMLNodeBuilder without loading
XML-XMLParser (which may mean, in a remote future, being able to use the
XSL engine with an Expat-based parser), and to load XML-SAXParser
without loading XML-DOM (because it does not make sense that you need
to).  In doing so, I removed one more abstract method from
XML-SAXParser.  Also, InputSource is a SAX defined class, so I moved it
up to XML-SAXDriver.

Paolo

* looking for [hidden email]--2004b/smalltalk--devo--2.2--patch-626 to compare with
* comparing to [hidden email]--2004b/smalltalk--devo--2.2--patch-626
M  packages/xml/builder/package.xml
M  packages/xml/parser/package.xml
M  packages/xml/saxparser/package.xml
M  packages/xml/dom/DOM.st
M  packages/xml/saxdriver/SAX.st
M  packages/xml/saxparser/Parser.st
M  packages.xml
M  packages/xml/ChangeLog
M  packages/xml/parser/XML.st

* modified files

--- orig/packages.xml
+++ mod/packages.xml
@@ -1,6 +1,7 @@
 <packages>
 <package>
   <name>XML</name>
+  <prereq>XML-XMLNodeBuilder</prereq>
   <prereq>XML-XMLParser</prereq>
 </package>
 


--- orig/packages/xml/ChangeLog
+++ mod/packages/xml/ChangeLog
@@ -1,10 +1,23 @@
 2007-11-06  Paolo Bonzini  <[hidden email]>
 
+ * saxdriver/SAX.st: Declare stub DOM_SAXDriver.  Move InputSource here...
+ * dom/DOM.st: ... from here.
+ * saxparser/Parser.st: Remove #pushSource:for: abstract method,
+ move #dtd (undoing part of the previous commit) and Entity>>#streamFor:...
+ * parser/XML.st: ... here as #pushSourceFor:.
+
+ * saxparser/package.xml: Remove XML-DOM dependency.
+ * parser/package.xml: Remove XML-XMLNodeBuilder dependency, add
+ XML-DOM dependency.
+ * builder/package.xml: Add XML-DOM dependency.
+
+2007-11-06  Paolo Bonzini  <[hidden email]>
+
  * saxparser/package.xml: Fix dependency.
  * parser/XMLParser.st: Remove #contentsOf:for:.  Test
  recursive expansion of entities in #pushSource:for:.  Add
  #wrapSourceInSpaces and use it instead of #streamFor:addSpaces:.
- Add #attributeTypeFor:subKey:from:.  Move dtd...
+ Add #attributeTypeFor:subKey:from:.  Move #dtd...
  * saxparser/Parser.st: ... here.  Port #mapEncoding: to gst.  Remove
  abstract methods #hasExpanded: and #contentsOf:for:.  Remove checks
  for recursive expansion of entities and #streamFor:addSpaces:.


--- orig/packages/xml/builder/package.xml
+++ mod/packages/xml/builder/package.xml
@@ -2,6 +2,7 @@
   <name>XML-XMLNodeBuilder</name>
   <namespace>XML</namespace>
 
+  <prereq>XML-DOM</prereq>
   <prereq>XML-SAXParser</prereq>
 
   <filein>NodeBuilder.st</filein>


--- orig/packages/xml/dom/DOM.st
+++ mod/packages/xml/dom/DOM.st
@@ -1941,69 +1941,6 @@ Instance Variables:
 ]
 
 
-Object subclass: InputSource [
-    | uri encoding stream |
-    
-    <category: 'XML-XML-Resources'>
-    <comment: '
-An InputSource represents a data source which may have been fetched
-locally or from the net, and which has various properties. An
-InputSource may be created by a SAXDriver in response to the
-#resolveEntity:systemID: message.
-
-In release 5i.4, we record the URI and the data, and if possible the
-encoding. In future we may want to also incorporate things like the
-MIME type or other attributes.
-
-Instance Variables:
-    uri <nil | NetClients.URL> The URI of the data source, if known
-    encoding <nil | Symbol> If the transport protocol specified an encoding,
-     this should take precedence over the encoding
-     contained in the <?xml?> declaration
-    stream <Stream> the data source'>
-
-    InputSource class >> for: uri [
- <category: 'private'>
- | stream |
- stream := NetClients.URIResolver openStreamOn: uri.
- ^self
-    uri: (uri isString ifTrue: [NetClients.URL fromString: uri] ifFalse: [uri])
-    encoding: nil
-    stream: stream
-    ]
-
-    InputSource class >> uri: aURI encoding: anEncodingName stream: aStream [
- <category: 'instance creation'>
- ^self new
-    uri: aURI
-    encoding: anEncodingName
-    stream: aStream
-    ]
-
-    uri: aURI encoding: anEncodingName stream: aStream [
- <category: 'initialize'>
- uri := aURI.
- encoding := anEncodingName.
- stream := aStream
-    ]
-
-    encoding [
- <category: 'accessing'>
- ^encoding
-    ]
-
-    stream [
- <category: 'accessing'>
- ^stream
-    ]
-
-    uri [
- <category: 'accessing'>
- ^uri
-    ]
-]
-
-
 SAXDriver extend [
     isValidating [
  "Allows a SAX driver to act like a parser when accessing a DocumentType"


--- orig/packages/xml/parser/XML.st
+++ mod/packages/xml/parser/XML.st
@@ -1749,7 +1749,7 @@ values exceed a particular value will al
 
 
 SAXParser subclass: XMLParser [
-    | sourceStack hereChar lastSource currentSource unresolvedIDREFs definedIDs latestID elementStack eol buffer nameBuffer |
+    | sourceStack dtd hereChar lastSource currentSource unresolvedIDREFs definedIDs latestID elementStack eol buffer nameBuffer |
     
     <category: 'XML-XML-Parsing'>
     <comment: '
@@ -1766,6 +1766,7 @@ Version 1.0 specification.
 
 Instance Variables:
     sourceStack <XML.StreamWrapper> stack of input streams that handles inclusion.
+    dtd                         <XML.DocumentType>      the document type definition for the current document
     hereChar <Character>   the current character being parsed
     lastSource <XML.StreamWrapper> record of previous source used to check correct nesting
     currentSource <XML.StreamWrapper> current input stream (the top of sourceStack)
@@ -2199,6 +2200,7 @@ Instance Variables:
  super on: dataSource.
  sourceStack := self wrapDataSource: dataSource.
  elementStack := OrderedCollection new.
+ dtd := DocumentType new.
  unresolvedIDREFs := Set new.
  definedIDs := Set new.
     ]
@@ -2221,6 +2223,11 @@ Instance Variables:
     from: self) isInternal: false
     ]
 
+    dtd [
+ <category: 'accessing'>
+ ^dtd
+    ]
+
     eol [
  <category: 'accessing'>
  ^eol
@@ -2334,6 +2341,23 @@ Instance Variables:
  self docTypeDecl ifTrue: [[self misc] whileTrue]
     ]
 
+    pushSourceFor: entity [
+        <category: 'entities'>
+        entity text == nil
+            ifTrue:
+                [| str input |
+                input := sax resolveEntity: entity publicID
+                            systemID: entity systemID.
+                input == nil ifTrue: [input := InputSource for: entity systemID].
+                self pushSource: input for: entity ]
+            ifFalse:
+                [self pushSource: (InputSource
+                                        uri: nil
+                                        encoding: nil
+                                        stream: entity text readStream)
+                        for: entity]
+    ]
+
     pushSource: anInputSource for: anEntity [
  | str |
         <category: 'api'>
@@ -2750,7 +2774,7 @@ Instance Variables:
     pushSource: (StreamWrapper emptyWithExtraSpace: refType ~= #data from: self).
  self getNextChar]]
     ifFalse:
- [exp streamFor: self.
+ [self pushSourceFor: exp.
  refType = #data ifFalse: [self wrapSourceInSpaces]].
  (refType ~= #data and: [self sourceWrapper uri notNil])
     ifTrue: [self sourceWrapper usedAsExternal: true].
@@ -3173,7 +3197,7 @@ Instance Variables:
     ifFalse:
  [self
     malformed: 'References to unparsed entities other than in an attribute of type ENTITY are not permitted'].
- exp streamFor: self]
+ self pushSourceFor: exp]
     ]
 
     getElement [


--- orig/packages/xml/parser/package.xml
+++ mod/packages/xml/parser/package.xml
@@ -2,7 +2,8 @@
   <name>XML-XMLParser</name>
   <namespace>XML</namespace>
 
-  <prereq>XML-XMLNodeBuilder</prereq>
+  <prereq>XML-SAXParser</prereq>
+  <prereq>XML-DOM</prereq>
 
   <filein>XML.st</filein>
   <file>XML.st</file>


--- orig/packages/xml/saxdriver/SAX.st
+++ mod/packages/xml/saxdriver/SAX.st
@@ -304,6 +304,14 @@ Instance Variables:
 ]
 
 
+SAXDriver subclass: DOM_SAXDriver [
+    <category: 'XML-XML-DOM'>
+    startElement [
+ self notYetImplemented
+    ]
+]
+
+
 SAXDriver subclass: SAXDispatcher [
     | contentHandler dtdHandler entityResolver errorHandler |
     
@@ -1048,3 +1056,66 @@ MalformedSignal subclass: BadCharacterSi
     <comment: nil>
 ]
 
+
+Object subclass: InputSource [
+    | uri encoding stream |
+    
+    <category: 'XML-XML-Resources'>
+    <comment: '
+An InputSource represents a data source which may have been fetched
+locally or from the net, and which has various properties. An
+InputSource may be created by a SAXDriver in response to the
+#resolveEntity:systemID: message.
+
+In release 5i.4, we record the URI and the data, and if possible the
+encoding. In future we may want to also incorporate things like the
+MIME type or other attributes.
+
+Instance Variables:
+    uri <nil | NetClients.URL> The URI of the data source, if known
+    encoding <nil | Symbol> If the transport protocol specified an encoding,
+     this should take precedence over the encoding
+     contained in the <?xml?> declaration
+    stream <Stream> the data source'>
+
+    InputSource class >> for: uri [
+ <category: 'private'>
+ | stream |
+ stream := NetClients.URIResolver openStreamOn: uri.
+ ^self
+    uri: (uri isString ifTrue: [NetClients.URL fromString: uri] ifFalse: [uri])
+    encoding: nil
+    stream: stream
+    ]
+
+    InputSource class >> uri: aURI encoding: anEncodingName stream: aStream [
+ <category: 'instance creation'>
+ ^self new
+    uri: aURI
+    encoding: anEncodingName
+    stream: aStream
+    ]
+
+    uri: aURI encoding: anEncodingName stream: aStream [
+ <category: 'initialize'>
+ uri := aURI.
+ encoding := anEncodingName.
+ stream := aStream
+    ]
+
+    encoding [
+ <category: 'accessing'>
+ ^encoding
+    ]
+
+    stream [
+ <category: 'accessing'>
+ ^stream
+    ]
+
+    uri [
+ <category: 'accessing'>
+ ^uri
+    ]
+]
+


--- orig/packages/xml/saxparser/Parser.st
+++ mod/packages/xml/saxparser/Parser.st
@@ -29,7 +29,7 @@
 
 
 Object subclass: SAXParser [
-    | sax dtd validating flags |
+    | sax validating flags |
     
     <category: 'XML-XML-SAX'>
     <comment: '
@@ -46,7 +46,6 @@ Version 1.0 specification.
 
 Instance Variables:
     sax <XML.SAXDriver> the output
-    dtd                         <XML.DocumentType>      the document type definition for the current document
     validating <Boolean> if true then the parse validates the XML
     flags <SmallInteger> sundry boolean values that are not accessed often enough
      to need separate instance variables.'>
@@ -113,7 +112,6 @@ Instance Variables:
  state of the parse, but retain those that
  relate to options."
  flags := flags bitAnd: 65535 bitInvert.
- dtd := DocumentType new.
     ]
 
     saxDriver: aSAXDriver [
@@ -127,11 +125,6 @@ Instance Variables:
  ^sax document
     ]
 
-    dtd [
- <category: 'accessing'>
- ^dtd
-    ]
-
     saxDriver [
  <category: 'accessing'>
  ^sax
@@ -147,11 +140,6 @@ Instance Variables:
  ^validating
     ]
 
-    pushSource: anInputSource for: anEntity [
-        <category: 'api'>
- self subclassResponsibility
-    ]
-
     scanDocument [
  <category: 'api'>
  self subclassResponsibility
@@ -415,26 +403,6 @@ Instance Variables:
 
 
 
-Entity extend [
-    streamFor: aParser [
- <category: 'accessing'>
- text == nil
-    ifTrue:
- [| str input |
- input := aParser saxDriver resolveEntity: self publicID
-    systemID: self systemID.
- input == nil ifTrue: [input := InputSource for: self systemID].
- aParser pushSource: input for: self]
-    ifFalse:
- [aParser pushSource: (InputSource
-        uri: nil
-        encoding: nil
-        stream: text readStream)
- for: self]
-    ]
-]
-
-
 SAXException subclass: SAXNotRecognizedException [
     
     <category: 'XML-XML-Exceptions'>


--- orig/packages/xml/saxparser/package.xml
+++ mod/packages/xml/saxparser/package.xml
@@ -3,7 +3,6 @@
   <namespace>XML</namespace>
 
   <prereq>XML-SAXDriver</prereq>
-  <prereq>XML-DOM</prereq>
 
   <filein>Parser.st</filein>
   <file>Parser.st</file>




_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk