Search in sources :

Example 1 with EntryKey

use of org.omegat.core.data.EntryKey in project omegat by omegat-org.

the class Searcher method searchProject.

private void searchProject() {
    // reset the number of search hits
    m_numFinds = 0;
    // search the Memory, if requested
    if (m_searchExpression.memory) {
        // search through all project entries
        IProject dataEngine = m_project;
        for (int i = 0; i < m_project.getAllEntries().size(); i++) {
            // stop searching if the max. nr of hits has been reached
            if (m_numFinds >= expression.numberOfResults) {
                return;
            }
            // get the source and translation of the next entry
            SourceTextEntry ste = dataEngine.getAllEntries().get(i);
            TMXEntry te = m_project.getTranslationInfo(ste);
            checkEntry(ste.getSrcText(), te.translation, te.note, ste.getComment(), te, i, null);
            checkStop.checkInterrupted();
        }
        // search in orphaned
        if (!m_searchExpression.excludeOrphans) {
            m_project.iterateByDefaultTranslations(new IProject.DefaultTranslationsIterator() {

                final String file = OStrings.getString("CT_ORPHAN_STRINGS");

                public void iterate(String source, TMXEntry en) {
                    // stop searching if the max. nr of hits has been reached
                    if (m_numFinds >= expression.numberOfResults) {
                        return;
                    }
                    checkStop.checkInterrupted();
                    if (m_project.isOrphaned(source)) {
                        checkEntry(en.source, en.translation, en.note, null, en, ENTRY_ORIGIN_ORPHAN, file);
                    }
                }
            });
            m_project.iterateByMultipleTranslations(new IProject.MultipleTranslationsIterator() {

                final String file = OStrings.getString("CT_ORPHAN_STRINGS");

                public void iterate(EntryKey source, TMXEntry en) {
                    // reached
                    if (m_numFinds >= expression.numberOfResults) {
                        return;
                    }
                    checkStop.checkInterrupted();
                    if (m_project.isOrphaned(source)) {
                        checkEntry(en.source, en.translation, en.note, null, en, ENTRY_ORIGIN_ORPHAN, file);
                    }
                }
            });
        }
    }
    // search the TM, if requested
    if (m_searchExpression.tm) {
        // that case.
        if (!expression.searchAuthor && !expression.searchDateAfter && !expression.searchDateBefore) {
            for (Map.Entry<String, ExternalTMX> tmEn : m_project.getTransMemories().entrySet()) {
                final String fileTM = tmEn.getKey();
                if (!searchEntries(tmEn.getValue().getEntries(), fileTM)) {
                    return;
                }
                checkStop.checkInterrupted();
            }
            for (Map.Entry<Language, ProjectTMX> tmEn : m_project.getOtherTargetLanguageTMs().entrySet()) {
                final Language langTM = tmEn.getKey();
                if (!searchEntriesAlternative(tmEn.getValue().getDefaults(), langTM.getLanguage())) {
                    return;
                }
                if (!searchEntriesAlternative(tmEn.getValue().getAlternatives(), langTM.getLanguage())) {
                    return;
                }
                checkStop.checkInterrupted();
            }
        }
    }
    // search the glossary, if requested
    if (m_searchExpression.glossary) {
        String intro = OStrings.getString("SW_GLOSSARY_RESULT");
        List<GlossaryEntry> entries = Core.getGlossaryManager().getLocalEntries();
        for (GlossaryEntry en : entries) {
            checkEntry(en.getSrcText(), en.getLocText(), null, null, null, ENTRY_ORIGIN_GLOSSARY, intro);
            // stop searching if the max. nr of hits has been reached
            if (m_numFinds >= expression.numberOfResults) {
                return;
            }
            checkStop.checkInterrupted();
        }
    }
}
Also used : ProjectTMX(org.omegat.core.data.ProjectTMX) EntryKey(org.omegat.core.data.EntryKey) IProject(org.omegat.core.data.IProject) Language(org.omegat.util.Language) GlossaryEntry(org.omegat.gui.glossary.GlossaryEntry) SourceTextEntry(org.omegat.core.data.SourceTextEntry) ExternalTMX(org.omegat.core.data.ExternalTMX) HashMap(java.util.HashMap) Map(java.util.Map) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) TMXEntry(org.omegat.core.data.TMXEntry)

Example 2 with EntryKey

use of org.omegat.core.data.EntryKey in project omegat by omegat-org.

the class TestCore method setUpCore.

@Before
public final void setUpCore() throws Exception {
    configDir = Files.createTempDirectory("omegat").toFile();
    TestPreferencesInitializer.init(configDir.getAbsolutePath());
    final IMainMenu mainMenu = new IMainMenu() {

        public JMenu getToolsMenu() {
            return new JMenu();
        }

        public JMenu getProjectMenu() {
            return new JMenu();
        }

        public JMenu getOptionsMenu() {
            return new JMenu();
        }

        public JMenu getMachineTranslationMenu() {
            return new JMenu();
        }

        public JMenu getGlossaryMenu() {
            return new JMenu();
        }

        public JMenuItem getProjectRecentMenuItem() {
            return new JMenu();
        }

        public JMenu getAutoCompletionMenu() {
            return new JMenu();
        }

        public void invokeAction(String action, int modifiers) {
        }
    };
    Core.setMainWindow(new IMainWindow() {

        public void addDockable(Dockable pane) {
        }

        public void displayErrorRB(Throwable ex, String errorKey, Object... params) {
        }

        public Font getApplicationFont() {
            return new Font("Dialog", Font.PLAIN, 12);
        }

        public JFrame getApplicationFrame() {
            return new JFrame();
        }

        public void lockUI() {
        }

        public void showLengthMessage(String messageText) {
        }

        public void showProgressMessage(String messageText) {
        }

        public void showStatusMessageRB(String messageKey, Object... params) {
        }

        public void showTimedStatusMessageRB(String messageKey, Object... params) {
        }

        public void displayWarningRB(String warningKey, Object... params) {
        }

        public void displayWarningRB(String warningKey, String supercedesKey, Object... params) {
        }

        public void showErrorDialogRB(String title, String message, Object... args) {
        }

        public void unlockUI() {
        }

        public IMainMenu getMainMenu() {
            return mainMenu;
        }

        public Cursor getCursor() {
            return null;
        }

        public void setCursor(Cursor cursor) {
        }

        public int showConfirmDialog(Object message, String title, int optionType, int messageType) throws HeadlessException {
            return 0;
        }

        public void showMessageDialog(String message) {
        }
    });
    Core.setCurrentProject(new NotLoadedProject());
    final IEditorSettings editorSettings = new IEditorSettings() {

        @Override
        public boolean isUseTabForAdvance() {
            return false;
        }

        @Override
        public void setUseTabForAdvance(boolean useTabForAdvance) {
        }

        @Override
        public boolean isMarkTranslated() {
            return false;
        }

        @Override
        public void setMarkTranslated(boolean markTranslated) {
        }

        @Override
        public boolean isMarkUntranslated() {
            return false;
        }

        @Override
        public void setMarkUntranslated(boolean markUntranslated) {
        }

        @Override
        public boolean isMarkAutoPopulated() {
            return false;
        }

        @Override
        public void setMarkAutoPopulated(boolean markAutoPopulated) {
        }

        @Override
        public boolean isDisplaySegmentSources() {
            return false;
        }

        @Override
        public void setDisplaySegmentSources(boolean displaySegmentSources) {
        }

        @Override
        public boolean isMarkNonUniqueSegments() {
            return false;
        }

        @Override
        public void setMarkNonUniqueSegments(boolean markNonUniqueSegments) {
        }

        @Override
        public boolean isMarkNotedSegments() {
            return false;
        }

        @Override
        public void setMarkNotedSegments(boolean markNotedSegments) {
        }

        @Override
        public boolean isMarkNBSP() {
            return false;
        }

        @Override
        public void setMarkNBSP(boolean markNBSP) {
        }

        @Override
        public boolean isMarkWhitespace() {
            return false;
        }

        @Override
        public void setMarkWhitespace(boolean markWhitespace) {
        }

        @Override
        public boolean isMarkBidi() {
            return false;
        }

        @Override
        public void setMarkBidi(boolean markBidi) {
        }

        @Override
        public boolean isAutoSpellChecking() {
            return false;
        }

        @Override
        public void setAutoSpellChecking(boolean isNeedToSpell) {
        }

        @Override
        public boolean isDoFontFallback() {
            return false;
        }

        @Override
        public void setDoFontFallback(boolean doFallback) {
        }

        @Override
        public String getDisplayModificationInfo() {
            return null;
        }

        @Override
        public void setDisplayModificationInfo(String displayModificationInfo) {
        }

        @Override
        public void updateTagValidationPreferences() {
        }

        @Override
        public void updateViewPreferences() {
        }

        @Override
        public boolean isMarkLanguageChecker() {
            return false;
        }

        @Override
        public void setMarkLanguageChecker(boolean markLanguageChecker) {
        }

        @Override
        public boolean isMarkGlossaryMatches() {
            return false;
        }

        @Override
        public void setMarkGlossaryMatches(boolean markGlossaryMatches) {
        }
    };
    TestCoreInitializer.initEditor(new IEditor() {

        @Override
        public void windowDeactivated() {
        }

        @Override
        public void undo() {
        }

        @Override
        public void setFilter(IEditorFilter filter) {
        }

        @Override
        public void setAlternateTranslationForCurrentEntry(boolean alternate) {
        }

        @Override
        public void requestFocus() {
        }

        @Override
        public void replaceEditTextAndMark(String text) {
        }

        @Override
        public void replaceEditText(String text) {
        }

        @Override
        public void removeFilter() {
        }

        @Override
        public void remarkOneMarker(String markerClassName) {
        }

        @Override
        public void registerUntranslated() {
        }

        @Override
        public void registerPopupMenuConstructors(int priority, IPopupMenuConstructor constructor) {
        }

        @Override
        public void registerIdenticalTranslation() {
        }

        @Override
        public void registerEmptyTranslation() {
        }

        @Override
        public void refreshViewAfterFix(List<Integer> fixedEntries) {
        }

        @Override
        public void refreshView(boolean doCommit) {
        }

        @Override
        public void redo() {
        }

        @Override
        public void prevEntryWithNote() {
        }

        @Override
        public void prevEntry() {
        }

        @Override
        public void nextUntranslatedEntry() {
        }

        @Override
        public void nextUniqueEntry() {
        }

        @Override
        public void nextTranslatedEntry() {
        }

        @Override
        public void nextEntryWithNote() {
        }

        @Override
        public void nextEntry() {
        }

        @Override
        public void markActiveEntrySource(SourceTextEntry requiredActiveEntry, List<Mark> marks, String markerClassName) {
        }

        @Override
        public void insertText(String text) {
        }

        @Override
        public void insertTextAndMark(String text) {
        }

        @Override
        public void insertTag(String tag) {
        }

        @Override
        public void gotoHistoryForward() {
        }

        @Override
        public void gotoHistoryBack() {
        }

        @Override
        public void gotoFile(int fileIndex) {
        }

        @Override
        public void gotoEntryAfterFix(int fixedEntry, String fixedSource) {
        }

        @Override
        public void gotoEntry(String srcString, EntryKey key) {
        }

        @Override
        public void gotoEntry(int entryNum) {
        }

        @Override
        public void gotoEntry(int entryNum, CaretPosition pos) {
        }

        @Override
        public IEditorSettings getSettings() {
            return editorSettings;
        }

        @Override
        public String getSelectedText() {
            return null;
        }

        @Override
        public IEditorFilter getFilter() {
            return null;
        }

        @Override
        public String getCurrentTranslation() {
            return null;
        }

        @Override
        public String getCurrentTargetFile() {
            return null;
        }

        @Override
        public String getCurrentFile() {
            return null;
        }

        @Override
        public int getCurrentEntryNumber() {
            return 0;
        }

        @Override
        public SourceTextEntry getCurrentEntry() {
            return null;
        }

        @Override
        public IAutoCompleter getAutoCompleter() {
            return null;
        }

        @Override
        public void commitAndLeave() {
        }

        @Override
        public void commitAndDeactivate() {
        }

        @Override
        public void changeCase(CHANGE_CASE_TO newCase) {
        }

        @Override
        public void activateEntry() {
        }
    });
}
Also used : IEditor(org.omegat.gui.editor.IEditor) HeadlessException(java.awt.HeadlessException) IMainWindow(org.omegat.gui.main.IMainWindow) Dockable(com.vlsolutions.swing.docking.Dockable) Mark(org.omegat.gui.editor.mark.Mark) Cursor(java.awt.Cursor) Font(java.awt.Font) JFrame(javax.swing.JFrame) SourceTextEntry(org.omegat.core.data.SourceTextEntry) IAutoCompleter(org.omegat.gui.editor.autocompleter.IAutoCompleter) IEditorFilter(org.omegat.gui.editor.IEditorFilter) EntryKey(org.omegat.core.data.EntryKey) IPopupMenuConstructor(org.omegat.gui.editor.IPopupMenuConstructor) IEditorSettings(org.omegat.gui.editor.IEditorSettings) NotLoadedProject(org.omegat.core.data.NotLoadedProject) IMainMenu(org.omegat.gui.main.IMainMenu) JMenu(javax.swing.JMenu) Before(org.junit.Before)

Example 3 with EntryKey

use of org.omegat.core.data.EntryKey in project omegat by omegat-org.

the class TestFilterBase method checkMulti.

protected void checkMulti(String sourceText, String id, String path, String prev, String next, String comment) {
    assertEquals(new EntryKey(fi.filePath, sourceText, id, prev, next, path), fi.entries.get(fiCount).getKey());
    assertEquals(comment, fi.entries.get(fiCount).getComment());
    fiCount++;
}
Also used : EntryKey(org.omegat.core.data.EntryKey)

Example 4 with EntryKey

use of org.omegat.core.data.EntryKey in project omegat by omegat-org.

the class TestFilterBase method checkMultiProps.

protected void checkMultiProps(String sourceText, String id, String path, String prev, String next, String... props) {
    assertEquals(new EntryKey(fi.filePath, sourceText, id, prev, next, path), fi.entries.get(fiCount).getKey());
    List<String> expected = Arrays.asList(props);
    String[] actual = fi.entries.get(fiCount).getRawProperties();
    assertEquals(props.length, actual.length);
    for (int i = 0; i < actual.length; i += 2) {
        int keyIndex = expected.indexOf(actual[i]);
        assertFalse(keyIndex == -1);
        int valIndex = expected.indexOf(actual[i + 1]);
        assertEquals(keyIndex + 1, valIndex);
    }
    fiCount++;
}
Also used : EntryKey(org.omegat.core.data.EntryKey)

Example 5 with EntryKey

use of org.omegat.core.data.EntryKey in project omegat by omegat-org.

the class FalseFriendsTest method setUp.

@Before
public final void setUp() {
    final ProjectProperties props = new ProjectProperties() {

        public Language getSourceLanguage() {
            return new Language("en");
        }

        public Language getTargetLanguage() {
            return new Language("pl");
        }
    };
    Core.setProject(new IProject() {

        public void setTranslation(SourceTextEntry entry, PrepareTMXEntry trans, boolean defaultTranslation, TMXEntry.ExternalLinked externalLinked) {
        }

        public void setTranslation(SourceTextEntry entry, PrepareTMXEntry trans, boolean defaultTranslation, ExternalLinked externalLinked, AllTranslations previousTranslations) throws OptimisticLockingFail {
        }

        public void setNote(SourceTextEntry entry, TMXEntry oldTrans, String note) {
        }

        public void saveProjectProperties() throws Exception {
        }

        public void saveProject(boolean doTeamSync) {
        }

        public void iterateByMultipleTranslations(MultipleTranslationsIterator it) {
        }

        public void iterateByDefaultTranslations(DefaultTranslationsIterator it) {
        }

        public boolean isProjectModified() {
            return false;
        }

        public boolean isProjectLoaded() {
            return true;
        }

        public boolean isOrphaned(EntryKey entry) {
            return false;
        }

        public boolean isOrphaned(String source) {
            return false;
        }

        public TMXEntry getTranslationInfo(SourceTextEntry ste) {
            return null;
        }

        public AllTranslations getAllTranslations(SourceTextEntry ste) {
            return null;
        }

        public Map<String, ExternalTMX> getTransMemories() {
            return null;
        }

        public ITokenizer getTargetTokenizer() {
            return null;
        }

        public StatisticsInfo getStatistics() {
            return null;
        }

        public ITokenizer getSourceTokenizer() {
            return null;
        }

        public ProjectProperties getProjectProperties() {
            return props;
        }

        public List<FileInfo> getProjectFiles() {
            return null;
        }

        public Map<Language, ProjectTMX> getOtherTargetLanguageTMs() {
            return null;
        }

        public List<SourceTextEntry> getAllEntries() {
            return null;
        }

        public void compileProject(String sourcePattern) throws Exception {
        }

        public void closeProject() {
        }

        public List<String> getSourceFilesOrder() {
            return null;
        }

        public void setSourceFilesOrder(List<String> filesList) {
        }

        @Override
        public String getTargetPathForSourceFile(String sourceFile) {
            return null;
        }

        @Override
        public boolean isTeamSyncPrepared() {
            return false;
        }

        @Override
        public void teamSync() {
        }

        @Override
        public void teamSyncPrepare() throws Exception {
        }

        @Override
        public boolean isRemoteProject() {
            return false;
        }

        @Override
        public void commitSourceFiles() throws Exception {
        }

        @Override
        public void compileProjectAndCommit(String sourcePattern, boolean doPostProcessing, boolean commitTargetFiles) throws Exception {
        }
    });
    LanguageToolWrapper.setBridgeFromCurrentProject();
}
Also used : ExternalLinked(org.omegat.core.data.TMXEntry.ExternalLinked) EntryKey(org.omegat.core.data.EntryKey) StatisticsInfo(org.omegat.core.statistics.StatisticsInfo) ProjectProperties(org.omegat.core.data.ProjectProperties) IProject(org.omegat.core.data.IProject) ExternalLinked(org.omegat.core.data.TMXEntry.ExternalLinked) ITokenizer(org.omegat.tokenizer.ITokenizer) Language(org.omegat.util.Language) SourceTextEntry(org.omegat.core.data.SourceTextEntry) List(java.util.List) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) Map(java.util.Map) PrepareTMXEntry(org.omegat.core.data.PrepareTMXEntry) TMXEntry(org.omegat.core.data.TMXEntry) Before(org.junit.Before)

Aggregations

EntryKey (org.omegat.core.data.EntryKey)7 SourceTextEntry (org.omegat.core.data.SourceTextEntry)5 Language (org.omegat.util.Language)4 Map (java.util.Map)3 Before (org.junit.Before)3 PrepareTMXEntry (org.omegat.core.data.PrepareTMXEntry)3 TMXEntry (org.omegat.core.data.TMXEntry)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ExternalTMX (org.omegat.core.data.ExternalTMX)2 IProject (org.omegat.core.data.IProject)2 NotLoadedProject (org.omegat.core.data.NotLoadedProject)2 ProjectProperties (org.omegat.core.data.ProjectProperties)2 IEditor (org.omegat.gui.editor.IEditor)2 IEditorFilter (org.omegat.gui.editor.IEditorFilter)2 IEditorSettings (org.omegat.gui.editor.IEditorSettings)2 IPopupMenuConstructor (org.omegat.gui.editor.IPopupMenuConstructor)2 IAutoCompleter (org.omegat.gui.editor.autocompleter.IAutoCompleter)2 Mark (org.omegat.gui.editor.mark.Mark)2