#
# $Id: Parser.pm,v 1.6 2003/03/02 11:12:12 dsw Exp $
#
# COPYRIGHT AND LICENSE
# Copyright (c) 2001-2003, Juniper Networks, Inc.
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# 3. The name of the copyright owner may not be used to
# endorse or promote products derived from this software without specific
# prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# ----------------------------------------------------------------------
#
# This package inserts itself as a filter between XML::Parser and
# XML::DOM in order to allow it to accept XML parser events and to
# selectively forward them to either the native JUNOScript logic or
# the DOM logic.
#
package JUNOS::DOM::Parser;
use JUNOS::Trace;
#
# Forward events from the expat parser to the DOM parser. The expat
# parser is basically doing the lexical analysis for us, breaking the
# input into xml tokens and doing callbacks to the hand up these tokens.
# Normally, these are forwarded directly to the DOM parser, which builds
# a DOM tree of DOM nodes that are manipulated thru DOM's API. If the
# DOM parser isn't active, we toss the events.
#
sub forward_event
{
tracept("Parse");
my $func = shift;
my $self = shift;
my $parser = shift;
$self = $parser->{JUNOS_Device} unless $self;
return unless $self->{JUNOS_DomMode} && $self->{JUNOS_Active};
return if $parser->{tag} eq "rpc-reply";
my $name = "XML::Parser::Dom::" . $func;
{
no strict qw(refs);
return unless defined &${name};
&${name}($parser, @_);
}
}
#
# The Init and Final events are of no interest to us, since we're
# creating them by hand for the DOM parser.
#
sub Init { }
sub Final { }
#
# Normal events are forwarded to the DOM parser
#
sub Proc { forward_event("Proc", undef, @_); }
sub Comment { forward_event("Comment", undef, @_); }
sub CdataStart { forward_event("CdataStart", undef, @_); }
sub CdataEnd { forward_event("CdataEnd", undef, @_); }
sub Default { forward_event("Default", undef, @_); }
sub Unparsed { forward_event("Unparsed", undef, @_); }
sub Notation { forward_event("Notation", undef, @_); }
sub ExternEnt { forward_event("ExternEnt", undef, @_); }
sub Entity { forward_event("Entity", undef, @_); }
sub Element { forward_event("Element", undef, @_); }
sub Attlist { forward_event("Attlist", undef, @_); }
sub Doctype { forward_event("Doctype", undef, @_); }
#
# Record values from the xml declaration so that we can pass these
# values to the DOM parser when we start/restart it.
=1= |