Search in sources :

Example 76 with AssertException

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);
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

Example 77 with AssertException

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();
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) OLATResourceableJustBeforeDeletedEvent(org.olat.core.util.resource.OLATResourceableJustBeforeDeletedEvent)

Example 78 with AssertException

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);
}
Also used : AssertException(org.olat.core.logging.AssertException) ArrayList(java.util.ArrayList)

Example 79 with AssertException

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);
        }
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) JarOutputStream(java.util.jar.JarOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) SortedProperties(org.olat.core.util.SortedProperties) Properties(java.util.Properties) SortedProperties(org.olat.core.util.SortedProperties) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 80 with AssertException

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);
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

AssertException (org.olat.core.logging.AssertException)364 IOException (java.io.IOException)38 File (java.io.File)28 Identity (org.olat.core.id.Identity)28 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)24 Controller (org.olat.core.gui.control.Controller)22 OLATResourceable (org.olat.core.id.OLATResourceable)22 RepositoryEntry (org.olat.repository.RepositoryEntry)22 WindowControl (org.olat.core.gui.control.WindowControl)20 UnsupportedEncodingException (java.io.UnsupportedEncodingException)18 JSONException (org.json.JSONException)18 BusinessGroup (org.olat.group.BusinessGroup)18 JSONObject (org.json.JSONObject)16 UserRequest (org.olat.core.gui.UserRequest)16 VFSContainer (org.olat.core.util.vfs.VFSContainer)16 VFSItem (org.olat.core.util.vfs.VFSItem)16 Date (java.util.Date)14 Properties (java.util.Properties)14 Property (org.olat.properties.Property)14