Package org.olat.core.util.vfs

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


  /**
   * @see org.olat.course.config.CourseConfigManager#saveConfigTo(org.olat.course.ICourse,
   *      org.olat.course.config.CourseConfig)
   */
  public void saveConfigTo(ICourse course, CourseConfig courseConfig) {
    VFSLeaf configFile = getConfigFile(course);
    if (configFile == null) {
      // create new config file
      configFile = course.getCourseBaseContainer().createChildLeaf(COURSECONFIG_XML);
    }
    XStreamHelper.writeObject(configFile, courseConfig);
View Full Code Here


  protected String addNewHTMLPage() {
    String newId = CPManager.getInstance().addBlankPage(cp, translate("cptreecontroller.newpage.title"), currentPage.getIdentifier());
    CPPage newPage = new CPPage(newId, cp);
    // Create an html file
    VFSContainer root = cp.getRootDir();
    VFSLeaf htmlFile = root.createChildLeaf(newId + ".html");
    newPage.setFile(htmlFile);
    updatePage(newPage);
    return newId;
  }
View Full Code Here

    VFSContainer root = cp.getRootDir();
    String filenName = file.getUploadFileName();
    // don't check on mimetypes - some browser use different mime types when sending files (OLAT-4547)
    if (filenName.toLowerCase().endsWith(".zip")) {
      // unzip and add files
      VFSLeaf archive = new LocalFileImpl(file.getUploadFile());
      String archiveName = file.getUploadFileName();
      String unzipDirName = archiveName.substring(0, archiveName.toLowerCase().indexOf(".zip"));
      unzipDirName = VFSManager.similarButNonExistingName(root, unzipDirName);
      VFSContainer unzipDir = root.createChildContainer(unzipDirName);
      ZipUtil.unzip(archive, unzipDir);
      // add items of unzipDir to tree
      pageToBeSelected = addItem(unzipDir, currentPage.getIdentifier(), true);
      CPManager.getInstance().writeToFile(cp);

    } else {
      // Single file
      VFSLeaf uploadedItem = new LocalFileImpl(file.getUploadFile());
      uploadedItem.rename(file.getUploadFileName());
      // rename to unique name in root folder
      renameToNonExistingDesignation(root, uploadedItem);
      // move item to root folder
      root.copyFrom(uploadedItem);
      pageToBeSelected = addItem(uploadedItem, currentPage.getIdentifier(), false);
View Full Code Here

        && containsItemsToAdd((VFSContainer) item, menuItemTypes)) {
      // Create the menu item
      String newId = cpMgr.addBlankPage(cp, item.getName(), parentId);
      newPage = new CPPage(newId, cp);
      if (item instanceof VFSLeaf) {
        VFSLeaf leaf = (VFSLeaf) item;
        newPage.setFile(leaf);
      }
      cpMgr.updatePage(cp, newPage);
    }
View Full Code Here

    if(page != null)this.pageId = page.getPageId();
  }


  private void deliverMediaFile(UserRequest ureq, String command) {
    VFSLeaf leaf = (VFSLeaf)WikiManager.getInstance().getMediaFolder(ores).resolve(command);
    if(leaf == null) showError("wiki.error.file.not.found");
    else ureq.getDispatchResult().setResultingMediaResource(new VFSMediaResource(leaf));
  }
View Full Code Here

    listenTo(mediaTableCtr);
   
    List filelist = getWiki().getMediaFileListWithMetadata();
    Map files = new HashMap();
    for (Iterator iter = filelist.iterator(); iter.hasNext();) {
      VFSLeaf elem = (VFSLeaf) iter.next();
      if(elem.getName().endsWith(METADATA_SUFFIX)) {  //*.metadata files go here
        Properties p = new Properties();
        try {
          p.load(elem.getInputStream());
          MediaFileElement mediaFileElement = new MediaFileElement(elem.getName(), p.getProperty(MEDIA_FILE_CREATED_BY), p.getProperty(MEDIA_FILE_CREATIONDATE));
          mediaFileElement.setDeletedBy(p.getProperty(MEDIA_FILE_DELETED_BY));
          mediaFileElement.setDeletionDate(p.getProperty(MEDIA_FILE_DELETIONDATE));
          files.put(p.getProperty(MEDIA_FILE_FILENAME), mediaFileElement);
        } catch (IOException e) {
          throw new OLATRuntimeException("Could'n read properties from media file: "+elem.getName(), e);
        }
      }
    }
    for (Iterator iter = filelist.iterator(); iter.hasNext();) {
      VFSLeaf elem = (VFSLeaf) iter.next();
      if(!elem.getName().endsWith(METADATA_SUFFIX)){
        if(!files.containsKey(elem.getName())) {
          //legacy file without metadata
          files.put(elem.getName(), new MediaFileElement(elem.getName(), 0, elem.getLastModified()));
        } else {
          //file with metadata, update name
          MediaFileElement element = (MediaFileElement)files.get(elem.getName());
          element.setFileName(elem.getName());
        }
      }
    }
   
    mediaFilesTableModel = new MediaFilesTableModel(new ArrayList(files.values()), getTranslator());
View Full Code Here

  private void createMediaMetadataFile(String filename, Long author) {
    VFSContainer mediaFolder = WikiManager.getInstance().getMediaFolder(ores);
    //only create metadatafile if base file exists
    if ((VFSLeaf)mediaFolder.resolve(filename) != null) {
      //metafile may exists when files get overwritten
      VFSLeaf metaFile = (VFSLeaf)mediaFolder.resolve(filename+METADATA_SUFFIX);
      if (metaFile == null) {
          // metafile does not exist => create one
        metaFile = mediaFolder.createChildLeaf(filename+METADATA_SUFFIX);
      }
      Properties p = new Properties();
      p.setProperty(MEDIA_FILE_FILENAME, filename);
      p.setProperty(MEDIA_FILE_CREATIONDATE, String.valueOf(System.currentTimeMillis()));
      p.setProperty(MEDIA_FILE_CREATED_BY, String.valueOf(author));
      try {
        p.store(metaFile.getOutputStream(false), "wiki media files meta properties");
      } catch (IOException e) {
        throw new OLATRuntimeException(WikiManager.class, "failed to save media files properties for file: " + filename +" and olatresource: " + ores.getResourceableId(), e);
      }
    }
  }
View Full Code Here

    for (Iterator iter = toDelete.iterator(); iter.hasNext();) {
      VFSContainer mediaFolder = WikiManager.getInstance().getMediaFolder(ores);
      MediaFileElement element = (MediaFileElement) iter.next();
      if(log.isDebug()) log.debug("deleting media file: "+element.getFilename());
      if(!element.getFilename().endsWith(METADATA_SUFFIX)) {
        VFSLeaf file = (VFSLeaf)mediaFolder.resolve(element.getFilename());
        if (file != null) {
          file.delete();
          VFSLeaf metadata = (VFSLeaf)mediaFolder.resolve(element.getFilename()+METADATA_SUFFIX);
          if(metadata != null) {
            Properties p = new Properties();
            try {
              p.load(metadata.getInputStream());
              p.setProperty(MEDIA_FILE_DELETIONDATE, String.valueOf(System.currentTimeMillis()));
              p.setProperty(MEDIA_FILE_DELETED_BY, String.valueOf(ureq.getIdentity().getKey()));
              OutputStream os = metadata.getOutputStream(false);
              p.store(os, "wiki media file meta properties");
              os.close();
            } catch (IOException e) {
              throw new OLATRuntimeException("Could'n read properties from media file: "+metadata.getName(), e);
            }
          }
        }
      }
    }
View Full Code Here

  protected WikiPage getPage(String pageId, boolean loadContent) {
    WikiPage page = getPage(pageId);
    // if not empty content is already loaded
    if (!page.getContent().equals("")) return page;
    if (loadContent) {
      VFSLeaf leaf = (VFSLeaf) pageContainer.resolve(page.getPageId() + "." + WikiManager.WIKI_FILE_SUFFIX);
      page.setContent(FileUtils.load(leaf.getInputStream(), "utf-8"));
    }
    return page;
  }
View Full Code Here

  protected List<WikiPage> getHistory(WikiPage page) {
    List<WikiPage> versions = new ArrayList<WikiPage>();
    List<VFSItem> leafs = versionsContainer.getItems(new VFSLeafFilter());
    if (leafs.size() > 0) {
      for (Iterator<VFSItem> iter = leafs.iterator(); iter.hasNext();) {
        VFSLeaf leaf = (VFSLeaf)iter.next();
        String filename = leaf.getName();
        // TODO:gs:a needs better filtering only for pagename.properties-xy
        // try this: List leafs = wikiCont.getItems(new VFSItemSuffixFilter(new String[]{WikiManager.WIKI_PROPERTIES_SUFFIX}));
        if (filename.indexOf(WikiManager.WIKI_PROPERTIES_SUFFIX) != -1 && filename.startsWith(page.getPageId())) {
          versions.add(assignPropertiesToPage(leaf));
        }
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.