176
|
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:
|
|
11 |
#
|
|
12 |
# Description:
|
|
13 |
# SAX Handler for the Raptor log
|
|
14 |
|
|
15 |
package RaptorSAXHandler;
|
|
16 |
use base qw(XML::SAX::Base);
|
|
17 |
|
|
18 |
sub new
|
|
19 |
{
|
|
20 |
my ($type) = @_;
|
|
21 |
|
|
22 |
return bless {}, $type;
|
|
23 |
}
|
|
24 |
|
|
25 |
sub add_observer
|
|
26 |
{
|
|
27 |
my ($self, $name, $initialstatus) = @_;
|
|
28 |
|
|
29 |
$self->{observers} = {} if (!defined $self->{observers});
|
|
30 |
|
|
31 |
$self->{observers}->{$name} = $initialstatus;
|
|
32 |
}
|
|
33 |
|
|
34 |
sub start_document
|
|
35 |
{
|
|
36 |
my ($self, $doc) = @_;
|
|
37 |
# process document start event
|
|
38 |
|
|
39 |
#print "start_document\n";
|
|
40 |
}
|
|
41 |
|
|
42 |
sub start_element
|
|
43 |
{
|
|
44 |
my ($self, $el) = @_;
|
|
45 |
# process element start event
|
|
46 |
|
|
47 |
my $tagname = $el->{LocalName};
|
|
48 |
|
|
49 |
#print "start_element($tagname)\n";
|
|
50 |
|
|
51 |
for my $observer (keys %{$self->{observers}})
|
|
52 |
{
|
|
53 |
#print "processing observer $observer: $self->{observers}->{$observer} $self->{observers}->{$observer}->{name}\n";
|
|
54 |
#for (keys %{$self->{observers}->{$observer}->{next_status}}) {print "$_\n";}
|
|
55 |
|
|
56 |
if (defined $self->{observers}->{$observer}->{next_status}->{$tagname})
|
|
57 |
{
|
|
58 |
#print "processing observer $observer\n";
|
|
59 |
my $oldstatus = $self->{observers}->{$observer};
|
|
60 |
$self->{observers}->{$observer} = $self->{observers}->{$observer}->{next_status}->{$tagname};
|
|
61 |
#print "$observer: status is now $self->{observers}->{$observer}->{name}\n";
|
|
62 |
$self->{observers}->{$observer}->{next_status}->{$tagname} = $oldstatus;
|
|
63 |
&{$self->{observers}->{$observer}->{on_start}}($el) if (defined $self->{observers}->{$observer}->{on_start});
|
|
64 |
}
|
|
65 |
elsif (defined $self->{observers}->{$observer}->{next_status}->{'?default?'})
|
|
66 |
{
|
|
67 |
#print "processing observer $observer\n";
|
|
68 |
#print "changing to default status\n";
|
|
69 |
my $oldstatus = $self->{observers}->{$observer};
|
|
70 |
$self->{observers}->{$observer} = $self->{observers}->{$observer}->{next_status}->{'?default?'};
|
|
71 |
#print "status is now ?default?\n";
|
|
72 |
$self->{observers}->{$observer}->{next_status}->{$tagname} = $oldstatus;
|
|
73 |
&{$self->{observers}->{$observer}->{on_start}}($el) if (defined $self->{observers}->{$observer}->{on_start});
|
|
74 |
}
|
|
75 |
}
|
|
76 |
}
|
|
77 |
|
|
78 |
sub end_element
|
|
79 |
{
|
|
80 |
my ($self, $el) = @_;
|
|
81 |
# process element start event
|
|
82 |
|
|
83 |
my $tagname = $el->{LocalName};
|
|
84 |
|
|
85 |
#print "end_element($tagname)\n";
|
|
86 |
|
|
87 |
for my $observer (keys %{$self->{observers}})
|
|
88 |
{
|
|
89 |
if (defined $self->{observers}->{$observer}->{next_status}->{$tagname})
|
|
90 |
{
|
|
91 |
&{$self->{observers}->{$observer}->{on_end}}($el) if (defined $self->{observers}->{$observer}->{on_end});
|
|
92 |
$self->{observers}->{$observer} = $self->{observers}->{$observer}->{next_status}->{$tagname};
|
|
93 |
#print "status is now $self->{observers}->{$observer}->{name}\n";
|
|
94 |
}
|
|
95 |
}
|
|
96 |
}
|
|
97 |
|
|
98 |
sub characters
|
|
99 |
{
|
|
100 |
my ($self, $ch) = @_;
|
|
101 |
|
|
102 |
for my $observer (keys %{$self->{observers}})
|
|
103 |
{
|
|
104 |
&{$self->{observers}->{$observer}->{on_chars}}($ch) if (defined $self->{observers}->{$observer}->{on_chars});
|
|
105 |
}
|
|
106 |
}
|
|
107 |
|
|
108 |
1;
|