Package org.olat.fileresource.types

Examples of org.olat.fileresource.types.FileResource


  /**
   * @return the new created resource
   */
  public FileResource createWiki() {
    FileResource resource = new WikiResource();
    createFolders(resource);
    OLATResourceManager rm = OLATResourceManager.getInstance();
    OLATResource ores = rm.createOLATResourceInstance(resource);
    rm.saveOLATResource(ores);
    return resource;
View Full Code Here


  public FileResource addFileResource(File fResource, String newName, FileResource knownResource) throws AddingResourceException {

    // ZIPDIR is a reserved name... check
    if (fResource.getName().equals(ZIPDIR)) throw new AssertException("Trying to add FileResource with reserved name '" + ZIPDIR + "'.");

    FileResource tempFr = new FileResource();
    if (knownResource != null) tempFr = knownResource;

    // move file to its new place
    File fResourceFileroot = getFileResourceRoot(tempFr);
    if (!FileUtils.copyFileToDir(fResource, fResourceFileroot)) return null;

    if (!fResource.getName().equals(newName)) { // need to rename file to new
      // name
      File fNewName = new File(fResourceFileroot, newName);
      if (!new File(fResourceFileroot, fResource.getName()).renameTo(fNewName)) {
        FileUtils.deleteDirsAndFiles(fResourceFileroot, true, true);
        return null;
      }
      fResource = fNewName;
    }

    if (knownResource == null) {
      // save resourceableID
      Long resourceableId = tempFr.getResourceableId();
      // extract type
      try {
        if (DocFileResource.validate(fResource)) tempFr = new DocFileResource();
        else if (XlsFileResource.validate(fResource)) tempFr = new XlsFileResource();
        else if (PowerpointFileResource.validate(fResource)) tempFr = new PowerpointFileResource();
        else if (PdfFileResource.validate(fResource)) tempFr = new PdfFileResource();
        else if (ImageFileResource.validate(fResource)) tempFr = new ImageFileResource();
        else if (MovieFileResource.validate(fResource)) tempFr = new MovieFileResource();
        else if (SoundFileResource.validate(fResource)) tempFr = new SoundFileResource();
        else if (AnimationFileResource.validate(fResource)) tempFr = new AnimationFileResource();
        else if (SharedFolderFileResource.validate(fResource)) tempFr = new SharedFolderFileResource();
        // add a wiki copy
        else if (WikiResource.validate(fResource)) tempFr = new WikiResource();
        // add a podcast copy
        else if (PodcastFileResource.validate(fResource)) tempFr = new PodcastFileResource(fResourceFileroot, fResource);
        // add a blog copy
        else if (BlogFileResource.validate(fResource)) tempFr = new BlogFileResource(fResourceFileroot, fResource);
        // add a glossary copy
        else if (GlossaryResource.validate(fResource)) tempFr = new GlossaryResource();
        // the following types need unzippedDir
        else if (fResource.getName().toLowerCase().endsWith(".zip")) {
          File fUnzippedDir = unzipFileResource(tempFr);
          if (fUnzippedDir == null) {
            // in case of failure we forward the error message
            throw new AddingResourceException("resource.error.zip");
          }
          if (TestFileResource.validate(fUnzippedDir)) tempFr = new TestFileResource();
          else if (WikiResource.validate(fUnzippedDir)) tempFr = new WikiResource();
          else if (PodcastFileResource.validate(fUnzippedDir)) tempFr = new PodcastFileResource(fResourceFileroot, fUnzippedDir);
          else if (BlogFileResource.validate(fUnzippedDir)) tempFr = new BlogFileResource(fResourceFileroot, fUnzippedDir);
          else if (SurveyFileResource.validate(fUnzippedDir)) tempFr = new SurveyFileResource();
          // CP must be later entry... Test- and SurveyFileResource may contain
          // imsmanifest.xml as well
          else if (ImsCPFileResource.validate(fUnzippedDir)) tempFr = new ImsCPFileResource();
          // scorm and cp now can throw an exception which helps to show a
          // better error message in case
          // of a failure in adding a new resource
          else if (ScormCPFileResource.validate(fUnzippedDir)) tempFr = new ScormCPFileResource();
          // glossary resources are packaged within zip for import/export
          else if (GlossaryResource.validate(fUnzippedDir)) tempFr = new GlossaryResource();
          else {
            // just a generic ZIP file... we can delete the temporary unziped
            // dir...
            throw new AddingResourceException("doesn't matter what error key is declared");
          }
        }
      } catch (AddingResourceException exception) {
        // in case of failure we delete the resource and forward the error
        // message
        deleteFileResource(tempFr);
        throw exception;
      }

      tempFr.overrideResourceableId(resourceableId);
    }

    // add olat resource
    OLATResourceManager rm = OLATResourceManager.getInstance();
    OLATResource ores = rm.findOrPersistResourceable(tempFr);
View Full Code Here

  /**
   * @param res
   * @return Get resourceable as file.
   */
  private File getFileResource(OLATResourceable res, String resourceFolderName) {
    FileResource fr = getAsGenericFileResource(res);
    File f = getFile(fr, resourceFolderName);
    if (f == null) // folder not existing or no file in it
    throw new OLATRuntimeException(FileResourceManager.class, "could not getFileResource for OLATResourceable " + res.getResourceableId()
        + ":" + res.getResourceableTypeName(), null);
    return f;
View Full Code Here

  /**
   * @param res
   * @return File resource as downloadeable media resource.
   */
  public MediaResource getAsDownloadeableMediaResource(OLATResourceable res) {
    FileResource fr = getAsGenericFileResource(res);
    File f = getFile(fr);
    if (f == null) // folder not existing or no file in it
    throw new OLATRuntimeException(FileResourceManager.class, "could not get File for OLATResourceable " + res.getResourceableId() + ":"
        + res.getResourceableTypeName(), null);
    return new DownloadeableMediaResource(f);
View Full Code Here

    Translator translator = Util.createPackageTranslator(this.getClass(), locale);
    return new FileDetailsForm("fileDetails", translator, res);
  }

  private FileResource getAsGenericFileResource(OLATResourceable res) {
    FileResource fr = new FileResource();
    fr.overrideResourceableId(res.getResourceableId());
    return fr;
  }
View Full Code Here

          folderOfResource.createChildContainer(QTIEditorPackage.FOLDERNAMEFOR_CHANGELOG);
         
          //these are eiterh surveys or tests
          //try it as testresource then as survey, after this give up
          Long oresId = new Long(folderOfResource.getName());
          FileResource fr = new TestFileResource();
          fr.overrideResourceableId(oresId);
          myEntry = rm.lookupRepositoryEntry(fr,false);
          if(myEntry==null){
            //no qti test found, try the qti survey
            fr = new SurveyFileResource();
            fr.overrideResourceableId(oresId);
            myEntry = rm.lookupRepositoryEntry(fr,false);
          }
          //
          if(myEntry!=null){
            List identites = manager.getVisibleIdentitiesByPowerSearch(folderOfUser.getName(),null,false, null,null,null,null,null);
View Full Code Here

  public OLATResourceable createCopy(OLATResourceable res, UserRequest ureq) {
    OLATResourceable oLATResourceable = super.createCopy(res, ureq);
   
    File sourceFile = FileResourceManager.getInstance().getFileResource(oLATResourceable);
    //unzip sourceFile in a temp dir, delete changelog if any, zip back, delete temp dir
    FileResource tempFr = new FileResource();
    // move file to its new place
    File fResourceFileroot = FileResourceManager.getInstance().getFileResourceRoot(tempFr);
    if (!FileUtils.copyFileToDir(sourceFile, fResourceFileroot)) return null;
    File fUnzippedDir = FileResourceManager.getInstance().unzipFileResource(tempFr);
    File changeLogDir = new File(fUnzippedDir, "changelog");
View Full Code Here

   * @return
   */
  public static RepositoryEntry doImport(RepositoryEntryImportExport importExport, CourseNode node, int importMode, boolean keepSoftkey,
      Identity owner) {
    File fExportedFile = importExport.importGetExportedFile();
    FileResource fileResource = null;
    try {
      fileResource = FileResourceManager.getInstance().addFileResource(fExportedFile, fExportedFile.getName());
    } catch (AddingResourceException e) {
      // e.printStackTrace();
      if (fileResource == null) {
View Full Code Here

TOP

Related Classes of org.olat.fileresource.types.FileResource

Copyright © 2018 www.massapicom. 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.