verson 0.2 LGPL licensed source and jars
[vamsas.git] / src / uk / ac / vamsas / test / document / SAXTreeViewer.java
1 /*\r
2  * This file is part of the Vamsas Client version 0.2. \r
3  * Copyright 2010 by Jim Procter, Iain Milne, Pierre Marguerite, \r
4  *  Andrew Waterhouse and Dominik Lindner.\r
5  * \r
6  * Earlier versions have also been incorporated into Jalview version 2.4 \r
7  * since 2008, and TOPALi version 2 since 2007.\r
8  * \r
9  * The Vamsas Client is free software: you can redistribute it and/or modify\r
10  * it under the terms of the GNU Lesser General Public License as published by\r
11  * the Free Software Foundation, either version 3 of the License, or\r
12  * (at your option) any later version.\r
13  *  \r
14  * The Vamsas Client is distributed in the hope that it will be useful,\r
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
17  * GNU Lesser General Public License for more details.\r
18  * \r
19  * You should have received a copy of the GNU Lesser General Public License\r
20  * along with the Vamsas Client.  If not, see <http://www.gnu.org/licenses/>.\r
21  */\r
22 package uk.ac.vamsas.test.document;\r
23 \r
24 \r
25 /*-- \r
26 \r
27  Copyright (C) 2001 Brett McLaughlin.\r
28  All rights reserved.\r
29  \r
30  Redistribution and use in source and binary forms, with or without\r
31  modification, are permitted provided that the following conditions\r
32  are met:\r
33  \r
34  1. Redistributions of source code must retain the above copyright\r
35     notice, this list of conditions, and the following disclaimer.\r
36  \r
37  2. Redistributions in binary form must reproduce the above copyright\r
38     notice, this list of conditions, and the disclaimer that follows \r
39     these conditions in the documentation and/or other materials \r
40     provided with the distribution.\r
41 \r
42  3. The name "Java and XML" must not be used to endorse or promote products\r
43     derived from this software without prior written permission.  For\r
44     written permission, please contact brett@newInstance.com.\r
45  \r
46  In addition, we request (but do not require) that you include in the \r
47  end-user documentation provided with the redistribution and/or in the \r
48  software itself an acknowledgement equivalent to the following:\r
49      "This product includes software developed for the\r
50       'Java and XML' book, by Brett McLaughlin (O'Reilly & Associates)."\r
51 \r
52  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED\r
53  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
54  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
55  DISCLAIMED.  IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT\r
56  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
57  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
58  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
59  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
60  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
61  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT\r
62  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
63  SUCH DAMAGE.\r
64 \r
65  */\r
66 import java.io.File;\r
67 import java.io.IOException;\r
68 import java.util.HashMap;\r
69 import java.util.Iterator;\r
70 import java.util.Map;\r
71 import org.xml.sax.Attributes;\r
72 import org.xml.sax.ContentHandler;\r
73 import org.xml.sax.ErrorHandler;\r
74 import org.xml.sax.InputSource;\r
75 import org.xml.sax.Locator;\r
76 import org.xml.sax.SAXException;\r
77 import org.xml.sax.SAXParseException;\r
78 import org.xml.sax.XMLReader;\r
79 import org.xml.sax.helpers.XMLReaderFactory;\r
80 \r
81 import uk.ac.vamsas.client.simpleclient.FileWatcher;\r
82 import uk.ac.vamsas.client.simpleclient.Lock;\r
83 import uk.ac.vamsas.client.simpleclient.SimpleDocument;\r
84 import uk.ac.vamsas.client.simpleclient.VamsasArchiveReader;\r
85 \r
86 // This is an XML book - no need for explicit Swing imports\r
87 import java.awt.*;\r
88 import javax.swing.*;\r
89 import javax.swing.tree.*;\r
90 \r
91 /**\r
92  * <b><code>SAXTreeViewer</code></b> uses Swing to graphically\r
93  *   display an XML document.\r
94  */\r
95 public class SAXTreeViewer extends JFrame {\r
96   /** Default parser to use */\r
97 private String vendorParserClass = \r
98     "org.apache.xerces.parsers.SAXParser";\r
99 \r
100 /** The base tree to render */\r
101 private JTree jTree;\r
102 \r
103 /** Tree model to use */\r
104 DefaultTreeModel defaultTreeModel;\r
105 \r
106 /**\r
107  * <p> This initializes the needed Swing settings. </p>\r
108  */\r
109 public SAXTreeViewer() {\r
110     // Handle Swing setup\r
111     super("SAX Tree Viewer");\r
112     setSize(600, 450);\r
113 }\r
114 \r
115 /**\r
116  * <p> This will construct the tree using Swing. </p>\r
117  *\r
118  * @param filename <code>String</code> path to XML document.\r
119  */\r
120 public void init(String xmlURI) throws IOException, SAXException {\r
121   init(xmlURI, null);\r
122 }\r
123 /**\r
124  * <p> This will construct the tree using Swing. </p>\r
125  *\r
126  * @param filename <code>String</code> apparent path to XML document.\r
127  * @param inputSource <code>InputSource</code> content of XML document\r
128  */\r
129   public void init(String xmlURI, InputSource inputSource) throws IOException, SAXException {\r
130     \r
131     DefaultMutableTreeNode base = \r
132         new DefaultMutableTreeNode("XML Document: " + \r
133             xmlURI);\r
134     \r
135     // Build the tree model\r
136     defaultTreeModel = new DefaultTreeModel(base);\r
137     jTree = new JTree(defaultTreeModel);\r
138 \r
139     // Construct the tree hierarchy\r
140     if (inputSource==null) {\r
141       buildTree(defaultTreeModel, base, xmlURI);\r
142     } else {\r
143       buildTree(defaultTreeModel, base, xmlURI,inputSource);\r
144     }\r
145     // Display the results\r
146     getContentPane().add(new JScrollPane(jTree), \r
147         BorderLayout.CENTER);\r
148 }\r
149 \r
150 /**\r
151  * <p>This handles building the Swing UI tree.</p>\r
152  *\r
153  * @param treeModel Swing component to build upon.\r
154  * @param base tree node to build on.\r
155  * @param xmlURI URI to build XML document from.\r
156  * @throws <code>IOException</code> - when reading the XML URI fails.\r
157  * @throws <code>SAXException</code> - when errors in parsing occur.\r
158  */\r
159 public void buildTree(DefaultTreeModel treeModel, \r
160                       DefaultMutableTreeNode base, String xmlURI) \r
161     throws IOException, SAXException {\r
162   // Parse\r
163   InputSource inputSource = \r
164       new InputSource(xmlURI);\r
165   buildTree(treeModel,base,xmlURI,inputSource);\r
166 }\r
167 /**\r
168  * <p>This handles building the Swing UI tree.</p>\r
169  *\r
170  * @param treeModel Swing component to build upon.\r
171  * @param base tree node to build on.\r
172  * @param xmlURI apparent URI to build XML document from.\r
173  * @param inputSource the xml datasource to get the content from\r
174  * @throws SAXException \r
175  * @throws IOException \r
176  * @throws <code>IOException</code> - when reading the XML URI fails.\r
177  * @throws <code>SAXException</code> - when errors in parsing occur.\r
178  */\r
179 public void buildTree(DefaultTreeModel treeModel, \r
180     DefaultMutableTreeNode base, String xmlURI, InputSource inputSource) throws IOException, SAXException {\r
181 \r
182     // Create instances needed for parsing\r
183     XMLReader reader = \r
184         XMLReaderFactory.createXMLReader(vendorParserClass);\r
185     ContentHandler jTreeContentHandler = \r
186         new JTreeContentHandler(treeModel, base);\r
187     ErrorHandler jTreeErrorHandler = new JTreeErrorHandler();\r
188 \r
189     // Register content handler\r
190     reader.setContentHandler(jTreeContentHandler);\r
191 \r
192     // Register error handler\r
193     reader.setErrorHandler(jTreeErrorHandler);\r
194 \r
195     reader.parse(inputSource);\r
196 }\r
197 private static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(SAXTreeViewer.class);\r
198 \r
199 /**\r
200  * <p> Static entry point for running the viewer. </p>\r
201  */\r
202 public static void main(String[] args) {\r
203     try {\r
204       File archive = new File(args[0]);\r
205       // start watching a vamsas document archive\r
206       // watch\r
207       log.info("Endlessly Watching file " + archive);\r
208       /*\r
209        * if (!archive.exists()) archive.createNewFile();\r
210        */// watch the new file... - taken straight from ClientsFileTest\r
211       FileWatcher w = new FileWatcher(archive);\r
212       SAXTreeViewer currentview = null;\r
213       boolean first=true;\r
214       while (true) {\r
215         // get watcher's lock to ensure state change is fixed for\r
216         // retrieval\r
217         Lock chlock = w.getChangedState();\r
218         if (first || chlock != null) {\r
219           log.info("Got lock on "\r
220               + archive\r
221               + (archive.exists() ? " exists l=" + archive.length()\r
222                   : "(non existant)"));\r
223           first = false;\r
224           if (archive.length() > 0) {\r
225             VamsasArchiveReader vreader = new VamsasArchiveReader(archive);\r
226             SimpleDocument sdoc = new SimpleDocument(\r
227                 "testing vamsas watcher");\r
228             try {\r
229               // pass the archive XML content to the xml viewer.\r
230               SAXTreeViewer newview = new SAXTreeViewer();\r
231               newview.init(archive.toURI().toString(), new org.xml.sax.InputSource(vreader.getVamsasDocumentStream()));\r
232               if (currentview != null)\r
233               {\r
234                 newview.setBounds(currentview.getBounds());\r
235                 // somehow copy over expanded state for existing objects and scroll state.\r
236                 // could also highlight new / modified nodes.\r
237                 newview.setVisible(true);\r
238                 currentview.setVisible(false);\r
239                 currentview.dispose();\r
240               } else {\r
241                 newview.setVisible(true);\r
242               }\r
243               currentview = newview;\r
244               \r
245               /* VamsasDocument d = sdoc.getVamsasDocument(vreader);\r
246               if (d != null) {\r
247                 ArchiveReports.reportDocument(d, vreader, false,\r
248                     System.out);\r
249               }*/\r
250               System.out\r
251                   .println("Update at "\r
252                       + System.currentTimeMillis()\r
253                       + "\n\n********************************************************\n");\r
254             } catch (Exception e) {\r
255               log.error("Unmarshalling failed.", e);\r
256             }\r
257             vreader.close();\r
258             w.setState();\r
259           } \r
260         }\r
261         Thread.sleep(2000);\r
262       }\r
263     } catch (Exception e) {\r
264       log.info("Going away now.",e);\r
265     }\r
266 }\r
267 }\r
268 \r
269 /**\r
270 * <b><code>JTreeContentHandler</code></b> implements the SAX\r
271 *   <code>ContentHandler</code> interface and defines callback\r
272 *   behavior for the SAX callbacks associated with an XML\r
273 *   document's content, bulding up JTree nodes.\r
274 */\r
275 class JTreeContentHandler implements ContentHandler {\r
276 \r
277 /** Hold onto the locator for location information */\r
278 private Locator locator;\r
279 \r
280 /** Store URI to prefix mappings */\r
281 private Map namespaceMappings;\r
282 \r
283 /** Tree Model to add nodes to */\r
284 private DefaultTreeModel treeModel;\r
285 \r
286 /** Current node to add sub-nodes to */\r
287 private DefaultMutableTreeNode current;\r
288 \r
289 /**\r
290  * <p> Set up for working with the JTree. </p>\r
291  *\r
292  * @param treeModel tree to add nodes to.\r
293  * @param base node to start adding sub-nodes to.\r
294  */\r
295 public JTreeContentHandler(DefaultTreeModel treeModel, \r
296                            DefaultMutableTreeNode base) {\r
297     this.treeModel = treeModel;\r
298     this.current = base;\r
299     this.namespaceMappings = new HashMap();\r
300 }\r
301 \r
302 /**\r
303  * <p>\r
304  *  Provide reference to <code>Locator</code> which provides\r
305  *    information about where in a document callbacks occur.\r
306  * </p>\r
307  *\r
308  * @param locator <code>Locator</code> object tied to callback\r
309  *        process\r
310  */\r
311 public void setDocumentLocator(Locator locator) {\r
312     // Save this for later use\r
313     this.locator = locator;\r
314 }\r
315 \r
316 /**\r
317  * <p>\r
318  *  This indicates the start of a Document parse-this precedes\r
319  *    all callbacks in all SAX Handlers with the sole exception\r
320  *    of <code>{@link #setDocumentLocator}</code>.\r
321  * </p>\r
322  *\r
323  * @throws <code>SAXException</code> when things go wrong\r
324  */\r
325 public void startDocument() throws SAXException {\r
326     // No visual events occur here\r
327 }\r
328 \r
329 /**\r
330  * <p>\r
331  *  This indicates the end of a Document parse-this occurs after\r
332  *    all callbacks in all SAX Handlers.</code>.\r
333  * </p>\r
334  *\r
335  * @throws <code>SAXException</code> when things go wrong\r
336  */\r
337 public void endDocument() throws SAXException {\r
338     // No visual events occur here\r
339 }\r
340 \r
341 /**\r
342  * <p>\r
343  *   This indicates that a processing instruction (other than\r
344  *     the XML declaration) has been encountered.\r
345  * </p>\r
346  *\r
347  * @param target <code>String</code> target of PI\r
348  * @param data <code>String</code containing all data sent to the PI.\r
349  *               This typically looks like one or more attribute value\r
350  *               pairs.\r
351  * @throws <code>SAXException</code> when things go wrong\r
352  */\r
353 public void processingInstruction(String target, String data)\r
354     throws SAXException {\r
355 \r
356     DefaultMutableTreeNode pi = \r
357         new DefaultMutableTreeNode("PI (target = '" + target +\r
358                                    "', data = '" + data + "')");\r
359     current.add(pi);\r
360 }\r
361 \r
362 /**\r
363  * <p>\r
364  *   This indicates the beginning of an XML Namespace prefix\r
365  *     mapping. Although this typically occurs within the root element\r
366  *     of an XML document, it can occur at any point within the\r
367  *     document. Note that a prefix mapping on an element triggers\r
368  *     this callback <i>before</i> the callback for the actual element\r
369  *     itself (<code>{@link #startElement}</code>) occurs.\r
370  * </p>\r
371  *\r
372  * @param prefix <code>String</code> prefix used for the namespace\r
373  *                being reported\r
374  * @param uri <code>String</code> URI for the namespace\r
375  *               being reported\r
376  * @throws <code>SAXException</code> when things go wrong\r
377  */\r
378 public void startPrefixMapping(String prefix, String uri) {\r
379     // No visual events occur here.\r
380     namespaceMappings.put(uri, prefix);\r
381 }\r
382 \r
383 /**\r
384  * <p>\r
385  *   This indicates the end of a prefix mapping, when the namespace\r
386  *     reported in a <code>{@link #startPrefixMapping}</code> callback\r
387  *     is no longer available.\r
388  * </p>\r
389  *\r
390  * @param prefix <code>String</code> of namespace being reported\r
391  * @throws <code>SAXException</code> when things go wrong\r
392  */\r
393 public void endPrefixMapping(String prefix) {\r
394     // No visual events occur here.\r
395     for (Iterator i = namespaceMappings.keySet().iterator(); \r
396          i.hasNext(); ) {\r
397 \r
398         String uri = (String)i.next();\r
399         String thisPrefix = (String)namespaceMappings.get(uri);\r
400         if (prefix.equals(thisPrefix)) {\r
401             namespaceMappings.remove(uri);\r
402             break;\r
403         }\r
404     }\r
405 }\r
406 \r
407 /**\r
408  * <p>\r
409  *   This reports the occurrence of an actual element. It includes\r
410  *     the element's attributes, with the exception of XML vocabulary\r
411  *     specific attributes, such as\r
412  *     <code>xmlns:[namespace prefix]</code> and\r
413  *     <code>xsi:schemaLocation</code>.\r
414  * </p>\r
415  *\r
416  * @param namespaceURI <code>String</code> namespace URI this element\r
417  *               is associated with, or an empty <code>String</code>\r
418  * @param localName <code>String</code> name of element (with no\r
419  *               namespace prefix, if one is present)\r
420  * @param qName <code>String</code> XML 1.0 version of element name:\r
421  *                [namespace prefix]:[localName]\r
422  * @param atts <code>Attributes</code> list for this element\r
423  * @throws <code>SAXException</code> when things go wrong\r
424  */\r
425 public void startElement(String namespaceURI, String localName,\r
426                          String qName, Attributes atts)\r
427     throws SAXException {\r
428 \r
429     DefaultMutableTreeNode element = \r
430         new DefaultMutableTreeNode("Element: " + localName);\r
431     current.add(element);\r
432     current = element;\r
433 \r
434     // Determine namespace\r
435     if (namespaceURI.length() > 0) {\r
436         String prefix = \r
437             (String)namespaceMappings.get(namespaceURI);\r
438         if (prefix.equals("")) {\r
439             prefix = "[None]";\r
440         }\r
441         DefaultMutableTreeNode namespace =\r
442             new DefaultMutableTreeNode("Namespace: prefix = '" +\r
443                 prefix + "', URI = '" + namespaceURI + "'");\r
444         current.add(namespace);\r
445     }\r
446 \r
447     // Process attributes\r
448     for (int i=0; i<atts.getLength(); i++) {\r
449         DefaultMutableTreeNode attribute =\r
450             new DefaultMutableTreeNode("Attribute (name = '" +\r
451                                        atts.getLocalName(i) + \r
452                                        "', value = '" +\r
453                                        atts.getValue(i) + "')");\r
454         String attURI = atts.getURI(i);\r
455         if (attURI.length() > 0) {\r
456             String attPrefix = \r
457                 (String)namespaceMappings.get(namespaceURI);\r
458             if (attPrefix.equals("")) {\r
459                 attPrefix = "[None]";\r
460             }\r
461             DefaultMutableTreeNode attNamespace =\r
462                 new DefaultMutableTreeNode("Namespace: prefix = '" +\r
463                     attPrefix + "', URI = '" + attURI + "'");\r
464             attribute.add(attNamespace);            \r
465         }\r
466         current.add(attribute);\r
467     }\r
468 }\r
469 \r
470 /**\r
471  * <p>\r
472  *   Indicates the end of an element\r
473  *     (<code>&lt;/[element name]&gt;</code>) is reached. Note that\r
474  *     the parser does not distinguish between empty\r
475  *     elements and non-empty elements, so this occurs uniformly.\r
476  * </p>\r
477  *\r
478  * @param namespaceURI <code>String</code> URI of namespace this\r
479  *                element is associated with\r
480  * @param localName <code>String</code> name of element without prefix\r
481  * @param qName <code>String</code> name of element in XML 1.0 form\r
482  * @throws <code>SAXException</code> when things go wrong\r
483  */\r
484 public void endElement(String namespaceURI, String localName,\r
485                        String qName)\r
486     throws SAXException {\r
487 \r
488     // Walk back up the tree\r
489     current = (DefaultMutableTreeNode)current.getParent();\r
490 }\r
491 \r
492 /**\r
493  * <p>\r
494  *   This reports character data (within an element).\r
495  * </p>\r
496  *\r
497  * @param ch <code>char[]</code> character array with character data\r
498  * @param start <code>int</code> index in array where data starts.\r
499  * @param length <code>int</code> index in array where data ends.\r
500  * @throws <code>SAXException</code> when things go wrong\r
501  */\r
502 public void characters(char[] ch, int start, int length)\r
503     throws SAXException {\r
504 \r
505     String s = new String(ch, start, length);\r
506     DefaultMutableTreeNode data =\r
507         new DefaultMutableTreeNode("Character Data: '" + s + "'");\r
508     current.add(data);\r
509 }\r
510 \r
511 /**\r
512  * <p>\r
513  * This reports whitespace that can be ignored in the\r
514  * originating document. This is typically invoked only when\r
515  * validation is ocurring in the parsing process.\r
516  * </p>\r
517  *\r
518  * @param ch <code>char[]</code> character array with character data\r
519  * @param start <code>int</code> index in array where data starts.\r
520  * @param end <code>int</code> index in array where data ends.\r
521  * @throws <code>SAXException</code> when things go wrong\r
522  */\r
523 public void ignorableWhitespace(char[] ch, int start, int length)\r
524     throws SAXException {\r
525     \r
526     // This is ignorable, so don't display it\r
527 }\r
528 \r
529 /**\r
530  * <p>\r
531  *   This reports an entity that is skipped by the parser. This\r
532  *     should only occur for non-validating parsers, and then is still\r
533  *     implementation-dependent behavior.\r
534  * </p>\r
535  *\r
536  * @param name <code>String</code> name of entity being skipped\r
537  * @throws <code>SAXException</code> when things go wrong\r
538  */\r
539 public void skippedEntity(String name) throws SAXException {\r
540     DefaultMutableTreeNode skipped =\r
541         new DefaultMutableTreeNode("Skipped Entity: '" + name + "'");\r
542     current.add(skipped);\r
543 }\r
544 }\r
545 \r
546 /**\r
547 * <b><code>JTreeErrorHandler</code></b> implements the SAX\r
548 *   <code>ErrorHandler</code> interface and defines callback\r
549 *   behavior for the SAX callbacks associated with an XML\r
550 *   document's warnings and errors.\r
551 */\r
552 class JTreeErrorHandler implements ErrorHandler {\r
553 \r
554 /**\r
555  * <p>\r
556  * This will report a warning that has occurred; this indicates\r
557  *   that while no XML rules were "broken", something appears\r
558  *   to be incorrect or missing.\r
559  * </p>\r
560  *\r
561  * @param exception <code>SAXParseException</code> that occurred.\r
562  * @throws <code>SAXException</code> when things go wrong \r
563  */\r
564 public void warning(SAXParseException exception)\r
565     throws SAXException {\r
566         \r
567     System.out.println("**Parsing Warning**\n" +\r
568                        "  Line:    " + \r
569                           exception.getLineNumber() + "\n" +\r
570                        "  URI:     " + \r
571                           exception.getSystemId() + "\n" +\r
572                        "  Message: " + \r
573                           exception.getMessage());        \r
574     throw new SAXException("Warning encountered");\r
575 }\r
576 \r
577 /**\r
578  * <p>\r
579  * This will report an error that has occurred; this indicates\r
580  *   that a rule was broken, typically in validation, but that\r
581  *   parsing can reasonably continue.\r
582  * </p>\r
583  *\r
584  * @param exception <code>SAXParseException</code> that occurred.\r
585  * @throws <code>SAXException</code> when things go wrong \r
586  */\r
587 public void error(SAXParseException exception)\r
588     throws SAXException {\r
589     \r
590     System.out.println("**Parsing Error**\n" +\r
591                        "  Line:    " + \r
592                           exception.getLineNumber() + "\n" +\r
593                        "  URI:     " + \r
594                           exception.getSystemId() + "\n" +\r
595                        "  Message: " + \r
596                           exception.getMessage());\r
597     throw new SAXException("Error encountered");\r
598 }\r
599 \r
600 /**\r
601  * <p>\r
602  * This will report a fatal error that has occurred; this indicates\r
603  *   that a rule has been broken that makes continued parsing either\r
604  *   impossible or an almost certain waste of time.\r
605  * </p>\r
606  *\r
607  * @param exception <code>SAXParseException</code> that occurred.\r
608  * @throws <code>SAXException</code> when things go wrong \r
609  */\r
610 public void fatalError(SAXParseException exception)\r
611     throws SAXException {\r
612 \r
613     System.out.println("**Parsing Fatal Error**\n" +\r
614                        "  Line:    " + \r
615                           exception.getLineNumber() + "\n" +\r
616                        "  URI:     " + \r
617                           exception.getSystemId() + "\n" +\r
618                        "  Message: " + \r
619                           exception.getMessage());        \r
620     throw new SAXException("Fatal Error encountered");\r
621 }\r
622 }\r