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

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

page 3 of 4



        return;
    }
    my $xsltdoc = $xsltparser->parsefile($input);
    unless ($xsltdoc) {
        print STDERR "ERROR: cannot parse the XSL input file $input\n";
        return;
    }
    if (ref($namespace) eq HASH_REFERENCE) {
	my %nstable = %$namespace;
	foreach my $k (keys(%nstable)) {
            setXSLtoRelease($self, $k, $nstable{$k}, $xsltdoc);
	}
    } else {
        setXSLtoRelease($self, $namespace, XML_NS_ATTRIBUTE, $xsltdoc);
    }
    $xsltdoc->printToFile($output);
    return $output;
}

sub setXSLtoRelease
{
    my ($self, $xslns, $xmlns, $xsltdoc) = @_;

    my $nselem = get_first_element_with_attribute($self, $xmlns);
    my $dfns = $nselem->getAttribute($xmlns) if $nselem;

    if ($dfns) {
        $nselem = get_first_element_with_attribute($xsltdoc, $xslns);
        return unless $nselem;
        $nselem->setAttribute($xslns, $dfns);
	return;
    }

    # if there is no instance of the specified namespace in the xml doc, 
    # make sure the prefix is removed from the xsl file.  This is for backward
    # compatiblitiy.  Some of the JUNOScript Responses from older
    # releases do not have the default namespace.  The XSL file would
    # not work with it unless we make this change.
  
    my ($declare, $prefix) = split(/:/, $xslns);
    $self->remove_prefix_from_element($xsltdoc, $prefix);
}

1;

__END__

=head1 NAME

JUNOS::Response - Response object from a remote Juniper box

=head1 SYNOPSIS

This example retrieves 'show chassis hardware' information and transforms
the input with XSLT.  A JUNOS::Response object is returned by the
$jnx->get_chassis_inventory() call.

    use JUNOS::Device;

    # connect TO the JUNOScript server
    $jnx = new JUNOS::Device(hostname => "router11",
                             login => "johndoe",
                             password => "secret",
                             access => "telnet");
    unless ( ref $jnx ) {
        die "ERROR: $deviceinfo{hostname}: can't connect.\n";
    }

    # send the command and receive a XML::DOM object
    my $res = $jnx->get_chassis_inventory(detail => 1);
    unless ( ref $res ) { 
        die "ERROR: $deviceinfo{hostname}: can't execute command $query.\n";   
    }

    # Check and see if there were any errors in executing the command.
    # If all is well, output the response using XSLT.
    my $err = $res->getFirstError();
    if ($err) {
        print STDERR "ERROR: $deviceinfo{'hostname'} - ", $err->{message}, "\n";
    } else {
        # 
        # Now do the transformation using XSLT.
        #
        my $xmlfile = "$deviceinfo{hostname}.xml";
	$res->printToFile($xmlfile);
        my $nm = $res->translateXSLtoRelease('xmlns:lc', $xslfile, "$xslfile.tmp");
        if ($nm) {
            my $command = "xsltproc $nm $deviceinfo{hostname}.xml";
            system($command);
        } else {
            print STDERR "ERROR: Invalid XSL File $xslfile\n";
        }
    }
    
    # always close the connection
    $jnx->request_end_session();
    $jnx->disconnect();

=head1 DESCRIPTION

=3=

1|2| < PREV = PAGE 3 = NEXT > |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.00670791 wallclock secs ( 0.01 usr + 0.01 sys = 0.02 CPU)