Exemplo n.º 1
0
 /**
  * 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;
 } // }}}
Exemplo n.º 2
0
  // {{{ 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);
    }
  } // }}}
Exemplo n.º 3
0
  // {{{ 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);
  } // }}}