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

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/ModeCatalogHandler.java

#
Java | 142 lines | 82 code | 20 blank | 40 comment | 25 complexity | 3a6e09d24a4518b20afbc7db3652e8ca 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. import com.microstar.xml.*;
  21. import java.io.*;
  22. import org.gjt.sp.util.Log;
  23. class ModeCatalogHandler extends HandlerBase
  24. {
  25. ModeCatalogHandler(String directory, boolean resource)
  26. {
  27. this.directory = directory;
  28. this.resource = resource;
  29. }
  30. public Object resolveEntity(String publicId, String systemId)
  31. {
  32. if("catalog.dtd".equals(systemId))
  33. {
  34. // this will result in a slight speed up, since we
  35. // don't need to read the DTD anyway, as AElfred is
  36. // non-validating
  37. return new StringReader("<!-- -->");
  38. /* try
  39. {
  40. return new BufferedReader(new InputStreamReader(
  41. getClass().getResourceAsStream("catalog.dtd")));
  42. }
  43. catch(Exception e)
  44. {
  45. Log.log(Log.ERROR,this,"Error while opening"
  46. + " catalog.dtd:");
  47. Log.log(Log.ERROR,this,e);
  48. } */
  49. }
  50. return null;
  51. }
  52. public void attribute(String aname, String value, boolean isSpecified)
  53. {
  54. aname = (aname == null) ? null : aname.intern();
  55. if(aname == "NAME")
  56. modeName = value;
  57. else if(aname == "FILE")
  58. {
  59. if(value == null)
  60. {
  61. Log.log(Log.ERROR,this,directory + "catalog:"
  62. + " mode " + modeName + " doesn't have"
  63. + " a FILE attribute");
  64. }
  65. else
  66. file = value;
  67. }
  68. else if(aname == "FILE_NAME_GLOB")
  69. filenameGlob = value;
  70. else if(aname == "FIRST_LINE_GLOB")
  71. firstlineGlob = value;
  72. }
  73. public void doctypeDecl(String name, String publicId,
  74. String systemId) throws Exception
  75. {
  76. // older jEdit versions used a DOCTYPE of CATALOG, which
  77. // is incorrect since the DOCTYPE must be the name of the
  78. // root element, which is MODES.
  79. // so you the avid code reader should use MODES as the
  80. // DOCTYPE instead, but we still let old catalogs through
  81. // to avoid annoying users.
  82. if("CATALOG".equals(name) || "MODES".equals(name))
  83. return;
  84. Log.log(Log.ERROR,this,directory + "catalog: DOCTYPE must be CATALOG");
  85. }
  86. public void endElement(String name)
  87. {
  88. if(name.equals("MODE"))
  89. {
  90. Mode mode = jEdit.getMode(modeName);
  91. if(mode == null)
  92. {
  93. mode = new Mode(modeName);
  94. jEdit.addMode(mode);
  95. }
  96. Object path;
  97. if(resource)
  98. path = jEdit.class.getResource(directory + file);
  99. else
  100. path = MiscUtilities.constructPath(directory,file);
  101. mode.setProperty("file",path);
  102. if(filenameGlob != null)
  103. mode.setProperty("filenameGlob",filenameGlob);
  104. else
  105. mode.unsetProperty("filenameGlob");
  106. if(firstlineGlob != null)
  107. mode.setProperty("firstlineGlob",firstlineGlob);
  108. else
  109. mode.unsetProperty("firstlineGlob");
  110. mode.init();
  111. modeName = file = filenameGlob = firstlineGlob = null;
  112. }
  113. }
  114. // end HandlerBase implementation
  115. // private members
  116. private String directory;
  117. private boolean resource;
  118. private String modeName;
  119. private String file;
  120. private String filenameGlob;
  121. private String firstlineGlob;
  122. }