/jEdit/branches/jedit43_nostrings/org/gjt/sp/jedit/ModeCatalogHandler.java

# · Java · 95 lines · 59 code · 18 blank · 18 comment · 10 complexity · f950777e418309ef80df04132a892bc4 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. import org.gjt.sp.util.XMLUtilities;
  26. class ModeCatalogHandler extends DefaultHandler
  27. {
  28. ModeCatalogHandler(String directory, boolean resource)
  29. {
  30. this.directory = directory;
  31. this.resource = resource;
  32. }
  33. public InputSource resolveEntity(String publicId, String systemId)
  34. {
  35. return XMLUtilities.findEntity(systemId, "catalog.dtd", getClass());
  36. }
  37. public void startElement(String uri, String localName,
  38. String qName, Attributes attrs)
  39. {
  40. if (qName.equals("MODE"))
  41. {
  42. String modeName = attrs.getValue("NAME");
  43. String file = attrs.getValue("FILE");
  44. if(file == null)
  45. {
  46. Log.log(Log.ERROR,this,directory + "catalog:"
  47. + " mode " + modeName + " doesn't have"
  48. + " a FILE attribute");
  49. }
  50. String filenameGlob = attrs.getValue("FILE_NAME_GLOB");
  51. String firstlineGlob = attrs.getValue("FIRST_LINE_GLOB");
  52. Mode mode = jEdit.getMode(modeName);
  53. if(mode == null)
  54. {
  55. mode = new Mode(modeName);
  56. jEdit.addMode(mode);
  57. }
  58. Object path;
  59. if(resource)
  60. path = jEdit.class.getResource(directory + file);
  61. else
  62. path = MiscUtilities.constructPath(directory,file);
  63. mode.setProperty("file",path);
  64. if(filenameGlob != null)
  65. mode.setProperty("filenameGlob",filenameGlob);
  66. else
  67. mode.unsetProperty("filenameGlob");
  68. if(firstlineGlob != null)
  69. mode.setProperty("firstlineGlob",firstlineGlob);
  70. else
  71. mode.unsetProperty("firstlineGlob");
  72. mode.init();
  73. }
  74. }
  75. private String directory;
  76. private boolean resource;
  77. }