[LON-CAPA-cvs] cvs: loncom /xml lonxml.pm
www
lon-capa-cvs-allow@mail.lon-capa.org
Fri, 07 Mar 2008 20:49:18 -0000
www Fri Mar 7 15:49:18 2008 EDT
Modified files:
/loncom/xml lonxml.pm
Log:
Part of Bug #3381: LON-CAPA yells if no <html>, <xml>, <body>, etc.
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.471 loncom/xml/lonxml.pm:1.472
--- loncom/xml/lonxml.pm:1.471 Fri Feb 15 07:59:50 2008
+++ loncom/xml/lonxml.pm Fri Mar 7 15:49:17 2008
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.471 2008/02/15 12:59:50 bisitz Exp $
+# $Id: lonxml.pm,v 1.472 2008/03/07 20:49:17 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1475,11 +1475,26 @@
return $filecontents;
}
+sub verify_html {
+ my ($filecontents)=@_;
+ if ($filecontents!~/(?:\<|\<\;)(?:html|xml)[^\<]*(?:\>|\>\;)/is) {
+ return &mt('File does not have [_1] or [_2] starting tag','<html>','<xml>');
+ }
+ if ($filecontents!~/(?:\<|\<\;)\/(?:html|xml)(?:\>|\>\;)/is) {
+ return &mt('File does not have [_1] or [_2] ending tag','<html>','<xml>');
+ }
+ if ($filecontents!~/(?:\<|\<\;)(?:body|frameset)[^\<]*(?:\>|\>\;)/is) {
+ return &mt('File does not have [_1] or [_2] starting tag','<body>','<frameset>');
+ }
+ if ($filecontents!~/(?:\<|\<\;)\/(?:body|frameset)[^\<]*(?:\>|\>\;)/is) {
+ return &mt('File does not have [_1] or [_2] ending tag','<body>','<frameset>');
+ }
+ return '';
+}
sub inserteditinfo {
my ($filecontents, $filetype, $filename)=@_;
$filecontents = &HTML::Entities::encode($filecontents,'<>&"');
-# my $editheader='<a href="#editsection">Edit below</a><hr />';
my $xml_help = '';
my $initialize='';
my $textarea_id = 'filecont';
@@ -1538,6 +1553,10 @@
my $spelllink .=&Apache::lonhtmlcommon::spelllink('xmledit','filecont');
my $textarea_events = &Apache::edit::element_change_detection();
my $form_events = &Apache::edit::form_change_detection();
+ my $htmlerror=&verify_html($filecontents);
+ if ($htmlerror) {
+ $htmlerror='<span class="LC_error">'.$htmlerror.'</span></p>';
+ }
my $editfooter=(<<ENDFOOTER);
$initialize
<a name="editsection" />
@@ -1552,7 +1571,7 @@
<div class="LC_edit_problem_discards">
<input type="submit" name="discardview" accesskey="d" value="$lt{'dv'}" />
<input type="submit" name="Undo" accesskey="u" value="$lt{'un'}" />
- $spelllink
+ $spelllink $htmlerror
</div>
<div class="LC_edit_problem_saves">
<input type="submit" name="savethisfile" accesskey="s" value="$lt{'st'}" />
@@ -1629,6 +1648,9 @@
if ($env{'form.savethisfile'} || $env{'form.viewmode'} || $env{'form.Undo'}) {
my $html_file=&Apache::lonnet::getfile($file);
my $error = &Apache::lonhomework::handle_save_or_undo($request, \$html_file, \$env{'form.filecont'});
+ if ($env{'form.savethisfile'}) {
+ $env{'form.editmode'}='Edit'; #force edit mode
+ }
}
}
my %mystyle;