Exemplo n.º 1
0
  /** Displays the dialog to set login and password for proxy. */
  public void optionsViewOptionsMenuLoginItemActionPerformed() {
    UserPassDialog proxyOptions = new UserPassDialog(mainWindow);

    String encodedUser = (Preferences.getPreference(Preferences.PROXY_USER_NAME));
    String encodedPassword = (Preferences.getPreference(Preferences.PROXY_PASSWORD));

    try {
      proxyOptions.userText.setText(new String(org.omegat.util.Base64.decode(encodedUser)));
      proxyOptions.passwordField.setText(
          new String(org.omegat.util.Base64.decode(encodedPassword)));
    } catch (IOException ex) {
      Log.logErrorRB("LOG_DECODING_ERROR");
      Log.log(ex);
    }

    proxyOptions.setVisible(true);

    if (proxyOptions.getReturnStatus() == UserPassDialog.RET_OK) {
      encodedUser = org.omegat.util.Base64.encodeBytes(proxyOptions.userText.getText().getBytes());
      encodedPassword =
          org.omegat.util.Base64.encodeBytes(
              new String(proxyOptions.passwordField.getPassword()).getBytes());

      Preferences.setPreference(Preferences.PROXY_USER_NAME, encodedUser);
      Preferences.setPreference(Preferences.PROXY_PASSWORD, encodedPassword);
    }
  }
Exemplo n.º 2
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;
  }
Exemplo n.º 3
0
 private static void saveIgnoreWords(Collection<String> words, File outFile) {
   try {
     File outFileTmp = new File(outFile.getPath() + ".new");
     Files.write(outFileTmp.toPath(), words);
     outFile.delete();
     FileUtil.rename(outFileTmp, outFile);
   } catch (IOException ex) {
     Log.log("Error saving ignore words");
     Log.log(ex);
   }
 }
Exemplo n.º 4
0
 /**
  * XHTML Filter shows a <b>modal</b> dialog to edit its own options.
  *
  * @param currentOptions Current options to edit.
  * @return Updated filter options if user confirmed the changes, and current options otherwise.
  */
 public Map<String, String> changeOptions(Dialog parent, Map<String, String> currentOptions) {
   try {
     EditXOptionsDialog dialog = new EditXOptionsDialog(parent, currentOptions);
     dialog.setVisible(true);
     if (EditXOptionsDialog.RET_OK == dialog.getReturnStatus())
       return dialog.getOptions().getOptionsMap();
     else return null;
   } catch (Exception e) {
     Log.logErrorRB("HTML_EXC_EDIT_OPTIONS");
     Log.log(e);
     return null;
   }
 }
Exemplo n.º 5
0
 private static void processSwingWorkerException(Exception ex, String errorCode) {
   if (ex instanceof ExecutionException) {
     Log.logErrorRB(ex.getCause(), errorCode);
     if (ex.getCause() instanceof KnownException) {
       KnownException e = (KnownException) ex.getCause();
       Core.getMainWindow().displayErrorRB(e.getCause(), e.getMessage(), e.getParams());
     } else {
       Core.getMainWindow().displayErrorRB(ex.getCause(), errorCode);
     }
   } else {
     Log.logErrorRB(ex, errorCode);
     Core.getMainWindow().displayErrorRB(ex, errorCode);
   }
 }
 @Override
 public Map<String, String> changeOptions(Dialog parent, Map<String, String> config) {
   try {
     ResourceBundleOptionsDialog dialog = new ResourceBundleOptionsDialog(parent, config);
     dialog.setVisible(true);
     if (ResourceBundleOptionsDialog.RET_OK == dialog.getReturnStatus())
       return dialog.getOptions();
     else return null;
   } catch (Exception e) {
     Log.log(OStrings.getString("RB_FILTER_EXCEPTION"));
     Log.log(e);
     return null;
   }
 }
Exemplo n.º 7
0
 @Override
 public void drop(DropTargetDropEvent dtde) {
   dtde.acceptDrop(info.getDnDAction());
   Transferable transferable = dtde.getTransferable();
   boolean success = false;
   try {
     Object result = transferable.getTransferData(info.getDataFlavor());
     success = info.handleDroppedObject(result);
   } catch (UnsupportedFlavorException e) {
     Log.log(e);
   } catch (IOException e) {
     Log.log(e);
   }
   dtde.dropComplete(success);
 }
Exemplo n.º 8
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;
   }
 }
Exemplo n.º 9
0
 public void fileChanged(File file) {
   synchronized (this) {
     glossaries.remove(file.getName());
   }
   if (file.exists()) {
     try {
       List<GlossaryEntry> entries = loadGlossaryFile(file);
       if (entries != null) {
         synchronized (this) {
           glossaries.put(file.getName(), entries);
         }
       }
     } catch (Exception ex) {
       Log.logRB("CT_ERROR_ACCESS_GLOSSARY_DIR");
       Log.log(ex);
     }
   }
   pane.refresh();
 }
Exemplo n.º 10
0
 /** Executed on file changed. */
 public void fileChanged(File file) {
   synchronized (dictionaries) {
     dictionaries.remove(file.getPath());
   }
   if (!file.exists()) {
     return;
   }
   try {
     long st = System.currentTimeMillis();
     if (file.getName().equals(IGNORE_FILE)) {
       loadIgnoreWords(file);
     } else if (loadDictionary(file)) {
       long en = System.currentTimeMillis();
       Log.log("Loaded dictionary from '" + file.getPath() + "': " + (en - st) + "ms");
     }
   } catch (Exception ex) {
     Log.log("Error load dictionary from '" + file.getPath() + "': " + ex.getMessage());
   }
   pane.refresh();
 }
Exemplo n.º 11
0
 /** 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;
   }
 }
Exemplo n.º 12
0
 private static void addListener(JComponent comp, DropTargetListener listener) {
   DropTarget target = comp.getDropTarget();
   if (target == null) {
     comp.setDropTarget(new DropTarget(comp, listener));
   } else {
     try {
       target.addDropTargetListener(listener);
     } catch (TooManyListenersException e) {
       Log.log(e);
     }
   }
 }
Exemplo n.º 13
0
  public GlossaryManager(final GlossaryTextArea pane) {
    this.pane = pane;

    List<IGlossary> gl = new ArrayList<IGlossary>();
    for (Class<?> glc : PluginUtils.getGlossaryClasses()) {
      try {
        gl.add((IGlossary) glc.newInstance());
      } catch (Exception ex) {
        Log.log(ex);
      }
    }
    externalGlossaries = gl.toArray(new IGlossary[gl.size()]);
  }
Exemplo n.º 14
0
  private void addExternalGlossaryEntries(List<GlossaryEntry> result, String src) {

    Language source = Core.getProject().getProjectProperties().getSourceLanguage();
    Language target = Core.getProject().getProjectProperties().getTargetLanguage();

    for (IGlossary gl : externalGlossaries) {
      try {
        result.addAll(gl.search(source, target, src));
      } catch (Exception ex) {
        Log.log(ex);
      }
    }
  }
Exemplo n.º 15
0
 private void openFile(File path) {
   try {
     path = path.getCanonicalFile(); // Normalize file name in case it is displayed
   } catch (Exception ex) {
     // Ignore
   }
   if (!path.exists()) {
     Core.getMainWindow().showStatusMessageRB("LFC_ERROR_FILE_DOESNT_EXIST", path);
     return;
   }
   try {
     Desktop.getDesktop().open(path);
   } catch (Exception ex) {
     Log.logErrorRB(ex, "RPF_ERROR");
     Core.getMainWindow().displayErrorRB(ex, "RPF_ERROR");
   }
 }
Exemplo n.º 16
0
  public static void projectRemote(String url) {
    String dir = url.replace("/", "_").replace(':', '_');
    File projectDir = new File(StaticUtils.getConfigDir() + "/remoteProjects/" + dir);
    File projectFile = new File(projectDir, OConsts.FILE_PROJECT);

    byte[] data;
    try {
      projectDir.mkdirs();
      data = WikiGet.getURLasByteArray(url);
      FileUtils.writeByteArrayToFile(projectFile, data);
    } catch (Exception ex) {
      Log.logErrorRB(ex, "TEAM_REMOTE_RETRIEVE_ERROR", url);
      Core.getMainWindow().displayErrorRB(ex, "TEAM_REMOTE_RETRIEVE_ERROR", url);
      return;
    }

    projectOpen(projectDir);
  }
Exemplo n.º 17
0
 /** Checking whether it is a valid XHTML file. */
 public boolean isFileSupported(File inFile, Map<String, String> config, FilterContext context) {
   boolean result = super.isFileSupported(inFile, config, context);
   if (result) {
     try {
       do_not_send_to_core = true;
       // Defining the actual dialect, because at this step
       // we have the options
       XHTMLDialect dialect = (XHTMLDialect) this.getDialect();
       dialect.defineDialect(new XHTMLOptions(config));
       super.processFile(inFile, null, context);
     } catch (Exception e) {
       Log.log("XHTML file " + inFile.getName() + " is not valid.");
       result = false;
     } finally {
       do_not_send_to_core = false;
     }
   }
   return result;
 }
Exemplo n.º 18
0
 /** Does wikiread */
 public static void doWikiImport() {
   String remote_url =
       JOptionPane.showInputDialog(
           Core.getMainWindow().getApplicationFrame(),
           OStrings.getString("TF_WIKI_IMPORT_PROMPT"),
           OStrings.getString("TF_WIKI_IMPORT_TITLE"),
           JOptionPane.OK_CANCEL_OPTION);
   String projectsource = Core.getProject().getProjectProperties().getSourceRoot();
   if (remote_url == null || remote_url.trim().isEmpty()) {
     // [1762625] Only try to get MediaWiki page if a string has been entered
     return;
   }
   try {
     WikiGet.doWikiGet(remote_url, projectsource);
     projectReload();
   } catch (Exception ex) {
     Log.log(ex);
     Core.getMainWindow().displayErrorRB(ex, "TF_WIKI_IMPORT_FAILED");
   }
 }
Exemplo n.º 19
0
 private List<DictionaryEntry> doLookUp(IDictionary dict, String word) {
   String[] stemmed = tokenizer.tokenizeWordsToStrings(word, StemmingMode.MATCHING);
   if (stemmed.length == 0) {
     // Stop word. Skip.
     return Collections.<DictionaryEntry>emptyList();
   }
   try {
     List<DictionaryEntry> result = dict.readArticles(word);
     if (!result.isEmpty()) {
       return result;
     }
     // The verbatim word didn't get any hits; try the stem.
     if (stemmed.length > 1 && doFuzzyMatching()) {
       return dict.readArticlesPredictive(stemmed[0]);
     }
   } catch (Exception ex) {
     Log.log(ex);
   }
   return Collections.<DictionaryEntry>emptyList();
 }