/**
  * Returns the edit mode with the specified name.
  *
  * @param name The edit mode
  * @since jEdit 4.3pre10
  */
 public Mode getMode(String name) {
   for (int i = 0; i < modes.size(); i++) {
     Mode mode = modes.get(i);
     if (mode.getName().equals(name)) return mode;
   }
   return null;
 } // }}}
  // {{{ loadMode() method
  public void loadMode(Mode mode, XModeHandler xmh) {
    String fileName = (String) mode.getProperty("file");

    Log.log(Log.NOTICE, this, "Loading edit mode " + fileName);

    XMLReader parser;
    try {
      parser = XMLReaderFactory.createXMLReader();
    } catch (SAXException saxe) {
      Log.log(Log.ERROR, this, saxe);
      return;
    }
    mode.setTokenMarker(xmh.getTokenMarker());

    InputStream resource = ClassLoader.getSystemClassLoader().getResourceAsStream(fileName);
    if (resource == null) {
      // don't just print an error to console. This is a problem.
      throw new RuntimeException("File not found " + fileName);
    }

    BufferedReader br = new BufferedReader(new InputStreamReader(resource));

    try {
      InputSource isrc = new InputSource(br);
      // isrc.setSystemId("jedit.jar");
      parser.setContentHandler(xmh);
      parser.setDTDHandler(xmh);
      parser.setEntityResolver(xmh);
      parser.setErrorHandler(xmh);
      parser.parse(isrc);

      mode.setProperties(xmh.getModeProperties());
    } catch (Throwable e) {
      error(fileName, e);
    } finally {
      IOUtilities.closeQuietly(resource);
    }
  } // }}}
  // {{{ loadMode() method
  public void loadMode(Mode mode) {
    XModeHandler xmh =
        new XModeHandler(mode.getName()) {
          @Override
          public void error(String what, Object subst) {
            Log.log(Log.ERROR, this, subst);
          }

          @Override
          public TokenMarker getTokenMarker(String modeName) {
            Mode mode = getMode(modeName);
            if (mode == null) return null;
            else return mode.getTokenMarker();
          }
        };
    loadMode(mode, xmh);
  } // }}}