PageRenderTime 38ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/ModeCatalogHandler.java

#
Java | 104 lines | 61 code | 17 blank | 26 comment | 10 complexity | f1737f6de97eddfa499ee859248ec3cb 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. * 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. //{{{ Imports
  21. import org.gjt.sp.jedit.syntax.ModeProvider;
  22. import org.gjt.sp.util.Log;
  23. import org.gjt.sp.util.XMLUtilities;
  24. import org.xml.sax.Attributes;
  25. import org.xml.sax.InputSource;
  26. import org.xml.sax.helpers.DefaultHandler;
  27. //}}}
  28. /**
  29. * @author Slava Pestov
  30. */
  31. class ModeCatalogHandler extends DefaultHandler
  32. {
  33. //{{{ ModeCatalogHandler constructor
  34. ModeCatalogHandler(String directory, boolean resource)
  35. {
  36. this.directory = directory;
  37. this.resource = resource;
  38. } //}}}
  39. //{{{ resolveEntity() method
  40. public InputSource resolveEntity(String publicId, String systemId)
  41. {
  42. return XMLUtilities.findEntity(systemId, "catalog.dtd", getClass());
  43. } //}}}
  44. //{{{ startElement() method
  45. public void startElement(String uri, String localName,
  46. String qName, Attributes attrs)
  47. {
  48. if (qName.equals("MODE"))
  49. {
  50. String modeName = attrs.getValue("NAME");
  51. String file = attrs.getValue("FILE");
  52. if(file == null)
  53. {
  54. Log.log(Log.ERROR,this,directory + "catalog:"
  55. + " mode " + modeName + " doesn't have"
  56. + " a FILE attribute");
  57. }
  58. String filenameGlob = attrs.getValue("FILE_NAME_GLOB");
  59. String firstlineGlob = attrs.getValue("FIRST_LINE_GLOB");
  60. Mode mode = ModeProvider.instance.getMode(modeName);
  61. if (mode == null)
  62. {
  63. mode = instantiateMode(modeName);
  64. }
  65. ModeProvider.instance.addMode(mode);
  66. Object path;
  67. if(resource)
  68. path = jEdit.class.getResource(directory + file);
  69. else
  70. path = MiscUtilities.constructPath(directory,file);
  71. mode.setProperty("file",path);
  72. mode.unsetProperty("filenameGlob");
  73. if(filenameGlob != null)
  74. mode.setProperty("filenameGlob",filenameGlob);
  75. mode.unsetProperty("firstlineGlob");
  76. if(firstlineGlob != null)
  77. mode.setProperty("firstlineGlob",firstlineGlob);
  78. mode.init();
  79. }
  80. } //}}}
  81. protected Mode instantiateMode(String modeName)
  82. {
  83. return new Mode(modeName);
  84. }
  85. private String directory;
  86. private boolean resource;
  87. }