Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / swingjs / j2s / swingjs / JSSAXParser.js
index e7012ff..dee6629 100644 (file)
-Clazz.declarePackage ("swingjs");\r
-Clazz.load (["org.xml.sax.Parser", "$.XMLReader"], "swingjs.JSSAXParser", ["java.io.BufferedInputStream", "$.BufferedReader", "java.lang.Boolean", "java.util.Hashtable", "JU.AU", "$.PT", "$.Rdr", "org.xml.sax.SAXParseException", "swingjs.JSSAXAttributes", "$.JSSAXContentHandler", "$.JSToolkit", "swingjs.api.DOMNode"], function () {\r
-c$ = Clazz.decorateAsClass (function () {\r
-this.resolver = null;\r
-this.dtdHandler = null;\r
-this.docHandler = null;\r
-this.contentHandler = null;\r
-this.errorHandler = null;\r
-this.havePre = false;\r
-this.uniqueSeq = null;\r
-this.ver2 = false;\r
-this.tempChars = null;\r
-this.props = null;\r
-Clazz.instantialize (this, arguments);\r
-}, swingjs, "JSSAXParser", null, [org.xml.sax.Parser, org.xml.sax.XMLReader]);\r
-Clazz.prepareFields (c$, function () {\r
-this.tempChars =  Clazz.newCharArray (1024, '\0');\r
-});\r
-Clazz.overrideMethod (c$, "setLocale", \r
-function (locale) {\r
-}, "java.util.Locale");\r
-Clazz.overrideMethod (c$, "setEntityResolver", \r
-function (resolver) {\r
-this.resolver = resolver;\r
-}, "org.xml.sax.EntityResolver");\r
-Clazz.overrideMethod (c$, "setDTDHandler", \r
-function (handler) {\r
-this.dtdHandler = handler;\r
-}, "org.xml.sax.DTDHandler");\r
-Clazz.overrideMethod (c$, "setDocumentHandler", \r
-function (handler) {\r
-this.docHandler = handler;\r
-}, "org.xml.sax.DocumentHandler");\r
-Clazz.overrideMethod (c$, "setErrorHandler", \r
-function (handler) {\r
-this.errorHandler = handler;\r
-}, "org.xml.sax.ErrorHandler");\r
-Clazz.defineMethod (c$, "parse", \r
-function (source, handler) {\r
-this.setContentHandler (handler);\r
-this.parseSource (source);\r
-}, "org.xml.sax.InputSource,swingjs.JSSAXContentHandler");\r
-Clazz.defineMethod (c$, "parse", \r
-function (source) {\r
-this.parseSource (source);\r
-}, "org.xml.sax.InputSource");\r
-Clazz.defineMethod (c$, "parseSource", \r
- function (source) {\r
-var rdr = source.getCharacterStream ();\r
-var data =  new Array (1);\r
-if (rdr == null) {\r
-var bs = source.getByteStream ();\r
-if (!(Clazz.instanceOf (bs, java.io.BufferedInputStream))) bs =  new java.io.BufferedInputStream (bs);\r
-data[0] = JU.Rdr.fixUTF (JU.Rdr.getStreamAsBytes (bs, null));\r
-} else {\r
-if (!(Clazz.instanceOf (rdr, java.io.BufferedReader))) rdr =  new java.io.BufferedReader (rdr);\r
-JU.Rdr.readAllAsString (rdr, -1, false, data, 0);\r
-}try {\r
-this.parseDocument (this.parseXML (data[0]));\r
-} catch (e) {\r
-if (Clazz.exceptionOf (e, Exception)) {\r
-this.error (e);\r
-} else {\r
-throw e;\r
-}\r
-}\r
-}, "org.xml.sax.InputSource");\r
-Clazz.defineMethod (c$, "parse", \r
-function (fileName) {\r
-try {\r
-this.parseDocument (this.parseXML (swingjs.JSToolkit.getFileContents (fileName)));\r
-} catch (e) {\r
-if (Clazz.exceptionOf (e, Exception)) {\r
-this.error (e);\r
-} else {\r
-throw e;\r
-}\r
-}\r
-}, "~S");\r
-Clazz.defineMethod (c$, "parseXMLString", \r
-function (data) {\r
-try {\r
-this.parseDocument (this.parseXML (data));\r
-} catch (e) {\r
-if (Clazz.exceptionOf (e, Exception)) {\r
-this.error (e);\r
-} else {\r
-throw e;\r
-}\r
-}\r
-}, "~S");\r
-Clazz.defineMethod (c$, "parseXML", \r
- function (data) {\r
-return swingjs.JSToolkit.getJQuery ().parseXML (this.removeProcessing (data));\r
-}, "~S");\r
-Clazz.defineMethod (c$, "removeProcessing", \r
- function (data) {\r
-if (data.indexOf ("<?") >= 0) {\r
-this.getUniqueSequence (data);\r
-data = JU.PT.rep (JU.PT.rep (data, "<?", "<![CDATA[" + this.uniqueSeq), "?>", "]]>");\r
-if (data.startsWith ("<!")) {\r
-data = "<pre>" + data + "</pre>";\r
-this.havePre = true;\r
-}}return data;\r
-}, "~S");\r
-Clazz.defineMethod (c$, "getUniqueSequence", \r
- function (data) {\r
-var s = "~";\r
-while (data.indexOf ("<![CDATA[" + s) >= 0) s += "~";\r
-\r
-this.uniqueSeq = s;\r
-}, "~S");\r
-Clazz.defineMethod (c$, "error", \r
- function (e) {\r
-var ee =  new org.xml.sax.SAXParseException ("Invalid Document", null);\r
-if (this.errorHandler == null) throw (ee);\r
- else this.errorHandler.fatalError (ee);\r
-}, "Exception");\r
-Clazz.defineMethod (c$, "parseDocument", \r
- function (doc) {\r
-if (this.docHandler == null && this.contentHandler == null) this.contentHandler =  new swingjs.JSSAXContentHandler ();\r
-this.ver2 = (this.contentHandler != null);\r
-if (this.ver2) this.contentHandler.startDocument ();\r
- else this.docHandler.startDocument ();\r
-this.walkDOMTree (swingjs.api.DOMNode.getAttr (doc, "firstChild"), this.havePre);\r
-if (this.ver2) this.contentHandler.endDocument ();\r
- else this.docHandler.endDocument ();\r
-}, "swingjs.api.DOMNode");\r
-Clazz.defineMethod (c$, "walkDOMTree", \r
- function (node, skipTag) {\r
-var localName = (swingjs.api.DOMNode.getAttr (node, "localName"));\r
-var qName = swingjs.api.DOMNode.getAttr (node, "nodeName");\r
-var uri = swingjs.api.DOMNode.getAttr (node, "namespaceURI");\r
-if (localName == null) {\r
-var isText = "#text".equals (qName);\r
-if (isText || "#cdata-section".equals (qName)) {\r
-var data = swingjs.api.DOMNode.getAttr (node, "textContent");\r
-if (isText || this.uniqueSeq == null || !data.startsWith (this.uniqueSeq)) {\r
-var len = data.length;\r
-var ch = this.tempChars;\r
-if (len > ch.length) ch = this.tempChars = JU.AU.ensureLength (ch, len * 2);\r
-for (var i = len; --i >= 0; ) ch[i] = data.charAt (i);\r
-\r
-if (this.ver2) this.contentHandler.characters (ch, 0, len);\r
- else this.docHandler.characters (ch, 0, len);\r
-return;\r
-}data = data.substring (this.uniqueSeq.length);\r
-var target = data + " ";\r
-target = target.substring (0, target.indexOf (" "));\r
-data = data.substring (target.length).trim ();\r
-if (this.ver2) this.contentHandler.processingInstruction (target, data);\r
- else this.docHandler.processingInstruction (target, data);\r
-}} else if (!skipTag) {\r
-var atts =  new swingjs.JSSAXAttributes (node);\r
-if (this.ver2) this.contentHandler.startElement (uri, localName, qName, atts);\r
- else this.docHandler.startElement (localName, atts);\r
-}node = swingjs.api.DOMNode.getAttr (node, "firstChild");\r
-while (node != null) {\r
-this.walkDOMTree (node, false);\r
-node = swingjs.api.DOMNode.getAttr (node, "nextSibling");\r
-}\r
-if (localName == null || skipTag) return;\r
-if (this.ver2) this.contentHandler.endElement (uri, localName, qName);\r
- else this.docHandler.endElement (localName);\r
-}, "swingjs.api.DOMNode,~B");\r
-Clazz.overrideMethod (c$, "getFeature", \r
-function (name) {\r
-return (this.getProperty ("\1" + name) != null);\r
-}, "~S");\r
-Clazz.overrideMethod (c$, "setFeature", \r
-function (name, value) {\r
-this.setProperty ("\1" + name, value ? Boolean.TRUE : null);\r
-}, "~S,~B");\r
-Clazz.overrideMethod (c$, "getProperty", \r
-function (name) {\r
-return (this.props == null ? null : this.props.get (name));\r
-}, "~S");\r
-Clazz.overrideMethod (c$, "setProperty", \r
-function (name, value) {\r
-if (value == null) {\r
-if (this.props != null) this.props.remove (name);\r
-return;\r
-}if (this.props == null) this.props =  new java.util.Hashtable ();\r
-this.props.put (name, value);\r
-}, "~S,~O");\r
-Clazz.overrideMethod (c$, "getEntityResolver", \r
-function () {\r
-return this.resolver;\r
-});\r
-Clazz.overrideMethod (c$, "getDTDHandler", \r
-function () {\r
-return this.dtdHandler;\r
-});\r
-Clazz.overrideMethod (c$, "setContentHandler", \r
-function (handler) {\r
-this.contentHandler = handler;\r
-}, "org.xml.sax.ContentHandler");\r
-Clazz.overrideMethod (c$, "getContentHandler", \r
-function () {\r
-return this.contentHandler;\r
-});\r
-Clazz.overrideMethod (c$, "getErrorHandler", \r
-function () {\r
-return this.errorHandler;\r
-});\r
-});\r
+Clazz.declarePackage ("swingjs");
+Clazz.load (["org.xml.sax.Parser", "$.XMLReader"], "swingjs.JSSAXParser", ["java.io.BufferedInputStream", "$.BufferedReader", "java.lang.Boolean", "java.util.Hashtable", "JU.AU", "$.PT", "$.Rdr", "org.xml.sax.SAXParseException", "swingjs.JSSAXAttributes", "$.JSSAXContentHandler", "$.JSToolkit", "swingjs.api.DOMNode"], function () {
+c$ = Clazz.decorateAsClass (function () {
+this.resolver = null;
+this.dtdHandler = null;
+this.docHandler = null;
+this.contentHandler = null;
+this.errorHandler = null;
+this.havePre = false;
+this.uniqueSeq = null;
+this.ver2 = false;
+this.tempChars = null;
+this.props = null;
+Clazz.instantialize (this, arguments);
+}, swingjs, "JSSAXParser", null, [org.xml.sax.Parser, org.xml.sax.XMLReader]);
+Clazz.prepareFields (c$, function () {
+this.tempChars =  Clazz.newCharArray (1024, '\0');
+});
+Clazz.overrideMethod (c$, "setLocale", 
+function (locale) {
+}, "java.util.Locale");
+Clazz.overrideMethod (c$, "setEntityResolver", 
+function (resolver) {
+this.resolver = resolver;
+}, "org.xml.sax.EntityResolver");
+Clazz.overrideMethod (c$, "setDTDHandler", 
+function (handler) {
+this.dtdHandler = handler;
+}, "org.xml.sax.DTDHandler");
+Clazz.overrideMethod (c$, "setDocumentHandler", 
+function (handler) {
+this.docHandler = handler;
+}, "org.xml.sax.DocumentHandler");
+Clazz.overrideMethod (c$, "setErrorHandler", 
+function (handler) {
+this.errorHandler = handler;
+}, "org.xml.sax.ErrorHandler");
+Clazz.defineMethod (c$, "parse", 
+function (source, handler) {
+this.setContentHandler (handler);
+this.parseSource (source);
+}, "org.xml.sax.InputSource,swingjs.JSSAXContentHandler");
+Clazz.defineMethod (c$, "parse", 
+function (source) {
+this.parseSource (source);
+}, "org.xml.sax.InputSource");
+Clazz.defineMethod (c$, "parseSource", 
+ function (source) {
+var rdr = source.getCharacterStream ();
+var data =  new Array (1);
+if (rdr == null) {
+var bs = source.getByteStream ();
+if (!(Clazz.instanceOf (bs, java.io.BufferedInputStream))) bs =  new java.io.BufferedInputStream (bs);
+data[0] = JU.Rdr.fixUTF (JU.Rdr.getStreamAsBytes (bs, null));
+} else {
+if (!(Clazz.instanceOf (rdr, java.io.BufferedReader))) rdr =  new java.io.BufferedReader (rdr);
+JU.Rdr.readAllAsString (rdr, -1, false, data, 0);
+}try {
+this.parseDocument (this.parseXML (data[0]));
+} catch (e) {
+if (Clazz.exceptionOf (e, Exception)) {
+this.error (e);
+} else {
+throw e;
+}
+}
+}, "org.xml.sax.InputSource");
+Clazz.defineMethod (c$, "parse", 
+function (fileName) {
+try {
+this.parseDocument (this.parseXML (swingjs.JSToolkit.getFileContents (fileName)));
+} catch (e) {
+if (Clazz.exceptionOf (e, Exception)) {
+this.error (e);
+} else {
+throw e;
+}
+}
+}, "~S");
+Clazz.defineMethod (c$, "parseXMLString", 
+function (data) {
+try {
+this.parseDocument (this.parseXML (data));
+} catch (e) {
+if (Clazz.exceptionOf (e, Exception)) {
+this.error (e);
+} else {
+throw e;
+}
+}
+}, "~S");
+Clazz.defineMethod (c$, "parseXML", 
+ function (data) {
+return swingjs.JSToolkit.getJQuery ().parseXML (this.removeProcessing (data));
+}, "~S");
+Clazz.defineMethod (c$, "removeProcessing", 
+ function (data) {
+if (data.indexOf ("<?") >= 0) {
+this.getUniqueSequence (data);
+data = JU.PT.rep (JU.PT.rep (data, "<?", "<![CDATA[" + this.uniqueSeq), "?>", "]]>");
+if (data.startsWith ("<!")) {
+data = "<pre>" + data + "</pre>";
+this.havePre = true;
+}}return data;
+}, "~S");
+Clazz.defineMethod (c$, "getUniqueSequence", 
+ function (data) {
+var s = "~";
+while (data.indexOf ("<![CDATA[" + s) >= 0) s += "~";
+
+this.uniqueSeq = s;
+}, "~S");
+Clazz.defineMethod (c$, "error", 
+ function (e) {
+var ee =  new org.xml.sax.SAXParseException ("Invalid Document", null);
+if (this.errorHandler == null) throw (ee);
+ else this.errorHandler.fatalError (ee);
+}, "Exception");
+Clazz.defineMethod (c$, "parseDocument", 
+ function (doc) {
+if (this.docHandler == null && this.contentHandler == null) this.contentHandler =  new swingjs.JSSAXContentHandler ();
+this.ver2 = (this.contentHandler != null);
+if (this.ver2) this.contentHandler.startDocument ();
+ else this.docHandler.startDocument ();
+this.walkDOMTree (swingjs.api.DOMNode.getAttr (doc, "firstChild"), this.havePre);
+if (this.ver2) this.contentHandler.endDocument ();
+ else this.docHandler.endDocument ();
+}, "swingjs.api.DOMNode");
+Clazz.defineMethod (c$, "walkDOMTree", 
+ function (node, skipTag) {
+var localName = (swingjs.api.DOMNode.getAttr (node, "localName"));
+var qName = swingjs.api.DOMNode.getAttr (node, "nodeName");
+var uri = swingjs.api.DOMNode.getAttr (node, "namespaceURI");
+if (localName == null) {
+var isText = "#text".equals (qName);
+if (isText || "#cdata-section".equals (qName)) {
+var data = swingjs.api.DOMNode.getAttr (node, "textContent");
+if (isText || this.uniqueSeq == null || !data.startsWith (this.uniqueSeq)) {
+var len = data.length;
+var ch = this.tempChars;
+if (len > ch.length) ch = this.tempChars = JU.AU.ensureLength (ch, len * 2);
+for (var i = len; --i >= 0; ) ch[i] = data.charAt (i);
+
+if (this.ver2) this.contentHandler.characters (ch, 0, len);
+ else this.docHandler.characters (ch, 0, len);
+return;
+}data = data.substring (this.uniqueSeq.length);
+var target = data + " ";
+target = target.substring (0, target.indexOf (" "));
+data = data.substring (target.length).trim ();
+if (this.ver2) this.contentHandler.processingInstruction (target, data);
+ else this.docHandler.processingInstruction (target, data);
+}} else if (!skipTag) {
+var atts =  new swingjs.JSSAXAttributes (node);
+if (this.ver2) this.contentHandler.startElement (uri, localName, qName, atts);
+ else this.docHandler.startElement (localName, atts);
+}node = swingjs.api.DOMNode.getAttr (node, "firstChild");
+while (node != null) {
+this.walkDOMTree (node, false);
+node = swingjs.api.DOMNode.getAttr (node, "nextSibling");
+}
+if (localName == null || skipTag) return;
+if (this.ver2) this.contentHandler.endElement (uri, localName, qName);
+ else this.docHandler.endElement (localName);
+}, "swingjs.api.DOMNode,~B");
+Clazz.overrideMethod (c$, "getFeature", 
+function (name) {
+return (this.getProperty ("\1" + name) != null);
+}, "~S");
+Clazz.overrideMethod (c$, "setFeature", 
+function (name, value) {
+this.setProperty ("\1" + name, value ? Boolean.TRUE : null);
+}, "~S,~B");
+Clazz.overrideMethod (c$, "getProperty", 
+function (name) {
+return (this.props == null ? null : this.props.get (name));
+}, "~S");
+Clazz.overrideMethod (c$, "setProperty", 
+function (name, value) {
+if (value == null) {
+if (this.props != null) this.props.remove (name);
+return;
+}if (this.props == null) this.props =  new java.util.Hashtable ();
+this.props.put (name, value);
+}, "~S,~O");
+Clazz.overrideMethod (c$, "getEntityResolver", 
+function () {
+return this.resolver;
+});
+Clazz.overrideMethod (c$, "getDTDHandler", 
+function () {
+return this.dtdHandler;
+});
+Clazz.overrideMethod (c$, "setContentHandler", 
+function (handler) {
+this.contentHandler = handler;
+}, "org.xml.sax.ContentHandler");
+Clazz.overrideMethod (c$, "getContentHandler", 
+function () {
+return this.contentHandler;
+});
+Clazz.overrideMethod (c$, "getErrorHandler", 
+function () {
+return this.errorHandler;
+});
+});