reports/Builder__ReportFormat.st
author Claus Gittinger <cg@exept.de>
Thu, 28 Mar 2019 13:54:38 +0100
changeset 542 aa25a71be62a
parent 202 730a466fbe35
permissions -rw-r--r--
#DOCUMENTATION by cg
class: stx_goodies_builder_quickSelfTest
class definition

class: stx_goodies_builder_quickSelfTest class
added:18 methods
jan@73
     1
"{ Package: 'stx:goodies/builder/reports' }"
jan@73
     2
jan@73
     3
"{ NameSpace: Builder }"
jan@73
     4
jan@73
     5
Object subclass:#ReportFormat
jan@73
     6
	instanceVariableNames:'report stream'
jan@73
     7
	classVariableNames:''
jan@73
     8
	poolDictionaries:''
jan@73
     9
	category:'Builder-Reports-Formats'
jan@73
    10
!
jan@73
    11
jan@73
    12
jan@73
    13
!ReportFormat class methodsFor:'instance creation'!
jan@73
    14
jan@73
    15
named:aString 
jan@73
    16
    "Return new format with given name. Name may be
jan@73
    17
     either class or symbolic name"
jan@73
    18
    
jan@73
    19
    self allSubclassesDo:
jan@73
    20
            [:cls |             
jan@73
    21
            (cls isAbstract not and:[cls name = aString or:[ cls symbolicNames includes:aString ]]) 
jan@73
    22
                ifTrue:[ ^ cls new ] ].
jan@73
    23
jan@73
    24
    self error:'No format named ' , aString.
jan@73
    25
jan@73
    26
    "
jan@73
    27
        ReportFormat named: 'tap'
jan@73
    28
        ReportFormat named: 'JUnitFormat'
jan@73
    29
        ReportFormat named: 'NONEX'
jan@73
    30
    "
jan@73
    31
jan@73
    32
    "Created: / 04-08-2011 / 11:47:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@73
    33
!
jan@73
    34
jan@73
    35
new
jan@73
    36
    "return an initialized instance"
jan@73
    37
jan@73
    38
    ^ self basicNew initialize.
jan@73
    39
! !
jan@73
    40
jan@73
    41
!ReportFormat class methodsFor:'accessing'!
jan@73
    42
jan@73
    43
symbolicNames
jan@73
    44
    "Returns a collection of symbolic names for this format"
jan@73
    45
    
jan@73
    46
    ^ self subclassResponsibility
jan@73
    47
jan@73
    48
    "Modified (comment): / 04-08-2011 / 11:46:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@73
    49
! !
jan@73
    50
jan@73
    51
!ReportFormat class methodsFor:'testing'!
jan@73
    52
jan@73
    53
isAbstract
jan@73
    54
jan@73
    55
    ^self == HDReportFormat
jan@73
    56
jan@73
    57
    "Created: / 04-08-2011 / 11:44:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@73
    58
! !
jan@73
    59
jan@73
    60
!ReportFormat methodsFor:'accessing - defaults'!
jan@73
    61
jan@73
    62
defaultFileSuffix
jan@73
    63
jan@73
    64
    ^self subclassResponsibility
jan@73
    65
jan@73
    66
    "Created: / 04-08-2011 / 12:47:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@73
    67
! !
jan@73
    68
jan@73
    69
!ReportFormat methodsFor:'initialization'!
jan@73
    70
jan@73
    71
initialize
jan@73
    72
    "Invoked when a new instance is created."
jan@73
    73
jan@73
    74
    "/ please change as required (and remove this comment)
jan@73
    75
    "/ stream := nil.
jan@73
    76
    "/ suite := nil.
jan@73
    77
jan@73
    78
    "/ super initialize.   -- commented since inherited method does nothing
jan@73
    79
!
jan@73
    80
jan@73
    81
report: aReport stream: aStream
jan@73
    82
jan@73
    83
    report := aReport.
jan@73
    84
    (aStream isKindOf: EncodedStream) ifTrue:[
jan@73
    85
        stream := aStream.
jan@73
    86
    ] ifFalse:[
jan@89
    87
        | encoder |
jan@89
    88
        "Kludge since ISO10646_to_XMLUTF8 encoder may not be present"
jan@89
    89
jan@89
    90
        CharacterEncoderImplementations::ISO10646_to_XMLUTF8 notNil ifTrue:[
jan@89
    91
            CharacterEncoderImplementations::ISO10646_to_XMLUTF8 autoload.
jan@89
    92
            encoder := CharacterEncoderImplementations::ISO10646_to_XMLUTF8 new.
jan@89
    93
        ] ifFalse:[
jan@89
    94
            encoder := CharacterEncoder encoderForUTF8.
jan@89
    95
        ].
jan@89
    96
        stream := EncodedStream stream: aStream encoder: encoder
jan@73
    97
    ]
jan@73
    98
jan@73
    99
    "Created: / 03-08-2011 / 18:54:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@73
   100
! !
jan@73
   101
jan@73
   102
!ReportFormat methodsFor:'stream - utilities'!
jan@73
   103
jan@73
   104
stream 
jan@73
   105
jan@73
   106
    ^ stream
jan@73
   107
jan@73
   108
!
jan@73
   109
jan@73
   110
streamClose
jan@73
   111
jan@73
   112
    "Temporarily closes the stream"
jan@73
   113
jan@73
   114
    "stream is EncodedStream..."             
jan@73
   115
    stream stream close.
jan@73
   116
jan@73
   117
    "Created: / 12-08-2011 / 09:30:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@73
   118
!
jan@73
   119
jan@73
   120
streamFlush
jan@73
   121
jan@73
   122
    "Temporarily closes the stream"
jan@73
   123
jan@73
   124
    "stream is EncodedStream..."             
jan@73
   125
    stream stream flush.
jan@73
   126
jan@73
   127
    "Created: / 12-08-2011 / 09:35:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@73
   128
!
jan@73
   129
jan@73
   130
streamOpenForAppend
jan@73
   131
jan@73
   132
    "Open previously closes stream"
jan@73
   133
    
jan@73
   134
    | s |
jan@73
   135
    "stream is EncodedStream..."             
jan@73
   136
    s := stream stream.
jan@73
   137
    s isExternalStream ifTrue:[
jan@73
   138
        s isOpen ifTrue:[s close].
jan@73
   139
        s openForWriting.
jan@73
   140
	s setToEnd.
jan@73
   141
    ].
jan@73
   142
jan@73
   143
    "Created: / 12-08-2011 / 09:31:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@73
   144
! !
jan@73
   145
jan@73
   146
!ReportFormat methodsFor:'writing'!
jan@73
   147
jan@73
   148
writeFooter
jan@73
   149
    "raise an error: must be redefined in concrete subclass(es)"
jan@73
   150
jan@73
   151
    ^ self subclassResponsibility
jan@73
   152
!
jan@73
   153
jan@73
   154
writeHeader
jan@73
   155
    "raise an error: must be redefined in concrete subclass(es)"
jan@73
   156
jan@73
   157
    ^ self subclassResponsibility
jan@73
   158
! !
jan@73
   159
jan@73
   160
!ReportFormat methodsFor:'writing - utilities'!
jan@73
   161
jan@73
   162
encode: aString
jan@73
   163
jan@73
   164
    ^Report encode: aString
jan@73
   165
jan@73
   166
    "Created: / 03-08-2011 / 14:37:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@202
   167
!
jan@202
   168
jan@202
   169
writeCDATA: string
jan@202
   170
    | start stop |
jan@202
   171
jan@202
   172
    start := 1. 
jan@202
   173
    stop := start.
jan@202
   174
    [ (stop := (string indexOf: $] startingAt: stop)) ~~ 0 ] whileTrue:[
jan@202
   175
        ((stop < (string size - 1)) 
jan@202
   176
            and:[(string at: stop + 1) == $]
jan@202
   177
                and:[(string at: stop + 2) == $>]]) ifTrue:[
jan@202
   178
                    " Okay, found CDATA end token "
jan@202
   179
                    stream nextPutAll: string startingAt: start to: stop + 1.
jan@202
   180
                    stream nextPutAll: ']]><!![CDATA[>'.
jan@202
   181
                    start := stop := stop + 3.
jan@202
   182
                ] ifFalse:[
jan@202
   183
                    stop := stop + 1.
jan@202
   184
                ].
jan@202
   185
    ].
jan@202
   186
    start < string size ifTrue:[
jan@202
   187
        stream nextPutAll: string startingAt: start to: string size.        
jan@202
   188
    ].
jan@202
   189
jan@202
   190
    "
jan@202
   191
    String streamContents:[:s | Builder::TestReportFormat::JUnit new report: nil stream: s; writeCDATA:'ABCD']
jan@202
   192
    String streamContents:[:s | Builder::TestReportFormat::JUnit new report: nil stream: s; writeCDATA:']]]]']         
jan@202
   193
    String streamContents:[:s | Builder::TestReportFormat::JUnit new report: nil stream: s; writeCDATA:'Some <[CDATA[ CDATA ]]> Some Text and stray terminator ]]> here']
jan@202
   194
    "
jan@202
   195
jan@202
   196
    "Created: / 05-07-2013 / 16:54:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
jan@73
   197
! !
jan@73
   198
jan@73
   199
!ReportFormat class methodsFor:'documentation'!
jan@73
   200
jan@73
   201
version
jan@73
   202
    ^ '$Header$'
jan@73
   203
!
jan@73
   204
jan@73
   205
version_CVS
jan@73
   206
    ^ '$Header$'
jan@73
   207
!
jan@73
   208
jan@73
   209
version_SVN
jan@202
   210
    ^ '$Id$'
jan@73
   211
! !
jan@202
   212