Search in sources :

Example 1 with DirectoryMonitor

use of org.omegat.util.DirectoryMonitor in project omegat by omegat-org.

the class RealProject method loadTM.

/**
 * Locates and loads external TMX files with legacy translations. Uses directory monitor for check file
 * updates.
 */
private void loadTM() throws IOException {
    File tmRoot = new File(config.getTMRoot());
    tmMonitor = new DirectoryMonitor(tmRoot, file -> {
        if (!ExternalTMFactory.isSupported(file)) {
            // not a TMX file
            return;
        }
        if (file.getPath().replace('\\', '/').startsWith(config.getTMOtherLangRoot())) {
            // tmx in other language, which is already shown in editor. Skip it.
            return;
        }
        // create new translation memories map
        Map<String, ExternalTMX> newTransMemories = new TreeMap<>(transMemories);
        if (file.exists()) {
            try {
                ExternalTMX newTMX = ExternalTMFactory.load(file);
                newTransMemories.put(file.getPath(), newTMX);
                // directory separators into "/".
                if (FileUtil.computeRelativePath(tmRoot, file).startsWith(OConsts.AUTO_TM + "/")) {
                    appendFromAutoTMX(newTMX, false);
                } else if (FileUtil.computeRelativePath(tmRoot, file).startsWith(OConsts.AUTO_ENFORCE_TM + '/')) {
                    appendFromAutoTMX(newTMX, true);
                }
            } catch (Exception e) {
                String filename = file.getPath();
                Log.logErrorRB(e, "TF_TM_LOAD_ERROR", filename);
                Core.getMainWindow().displayErrorRB(e, "TF_TM_LOAD_ERROR", filename);
            }
        } else {
            newTransMemories.remove(file.getPath());
        }
        transMemories = newTransMemories;
    });
    tmMonitor.checkChanges();
    tmMonitor.start();
}
Also used : OConsts(org.omegat.util.OConsts) RandomAccessFile(java.io.RandomAccessFile) SRX(org.omegat.core.segmentation.SRX) IFilter(org.omegat.filters2.IFilter) PatternConsts(org.omegat.util.PatternConsts) StaticUtils(org.omegat.util.StaticUtils) FileLock(java.nio.channels.FileLock) KnownException(org.omegat.core.KnownException) Matcher(java.util.regex.Matcher) StringUtil(org.omegat.util.StringUtil) CalcStandardStatistics(org.omegat.core.statistics.CalcStandardStatistics) Core(org.omegat.core.Core) Filters(gen.core.filters.Filters) Map(java.util.Map) ProjectFileStorage(org.omegat.util.ProjectFileStorage) Path(java.nio.file.Path) Set(java.util.Set) FilterMaster(org.omegat.filters2.master.FilterMaster) GlossaryReaderTSV(org.omegat.gui.glossary.GlossaryReaderTSV) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) Writer(java.io.Writer) FilterContext(org.omegat.filters2.FilterContext) TagUtil(org.omegat.util.TagUtil) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) DirectoryMonitor(org.omegat.util.DirectoryMonitor) Preferences(org.omegat.util.Preferences) StmProperties(org.madlonkay.supertmxmerge.StmProperties) ITokenizer(org.omegat.tokenizer.ITokenizer) CLIParameters(org.omegat.CLIParameters) RebaseAndCommit(org.omegat.core.team2.RebaseAndCommit) Log(org.omegat.util.Log) FileUtil(org.omegat.util.FileUtil) TMXReader2(org.omegat.util.TMXReader2) HashMap(java.util.HashMap) Stack(java.util.Stack) CoreEvents(org.omegat.core.CoreEvents) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OStrings(org.omegat.util.OStrings) StreamUtil(org.omegat.util.StreamUtil) IAlignCallback(org.omegat.filters2.IAlignCallback) DefaultTokenizer(org.omegat.tokenizer.DefaultTokenizer) RuntimePreferences(org.omegat.util.RuntimePreferences) Segmenter(org.omegat.core.segmentation.Segmenter) Files(java.nio.file.Files) UIThreadsUtil(org.omegat.util.gui.UIThreadsUtil) ExternalLinked(org.omegat.core.data.TMXEntry.ExternalLinked) IProjectEventListener(org.omegat.core.events.IProjectEventListener) IOException(java.io.IOException) Language(org.omegat.util.Language) Statistics(org.omegat.core.statistics.Statistics) StatisticsInfo(org.omegat.core.statistics.StatisticsInfo) RemoteRepositoryProvider(org.omegat.core.team2.RemoteRepositoryProvider) File(java.io.File) SuperTmxMerge(org.madlonkay.supertmxmerge.SuperTmxMerge) SAXParseException(org.xml.sax.SAXParseException) TreeMap(java.util.TreeMap) Paths(java.nio.file.Paths) CommandMonitor(org.omegat.core.threads.CommandMonitor) GlossaryEntry(org.omegat.gui.glossary.GlossaryEntry) FileChannel(java.nio.channels.FileChannel) Collections(java.util.Collections) DirectoryMonitor(org.omegat.util.DirectoryMonitor) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) KnownException(org.omegat.core.KnownException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException)

Example 2 with DirectoryMonitor

use of org.omegat.util.DirectoryMonitor in project omegat by omegat-org.

the class ScriptsMonitor method start.

public void start(final File scriptDir) {
    this.m_scriptDir = scriptDir;
    m_monitor = new DirectoryMonitor(scriptDir, this, this);
    m_monitor.start();
    // Immediately execute APPLICATION_STARTUP event scripts
    if (!applicationStartupEventScriptsExecuted) {
        // first-time only
        applicationStartupEventScriptsExecuted = true;
        addEventScripts(EventType.APPLICATION_STARTUP);
        ArrayList<ScriptItem> scripts = m_eventsScript.get(EventType.APPLICATION_STARTUP);
        for (ScriptItem si : scripts) {
            m_scriptingWindow.executeScriptFile(si);
        }
        scripts.clear();
    }
}
Also used : DirectoryMonitor(org.omegat.util.DirectoryMonitor)

Example 3 with DirectoryMonitor

use of org.omegat.util.DirectoryMonitor in project omegat by omegat-org.

the class GlossaryManager method start.

public void start() {
    File dir = new File(Core.getProject().getProjectProperties().getGlossaryRoot());
    priorityGlossary = new File(Core.getProject().getProjectProperties().getWriteableGlossary());
    monitor = new DirectoryMonitor(dir, this);
    monitor.start();
}
Also used : DirectoryMonitor(org.omegat.util.DirectoryMonitor) File(java.io.File)

Example 4 with DirectoryMonitor

use of org.omegat.util.DirectoryMonitor in project omegat by omegat-org.

the class RealProject method loadOtherLanguages.

/**
 * Locates and loads external TMX files with legacy translations. Uses directory monitor for check file
 * updates.
 */
private void loadOtherLanguages() throws IOException {
    File tmOtherLanguagesRoot = new File(config.getTMOtherLangRoot());
    tmOtherLanguagesMonitor = new DirectoryMonitor(tmOtherLanguagesRoot, file -> {
        String name = file.getName();
        if (!name.matches("[A-Z]{2}([-_][A-Z]{2})?\\.tmx")) {
            // not a TMX file in XX_XX.tmx format
            return;
        }
        Language targetLanguage = new Language(name.substring(0, name.length() - ".tmx".length()));
        // create new translation memories map
        Map<Language, ProjectTMX> newOtherTargetLangTMs = new TreeMap<>(otherTargetLangTMs);
        if (file.exists()) {
            try {
                ProjectTMX newTMX = new ProjectTMX(config.getSourceLanguage(), targetLanguage, config.isSentenceSegmentingEnabled(), file, checkOrphanedCallback);
                newOtherTargetLangTMs.put(targetLanguage, newTMX);
            } catch (Exception e) {
                String filename = file.getPath();
                Log.logErrorRB(e, "TF_TM_LOAD_ERROR", filename);
                Core.getMainWindow().displayErrorRB(e, "TF_TM_LOAD_ERROR", filename);
            }
        } else {
            newOtherTargetLangTMs.remove(targetLanguage);
        }
        otherTargetLangTMs = newOtherTargetLangTMs;
    });
    tmOtherLanguagesMonitor.checkChanges();
    tmOtherLanguagesMonitor.start();
}
Also used : OConsts(org.omegat.util.OConsts) RandomAccessFile(java.io.RandomAccessFile) SRX(org.omegat.core.segmentation.SRX) IFilter(org.omegat.filters2.IFilter) PatternConsts(org.omegat.util.PatternConsts) StaticUtils(org.omegat.util.StaticUtils) FileLock(java.nio.channels.FileLock) KnownException(org.omegat.core.KnownException) Matcher(java.util.regex.Matcher) StringUtil(org.omegat.util.StringUtil) CalcStandardStatistics(org.omegat.core.statistics.CalcStandardStatistics) Core(org.omegat.core.Core) Filters(gen.core.filters.Filters) Map(java.util.Map) ProjectFileStorage(org.omegat.util.ProjectFileStorage) Path(java.nio.file.Path) Set(java.util.Set) FilterMaster(org.omegat.filters2.master.FilterMaster) GlossaryReaderTSV(org.omegat.gui.glossary.GlossaryReaderTSV) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) Writer(java.io.Writer) FilterContext(org.omegat.filters2.FilterContext) TagUtil(org.omegat.util.TagUtil) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) DirectoryMonitor(org.omegat.util.DirectoryMonitor) Preferences(org.omegat.util.Preferences) StmProperties(org.madlonkay.supertmxmerge.StmProperties) ITokenizer(org.omegat.tokenizer.ITokenizer) CLIParameters(org.omegat.CLIParameters) RebaseAndCommit(org.omegat.core.team2.RebaseAndCommit) Log(org.omegat.util.Log) FileUtil(org.omegat.util.FileUtil) TMXReader2(org.omegat.util.TMXReader2) HashMap(java.util.HashMap) Stack(java.util.Stack) CoreEvents(org.omegat.core.CoreEvents) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OStrings(org.omegat.util.OStrings) StreamUtil(org.omegat.util.StreamUtil) IAlignCallback(org.omegat.filters2.IAlignCallback) DefaultTokenizer(org.omegat.tokenizer.DefaultTokenizer) RuntimePreferences(org.omegat.util.RuntimePreferences) Segmenter(org.omegat.core.segmentation.Segmenter) Files(java.nio.file.Files) UIThreadsUtil(org.omegat.util.gui.UIThreadsUtil) ExternalLinked(org.omegat.core.data.TMXEntry.ExternalLinked) IProjectEventListener(org.omegat.core.events.IProjectEventListener) IOException(java.io.IOException) Language(org.omegat.util.Language) Statistics(org.omegat.core.statistics.Statistics) StatisticsInfo(org.omegat.core.statistics.StatisticsInfo) RemoteRepositoryProvider(org.omegat.core.team2.RemoteRepositoryProvider) File(java.io.File) SuperTmxMerge(org.madlonkay.supertmxmerge.SuperTmxMerge) SAXParseException(org.xml.sax.SAXParseException) TreeMap(java.util.TreeMap) Paths(java.nio.file.Paths) CommandMonitor(org.omegat.core.threads.CommandMonitor) GlossaryEntry(org.omegat.gui.glossary.GlossaryEntry) FileChannel(java.nio.channels.FileChannel) Collections(java.util.Collections) DirectoryMonitor(org.omegat.util.DirectoryMonitor) Language(org.omegat.util.Language) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) KnownException(org.omegat.core.KnownException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException)

Example 5 with DirectoryMonitor

use of org.omegat.util.DirectoryMonitor in project omegat by omegat-org.

the class DictionariesManager method start.

public void start(File dictDir) {
    monitor = new DirectoryMonitor(dictDir, this);
    monitor.start();
}
Also used : DirectoryMonitor(org.omegat.util.DirectoryMonitor)

Aggregations

DirectoryMonitor (org.omegat.util.DirectoryMonitor)4 File (java.io.File)3 Filters (gen.core.filters.Filters)2 IOException (java.io.IOException)2 RandomAccessFile (java.io.RandomAccessFile)2 Writer (java.io.Writer)2 FileChannel (java.nio.channels.FileChannel)2 FileLock (java.nio.channels.FileLock)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2