'From Squeak3.11alpha of 13 February 2010 [latest update: #9371] on 16 February 2010 at 11:13:37 am'! Installer subclass: #InstallerInternetBased instanceVariableNames: 'url pageDataStream markers' classVariableNames: 'Entities' poolDictionaries: '' category: 'Installer-Core'! !InstallerInternetBased methodsFor: 'class references' stamp: 'sd 3/6/2008 20:16'! classHTTPSocket ^Smalltalk at: #HTTPSocket ifAbsent: [ self error: 'Network package not present' ]! ! !InstallerInternetBased methodsFor: 'as yet unclassified' stamp: 'kph 12/9/2008 03:07'! extractFromHtml: html option: allOrLast | start stop test in | start := self markersBegin. stop := self markersEnd. test := self markersTest. in := ReadWriteStream with: String new. [ html upToAll: start; atEnd ] whileFalse: [ | chunk | (allOrLast == #last) ifTrue: [ in resetToStart ]. chunk := html upToAll: stop. self isSkipLoadingTestsSet ifTrue: [ chunk := chunk readStream upToAll: test ]. in nextPutAll: chunk. ]. ^self removeHtmlMarkupFrom: in reset ! ! !InstallerInternetBased methodsFor: 'as yet unclassified' stamp: 'kph 12/9/2008 03:07'! markers ^ markers ifNil: [ '..."test ...' ]! ! !InstallerInternetBased methodsFor: 'as yet unclassified' stamp: 'kph 12/9/2008 03:07'! markers: anObject markers := anObject! ! !InstallerInternetBased methodsFor: 'as yet unclassified' stamp: 'kph 12/9/2008 03:08'! markersBegin ^ self markers copyUpTo: $.! ! !InstallerInternetBased methodsFor: 'as yet unclassified' stamp: 'kph 12/9/2008 03:08'! markersEnd "return the third marker or the second if there are only two" | str a | str := self markers readStream. a := str upToAll: '...'; upToAll: '...'. str atEnd ifTrue: [ ^a ] ifFalse: [ ^str upToEnd ] ! ! !InstallerInternetBased methodsFor: 'as yet unclassified' stamp: 'kph 12/9/2008 03:08'! markersTest ^ self markers readStream upToAll: '...'; upToAll: '...'! ! !InstallerInternetBased methodsFor: 'as yet unclassified' stamp: 'kph 12/9/2008 03:08'! removeHtmlMarkupFrom: in | out | out := ReadWriteStream on: (String new: 100). [ in atEnd ] whileFalse: [ out nextPutAll: (in upTo: $<). (((in upTo: $>) asLowercase beginsWith: 'br') and: [ (in peek = Character cr) ]) ifTrue: [ in next ]. ]. ^self replaceEntitiesIn: out reset. ! ! !InstallerInternetBased methodsFor: 'url' stamp: 'kph 10/11/2008 17:02'! hasPage ^ pageDataStream notNil and: [ pageDataStream size > 0 ] ! ! !InstallerInternetBased methodsFor: 'url' stamp: 'sd 3/6/2008 20:18'! isHtmlStream: page "matches '' " | first | first := (page next: 14) asUppercase. ^ (first = '') ! ! !InstallerInternetBased methodsFor: 'url' stamp: 'sd 3/6/2008 20:19'! replaceEntitiesIn: in | out | out := ReadWriteStream on: (String new: 100). [ in atEnd ] whileFalse: [ out nextPutAll: ((in upTo: $&) replaceAll: Character lf with: Character cr). in atEnd ifFalse: [ out nextPutAll: (self class entities at: (in upTo: $;) ifAbsent: '?') ]. ]. ^out reset! ! !InstallerInternetBased methodsFor: 'url' stamp: 'sd 3/6/2008 20:19'! urlGet ^ self urlGet: self urlToDownload! ! !InstallerInternetBased methodsFor: 'url' stamp: 'kph 12/9/2008 03:17'! urlGet: aUrl | page | page := HTTPSocket httpGet: aUrl accept: 'application/octet-stream'. (page respondsTo: #reset) ifFalse: [ ^ nil ]. (self isHtmlStream: page) ifTrue: [ page := self extractFromHtml: page option: nil ]. ^ page reset ! ! !InstallerInternetBased methodsFor: 'url' stamp: 'kph 10/11/2008 17:02'! wasPbwikiSpeedWarning ^ self hasPage and: [pageDataStream contents includesSubString: 'Please slow down a bit' ] ! ! !InstallerInternetBased methodsFor: 'utils' stamp: 'sd 3/6/2008 20:15'! httpGet: aUrl | page | page := self classHTTPSocket httpGet: aUrl accept: 'application/octet-stream'. (page respondsTo: #reset) ifFalse: [ self error: 'unable to contact web site' ]. ^ page ! ! !InstallerInternetBased methodsFor: 'accessing' stamp: 'sd 3/6/2008 19:06'! url ^url! ! !InstallerInternetBased methodsFor: 'accessing' stamp: 'sd 3/6/2008 19:06'! url: aUrl url := aUrl! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! InstallerInternetBased class instanceVariableNames: ''! !InstallerInternetBased class methodsFor: 'accessing' stamp: 'stephane.ducasse 9/30/2008 18:20'! entities ^ Entities ifNil: [ Entities := "enough entities to be going on with" Dictionary new. Entities at: 'lt' put: '<'; at: 'gt' put: '>'; at: 'amp' put: '&'; at: 'star' put: '*'; at: 'quot' put: '"'; at: 'nbsp' put: ' '; yourself ] ! !