PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|site_perl|JUNOS|Response.pm =

page 2 of 4




    return undef if $#$self < 0;
    $self->SUPER::toString(@_);
}

#
# private: get_first_element_with_attribute
# 
# This subroutine is called to return the first element containing a specific
# attribute, so the caller of this subroutine can get, set or delete
# this attribute.
#
sub get_first_element_with_attribute
{
    my ($node, $attrname) = @_;

    my $attributes = $node->getAttributes();
    return $node if ($attributes && $node->getAttribute($attrname));

    my $nodes = $node->getChildNodes();
    my $len  = $nodes->getLength;

    for (my $i = 0; $i < $len; $i++) {
        my $nsnode = get_first_element_with_attribute($nodes->item($i), $attrname);
	return $nsnode if $nsnode;
    }
    return;
}

#
# private: remove_prefix_from_element
# 
# This subroutine is called to remove the namespace prefix from the
# XSL file to deal with the JUNOScript responses from old versions
# of JUNOS that do not contain default namespace.
#
sub remove_prefix_from_element
{
    my ($self, $node, $prefix) = @_;

    my $nodes = $node->getChildNodes();
    return unless $nodes;
	
    my $len  = $nodes->getLength;
    return unless $len;
    
    for (my $i = 0; $i < $len; $i++) {
	my $item = $nodes->item($i);
        my $attributes = $item->getAttributes();
	if ($attributes) {
            my $attrcount = $attributes->getLength();

            for (my $i = 0; $i < $attrcount; $i++) {
	        my $attr = $attributes->item($i);
	        my $value = $attr->getNodeValue();
	        $value =~ s/$prefix://g;
	        $attr->setNodeValue($value);
            }
	}

  	$self->remove_prefix_from_element($item, $prefix);
    }

    return;
}

use constant XML_NS_ATTRIBUTE => 'xmlns';

#
# translateXSLtoRelease
#
# XSLT 1.0 does not deal with default namespace as well as we had hoped.
# It requires the xsl file to declare a namspace given the default namespace
# from the XML data.  It must also prefix all the element names with the 
# local name.
#
# Because the default namespace in all JUNOScript responses contains
# the JUNOS version, the xsl file cannot point to the same default
# namespace for all routers.  Also there are backward compatibility
# problems in dealing with some JUNOScript responses form older versions
# of JUNOS that do not have default namespace (e.g. 
# <get-bgp-neighbor-information> response from pre-5.1 releases)
#
# Before transforming the response, the xsl file should be parsed and
# its namespace attribute for the JUNOScript response should be replaced with
# the default namespace in the response.  If the default namespace is not
# defined in the xml doc, the prefix will be removed from the XSL file
# to deal with the abovementioned backward compatibility problem.
#
# Hopefully, this subroutine will be made obsolete when XLST 2.0 implementation
# is made available.
#
use constant HASH_REFERENCE => 'HASH';
sub translateXSLtoRelease
{
    my ($self, $namespace, $input, $output) = @_;

    my $xsltparser = new XML::DOM::Parser;
    unless ($xsltparser) {
        print STDERR "ERROR: cannot create an XML::DOM::Parser object\n";
=2=

1| < PREV = PAGE 2 = NEXT > |3|4

UP TO ROOT | UP TO DIR | TO FIRST PAGE

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.014755 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU)