2009/dap/ReSpec.js/js respec.js,1.129,1.130

Update of /sources/public/2009/dap/ReSpec.js/js
In directory hutz:/tmp/cvs-serv26074/js

Modified Files:
	respec.js 
Log Message:
Added support for outputting XHTML.

Index: respec.js
===================================================================
RCS file: /sources/public/2009/dap/ReSpec.js/js/respec.js,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -d -r1.129 -r1.130
--- respec.js	6 Jul 2010 19:39:55 -0000	1.129
+++ respec.js	9 Jul 2010 22:18:12 -0000	1.130
@@ -266,6 +266,10 @@
         butH.onclick = function () { obj.hideSaveOptions(); obj.toHTML(); };
         var butS = sn.element("button", {}, this.saveMenu, "Save as HTML (Source)");
         butS.onclick = function () { obj.hideSaveOptions(); obj.toHTMLSource(); };
+        var butS = sn.element("button", {}, this.saveMenu, "Save as XHTML");
+        butS.onclick = function () { obj.hideSaveOptions(); obj.toXHTML(); };
+        var butS = sn.element("button", {}, this.saveMenu, "Save as XHTML (Source)");
+        butS.onclick = function () { obj.hideSaveOptions(); obj.toXHTMLSource(); };
         if (this.diffTool && (this.previousDiffURI || this.previousURI) ) {
             var butD = sn.element("button", {}, this.saveMenu, "Diffmark");
             butD.onclick = function () { obj.hideSaveOptions(); obj.toDiffHTML(); };
@@ -297,7 +301,7 @@
             if (an == "xmlns" || an == "xml:lang") continue;
             if (an == "prefix") {
                 prefixAtr = ats[i].value;
-                contine;
+                continue;
             }
             str += " " + an + "=\"" + this._esc(ats[i].value) + "\"";
         }
@@ -312,6 +316,118 @@
         str += "</html>";
         return str;
     },
+
+    toXML:        function () {
+        var str = "<?xml version='1.0' encoding='UTF-8'?>\n<!DOCTYPE html";
+        var dt = document.doctype;
+        if (dt && dt.publicId) {
+            str += " PUBLIC '" + dt.publicId + "' '" + dt.systemId + "'";
+        }
+        else { 
+            if (this.doRDFa) {
+                // use the standard RDFa doctype
+                str += " PUBLIC '-//W3C//DTD XHTML+RDFa 1.0//EN' 'http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd'";
+            } else {
+                str += " PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'";
+            }
+        }
+        str += ">\n";
+        str += "<html";
+        var ats = document.documentElement.attributes;
+        var prefixAtr = '' ;
+
+        var hasxmlns = 0 ;
+        for (var i = 0; i < ats.length; i++) {
+            var an = ats[i].name;
+            if (an == "xmlns" ) {
+                hasxmlns = 1;
+            }
+            if (an == "prefix") {
+                prefixAtr = ats[i].value;
+                continue;
+            }
+            str += " " + an + "=\"" + this._esc(ats[i].value) + "\"";
+        }
+        if (!hasxmlns) {
+            str += ' xmlns="http://www.w3.org/1999/xhtml"';
+        }
+        if (this.doRDFa) {
+            str += " xmlns:dcterms='http://purl.org/dc/terms/' xmlns:bibo='http://purl.org/ontology/bibo/' xmlns:foaf='http://xmlns.com/foaf/0.1/' xmlns:xsd='http://www.w3.org/2001/XMLSchema#'";
+            if (prefixAtr != '') {
+                var list = prefixAtr.split(/\s+/) ;
+                for (var i = 0; i < list.length; i += 2) {
+                    var n = list[i] ;
+                    n = n.replace(/:$/,'');
+                    str += ' xmlns:'+n+'="' + list[i+1] + '"';
+                }
+            }
+        }
+
+        str += ">\n";
+        // walk the entire DOM tree grabbing nodes and emitting them - possibly modifying them
+        // if they need the funny closing tag
+        var pRef = this ;
+        var closers = [ "br", "img", "input", "area", "base", "basefont", "col", "isindex", "link", "meta", "param"] ;
+        var dumpNode = function(node) {
+            var out = '' ;
+            // if the node is the document node.. process the children
+            if ( node.nodeType == 9 || ( node.nodeType == 1 && node.nodeName.toLowerCase() == 'html' ) ) {
+                var children = node.childNodes;
+                var cLen = children.length ;
+                if (cLen) {
+                    for (var i = 0; i < cLen; i++) {
+                        out += dumpNode(children[i]) ;
+                    }
+                }
+            } else 
+            // if the node is an element, process it
+            if ( node.nodeType == 1 ) {
+                var ename = node.nodeName.toLowerCase() ;
+                var empty = 0 ;
+                for (var i = 0; i < closers.length; i++) {
+                    if (ename == closers[i]) {
+                        empty = 1;
+                    }
+                }
+                out += '<' + ename ;
+                var attrs = node.attributes;
+                var aLen = attrs.length ;
+                if (aLen) {
+                    for (var i = 0; i < aLen; i++) {
+                        out += " " + attrs[i].name + "=\"" + pRef._esc(attrs[i].value) + "\"";
+                    }
+                }
+                if (empty) {
+                    out += ' />';
+                } else {
+                    out += '>' ;
+                    if ( ename == 'pre' ) {
+                        out += "\n" + node.innerHTML;
+                    } else {
+                        var children = node.childNodes;
+                        var cLen = children.length ;
+                        if (cLen) {
+                            for (var i = 0; i < cLen; i++) {
+                                out += dumpNode(children[i]) ;
+                            }
+                        }
+                    }
+                    out += '</' + ename + '>' ;
+                }
+            } else if (node.nodeType == 8 ) {
+                out += "\n<!-- " + node.nodeValue + " -->\n";
+            } else {
+                // otherwise, return the content of the node as a string
+                out += node.nodeValue ;
+            }
+            return out ;
+        };
+        var node = document.documentElement;
+        str += dumpNode(document.documentElement) ;
+        str += "</html>";
+        return str;
+
+    },
     
     toDiffHTMLSource:  function () {
 
@@ -362,6 +478,18 @@
         x.document.close();
     },
     
+    toXHTML:    function () {
+        var x = window.open();
+        x.document.write(this.toXML()) ;
+        x.document.close();
+    },
+    
+    toXHTMLSource:    function () {
+        var x = window.open();
+        x.document.write("<pre>" + this._esc(this.toXML()) + "</pre>");
+        x.document.close();
+    },
+    
     // --- METADATA -------------------------------------------------------
     extractConfig:    function () {
         this.title = document.title;

Received on Friday, 9 July 2010 22:18:16 UTC