[LON-CAPA-cvs] cvs: loncom(version_2_10_X) /xml lonxml.pm

raeburn raeburn@source.lon-capa.org
Wed, 29 Sep 2010 16:02:19 -0000


raeburn		Wed Sep 29 16:02:19 2010 EDT

  Modified files:              (Branch: version_2_10_X)
    /loncom/xml	lonxml.pm 
  Log:
  - Backport 1.515, 1.516, 1.517.
  
  
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.505.2.2 loncom/xml/lonxml.pm:1.505.2.3
--- loncom/xml/lonxml.pm:1.505.2.2	Mon Aug 16 17:29:11 2010
+++ loncom/xml/lonxml.pm	Wed Sep 29 16:02:19 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.505.2.2 2010/08/16 17:29:11 raeburn Exp $
+# $Id: lonxml.pm,v 1.505.2.3 2010/09/29 16:02:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1528,17 +1528,25 @@
 
 sub verify_html {
     my ($filecontents)=@_;
-    if ($filecontents!~/(?:\<|\&lt\;)(?:html|xml)[^\<]*(?:\>|\&gt\;)/is) {
-       return &mt('File does not have [_1] or [_2] starting tag','&lt;html&gt;','&lt;xml&gt;');
-    }
-    if ($filecontents!~/(?:\<|\&lt\;)\/(?:html|xml)(?:\>|\&gt\;)/is) {
-       return &mt('File does not have [_1] or [_2] ending tag','&lt;html&gt;','&lt;xml&gt;');
-    }
-    if ($filecontents!~/(?:\<|\&lt\;)(?:body|frameset)[^\<]*(?:\>|\&gt\;)/is) {
-       return &mt('File does not have [_1] or [_2] starting tag','&lt;body&gt;','&lt;frameset&gt;');
-    }
-    if ($filecontents!~/(?:\<|\&lt\;)\/(?:body|frameset)[^\<]*(?:\>|\&gt\;)/is) {
-       return &mt('File does not have [_1] or [_2] ending tag','&lt;body&gt;','&lt;frameset&gt;');
+    my ($is_html,$is_xml);
+    if ($filecontents =~/(?:\<|\&lt\;)\?xml[^\<]*\?(?:\>|\&gt\;)/is) {
+        $is_xml = 1;
+    } elsif ($filecontents =~/(?:\<|\&lt\;)html(?:\s+[^\<]+|\s*)[^\<]*(?:\>|\&gt\;)/is) {
+        $is_html = 1;
+    }
+    unless ($is_xml || $is_html) {
+        return &mt('File does not have [_1] or [_2] starting tag','&lt;html&gt;','&lt;?xml ?&gt;');
+    }
+    if ($is_html) {
+        if ($filecontents!~/(?:\<|\&lt\;)\/html(?:\>|\&gt\;)/is) {
+            return &mt('File does not have [_1] ending tag','&lt;html&gt;');
+        }
+        if ($filecontents!~/(?:\<|\&lt\;)(?:body|frameset)[^\<]*(?:\>|\&gt\;)/is) {
+            return &mt('File does not have [_1] or [_2] starting tag','&lt;body&gt;','&lt;frameset&gt;');
+        }
+        if ($filecontents!~/(?:\<|\&lt\;)\/(?:body|frameset)[^\<]*(?:\>|\&gt\;)/is) {
+            return &mt('File does not have [_1] or [_2] ending tag','&lt;body&gt;','&lt;frameset&gt;');
+        }
     }
     return '';
 }
@@ -1631,7 +1639,7 @@
               $htmlerror='<span class="LC_error">'.$htmlerror.'</span>';
           }
           if (&Apache::lonhtmlcommon::htmlareabrowser()) {
-              $textareaclass = 'class="LC_richDetectHtml"';
+              $textareaclass = 'class="LC_richDefaultOff"';
           }
       }
       my $editfooter=(<<ENDFOOTER);
@@ -1807,9 +1815,6 @@
                 $result = &Apache::lontexconvert::converted(\$filecontents,
                               $env{'form.texengine'});
                 if ($env{'form.return_only_error_and_warning_counts'}) {
-                    if (&verify_html('<html><body>'.$result.'</body></html>')) {
-                        $errorcount++;
-                    }
                     $result = "$errorcount:$warningcount";
                 }
             } else {