Package org.olat.core.util.vfs

Examples of org.olat.core.util.vfs.VFSLeaf


    VFSItem restoredItem = container.resolve(filename);
    if (restoredItem == null) {
      restoredItem = container.createChildLeaf(filename);
    }
    if (restoredItem instanceof VFSLeaf) {
      VFSLeaf restoredLeaf = (VFSLeaf) restoredItem;
      InputStream inStream = revision.getInputStream();
      if (VFSManager.copyContent(inStream, restoredLeaf)) {
        VFSLeaf versionFile = getCanonicalVersionXmlFile(restoredLeaf, true);
        Versions versions = readVersions(restoredLeaf, versionFile);
        if (versions instanceof VersionsFileImpl) {
          versions.getRevisions().remove(revision);
          ((VersionsFileImpl) versions).setRevisionNr(getNextRevisionNr(versions));
        }
View Full Code Here


    return false;
  }

  @Override
  public boolean deleteRevisions(Versionable currentVersion, List<VFSRevision> versionsToDelete) {
    VFSLeaf currentFile = (VFSLeaf) currentVersion;
    Versions versions = readVersions(currentFile, true);
    List<VFSRevision> allVersions = versions.getRevisions();

    for (VFSRevision versionToDelete : versionsToDelete) {
      RevisionFileImpl versionImpl = (RevisionFileImpl) versionToDelete;
      for (Iterator<VFSRevision> allVersionIt = allVersions.iterator(); allVersionIt.hasNext();) {
        RevisionFileImpl allVersionImpl = (RevisionFileImpl) allVersionIt.next();
        if (allVersionImpl.getFilename() != null && allVersionImpl.getFilename().equals(versionImpl.getFilename())) {
          allVersionIt.remove();
          break;
        }
      }

      VFSLeaf fileToDelete = versionImpl.getFile();
      if (fileToDelete != null) {
        fileToDelete.delete();
      }
    }

    VFSLeaf versionFile = getCanonicalVersionXmlFile(currentFile, true);
    XStreamHelper.writeObject(mystream, versionFile, versions);
    if (currentVersion.getVersions() instanceof VersionsFileImpl) {
      ((VersionsFileImpl) currentVersion.getVersions()).update(versions);
    }
    return true;
View Full Code Here

  @Override
  public boolean deleteVersions(List<Versions> versions) {
    for(Versions versionToDelete:versions) {
      if(versionToDelete instanceof VersionsFileImpl) {
        VersionsFileImpl versionsImpl = (VersionsFileImpl)versionToDelete;
        VFSLeaf versionFile = versionsImpl.getVersionFile();
        if(versionFile != null) {
          //robust against manual file system manipulation
          versionFile.delete();
        }
        for (VFSRevision revisionToDelete : versionsImpl.getRevisions()) {
          RevisionFileImpl versionImpl = (RevisionFileImpl)revisionToDelete;
          VFSLeaf fileToDelete = versionImpl.getFile();
          if (fileToDelete != null) {
            fileToDelete.delete();
          }
        }
      }
    }
    return true;
View Full Code Here

        if (versionContainer == null) { return true; }
        return VFSConstants.YES.equals(versionContainer.delete());
      }
      return true;
    } else if (item instanceof VFSLeaf && item instanceof Versionable) {
      VFSLeaf leaf = (VFSLeaf)item;
      if (force) {
        cleanUp(leaf);
      } else {
        addToRevisions((Versionable)leaf, null, null);
      }
View Full Code Here

    String parent = name.substring(0, lastSlash);
    VFSItem folder = resolveFile(parent);
    if (folder == null || (!(folder instanceof VFSContainer)))
      throw new NamingException(smgr.getString("resources.bindFailed", name));
    String newName = name.substring(lastSlash + 1);
    VFSLeaf childLeaf = ((VFSContainer)folder).createChildLeaf(newName);
    if (childLeaf == null)
      throw new NamingException(smgr.getString("resources.bindFailed", name));
    copyVFS(childLeaf, name, obj, attrs);
    if(childLeaf instanceof MetaTagged) {
      MetaInfo infos = ((MetaTagged)childLeaf).getMetaInfo();
      if(infos != null && infos.getAuthorIdentity() == null) {
        infos.setAuthor(userSession.getIdentity().getName());
        infos.write();
      }
    }
   
    //used by move operations
    if(obj instanceof VFSResource) {
      VFSResource vfsResource = (VFSResource)obj;
      if(vfsResource.vfsItem instanceof Versionable
          && ((Versionable)vfsResource.vfsItem).getVersions().isVersioned()) {
        Versionable currentVersion = (Versionable)vfsResource.vfsItem;
        VersionsManager.getInstance().move(currentVersion, childLeaf.getParentContainer());
      }
    }
  }
View Full Code Here

    File fVersion = new File(getRootVersionsFile(), relPath + ".xml");
    File fParentVersion = fVersion.getParentFile();
    if (!fParentVersion.exists()) return; //already deleted

    VFSLeaf versionLeaf = null;
    if (fVersion.exists()) {
      LocalFolderImpl localVersionContainer = new LocalFolderImpl(fParentVersion);
      versionLeaf = (VFSLeaf) localVersionContainer.resolve(fVersion.getName());
    }
   
    if (versionLeaf == null) return; //already deleted
    Versions versions = readVersions(leaf, versionLeaf);
    for (VFSRevision versionToDelete : versions.getRevisions()) {
      RevisionFileImpl versionImpl = (RevisionFileImpl) versionToDelete;
      VFSLeaf fileToDelete = versionImpl.getFile();
      if (fileToDelete != null) {
        fileToDelete.delete();
      }
    }
    versionLeaf.delete();
  }
View Full Code Here

  }

  @Override
  public boolean rename(VFSItem item, String newname) {
    if (item instanceof VFSLeaf) {
      VFSLeaf currentFile = (VFSLeaf) item;
      VFSLeaf versionFile = getCanonicalVersionXmlFile(currentFile, true);
      // infinite loop if rename is own versions file
      return VFSConstants.YES.equals(versionFile.rename(newname + ".xml"));
    } else if (item instanceof VFSContainer) {
      VFSContainer container = (VFSContainer) item;
      VFSContainer versionContainer = getCanonicalVersionFolder(container, false);
      if (versionContainer == null) { return true; }
      return VFSConstants.YES.equals(versionContainer.rename(newname));
View Full Code Here

    // Note: No custom attributes allowed
    // Check obj type

    VFSItem vfsItem = resolveFile(name);
    if (vfsItem == null || (!(vfsItem instanceof VFSLeaf))) throw new NamingException(smgr.getString("resources.bindFailed", name));
    VFSLeaf file = (VFSLeaf)vfsItem;
   
    if(file instanceof Versionable && ((Versionable)file).getVersions().isVersioned()) {
      VersionsManager.getInstance().addToRevisions((Versionable)file, identity, "");
    }
   
    copyVFS(file, name, obj, attrs);
    if(file instanceof MetaTagged) {
      MetaInfo infos = ((MetaTagged)file).getMetaInfo();
      if(infos != null && infos.getAuthorIdentity() == null) {
        infos.setAuthor(userSession.getIdentity().getName());
        infos.write();
      }
    }
   
    //used by move operations
    if(obj instanceof VFSResource) {
      VFSResource vfsResource = (VFSResource)obj;
      if(vfsResource.vfsItem instanceof Versionable
          && ((Versionable)vfsResource.vfsItem).getVersions().isVersioned()) {
        Versionable currentVersion = (Versionable)vfsResource.vfsItem;
        VersionsManager.getInstance().move(currentVersion, file.getParentContainer());
      }
    }
  }
View Full Code Here

  /**
   * @see org.olat.core.util.vfs.version.VersionsManager#addToRevisions(org.olat.core.util.vfs.version.Versionable, org.olat.core.id.Identity, java.lang.String)
   */
  @Override
  public boolean addToRevisions(Versionable currentVersion, Identity identity, String comment) {
    VFSLeaf currentFile = (VFSLeaf) currentVersion;
   
    VFSLeaf versionFile = getCanonicalVersionXmlFile(currentFile, true);
    if(versionFile == null) {
      return false;//cannot do something with the current file
    }
   
    VFSContainer versionContainer = versionFile.getParentContainer();

    String name = currentFile.getName();

    // read from the
    Versions v = readVersions(currentFile, versionFile);
    if (!(v instanceof VersionsFileImpl)) {
      log.error("Wrong implementation of Versions: " + v);
      return false;
    }
    VersionsFileImpl versions = (VersionsFileImpl) v;

    String uuid = UUID.randomUUID().toString() + "_" + name;
    String versionNr = getNextRevisionNr(versions);
    String currentAuthor = versions.getAuthor();
    long lastModifiedDate = 0;
    if (currentFile instanceof MetaTagged) {
      MetaInfo metaInfo = ((MetaTagged) currentFile).getMetaInfo();
      if(currentAuthor == null) {
        currentAuthor = metaInfo.getAuthor();
      }
      lastModifiedDate = metaInfo.getLastModified();
    }
   
    if(lastModifiedDate <= 0) {
      Calendar cal = Calendar.getInstance();
      cal.setTime(new Date());
      lastModifiedDate = cal.getTimeInMillis();
    }

    RevisionFileImpl newRevision = new RevisionFileImpl();
    newRevision.setName(name);
    newRevision.setFilename(uuid);
    newRevision.setRevisionNr(versionNr);
    newRevision.setComment(versions.getComment());
    newRevision.setAuthor(currentAuthor);
    newRevision.setLastModified(lastModifiedDate);

    if (versions.getRevisions().isEmpty() && currentVersion instanceof MetaTagged) {
      MetaTagged metaTagged = (MetaTagged) currentVersion;
      versions.setCreator(metaTagged.getMetaInfo().getAuthor());
    }

    VFSLeaf target = versionContainer.createChildLeaf(uuid);
    if (VFSManager.copyContent(currentFile, target)) {
      if (identity != null) {
        versions.setAuthor(identity.getName());
      }
      versions.setComment(comment);
View Full Code Here

        }
      } else  if (com.equals("vc")) {
        // ------- open velocity container for editing -------
        VelocityContainer vc = (VelocityContainer) infoComponent;
        String velocityTemplatePath  = WebappHelper.getSourcePath()+"/"+vc.getPage();
        VFSLeaf vcContentFile = new LocalFileImpl(new File(velocityTemplatePath));
        boolean readOnly = Settings.isReadOnlyDebug();
        vcEditorController = new PlainTextEditorController(ureq, getWindowControl(), vcContentFile, "utf-8", true, true, null);
        vcEditorController.setReadOnly(readOnly);
        vcEditorController.addControllerListener(this);
        VelocityContainer vcWrap = createVelocityContainer("vcWrapper");
View Full Code Here

TOP

Related Classes of org.olat.core.util.vfs.VFSLeaf

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.