Beispiel #1
0
  public static Object executeScriptFileHeadless(
      ScriptItem scriptItem, boolean forceFromFile, Map<String, Object> additionalBindings) {
    ScriptEngineManager manager = new ScriptEngineManager(ScriptingWindow.class.getClassLoader());
    ScriptEngine scriptEngine =
        manager.getEngineByExtension(getFileExtension(scriptItem.getName()));

    if (scriptEngine == null) {
      scriptEngine = manager.getEngineByName(DEFAULT_SCRIPT);
    }

    SimpleBindings bindings = new SimpleBindings();
    bindings.put(VAR_PROJECT, Core.getProject());
    bindings.put(VAR_EDITOR, Core.getEditor());
    bindings.put(VAR_GLOSSARY, Core.getGlossary());
    bindings.put(VAR_MAINWINDOW, Core.getMainWindow());
    bindings.put(VAR_RESOURCES, scriptItem.getResourceBundle());

    if (additionalBindings != null) {
      bindings.putAll(additionalBindings);
    }

    Object eval = null;
    try {
      eval = scriptEngine.eval(scriptItem.getText(), bindings);
      if (eval != null) {
        Log.logRB("SCW_SCRIPT_RESULT");
        Log.log(eval.toString());
      }
    } catch (Throwable e) {
      Log.logErrorRB(e, "SCW_SCRIPT_ERROR");
    }

    return eval;
  }
Beispiel #2
0
 /** Loads one glossary file. It choose and calls required required reader. */
 private List<GlossaryEntry> loadGlossaryFile(final File file) throws Exception {
   String fname_lower = file.getName().toLowerCase();
   if (fname_lower.endsWith(EXT_TSV_DEF)) {
     Log.logRB("CT_LOADING_GLOSSARY", new Object[] {file.getName()});
     return GlossaryReaderTSV.read(file);
   } else if (fname_lower.endsWith(EXT_TSV_UTF8) || fname_lower.endsWith(EXT_TSV_TXT)) {
     Log.logRB("CT_LOADING_GLOSSARY", new Object[] {file.getName()});
     return GlossaryReaderTSV.read(file);
   } else if (fname_lower.endsWith(EXT_CSV_UTF8)) {
     Log.logRB("CT_LOADING_GLOSSARY", new Object[] {file.getName()});
     return GlossaryReaderCSV.read(file);
   } else if (fname_lower.endsWith(EXT_TBX)) {
     Log.logRB("CT_LOADING_GLOSSARY", new Object[] {file.getName()});
     return GlossaryReaderTBX.read(file);
   } else {
     return null;
   }
 }
 /** Loads one glossary file. It choose and calls required required reader. */
 private List<GlossaryEntry> loadGlossaryFile(final File file) throws Exception {
   boolean isPriority = priorityGlossary.equals(file);
   String fname_lower = file.getName().toLowerCase();
   if (fname_lower.endsWith(OConsts.EXT_TSV_DEF)) {
     Log.logRB("CT_LOADING_GLOSSARY", file.getName());
     return GlossaryReaderTSV.read(file, isPriority);
   } else if (fname_lower.endsWith(OConsts.EXT_TSV_UTF8)
       || fname_lower.endsWith(OConsts.EXT_TSV_TXT)) {
     Log.logRB("CT_LOADING_GLOSSARY", file.getName());
     return GlossaryReaderTSV.read(file, isPriority);
   } else if (fname_lower.endsWith(OConsts.EXT_CSV_UTF8)) {
     Log.logRB("CT_LOADING_GLOSSARY", file.getName());
     return GlossaryReaderCSV.read(file, isPriority);
   } else if (fname_lower.endsWith(OConsts.EXT_TBX)) {
     Log.logRB("CT_LOADING_GLOSSARY", file.getName());
     return GlossaryReaderTBX.read(file, isPriority);
   } else {
     return null;
   }
 }
 @Override
 public void fileChanged(File file) {
   synchronized (this) {
     glossaries.remove(file.getPath());
   }
   if (file.exists()) {
     try {
       List<GlossaryEntry> entries = loadGlossaryFile(file);
       if (entries != null) {
         synchronized (this) {
           Log.logRB("CT_LOADING_GLOSSARY_DETAILS", entries.size(), file.getName());
           glossaries.put(file.getPath(), entries);
         }
       }
     } catch (Exception ex) {
       Log.logRB("CT_ERROR_ACCESS_GLOSSARY_DIR");
       Log.log(ex);
     }
   }
   pane.refresh();
 }