From: Jan T. <de...@us...> - 2003-06-02 21:49:59
|
Update of /cvsroot/net-script/netscript2/src/perl/NetScript/Libraries In directory sc8-pr-cvs1:/tmp/cvs-serv7847/perl/NetScript/Libraries Modified Files: ControlStructuresLibrary.pm Log Message: * added <?netscript include ?> directive Index: ControlStructuresLibrary.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/NetScript/Libraries/ControlStructuresLibrary.pm,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** ControlStructuresLibrary.pm 31 May 2003 22:39:33 -0000 1.16 --- ControlStructuresLibrary.pm 2 Jun 2003 21:49:16 -0000 1.17 *************** *** 75,78 **** --- 75,85 ---- # destination document, the <ns:ignore>-tag disappears. # </p> + # Another import variant is the + # <pre> + # <?netscript include URL?> + # </pre> + # instruction. This works mostly like the <?netscript import URL?> instruction however, the + # code imported by this function is directly copied to the output document without + # any further processing. # <p> # There are occasions when the import-facility is not enough. One thing is *************** *** 541,551 **** return 0; # consume event } ! elsif ( $data =~ /^\s*import\s*([^\s]+)/ ) { #check for "import FILEURL" ! my $fileURL = $1; $fileURL = $se -> evaluateStatement( $fileURL ); $fileURL = $this -> checkURL( $fileURL ); if ( $fileURL =~ /^http:/ || $fileURL =~ /^ftp:/ ) { ! unless ( $this -> interpreter() -> getConfig() -> getSetting( "ALLOW_REMOTE_SCRIPTS" ) =~ /yes/ ) { $this -> getEventRelay() -> createAndRaiseEvent( $NetScript::Interpreter::FATAL_EVENT, --- 548,559 ---- return 0; # consume event } ! elsif ( $data =~ /^\s*(import|include)\s*([^\s]+)/ ) { #check for "import/include FILEURL" ! my $type = $1; ! my $fileURL = $2; $fileURL = $se -> evaluateStatement( $fileURL ); $fileURL = $this -> checkURL( $fileURL ); if ( $fileURL =~ /^http:/ || $fileURL =~ /^ftp:/ ) { ! unless ( $this -> interpreter() -> getConfig() -> getSetting( "ALLOW_REMOTE_ACCESS" ) =~ /yes/ ) { $this -> getEventRelay() -> createAndRaiseEvent( $NetScript::Interpreter::FATAL_EVENT, *************** *** 571,575 **** } ! $this -> importDocument( $document, $domWalker, $node ); return 0; # consume event } --- 579,588 ---- } ! if ( $type eq "import" ) { ! $this -> importDocument( $document, $domWalker, $node ); ! } ! else { ! $this -> includeDocument( $document, $domWalker, $node ); ! } return 0; # consume event } *************** *** 589,592 **** --- 602,628 ---- return 1; # do not consume event } + + + #/** + # Includes the given document into the target document. + # @param the document to import + # @param the DOMWalker + # @param the reference node + #*/ + sub includeDocument { + my ( $this, $document, $domWalker, $node ) = @_; + my $targetDocument = $domWalker -> targetDocument(); + my $children = $this -> dal() -> getChildNodes( $document ); + my $length = $this -> dal() -> getLength( $children ) - 1; + + # Import all nodes of the document to the current target document + for ( 0..$length ) { + $domWalker -> insertSubtreeIntoTarget( + $this -> dal() -> getItemAt( $children, $_ ) ); + } + # move source pointer to next node + $domWalker -> stepSourceNext(); + } + #/** |