'From Squeak3.8 of ''5 May 2005'' [latest update: #6665] on 9 March 2010 at 8:52:22 am'! Object subclass: #HtmlEntity instanceVariableNames: 'contents attribs' classVariableNames: 'ReverseCharacterEntities' poolDictionaries: '' category: 'Network-HTML-Parser'! !HtmlEntity commentStamp: '' prior: 0! When HtmlParser runs, it generates a tree whose nodes are in HtmlEntity's subclasses. There is a separate class for most of the available elements in HTML, though some are grouped together under generic classes like HtmlBoldEntity. Methods of particular interest when modifying or adding subclasses are: ! !HtmlEntity methodsFor: 'contents' stamp: 'ls 6/25/1998 02:03'! addEntity: anEntity "add an entity to the receiver" contents add: anEntity! ! !HtmlEntity methodsFor: 'contents' stamp: 'ls 6/25/1998 02:02'! contents "return an ordered collection of this entity's contents" ^contents! ! !HtmlEntity methodsFor: 'contents' stamp: 'ls 10/26/1998 17:24'! removeEntity: anEntity "remove the specified entity" contents remove: anEntity! ! !HtmlEntity methodsFor: 'contents' stamp: 'ls 10/26/1998 17:25'! subEntities "return an ordered collection of this entity's contents" ^ contents! ! !HtmlEntity methodsFor: 'contents' stamp: 'ls 7/5/1998 00:37'! textualContents "return a string with the concatenated contents of all textual sub-entities" ^String streamContents: [ :s | contents do: [ :e | s nextPutAll: e textualContents ] ]! ! !HtmlEntity methodsFor: 'formatting' stamp: 'ls 6/25/1998 15:01'! addToFormatter: aFormatter "by default, just format our childer" contents do: [ :e | e addToFormatter: aFormatter ]! ! !HtmlEntity methodsFor: 'formatting' stamp: 'ls 7/15/1998 18:31'! parsingFinished "some entities need to make a final pass *after* parsing has finished and all the contents of each entity have been established; here is a place to do that" contents do: [ :e | e parsingFinished ].! ! !HtmlEntity methodsFor: 'accessing' stamp: 'djp 7/21/1998 16:21'! add: anObject "add an object to the receiver" (anObject isKindOf: String) ifTrue: [contents add: (HtmlTextEntity new text: anObject)] ifFalse: [contents add: anObject]! ! !HtmlEntity methodsFor: 'accessing' stamp: 'djp 7/21/1998 16:28'! attributes ^attribs ifNil: [attribs := HtmlAttributes new]! ! !HtmlEntity methodsFor: 'accessing' stamp: 'djp 7/21/1998 13:51'! at: key put: anObject self attributes ifNil: [self attributes: (HtmlAttributes new)]. (self attributes) at: key put: anObject! ! !HtmlEntity methodsFor: 'enumeration' stamp: 'ls 7/16/1998 23:17'! allSubentitiesDo: aBlock "perform the block recursively on all sub-entities" contents do: [ :e | aBlock value: e . e allSubentitiesDo: aBlock. ]. ! ! !HtmlEntity methodsFor: 'converting' stamp: 'djp 7/21/1998 11:58'! asHtml | aStream | aStream := WriteStream on: ''. self printHtmlOn: aStream. ^aStream contents.! ! !HtmlEntity methodsFor: 'attributes' stamp: 'ls 7/26/1998 19:59'! attributes: newAttributes "set all of the attributes at once. newAttributes should not be modified after passing it in" ^attribs _ newAttributes! ! !HtmlEntity methodsFor: 'attributes' stamp: 'ls 7/31/1998 02:55'! doesNotUnderstand: aMessage "treat the message as an attribute name" | selector | selector _ aMessage selector. selector asLowercase = selector ifFalse: [ "attribute accesses must be in all lowercase. This should cut down on some false doesNotUnderstand: traps" ^super doesNotUnderstand: aMessage ]. selector numArgs == 0 ifTrue: [ "return the named attribute" ^self getAttribute: selector asString default: nil ]. selector numArgs == 1 ifTrue: [ "set the named attribute" self setAttribute: (selector asString copyFrom: 1 to: (selector size-1)) to: aMessage argument. ^self ]. ^super doesNotUnderstand: aMessage! ! !HtmlEntity methodsFor: 'attributes' stamp: 'ls 8/5/1998 07:20'! getAttribute: name ^self getAttribute: name default: nil! ! !HtmlEntity methodsFor: 'attributes' stamp: 'ls 7/15/1998 18:52'! getAttribute: name default: anObject ^self getAttribute: name ifAbsent: [anObject]! ! !HtmlEntity methodsFor: 'attributes' stamp: 'ls 7/15/1998 18:51'! getAttribute: name ifAbsent: aBlock ^attribs at: name ifAbsent: aBlock! ! !HtmlEntity methodsFor: 'attributes' stamp: 'ls 7/17/1998 19:04'! name ^self getAttribute: 'name' default: nil! ! !HtmlEntity methodsFor: 'attributes' stamp: 'ls 7/31/1998 03:00'! setAttribute: name to: value "set the given attribute to the given value" attribs at: name asLowercase put: value! ! !HtmlEntity methodsFor: 'downloading' stamp: 'ls 7/29/1998 00:52'! downloadState: baseUrl "download any state needed for full rendering. eg, images need this" ! ! !HtmlEntity methodsFor: 'private-initialization' stamp: 'ls 7/31/1998 02:57'! initialize contents _ OrderedCollection new. attribs _ HtmlAttributes new.! ! !HtmlEntity methodsFor: 'private-initialization' stamp: 'djp 7/20/1998 20:52'! initialize: aTag self initialize. attribs _ HtmlAttributes newFrom: aTag attribs.! ! !HtmlEntity methodsFor: 'user interface' stamp: 'djp 7/21/1998 18:35'! inspect "Open an HtmlEntityInspector on the receiver. Use basicInspect to get a normal type of inspector." HtmlEntityInspector openOn: self withEvalPane: true! ! !HtmlEntity methodsFor: 'user interface' stamp: 'djp 7/21/1998 18:35'! inspectWithLabel: aLabel "Open a HtmlEntityInspector on the receiver. Use basicInspect to get a normal (less useful) type of inspector." HtmlEntityInspector openOn: self withEvalPane: true withLabel: aLabel! ! !HtmlEntity methodsFor: 'testing' stamp: 'bolot 11/4/1999 04:42'! isArea ^false! ! !HtmlEntity methodsFor: 'testing' stamp: 'ls 6/25/1998 03:02'! isBlockEntity ^false! ! !HtmlEntity methodsFor: 'testing' stamp: 'ls 7/4/1998 16:30'! isComment ^false! ! !HtmlEntity methodsFor: 'testing' stamp: 'ls 6/25/1998 02:20'! isDefinitionListElement "whether receiver can appear in a DefinitionList" ^false! ! !HtmlEntity methodsFor: 'testing' stamp: 'ls 7/16/1998 23:18'! isFormEntity ^false! ! !HtmlEntity methodsFor: 'testing' stamp: 'ls 6/25/1998 02:54'! isHeadElement "whether this can appear in a header" ^false! ! !HtmlEntity methodsFor: 'testing' stamp: 'ls 7/4/1998 12:55'! isHeader ^false! ! !HtmlEntity methodsFor: 'testing' stamp: 'ls 6/25/1998 02:18'! isListElement "is this an HtmlListElement, ie can it appear in a (non-definition) list?" ^false! ! !HtmlEntity methodsFor: 'testing' stamp: 'ls 6/25/1998 03:12'! isListItem "is this an HtmlListItem, ie can it appear in a (non-definition) list?" ^false! ! !HtmlEntity methodsFor: 'testing' stamp: 'ls 7/21/1998 07:33'! isOption "whether this is an