2009-06-18 20:14:52 +00:00
|
|
|
|
"======================================================================
|
|
|
|
|
|
|
2009-11-20 14:20:28 +00:00
|
|
|
|
| Iliad.ILElement class definition
|
2009-06-18 20:14:52 +00:00
|
|
|
|
|
|
|
|
|
|
======================================================================"
|
|
|
|
|
|
|
|
|
|
"======================================================================
|
|
|
|
|
|
|
2010-01-13 11:12:57 +00:00
|
|
|
|
| Copyright (c) 2008-2010
|
2009-06-18 20:14:52 +00:00
|
|
|
|
| Nicolas Petton <petton.nicolas@gmail.com>,
|
|
|
|
|
| Sébastien Audier <sebastien.audier@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| This file is part of the Iliad framework.
|
|
|
|
|
|
|
|
|
|
|
| Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
|
| a copy of this software and associated documentation files (the
|
|
|
|
|
| 'Software'), to deal in the Software without restriction, including
|
|
|
|
|
| without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
| distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
|
| permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
|
| the following conditions:
|
|
|
|
|
|
|
|
|
|
|
| The above copyright notice and this permission notice shall be
|
|
|
|
|
| included in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
|
| THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
| EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
| MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
|
| IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
|
| CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
|
| TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
|
| SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
======================================================================"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-20 14:20:28 +00:00
|
|
|
|
ILComposite subclass: ILElement [
|
2009-07-22 04:25:59 +00:00
|
|
|
|
| attributes |
|
2009-06-18 20:14:52 +00:00
|
|
|
|
|
|
|
|
|
<category: 'Iliad-Core-Elements'>
|
|
|
|
|
<comment: 'I am the abstract root class of the composite element hierarchy.
|
|
|
|
|
|
|
|
|
|
I know how to print myself in HTML format with the #printHtmlOn: method'>
|
|
|
|
|
|
2009-10-31 21:48:22 +00:00
|
|
|
|
|
|
|
|
|
= anObject [
|
|
|
|
|
<category: 'comparing'>
|
|
|
|
|
^super = anObject and: [
|
|
|
|
|
self attributes = anObject attributes]
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
hash [
|
|
|
|
|
<category: 'comparing'>
|
|
|
|
|
^super hash bitXor: self attributes hash
|
|
|
|
|
]
|
|
|
|
|
|
2009-06-18 20:14:52 +00:00
|
|
|
|
attributes [
|
|
|
|
|
<category: 'accessing'>
|
2010-04-04 16:46:22 +00:00
|
|
|
|
^attributes ifNil: [attributes := Grease.GRSmallDictionary new]
|
2009-06-18 20:14:52 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
attributeAt: akey [
|
|
|
|
|
<category: 'accessing'>
|
|
|
|
|
^self attributes at: akey ifAbsent: [nil]
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
attributeAt: akey ifAbsent: aBlock [
|
|
|
|
|
<category: 'accessing'>
|
|
|
|
|
^self attributes at: akey ifAbsent: aBlock
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
attributeAt: akey ifAbsentPut: aBlock [
|
|
|
|
|
<category: 'accessing'>
|
|
|
|
|
^self attributes at: akey ifAbsentPut: aBlock
|
|
|
|
|
]
|
|
|
|
|
|
2009-11-22 17:25:20 +00:00
|
|
|
|
attributeAt: aKey put: aValue [
|
2009-06-18 20:14:52 +00:00
|
|
|
|
<category: 'accessing'>
|
2009-11-22 17:25:20 +00:00
|
|
|
|
^self attributes at: aKey put: aValue
|
2009-06-18 20:14:52 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
contentType [
|
|
|
|
|
<category: 'accessing'>
|
|
|
|
|
self subclassResponsibility
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
tag [
|
|
|
|
|
<category: 'accessing'>
|
|
|
|
|
^nil
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
printJsonOn: aStream [
|
|
|
|
|
<category: 'printing'>
|
|
|
|
|
| str |
|
|
|
|
|
str := WriteStream on: String new.
|
|
|
|
|
self printHtmlOn: str.
|
|
|
|
|
str contents printJsonOn: aStream
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
printHtmlOn: aStream [
|
|
|
|
|
<category: 'printing'>
|
|
|
|
|
self beforePrintHtml.
|
|
|
|
|
self printOpenTagOn: aStream.
|
2009-07-22 04:25:59 +00:00
|
|
|
|
self childrenDo: [:each |
|
|
|
|
|
each printHtmlOn: aStream].
|
2009-06-18 20:14:52 +00:00
|
|
|
|
self printCloseTagOn: aStream.
|
|
|
|
|
self afterPrintHtml
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
afterPrintHtml [
|
|
|
|
|
<category: 'printing'>
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
beforePrintHtml [
|
|
|
|
|
<category: 'printing'>
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
printAttribute: anAttribute on: aStream [
|
|
|
|
|
<category: 'printing'>
|
|
|
|
|
aStream
|
|
|
|
|
nextPut: Character space;
|
|
|
|
|
nextPutAll: anAttribute key;
|
2010-05-05 18:30:19 +00:00
|
|
|
|
nextPutAll: '="'.
|
2010-05-21 11:26:40 +00:00
|
|
|
|
anAttribute value printEncodedOn: aStream.
|
2010-05-05 18:30:19 +00:00
|
|
|
|
aStream nextPut: $"
|
2009-06-18 20:14:52 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
printCloseTagOn: aStream [
|
|
|
|
|
<category: 'printing'>
|
|
|
|
|
self tag ifNotNil: [aStream nextPutAll: '</' , self tag , '>']
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
printOpenTagOn: aStream [
|
|
|
|
|
<category: 'printing'>
|
|
|
|
|
self tag ifNotNil: [
|
|
|
|
|
aStream nextPutAll: '<' , self tag.
|
|
|
|
|
self attributes associationsDo: [:each |
|
|
|
|
|
each value ifNotNil: [
|
|
|
|
|
self printAttribute: each on: aStream]].
|
|
|
|
|
aStream nextPutAll: '>']
|
|
|
|
|
]
|
|
|
|
|
|
2009-06-22 23:33:16 +00:00
|
|
|
|
build: aBuildable [
|
2009-06-18 20:14:52 +00:00
|
|
|
|
<category: 'building'>
|
2009-06-22 23:33:16 +00:00
|
|
|
|
aBuildable buildOn: self
|
2009-06-18 20:14:52 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
text: aString [
|
|
|
|
|
<category: 'adding-conveniance'>
|
2009-11-20 14:20:28 +00:00
|
|
|
|
^self add: (ILTextElement new
|
2009-06-18 20:14:52 +00:00
|
|
|
|
contents: aString;
|
|
|
|
|
yourself)
|
|
|
|
|
]
|
|
|
|
|
|
2010-02-12 11:07:11 +00:00
|
|
|
|
xml [
|
|
|
|
|
<category: 'adding-conveniance'>
|
|
|
|
|
^self add: ILXmlElement new
|
|
|
|
|
]
|
|
|
|
|
|
2009-06-18 20:14:52 +00:00
|
|
|
|
attributeError: key [
|
|
|
|
|
<category: 'error handling'>
|
2009-11-20 14:20:28 +00:00
|
|
|
|
ILAttributeError signal: key
|
2009-06-18 20:14:52 +00:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
doesNotUnderstandAttribute: aString [
|
|
|
|
|
<category: 'error handling'>
|
|
|
|
|
^(AttributeNotUnderstood element: self attribute: aString) signal
|
|
|
|
|
]
|
|
|
|
|
|
2009-06-22 00:32:14 +00:00
|
|
|
|
respondOn: aResponse [
|
|
|
|
|
<category: 'converting'>
|
|
|
|
|
self printHtmlOn: aResponse.
|
|
|
|
|
aResponse contentType: self contentType
|
2009-06-18 20:14:52 +00:00
|
|
|
|
]
|
|
|
|
|
]
|