/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/ModeCatalogHandler.java

# · Java · 94 lines · 58 code · 18 blank · 18 comment · 10 complexity · 3e5a78e33a14b0e216e0385a9eb43578 MD5 · raw file

  1. /*
  2. * ModeCatalogHandler.java - XML handler for mode catalog files
  3. * Copyright (C) 2000, 2001 Slava Pestov
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. package org.gjt.sp.jedit;
  20. import java.io.*;
  21. import org.xml.sax.Attributes;
  22. import org.xml.sax.InputSource;
  23. import org.xml.sax.helpers.DefaultHandler;
  24. import org.gjt.sp.util.Log;
  25. class ModeCatalogHandler extends DefaultHandler
  26. {
  27. ModeCatalogHandler(String directory, boolean resource)
  28. {
  29. this.directory = directory;
  30. this.resource = resource;
  31. }
  32. public InputSource resolveEntity(String publicId, String systemId)
  33. {
  34. return MiscUtilities.findEntity(systemId, "catalog.dtd", getClass());
  35. }
  36. public void startElement(String uri, String localName,
  37. String qName, Attributes attrs)
  38. {
  39. if (qName.equals("MODE"))
  40. {
  41. String modeName = attrs.getValue("NAME");
  42. String file = attrs.getValue("FILE");
  43. if(file == null)
  44. {
  45. Log.log(Log.ERROR,this,directory + "catalog:"
  46. + " mode " + modeName + " doesn't have"
  47. + " a FILE attribute");
  48. }
  49. String filenameGlob = attrs.getValue("FILE_NAME_GLOB");
  50. String firstlineGlob = attrs.getValue("FIRST_LINE_GLOB");
  51. Mode mode = jEdit.getMode(modeName);
  52. if(mode == null)
  53. {
  54. mode = new Mode(modeName);
  55. jEdit.addMode(mode);
  56. }
  57. Object path;
  58. if(resource)
  59. path = jEdit.class.getResource(directory + file);
  60. else
  61. path = MiscUtilities.constructPath(directory,file);
  62. mode.setProperty("file",path);
  63. if(filenameGlob != null)
  64. mode.setProperty("filenameGlob",filenameGlob);
  65. else
  66. mode.unsetProperty("filenameGlob");
  67. if(firstlineGlob != null)
  68. mode.setProperty("firstlineGlob",firstlineGlob);
  69. else
  70. mode.unsetProperty("firstlineGlob");
  71. mode.init();
  72. }
  73. }
  74. private String directory;
  75. private boolean resource;
  76. }