use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.
the class FileUtils method createEmptyFile.
// end deleteDirContents
/**
* @param newF
*/
public static void createEmptyFile(File newF) {
try {
FileOutputStream fos = new FileOutputStream(newF);
fos.close();
} catch (IOException e) {
throw new AssertException("empty file could not be created for path " + newF.getAbsolutePath(), e);
}
}
use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.
the class OLATResourceableListeningWrapperController method event.
/**
* @see org.olat.core.util.event.GenericEventListener#event(org.olat.core.gui.control.Event)
*/
public void event(Event event) {
if (event instanceof OLATResourceableJustBeforeDeletedEvent) {
OLATResourceableJustBeforeDeletedEvent orj = (OLATResourceableJustBeforeDeletedEvent) event;
if (!orj.targetEquals(ores))
throw new AssertException("disposingwrappercontroller only listens to del event for resource " + ores.getResourceableTypeName() + " / " + ores.getResourceableId() + ", but event was for " + orj.getDerivedOres());
dispose();
}
}
use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.
the class StackedBusinessControl method setCurrentContextEntry.
public void setCurrentContextEntry(ContextEntry ce) {
if (ce == null)
throw new AssertException("ContextEntry can not be null!");
this.currentCe = ce;
List<ContextEntry> ces = new ArrayList<ContextEntry>();
notifyParent(ces);
}
use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.
the class I18nManager method createNewLanguage.
public boolean createNewLanguage(String localeKey, String languageInEnglish, String languageTranslated, String authors) {
if (!i18nModule.isTransToolEnabled()) {
throw new AssertException("Can not create a new language when the translation tool is not enabled and the transtool source pathes are not configured! Check your olat.properties files");
}
if (i18nModule.getAvailableLanguageKeys().contains(localeKey)) {
return false;
}
// Create new property file in the brasato bundle and re-initialize
// everything
String coreFallbackBundle = i18nModule.getApplicationFallbackBundle();
File transToolCoreLanguagesDir = i18nModule.getTransToolApplicationOptLanguagesSrcDir();
String i18nDirRelPath = "/" + coreFallbackBundle.replace(".", "/") + "/" + I18nManager.I18N_DIRNAME;
File transToolCoreLanguagesDir_I18n = new File(transToolCoreLanguagesDir, i18nDirRelPath);
File newPropertiesFile = new File(transToolCoreLanguagesDir_I18n, I18nModule.LOCAL_STRINGS_FILE_PREFIX + localeKey + I18nModule.LOCAL_STRINGS_FILE_POSTFIX);
// Prepare property file
// Use a sorted properties object that saves the keys sorted alphabetically to disk
Properties newProperties = new SortedProperties();
if (StringHelper.containsNonWhitespace(languageInEnglish)) {
newProperties.setProperty("this.language.in.english", languageInEnglish);
}
if (StringHelper.containsNonWhitespace(languageTranslated)) {
newProperties.setProperty("this.language.translated", languageTranslated);
}
if (StringHelper.containsNonWhitespace(authors)) {
newProperties.setProperty("this.language.translator.names", authors);
}
OutputStream fileStream = null;
try {
// Create necessary directories
File directory = newPropertiesFile.getParentFile();
if (!directory.exists())
directory.mkdirs();
// Write to file file now
fileStream = new FileOutputStream(newPropertiesFile);
newProperties.store(fileStream, null);
fileStream.flush();
// Now set new language as enabled to allow user to translate the language.
Collection<String> enabledLangKeys = i18nModule.getEnabledLanguageKeys();
enabledLangKeys.add(localeKey);
// Reinitialize languages with new language
i18nModule.reInitializeAndFlushCache();
// Now add new language as new language (will re-initialize everything a second time)
i18nModule.setEnabledLanguageKeys(enabledLangKeys);
return true;
} catch (FileNotFoundException e) {
throw new OLATRuntimeException("Could not create new language file::" + newPropertiesFile.getAbsolutePath(), e);
} catch (IOException e) {
throw new OLATRuntimeException("Could not create new language file::" + newPropertiesFile.getAbsolutePath() + ", maybe permission denied? Check your directory permissions", e);
} finally {
try {
if (fileStream != null)
fileStream.close();
} catch (IOException e) {
log.error("Could not close stream after creating new language file::" + newPropertiesFile.getAbsolutePath(), e);
}
}
}
use of org.olat.core.logging.AssertException in project OpenOLAT by OpenOLAT.
the class I18nManager method deleteProperties.
/**
* Delete the given property file from disk
*
* @param locale
* @param bundleName
*/
public void deleteProperties(Locale locale, String bundleName) {
String key = calcPropertiesFileKey(locale, bundleName);
if (log.isDebug())
log.debug("deleteProperties for key::" + key, null);
if (locale != null) {
// 1) Remove from cache first
if (cachedBundles.containsKey(key)) {
cachedBundles.remove(key);
// initialization will happen lazy
if (cachedJSTranslatorData.containsKey(key))
cachedJSTranslatorData.remove(key);
}
}
// 2) Remove from filesystem
File baseDir = i18nModule.getPropertyFilesBaseDir(locale, bundleName);
if (baseDir == null) {
if (baseDir == null) {
throw new AssertException("Can not delete properties file for bundle::" + bundleName + " and language::" + locale.toString() + " - no base directory found, probably loaded from jar!");
}
}
File f = getPropertiesFile(locale, bundleName, baseDir);
if (f.exists())
f.delete();
// 3) Check if for this bundle any other language file exists, if
// not remove
// the bundle from the list of translatable bundles
List<String> knownBundles = i18nModule.getBundleNamesContainingI18nFiles();
Set<String> knownLangs = i18nModule.getAvailableLanguageKeys();
boolean foundOther = false;
for (String lang : knownLangs) {
f = getPropertiesFile(getLocaleOrDefault(lang), bundleName, baseDir);
if (f.exists()) {
foundOther = true;
break;
}
}
if (!foundOther) {
knownBundles.remove(bundleName);
}
}
Aggregations