use of org.olat.core.gui.control.generic.textmarker.TextMarkerManager 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();
}
}
use of org.olat.core.gui.control.generic.textmarker.TextMarkerManager 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();
}
}
Aggregations