From: Jan T. <de...@us...> - 2002-10-26 21:08:43
|
Update of /cvsroot/net-script/netscript2/src/perl/NetScript/Libraries In directory usw-pr-cvs1:/tmp/cvs-serv2556 Modified Files: ControlStructuresLibrary.pm Log Message: * fixed "internal server error" when importing / rimporing a non-valid file Index: ControlStructuresLibrary.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/NetScript/Libraries/ControlStructuresLibrary.pm,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ControlStructuresLibrary.pm 27 Sep 2002 17:52:23 -0000 1.11 --- ControlStructuresLibrary.pm 26 Oct 2002 21:08:39 -0000 1.12 *************** *** 60,64 **** # document after the processing instruction.If the URL has no protocol and # starts with . or .. it is treated as relative URL to the currently executed ! # script. The given document has to be an XML-compliant structure. # Hence, it must have a document element. Since # there are occasions, where you do not have or want a document element --- 60,66 ---- # document after the processing instruction.If the URL has no protocol and # starts with . or .. it is treated as relative URL to the currently executed ! # script. Note, that <?netscript import URL?> always has to be enclosed by ! # an element. ! # The given document has to be an XML-compliant structure. # Hence, it must have a document element. Since # there are occasions, where you do not have or want a document element *************** *** 78,82 **** # by using tables. So the head and the foot themselves are not valid XML # documents, and using <code>ns:ignore</code> will not help in these cases. ! # For this, this library has a reature names reverse-import. It will not import # another file into the current file, but will do the opposite of it, # import the current file into a location of another file. --- 80,84 ---- # by using tables. So the head and the foot themselves are not valid XML # documents, and using <code>ns:ignore</code> will not help in these cases. ! # For this, this library has a feature named "reverse-import". It will not import # another file into the current file, but will do the opposite of it, # import the current file into a location of another file. *************** *** 458,461 **** --- 460,464 ---- sub processingInstruction { my ( $this, $event ) = @_; + my $se = $this -> interpreter() -> getStatementEvaluator(); my $domWalker = $event -> getEventUnknown(); my $node = $domWalker -> currentSource(); *************** *** 465,468 **** --- 468,473 ---- my $data = $node -> getData(); if ( $data =~ /^\s*use\s*([^\s]*)/) { # check for "use LIBNAME" + my $libName = $1; + $libName = $se -> evaluateStatement( $libName ); $this -> interpreter() -> getLibLoader() -> loadLibrary( $1 ); $domWalker -> stepSourceNext(); *************** *** 471,474 **** --- 476,480 ---- elsif ( $data =~ /^\s*import\s*([^\s]+)/ ) { #check for "import FILEURL" my $fileURL = $1; + $fileURL = $se -> evaluateStatement( $fileURL ); $fileURL = $this -> checkURL( $fileURL ); *************** *** 483,495 **** my $fileData = $this -> interpreter() -> getFileRetriever() -> retrieveFile( $fileURL ); ! my $document = $this -> interpreter() -> getDOMParser() -> ! parseString( $fileData ); $this -> importDocument( $document, $domWalker, $node ); return 0; # consume event } ! elsif ( $data =~ /^\s*ripoint\s*([^\s]+)/ ) { #check for "ripoint NAME" ! my $ripointName = $1; my $targetDoc = $domWalker -> sourceDocument(); ! my $document = $this -> getReferencedDocument( $ripointName, $targetDoc ); if ( defined( $document ) ) { $this -> importDocument( $document, $domWalker, $node ); --- 489,514 ---- my $fileData = $this -> interpreter() -> getFileRetriever() -> retrieveFile( $fileURL ); ! my $document = undef; ! unless( eval { ! $document = $this -> interpreter() -> getDOMParser() -> ! parseString( $fileData ); ! 1; ! } ) { ! my $string = $@; ! $string =~ s/&/&/g; ! $string =~ s/</</g; ! $string =~ s/>/>/g; ! ! $this -> interpreter() -> getEventRelay() -> createAndRaiseEvent( ! $NetScript::Interpreter::FATAL_EVENT, ! "Error while parsing the input file: " . $string ); ! } ! $this -> importDocument( $document, $domWalker, $node ); return 0; # consume event } ! elsif ( $data =~ /^\s*ripoint\s*/ ) { #check for "ripoint" my $targetDoc = $domWalker -> sourceDocument(); ! my $document = $this -> getReferencedDocument( $targetDoc ); if ( defined( $document ) ) { $this -> importDocument( $document, $domWalker, $node ); *************** *** 497,501 **** return 0; # consume event } ! elsif ( $data =~ /^\s*rimport\s+([^\s]+)\s+([^\s]+)\s*/ ) { # filter out "rimport"-PIs $domWalker -> stepSourceNext(); return 0; # consume event --- 516,520 ---- return 0; # consume event } ! elsif ( $data =~ /^\s*rimport\s+([^\s]+)\s*/ ) { # filter out "rimport"-PIs $domWalker -> stepSourceNext(); return 0; # consume event *************** *** 520,524 **** my $parent = $node -> getParentNode(); my $sibling = $node -> getNextSibling(); ! # Import all nodes of the document to the current source document for ( 0..$length ) { --- 539,548 ---- my $parent = $node -> getParentNode(); my $sibling = $node -> getNextSibling(); ! ! if ( $parent -> getNodeType() != $XML::DOM2::Node::ELEMENT_NODE ) { ! $this -> interpreter() -> getEventRelay() -> createAndRaiseEvent( ! $NetScript::Interpreter::FATAL_EVENT, ! "Cannot import! <?netscript import?> must be enclosed by an element." ); ! } # Import all nodes of the document to the current source document for ( 0..$length ) { *************** *** 571,574 **** --- 595,599 ---- my $children = $sourceDocument -> getChildNodes(); my $length = $children -> getLength() - 1; + my $se = $this -> interpreter() -> getStatementEvaluator(); for ( 0..$length ) { *************** *** 578,591 **** if ( $child -> getTarget() eq "netscript" ) { my $data = $child -> getData(); ! if ( $data =~ /^\s*rimport\s+([^\s]+)\s+([^\s]+)\s*/ ) { my $fileURL = $1; ! my $importPoint = $2; $fileURL = $this -> checkURL( $fileURL ); my $fileData = $this -> interpreter() -> getFileRetriever() -> retrieveFile( $fileURL ); ! my $document = $this -> interpreter() -> getDOMParser() -> parseString( $fileData ); $domWalker -> resetDocument( $document ); ! $this -> addDocumentReference( $importPoint, $document, $sourceDocument ); $domWalker -> sourceAgain(); return 0; # consume event; --- 603,631 ---- if ( $child -> getTarget() eq "netscript" ) { my $data = $child -> getData(); ! if ( $data =~ /^\s*rimport\s+([^\s]+)\s*/ ) { my $fileURL = $1; ! $fileURL = $se -> evaluateStatement( $fileURL ); $fileURL = $this -> checkURL( $fileURL ); my $fileData = $this -> interpreter() -> getFileRetriever() -> retrieveFile( $fileURL ); ! my $document = undef; ! ! unless( eval { ! $document = $this -> interpreter() -> getDOMParser() -> parseString( $fileData ); + 1; + } ) { + my $string = $@; + $string =~ s/&/&/g; + $string =~ s/</</g; + $string =~ s/>/>/g; + + $this -> interpreter() -> getEventRelay() -> createAndRaiseEvent( + $NetScript::Interpreter::FATAL_EVENT, + "Error while parsing the input file: " . $string ); + } + $domWalker -> resetDocument( $document ); ! $this -> addDocumentReference( $document, $sourceDocument ); $domWalker -> sourceAgain(); return 0; # consume event; *************** *** 600,604 **** # Adds a document reference. This can be used to retrieve the document which should # be inserted into an import point. - # @param the name of the import point # @param the document in which the import point must be located # @param the document to mount into the import point --- 640,643 ---- *************** *** 606,616 **** #*/ sub addDocumentReference { ! my ( $this, $name, $target, $source ) = @_; ! $this -> { m_referencedDocuments } -> { $name.$target } = $source; } #/** # Returns a document for a import point name and document. - # @param the name of the import point # @param the document in which the import point is located. # @return the document to insert into the given mountpoint, or undef --- 645,654 ---- #*/ sub addDocumentReference { ! my ( $this, $target, $source ) = @_; ! $this -> { m_referencedDocuments } -> { $target } = $source; } #/** # Returns a document for a import point name and document. # @param the document in which the import point is located. # @return the document to insert into the given mountpoint, or undef *************** *** 619,624 **** #*/ sub getReferencedDocument { ! my ( $this , $name, $target ) = @_; ! $this -> { m_referencedDocuments } -> { $name.$target }; } --- 657,662 ---- #*/ sub getReferencedDocument { ! my ( $this , $target ) = @_; ! $this -> { m_referencedDocuments } -> { $target }; } |