9662dc37a8721db84bbe6174527f0b31498262ef
[jalviewjs.git] / site / j2s / org / xml / sax / demo / DemoHandler.js
1 Clazz.declarePackage ("org.xml.sax.demo");
2 Clazz.load (["org.xml.sax.DTDHandler", "$.DocumentHandler", "$.EntityResolver", "$.ErrorHandler"], "org.xml.sax.demo.DemoHandler", null, function () {
3 c$ = Clazz.declareType (org.xml.sax.demo, "DemoHandler", null, [org.xml.sax.EntityResolver, org.xml.sax.DTDHandler, org.xml.sax.DocumentHandler, org.xml.sax.ErrorHandler]);
4 Clazz.overrideMethod (c$, "resolveEntity", 
5 function (publicId, systemId) {
6 System.out.print ("Resolve entity:");
7 if (publicId != null) {
8 System.out.print (" publicId=\"" + publicId + '"');
9 }System.out.println (" systemId=\"" + systemId + '"');
10 return null;
11 }, "~S,~S");
12 Clazz.overrideMethod (c$, "notationDecl", 
13 function (name, publicId, systemId) {
14 System.out.print ("Notation declaration: " + name);
15 if (publicId != null) {
16 System.out.print (" publicId=\"" + publicId + '"');
17 }if (systemId != null) {
18 System.out.print (" systemId=\"" + systemId + '"');
19 }System.out.print ('\n');
20 }, "~S,~S,~S");
21 Clazz.overrideMethod (c$, "unparsedEntityDecl", 
22 function (name, publicId, systemId, notationName) {
23 System.out.print ("Unparsed Entity Declaration: " + name);
24 if (publicId != null) {
25 System.out.print (" publicId=\"" + publicId + '"');
26 }if (systemId != null) {
27 System.out.print (" systemId=\"" + systemId + '"');
28 }System.out.println (" notationName=\"" + notationName + '"');
29 }, "~S,~S,~S,~S");
30 Clazz.overrideMethod (c$, "setDocumentLocator", 
31 function (locator) {
32 System.out.println ("Document locator supplied.");
33 }, "org.xml.sax.Locator");
34 Clazz.overrideMethod (c$, "startDocument", 
35 function () {
36 System.out.println ("Start document");
37 });
38 Clazz.overrideMethod (c$, "endDocument", 
39 function () {
40 System.out.println ("End document");
41 });
42 Clazz.overrideMethod (c$, "startElement", 
43 function (name, attributes) {
44 System.out.println ("Start element: " + name);
45 for (var i = 0; i < attributes.getLength (); i++) {
46 System.out.println ("  Attribute: " + attributes.getName (i) + ' ' + attributes.getType (i) + " \"" + attributes.getValue (i) + '"');
47 }
48 }, "~S,org.xml.sax.AttributeList");
49 Clazz.overrideMethod (c$, "endElement", 
50 function (name) {
51 System.out.println ("End element: " + name);
52 }, "~S");
53 Clazz.overrideMethod (c$, "characters", 
54 function (ch, start, length) {
55 System.out.print ("Characters: ");
56 org.xml.sax.demo.DemoHandler.display (ch, start, length);
57 }, "~A,~N,~N");
58 Clazz.overrideMethod (c$, "ignorableWhitespace", 
59 function (ch, start, length) {
60 System.out.print ("Ignorable Whitespace: ");
61 org.xml.sax.demo.DemoHandler.display (ch, start, length);
62 }, "~A,~N,~N");
63 Clazz.overrideMethod (c$, "processingInstruction", 
64 function (target, data) {
65 System.out.println ("Processing instruction: " + target + ' ' + data);
66 }, "~S,~S");
67 Clazz.overrideMethod (c$, "warning", 
68 function (exception) {
69 System.out.println ("Warning: " + exception.getMessage () + " (" + exception.getSystemId () + ':' + exception.getLineNumber () + ',' + exception.getColumnNumber () + ')');
70 }, "org.xml.sax.SAXParseException");
71 Clazz.overrideMethod (c$, "error", 
72 function (exception) {
73 System.out.println ("Recoverable Error: " + exception.getMessage () + " (" + exception.getSystemId () + ':' + exception.getLineNumber () + ',' + exception.getColumnNumber () + ')');
74 }, "org.xml.sax.SAXParseException");
75 Clazz.overrideMethod (c$, "fatalError", 
76 function (exception) {
77 System.out.println ("Fatal Error: " + exception.getMessage () + " (" + exception.getSystemId () + ':' + exception.getLineNumber () + ',' + exception.getColumnNumber () + ')');
78 }, "org.xml.sax.SAXParseException");
79 c$.display = Clazz.defineMethod (c$, "display", 
80  function (ch, start, length) {
81 for (var i = start; i < start + length; i++) {
82 switch (ch[i]) {
83 case '\n':
84 System.out.print ("\\n");
85 break;
86 case '\t':
87 System.out.print ("\\t");
88 break;
89 default:
90 System.out.print (ch[i]);
91 break;
92 }
93 }
94 System.out.print ("\n");
95 }, "~A,~N,~N");
96 });