Package org.olat.core.commons.modules.bc

Source Code of org.olat.core.commons.modules.bc.FolderModule

/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) 1999-2006 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/

package org.olat.core.commons.modules.bc;

import java.io.File;

import org.olat.core.CoreSpringFactory;
import org.olat.core.configuration.OLATModule;
import org.olat.core.helpers.Settings;
import org.olat.core.logging.StartupException;
import org.olat.core.logging.Tracing;
import org.olat.core.util.vfs.version.FolderVersioningConfigurator;

import com.anthonyeden.lib.config.Configuration;

/**
* Initial Date:  13.11.2002
*
* @author Mike Stock
*/
public class FolderModule implements OLATModule
 
  private static final String CONFIG_ROOT = "Root";
  private static final String CONFIG_LIMITULMB = "LimitULMB";
  private static final String CONFIG_QUOTAMB = "QuotaMB";
 
  /**
   * @see org.olat.core.configuration.OLATModule#init(com.anthonyeden.lib.config.Configuration)
   */
  public void init(Configuration configuration) {
    // Set folder root
    try {
      String homesRoot = configuration.getChildValue(CONFIG_ROOT);
      if (Settings.isJUnitTest()) {
        // use dummy directory for junit testcases to not conflict with actual data
        // on current server. someone may start junit test and not realize that this
        // can have side effects to a running instance on the same server...
        FolderConfig.setFolderRoot(homesRoot + "_junittest");
      } else {
        FolderConfig.setFolderRoot(homesRoot);
      }
    } catch (Exception e) {
      throw new StartupException("Unable to find folder root config. Please fix!", e);
    }
    Tracing.logInfo("Folder root set to '" + FolderConfig.getCanonicalRoot() + "'.", FolderModule.class);

    // Set maximum upload filesize
    try {
      int maxULMB = Integer.parseInt(configuration.getChildValue(CONFIG_LIMITULMB));
      FolderConfig.setLimitULKB(maxULMB * 1024);
    } catch (Exception e) {
      // ok, revert to default settings.
    }
    Tracing.logInfo("Maximum file upload size set to " + FolderConfig.getLimitULKB() + " KB.", FolderModule.class);
   
    // Set default quotas
    try {
      int quotaMB = Integer.parseInt(configuration.getChildValue(CONFIG_QUOTAMB));
      FolderConfig.setDefaultQuotaKB(quotaMB * 1024);
    } catch (Exception e) {
      // ok, revert to default settings.
    }
    Tracing.logInfo("Default user quota set to " + FolderConfig.getDefaultQuotaKB() + " KB.", FolderModule.class);

    // create tmp directory
    File fTmp = new File(FolderConfig.getCanonicalTmpDir());
    fTmp.mkdirs();

    //find a configurator for versioning
    if(CoreSpringFactory.containsBean("org.olat.core.util.vfs.version.FolderVersioningConfigurator")) {
      FolderVersioningConfigurator versioningConfigurator = (FolderVersioningConfigurator)CoreSpringFactory.getBean("org.olat.core.util.vfs.version.FolderVersioningConfigurator");
      FolderConfig.setVersioningConfigurator(versioningConfigurator);
    }
  }

  /**
   * @see org.olat.core.configuration.OLATModule#destroy()
   */
  public void destroy() {
    // nothing to do here.
  }

}
TOP

Related Classes of org.olat.core.commons.modules.bc.FolderModule

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.