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