author | William Roberts <williamr@symbian.org> |
Tue, 29 Jun 2010 17:58:44 +0100 | |
changeset 300 | 3b8bce67b574 |
parent 258 | 08436a227940 |
permissions | -rw-r--r-- |
177 | 1 |
# Copyright (c) 2009 Symbian Foundation Ltd |
2 |
# This component and the accompanying materials are made available |
|
3 |
# under the terms of the License "Eclipse Public License v1.0" |
|
4 |
# which accompanies this distribution, and is available |
|
5 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
6 |
# |
|
7 |
# Initial Contributors: |
|
8 |
# Symbian Foundation Ltd - initial contribution. |
|
9 |
# |
|
10 |
# Contributors: |
|
258
08436a227940
Add author information. Reviewed descriptions
Dario Sestito <darios@symbian.org>
parents:
177
diff
changeset
|
11 |
# Dario Sestito <darios@symbian.org> |
177 | 12 |
# |
13 |
# Description: |
|
14 |
# SAX Handler for the Raptor log |
|
15 |
||
16 |
package RaptorSAXHandler; |
|
17 |
use base qw(XML::SAX::Base); |
|
18 |
||
19 |
sub new |
|
20 |
{ |
|
21 |
my ($type) = @_; |
|
22 |
||
23 |
return bless {}, $type; |
|
24 |
} |
|
25 |
||
26 |
sub add_observer |
|
27 |
{ |
|
28 |
my ($self, $name, $initialstatus) = @_; |
|
29 |
||
30 |
$self->{observers} = {} if (!defined $self->{observers}); |
|
31 |
||
32 |
$self->{observers}->{$name} = $initialstatus; |
|
33 |
} |
|
34 |
||
35 |
sub start_document |
|
36 |
{ |
|
37 |
my ($self, $doc) = @_; |
|
38 |
# process document start event |
|
39 |
||
40 |
#print "start_document\n"; |
|
41 |
} |
|
42 |
||
43 |
sub start_element |
|
44 |
{ |
|
45 |
my ($self, $el) = @_; |
|
46 |
# process element start event |
|
47 |
||
48 |
my $tagname = $el->{LocalName}; |
|
49 |
||
50 |
#print "start_element($tagname)\n"; |
|
51 |
||
52 |
for my $observer (keys %{$self->{observers}}) |
|
53 |
{ |
|
54 |
#print "processing observer $observer: $self->{observers}->{$observer} $self->{observers}->{$observer}->{name}\n"; |
|
55 |
#for (keys %{$self->{observers}->{$observer}->{next_status}}) {print "$_\n";} |
|
56 |
||
57 |
if (defined $self->{observers}->{$observer}->{next_status}->{$tagname}) |
|
58 |
{ |
|
59 |
#print "processing observer $observer\n"; |
|
60 |
my $oldstatus = $self->{observers}->{$observer}; |
|
61 |
$self->{observers}->{$observer} = $self->{observers}->{$observer}->{next_status}->{$tagname}; |
|
62 |
#print "$observer: status is now $self->{observers}->{$observer}->{name}\n"; |
|
63 |
$self->{observers}->{$observer}->{next_status}->{$tagname} = $oldstatus; |
|
64 |
&{$self->{observers}->{$observer}->{on_start}}($el) if (defined $self->{observers}->{$observer}->{on_start}); |
|
65 |
} |
|
66 |
elsif (defined $self->{observers}->{$observer}->{next_status}->{'?default?'}) |
|
67 |
{ |
|
68 |
#print "processing observer $observer\n"; |
|
69 |
#print "changing to default status\n"; |
|
70 |
my $oldstatus = $self->{observers}->{$observer}; |
|
71 |
$self->{observers}->{$observer} = $self->{observers}->{$observer}->{next_status}->{'?default?'}; |
|
72 |
#print "status is now ?default?\n"; |
|
73 |
$self->{observers}->{$observer}->{next_status}->{$tagname} = $oldstatus; |
|
74 |
&{$self->{observers}->{$observer}->{on_start}}($el) if (defined $self->{observers}->{$observer}->{on_start}); |
|
75 |
} |
|
76 |
} |
|
77 |
} |
|
78 |
||
79 |
sub end_element |
|
80 |
{ |
|
81 |
my ($self, $el) = @_; |
|
82 |
# process element start event |
|
83 |
||
84 |
my $tagname = $el->{LocalName}; |
|
85 |
||
86 |
#print "end_element($tagname)\n"; |
|
87 |
||
88 |
for my $observer (keys %{$self->{observers}}) |
|
89 |
{ |
|
90 |
if (defined $self->{observers}->{$observer}->{next_status}->{$tagname}) |
|
91 |
{ |
|
92 |
&{$self->{observers}->{$observer}->{on_end}}($el) if (defined $self->{observers}->{$observer}->{on_end}); |
|
93 |
$self->{observers}->{$observer} = $self->{observers}->{$observer}->{next_status}->{$tagname}; |
|
94 |
#print "status is now $self->{observers}->{$observer}->{name}\n"; |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
||
99 |
sub characters |
|
100 |
{ |
|
101 |
my ($self, $ch) = @_; |
|
102 |
||
103 |
for my $observer (keys %{$self->{observers}}) |
|
104 |
{ |
|
105 |
&{$self->{observers}->{$observer}->{on_chars}}($ch) if (defined $self->{observers}->{$observer}->{on_chars}); |
|
106 |
} |
|
107 |
} |
|
108 |
||
109 |
1; |