common/tools/raptor/RaptorSAXHandler.pm
author Simon Howkins <simonh@symbian.org>
Wed, 11 Nov 2009 13:22:02 +0000
changeset 753 5069de517698
parent 242 51e429810aba
permissions -rw-r--r--
New script which parses raptor logs directly to produce a BRAG summary. New version of XML structure accommodates causes of failure as well as the effect of the failure, and deals with excessive error messages. New structure also avoids a potential problem (bug?, questionable feature?) that both IE and firefox exhibit. Some simplifications of brag utilities module.

# Copyright (c) 2009 Symbian Foundation Ltd
# This component and the accompanying materials are made available
# under the terms of the License "Eclipse Public License v1.0"
# which accompanies this distribution, and is available
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
#
# Initial Contributors:
# Symbian Foundation Ltd - initial contribution.
#
# Contributors:
#
# Description:
# SAX Handler for the Raptor log

package RaptorSAXHandler;
use base qw(XML::SAX::Base);

sub new
{
    my ($type) = @_;
    
    return bless {}, $type;
}

sub add_observer
{
	my ($self, $name, $initialstatus) = @_;
	
	$self->{observers} = {} if (!defined $self->{observers});
	
	$self->{observers}->{$name} = $initialstatus;
}

sub start_document
{
	my ($self, $doc) = @_;
	# process document start event
	
	#print "start_document\n";
}
  
sub start_element
{
	my ($self, $el) = @_;
	# process element start event
	
	my $tagname = $el->{LocalName};
	
	#print "start_element($tagname)\n";
	
	for my $observer (keys %{$self->{observers}})
	{
		#print "processing observer $observer: $self->{observers}->{$observer} $self->{observers}->{$observer}->{name}\n";
		#for (keys %{$self->{observers}->{$observer}->{next_status}}) {print "$_\n";}
		
		if (defined $self->{observers}->{$observer}->{next_status}->{$tagname})
		{
			#print "processing observer $observer\n";
			my $oldstatus = $self->{observers}->{$observer};
			$self->{observers}->{$observer} = $self->{observers}->{$observer}->{next_status}->{$tagname};
			#print "$observer: status is now $self->{observers}->{$observer}->{name}\n";
			$self->{observers}->{$observer}->{next_status}->{$tagname} = $oldstatus;
			&{$self->{observers}->{$observer}->{on_start}}($el) if (defined $self->{observers}->{$observer}->{on_start});
		}
		elsif (defined $self->{observers}->{$observer}->{next_status}->{'?default?'})
		{
			#print "processing observer $observer\n";
			#print "changing to default status\n";
			my $oldstatus = $self->{observers}->{$observer};
			$self->{observers}->{$observer} = $self->{observers}->{$observer}->{next_status}->{'?default?'};
			#print "status is now ?default?\n";
			$self->{observers}->{$observer}->{next_status}->{$tagname} = $oldstatus;
			&{$self->{observers}->{$observer}->{on_start}}($el) if (defined $self->{observers}->{$observer}->{on_start});
		}
	}
}

sub end_element
{
	my ($self, $el) = @_;
	# process element start event
	
	my $tagname = $el->{LocalName};
	
	#print "end_element($tagname)\n";
	
	for my $observer (keys %{$self->{observers}})
	{
		if (defined $self->{observers}->{$observer}->{next_status}->{$tagname})
		{
			&{$self->{observers}->{$observer}->{on_end}}($el) if (defined $self->{observers}->{$observer}->{on_end});
			$self->{observers}->{$observer} = $self->{observers}->{$observer}->{next_status}->{$tagname};
			#print "status is now $self->{observers}->{$observer}->{name}\n";
		}
	}
}

sub characters
{
	my ($self, $ch) = @_;
	
	for my $observer (keys %{$self->{observers}})
	{
		&{$self->{observers}->{$observer}->{on_chars}}($ch) if (defined $self->{observers}->{$observer}->{on_chars});
	}
}

1;