Class: SAXdemo

Inherits:
Object
  • Object
show all
Includes:
SAXishHandler
Defined in:
lib/xamplr-pp/saxdemo.rb

Overview

This module uses the saxish api. The saxish api is meant to demonstrate the use of Xampl_PP pull parser, while being useful in itself. If you are meaning to learn about the Xampl_PP parser, you should look at the saxish.rb file – this one isn’t going to help you a lot.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SAXishHandler

#endDocument, #startDocument

Instance Attribute Details

#verboseObject

Returns the value of attribute verbose.



35
36
37
# File 'lib/xamplr-pp/saxdemo.rb', line 35

def verbose
  @verbose
end

Instance Method Details

#cdataSection(text) ⇒ Object



93
94
95
96
97
# File 'lib/xamplr-pp/saxdemo.rb', line 93

def cdataSection(text)
  printf("CDATA -- length: %s\n", text.length) if verbose
  @cdataEventCount += 1
  @eventCount += 1
end

#comment(text) ⇒ Object



111
112
113
114
115
# File 'lib/xamplr-pp/saxdemo.rb', line 111

def comment(text)
  printf("comment -- [%s]\n", text) if verbose
  @commentEventCount += 1
  @eventCount += 1
end

#doctype(text) ⇒ Object



117
118
119
120
121
# File 'lib/xamplr-pp/saxdemo.rb', line 117

def doctype(text)
  printf("doctype -- [%s]\n", text) if verbose
  @doctypeEventCount += 1
  @eventCount += 1
end

#endElement(name, namespace, qname, prefix) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/xamplr-pp/saxdemo.rb', line 67

def endElement(name, namespace, qname, prefix)
  printf("EndElement -- name: '%s'\n", name) if verbose
  printf("              namespace: '%s'\n", namespace) if verbose
  printf("              qname: '%s'\n", qname) if verbose
  printf("              prefix: '%s'\n", prefix) if verbose
  @endElementEventCount += 1
  @eventCount += 1
end

#entityRef(name, text) ⇒ Object



76
77
78
79
80
# File 'lib/xamplr-pp/saxdemo.rb', line 76

def entityRef(name, text)
  printf("EntityRef -- name '%s' text '%s'\n", name, text) if verbose
  @entityRefCount += 1
  @eventCount += 1
end

#fileNames(fileNames) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/xamplr-pp/saxdemo.rb', line 159

def fileNames(fileNames)
init

  @saxparser = SAXish.new
  @saxparser.handler = self
  @saxparser.processNamespace = true
  @saxparser.reportNamespaceAttributes = false

  fileNames.each do
    | filename |
    begin
      @saxparser.parse filename
      @successCount += 1
    rescue Exception => message
      @failureCount += 1
      print message.backtrace.join("\n")
      printf("FAILED [%s] '%s'\n", message, filename)
    end
  end

report
end

#ignoreableWhitespace(text) ⇒ Object



99
100
101
102
103
# File 'lib/xamplr-pp/saxdemo.rb', line 99

def ignoreableWhitespace(text)
  printf("IgnoreableWhitespace -- length: %s\n", text.length) if verbose
  @ignorableWhitespaceEventCount += 1
  @eventCount += 1
end

#initObject



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/xamplr-pp/saxdemo.rb', line 123

def init
   @startElementEventCount = 0
   @endElementEventCount = 0
   @entityRefCount = 0
   @resolverCount = 0
   @textEventCount = 0
   @cdataEventCount = 0
   @whitespaceTextEventCount = 0
   @ignorableWhitespaceEventCount = 0
   @processingInstructionEventCount = 0
   @doctypeEventCount = 0
   @commentEventCount = 0
   @eventCount = 0
   @failureCount = 0
   @successCount = 0
	@maxDepth = -1
end

#processingInstruction(text) ⇒ Object



105
106
107
108
109
# File 'lib/xamplr-pp/saxdemo.rb', line 105

def processingInstruction(text)
  printf("ProcessingInstruction -- [%s]\n", text) if verbose
  @processingInstructionEventCount += 1
  @eventCount += 1
end

#reportObject



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/xamplr-pp/saxdemo.rb', line 141

def report
   printf("%5d eventCount\n", @eventCount)
   printf("%5d successCount\n", @successCount)
   printf("%5d maxDepth [%d, %d]\n", @maxDepth, @maxDepthLine, @maxDepthColumn)
   printf("%5d failureCount\n", @failureCount)
   printf("%5d startElementEventCount\n", @startElementEventCount)
   printf("%5d endElementEventCount\n", @endElementEventCount)
   printf("%5d entityRefCount\n", @entityRefCount)
   printf("%5d resolverCount\n", @resolverCount)
   printf("%5d textEventCount\n", @textEventCount)
   printf("%5d cdataEventCount\n", @cdataEventCount)
   printf("%5d whitespaceTextEventCount\n", @whitespaceTextEventCount)
   printf("%5d ignorableWhitespaceEventCount\n", @ignorableWhitespaceEventCount)
   printf("%5d processingInstructionEventCount\n", @processingInstructionEventCount)
   printf("%5d doctypeEventCount\n", @doctypeEventCount)
   printf("%5d commentEventCount\n", @commentEventCount)
end

#resolve(name) ⇒ Object



37
38
39
40
# File 'lib/xamplr-pp/saxdemo.rb', line 37

def resolve(name)
  @resolverCount += 1
  return "fake it"
end

#startElement(name, namespace, qname, prefix, attributeCount, isEmpty, saxparser) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/xamplr-pp/saxdemo.rb', line 42

def startElement(name, namespace, qname, prefix, attributeCount, isEmpty, saxparser)
  printf("StartElement -- name: '%s'\n", name) if verbose
  printf("                namespace: '%s'\n", namespace) if verbose
  printf("                qname: '%s'\n", qname) if verbose
  printf("                prefix: '%s'\n", prefix) if verbose
  printf("                attributeCount: %d\n", attributeCount) if verbose
  printf("                isEmpty: %s\n", isEmpty) if verbose
  i = 0
  while i < attributeCount do
    printf("  attribute[%d] -- name: '%s'\n", i, saxparser.attributeName(i)) if verbose
    printf("  attribute[%d] -- namespace: '%s'\n", i, saxparser.attributeNamespace(i)) if verbose
    printf("  attribute[%d] -- qname: '%s'\n", i, saxparser.attributeQName(i)) if verbose
    printf("  attribute[%d] -- prefix: '%s'\n", i, saxparser.attributePrefix(i)) if verbose
    printf("  attribute[%d] -- value: '%s'\n", i, saxparser.attributeValue(i)) if verbose
    i += 1
  end
  @startElementEventCount += 1
  @eventCount += 1
if @maxDepth < saxparser.depth then
	@maxDepth = saxparser.depth
	@maxDepthLine = saxparser.line
	@maxDepthColumn = saxparser.column
end
end

#string(string) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/xamplr-pp/saxdemo.rb', line 182

def string(string)
init

  @saxparser = SAXish.new
  @saxparser.handler = self
  @saxparser.processNamespace = true
  @saxparser.reportNamespaceAttributes = false

  begin
    @saxparser.parseString string
    @successCount += 1
  rescue Exception => message
    @failureCount += 1
    print message.backtrace.join("\n")
    printf("FAILED [%s] '%s'\n", message, string)
  end

report
end

#text(text, isWhitespace) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/xamplr-pp/saxdemo.rb', line 82

def text(text, isWhitespace)
  if not isWhitespace then
    printf("Text -- length: %d\n", text.length) if verbose
    @textEventCount += 1
  else
    printf("Text -- length: %d WHITESPACE\n", text.length) if verbose
    @whitespaceTextEventCount += 1
  end
  @eventCount += 1
end