|
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 set_init_status |
|
26 { |
|
27 my ($self, $initialstatus) = @_; |
|
28 |
|
29 $self->{status} = $initialstatus; |
|
30 } |
|
31 |
|
32 sub start_document |
|
33 { |
|
34 my ($self, $doc) = @_; |
|
35 # process document start event |
|
36 |
|
37 #print "start_document\n"; |
|
38 } |
|
39 |
|
40 sub start_element |
|
41 { |
|
42 my ($self, $el) = @_; |
|
43 # process element start event |
|
44 |
|
45 my $tagname = $el->{LocalName}; |
|
46 |
|
47 #print "start_element($tagname)\n"; |
|
48 |
|
49 |
|
50 if (defined $self->{status}->{next_status}->{$tagname}) |
|
51 { |
|
52 my $oldstatus = $self->{status}; |
|
53 $self->{status} = $self->{status}->{next_status}->{$tagname}; |
|
54 #print "status is now $self->{status}->{name}\n"; |
|
55 $self->{status}->{next_status}->{$tagname} = $oldstatus; |
|
56 &{$self->{status}->{on_start}}($el) if (defined $self->{status}->{on_start}); |
|
57 } |
|
58 elsif (defined $self->{status}->{next_status}->{'?default?'}) |
|
59 { |
|
60 #print "changing to default status\n"; |
|
61 my $oldstatus = $self->{status}; |
|
62 $self->{status} = $self->{status}->{next_status}->{'?default?'}; |
|
63 #print "status is now ?default?\n"; |
|
64 $self->{status}->{next_status}->{$tagname} = $oldstatus; |
|
65 &{$self->{status}->{on_start}}($el) if (defined $self->{status}->{on_start}); |
|
66 } |
|
67 } |
|
68 |
|
69 sub end_element |
|
70 { |
|
71 my ($self, $el) = @_; |
|
72 # process element start event |
|
73 |
|
74 my $tagname = $el->{LocalName}; |
|
75 |
|
76 #print "end_element($tagname)\n"; |
|
77 |
|
78 if (defined $self->{status}->{next_status}->{$tagname}) |
|
79 { |
|
80 &{$self->{status}->{on_end}}($el) if (defined $self->{status}->{on_end}); |
|
81 $self->{status} = $self->{status}->{next_status}->{$tagname}; |
|
82 #print "status is now $self->{status}->{name}\n"; |
|
83 } |
|
84 } |
|
85 |
|
86 sub characters |
|
87 { |
|
88 my ($self, $ch) = @_; |
|
89 |
|
90 &{$self->{status}->{on_chars}}($ch) if (defined $self->{status}->{on_chars}); |
|
91 } |
|
92 |
|
93 1; |