PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/XInsert/src/XInsertReader.java

#
Java | 72 lines | 42 code | 6 blank | 24 comment | 0 complexity | feb5cc0beac1c09ec8ea2d74d2e7409d MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * 13:44:51 17/06/99
  3. *
  4. * XInsertReader.java - Reads xml-insert files
  5. * Copyright (C) 1999 Romain Guy
  6. * www.chez.com/powerteam
  7. * powerteam@chez.com
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. import java.io.*;
  24. import org.gjt.sp.util.Log;
  25. import org.xml.sax.helpers.XMLReaderFactory;
  26. import org.xml.sax.XMLReader;
  27. import org.xml.sax.InputSource;
  28. import org.xml.sax.SAXException;
  29. import org.xml.sax.SAXParseException;
  30. public class XInsertReader {
  31. public XInsertReader() { }
  32. public static boolean read(XTree tree, InputStream inputStream, String file) {
  33. InputStreamReader reader = new InputStreamReader(inputStream);
  34. XInsertHandler xmh = new XInsertHandler(tree);
  35. try
  36. {
  37. XMLReader parser = XMLReaderFactory.createXMLReader();
  38. parser.setErrorHandler(xmh);
  39. parser.setContentHandler(xmh);
  40. parser.setEntityResolver(xmh);
  41. parser.parse(new InputSource(reader));
  42. } catch(SAXParseException e) {
  43. Log.log(Log.ERROR,tree,"XInsert: Error parsing grammar " + file);
  44. Log.log(Log.ERROR,tree,"XInsert: Error occured at line " + e.getLineNumber() +
  45. ", column " + e.getColumnNumber());
  46. Log.log(Log.ERROR,tree,"XInsert: " + e.getMessage());
  47. return false;
  48. } catch(IOException ioe) {
  49. Log.log(Log.ERROR,tree,"XInsert: Error parsing grammar " + file);
  50. Log.log(Log.ERROR,tree,ioe);
  51. return false;
  52. } catch (Exception e) {
  53. // Should NEVER happend !
  54. e.printStackTrace();
  55. return false;
  56. } finally {
  57. try {
  58. reader.close();
  59. } catch (IOException ioe) {
  60. ioe.printStackTrace();
  61. }
  62. }
  63. return true;
  64. }
  65. }
  66. // End of XInsertReader.java