--- loncom/xml/lonxml.pm 2009/04/13 20:15:44 1.492 +++ loncom/xml/lonxml.pm 2009/04/13 20:42:32 1.493 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.492 2009/04/13 20:15:44 raeburn Exp $ +# $Id: lonxml.pm,v 1.493 2009/04/13 20:42:32 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1504,6 +1504,15 @@ SIMPLECONTENT return $filecontents; } +sub createnewjs { + my $filecontents=(< + + +SIMPLECONTENT + return $filecontents; +} + sub verify_html { my ($filecontents)=@_; if ($filecontents!~/(?:\<|\<\;)(?:html|xml)[^\<]*(?:\>|\>\;)/is) { @@ -1679,9 +1688,8 @@ sub get_target { sub handler { my $request=shift; - + my $target=&get_target(); - $Apache::lonxml::debug=$env{'user.debug'}; &Apache::loncommon::content_type($request,'text/html'); @@ -1697,11 +1705,12 @@ sub handler { my $file=&Apache::lonnet::filelocation("",$request->uri); my $filetype; - if ($file =~ /\.sty$/) { - $filetype='sty'; + if ($file =~ /\.(sty|css|js|txt)$/) { + $filetype=$1; } else { $filetype='html'; } + # # Edit action? Save file. # @@ -1730,7 +1739,9 @@ ENDNOTFOUND if ($env{'request.state'} ne 'published') { if ($filetype eq 'sty') { $filecontents=&createnewsty(); - } else { + } elsif ($filetype eq 'js') { + $filecontents=&createnewjs(); + } elsif (($filetype ne 'css') && ($filetype ne 'txt')) { $filecontents=&createnewhtml(); } $env{'form.editmode'}='Edit'; #force edit mode @@ -1746,27 +1757,43 @@ ENDNOTFOUND ['editmode']); } if (!$env{'form.editmode'} || $env{'form.viewmode'} || $env{'form.discardview'}) { - &Apache::structuretags::reset_problem_globals(); - $result = &Apache::lonxml::xmlparse($request,$target,$filecontents, - '',%mystyle); + if ($filetype eq 'html' || $filetype eq 'sty') { + &Apache::structuretags::reset_problem_globals(); + $result = &Apache::lonxml::xmlparse($request,$target, + $filecontents,'',%mystyle); # .html files may contain or need to clean # up if it did - &Apache::structuretags::reset_problem_globals(); - &Apache::lonhomework::finished_parsing(); + &Apache::structuretags::reset_problem_globals(); + &Apache::lonhomework::finished_parsing(); + } else { + $result = $filecontents; + } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['rawmode']); if ($env{'form.rawmode'}) { $result = $filecontents; } - if ($filetype eq 'sty') { + if ($filetype ne 'html') { + my $nochgview = 1; my $controls = - ($env{'request.state'} eq 'construct') ? &Apache::londefdef::edit_controls() + ($env{'request.state'} eq 'construct') ? &Apache::londefdef::edit_controls($nochgview) : ''; - my %options = ('bgcolor' => '#FFFFFF'); - $result = - &Apache::loncommon::start_page(undef,undef,\%options). - $controls. - $result. - &Apache::loncommon::end_page(); - } + if ($filetype ne 'sty') { + $result =~ s//>/g; + $result = ''. + '
'.$result.
+                              '
'; + } + if ($env{'environment.remote'} eq 'off') { + my %options = ('bgcolor' => '#FFFFFF'); + $result = + &Apache::loncommon::start_page(undef,undef,\%options). + $controls. + $result. + &Apache::loncommon::end_page(); + } else { + $result = $controls.$result; + } + } } } @@ -1800,7 +1827,7 @@ ENDNOTFOUND &Apache::lonxml::message_location(). $edit_info. &Apache::loncommon::end_page(); - } + } } if ($filetype eq 'html') { &writeallows($request->uri); }