Search in sources :

Example 1 with TextMarker

use of org.olat.core.gui.control.generic.textmarker.TextMarker in project OpenOLAT by OpenOLAT.

the class GlossaryItemManager method upgradeAndDeleteOldGlossary.

/**
 * upgrades the old textmarker-format into the new DocBook-glossary-format
 *
 * @param folderContainingGlossary
 * @param textMarkerFile
 */
protected void upgradeAndDeleteOldGlossary(VFSContainer folderContainingGlossary, VFSLeaf textMarkerFile) {
    // check if a new glossary exists, warn
    if (folderContainingGlossary.resolve(GLOSSARY_FILENAME) != null) {
        logError("Upgrading Glossary in " + folderContainingGlossary.toString() + ": There is already a new glossary-file. There can't be an old and a new version in the same directory!", null);
    } else {
        // upgrade it
        TextMarkerManager textMarkerManager = TextMarkerManagerImpl.getInstance();
        List<TextMarker> textMarkerList = textMarkerManager.loadTextMarkerList(textMarkerFile);
        Collections.sort(textMarkerList);
        ArrayList<GlossaryItem> glossaryItemArr = new ArrayList<GlossaryItem>();
        for (TextMarker tm : textMarkerList) {
            String glossTerm = tm.getMarkedMainText();
            String glossDef = tm.getHooverText();
            GlossaryItem glossItem = new GlossaryItem(glossTerm, glossDef);
            // handle alias -> save as synonyms
            String aliasString = tm.getMarkedAliasText();
            if (StringHelper.containsNonWhitespace(aliasString)) {
                String[] aliasArr = aliasString.split(";");
                ArrayList<String> glossSynonyms = new ArrayList<String>();
                glossSynonyms.addAll(Arrays.asList(aliasArr));
                glossItem.setGlossSynonyms(glossSynonyms);
            }
            glossaryItemArr.add(glossItem);
        }
        VFSLeaf glossaryFile = folderContainingGlossary.createChildLeaf(GLOSSARY_FILENAME);
        saveToFile(glossaryFile, glossaryItemArr);
        // keep a backup in debug mode:
        if (Settings.isDebuging()) {
            File tmFile = ((LocalFileImpl) textMarkerFile).getBasefile();
            File tmCont = ((LocalFolderImpl) folderContainingGlossary).getBasefile();
            FileUtils.copyFileToDir(tmFile, new File(tmCont + "/bkp"), "backup old glossary");
        }
        textMarkerFile.delete();
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ArrayList(java.util.ArrayList) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) TextMarkerManager(org.olat.core.gui.control.generic.textmarker.TextMarkerManager) TextMarker(org.olat.core.gui.control.generic.textmarker.TextMarker) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) File(java.io.File)

Example 2 with TextMarker

use of org.olat.core.gui.control.generic.textmarker.TextMarker in project openolat by klemens.

the class GlossaryItemManager method upgradeAndDeleteOldGlossary.

/**
 * upgrades the old textmarker-format into the new DocBook-glossary-format
 *
 * @param folderContainingGlossary
 * @param textMarkerFile
 */
protected void upgradeAndDeleteOldGlossary(VFSContainer folderContainingGlossary, VFSLeaf textMarkerFile) {
    // check if a new glossary exists, warn
    if (folderContainingGlossary.resolve(GLOSSARY_FILENAME) != null) {
        logError("Upgrading Glossary in " + folderContainingGlossary.toString() + ": There is already a new glossary-file. There can't be an old and a new version in the same directory!", null);
    } else {
        // upgrade it
        TextMarkerManager textMarkerManager = TextMarkerManagerImpl.getInstance();
        List<TextMarker> textMarkerList = textMarkerManager.loadTextMarkerList(textMarkerFile);
        Collections.sort(textMarkerList);
        ArrayList<GlossaryItem> glossaryItemArr = new ArrayList<GlossaryItem>();
        for (TextMarker tm : textMarkerList) {
            String glossTerm = tm.getMarkedMainText();
            String glossDef = tm.getHooverText();
            GlossaryItem glossItem = new GlossaryItem(glossTerm, glossDef);
            // handle alias -> save as synonyms
            String aliasString = tm.getMarkedAliasText();
            if (StringHelper.containsNonWhitespace(aliasString)) {
                String[] aliasArr = aliasString.split(";");
                ArrayList<String> glossSynonyms = new ArrayList<String>();
                glossSynonyms.addAll(Arrays.asList(aliasArr));
                glossItem.setGlossSynonyms(glossSynonyms);
            }
            glossaryItemArr.add(glossItem);
        }
        VFSLeaf glossaryFile = folderContainingGlossary.createChildLeaf(GLOSSARY_FILENAME);
        saveToFile(glossaryFile, glossaryItemArr);
        // keep a backup in debug mode:
        if (Settings.isDebuging()) {
            File tmFile = ((LocalFileImpl) textMarkerFile).getBasefile();
            File tmCont = ((LocalFolderImpl) folderContainingGlossary).getBasefile();
            FileUtils.copyFileToDir(tmFile, new File(tmCont + "/bkp"), "backup old glossary");
        }
        textMarkerFile.delete();
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ArrayList(java.util.ArrayList) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) TextMarkerManager(org.olat.core.gui.control.generic.textmarker.TextMarkerManager) TextMarker(org.olat.core.gui.control.generic.textmarker.TextMarker) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) File(java.io.File)

Aggregations

File (java.io.File)2 ArrayList (java.util.ArrayList)2 TextMarker (org.olat.core.gui.control.generic.textmarker.TextMarker)2 TextMarkerManager (org.olat.core.gui.control.generic.textmarker.TextMarkerManager)2 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)2 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2