Examples of VFSLeaf


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

      throw new RuntimeException("Illegal read attempt: " + folderComponent.getCurrentContainerPath());
   
    // extract file
    String path = ureq.getModuleURI();
    MediaResource mr = null;
    VFSLeaf vfsfile = (VFSLeaf)folderComponent.getRootContainer().resolve(path);
   
   
   
    if (vfsfile == null) {
      mr = new NotFoundMediaResource(path);
    } else {
      if (path.toLowerCase().endsWith(".html") || path.toLowerCase().endsWith(".htm")) {
        // setCurrentURI(path);
        // set the http content-type and the encoding
        // try to load in iso-8859-1
        InputStream is = vfsfile.getInputStream();
        String page = FileUtils.load(is, DEFAULT_ENCODING);
        // search for the <meta content="text/html; charset=utf-8"
        // http-equiv="Content-Type" /> tag
        // if none found, assume iso-8859-1
        String enc = DEFAULT_ENCODING;
View Full Code Here

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

   * TODO: firefox 2.0 has an strange error when the iframe is loaded the browser requests the first file always twice
   * @param isPopUp
   */
  protected MediaResource deliverFile(String path, boolean isPopUp) {
    MediaResource mr;
    VFSLeaf vfsLeaf = null;
    VFSItem vfsItem = null;
    //if directory gets renamed root becomes null
    if (rootDir == null) {
      return new NotFoundMediaResource("directory not found"+path);
    } else {
      vfsItem = rootDir.resolve(path);
    }
    //only files are allowed, but somehow it happened that folders showed up here
    if (vfsItem instanceof VFSLeaf) {
      vfsLeaf = (VFSLeaf) rootDir.resolve(path);
    } else {
      mr = new NotFoundMediaResource(path);
    }
    if (vfsLeaf == null) {
      mr = new NotFoundMediaResource(path);
    } else {
      // check if path ends with .html, .htm or .xhtml. We do this by searching for "htm"
      // and accept positions of this string at length-3 or length-4
      if (path.toLowerCase().lastIndexOf(FILE_SUFFIX_HTM) >= (path.length()-4)) {
        // set the http content-type and the encoding
        // try to load in iso-8859-1
        String page = FileUtils.load(vfsLeaf.getInputStream(), DEFAULT_ENCODING);
       
        // search for the <meta content="text/html; charset=utf-8"
        // http-equiv="Content-Type" /> tag
        // if none found, assume iso-8859-1
        String enc = DEFAULT_ENCODING;
        boolean useLoadedPageString = false;
        // <meta.*charset=([^"]*)"
       
        //extract only the charset attribute without the overhead of creating an htmlparser
        Matcher m = PATTERN_ENCTYPE.matcher(page);
        boolean found = m.find();
       
        if (found) {
          // use found char set
          String htmlcharset = m.group(1);
          //if longer than 50 the regexp did fail
          if (htmlcharset.length() < 50) enc
          = htmlcharset;
          // reuse already loaded page when page uses the default encoding
          if (htmlcharset.equalsIgnoreCase(DEFAULT_ENCODING) || htmlcharset.contains(DEFAULT_ENCODING) || htmlcharset.toLowerCase().contains(DEFAULT_ENCODING)) {
            useLoadedPageString = true;
          }
        } else {
          // try it with unicode character set as a fallback
          String pageUnicode = FileUtils.load(vfsLeaf.getInputStream(), UNICODE_ENCODING);
          m = PATTERN_ENCTYPE.matcher(pageUnicode);
          found = m.find();
          if (found) {
            page = pageUnicode; // reuse already loaded page
            useLoadedPageString = true;
          } else {
            // fallback, use the default encoding and reuse the already loaded page
            useLoadedPageString = true;           
          }
        }
        //test the encoding first, sometime the regexp delivers fancy stuff. If it fails use fallback to default
        try {
          Charset.isSupported(enc);
        } catch (IllegalCharsetNameException e) {
          //TODO: see OLAT-5407
          log.warn("IllegalCharsetNameException in:"+path+", enc="+enc+", overwriting to "+DEFAULT_ENCODING);
          enc = DEFAULT_ENCODING;
        }
        // set the new encoding to remember for any following .js file loads
        g_encoding = enc;
        if (useLoadedPageString) {
          mr = prepareMediaResource(page, enc, isPopUp);
        } else {
          // found a new charset other than iso-8859-1, load string with proper encoding
          page = FileUtils.load(vfsLeaf.getInputStream(), enc);
          mr = prepareMediaResource(page, enc, isPopUp);
        }
       
      } else if (path.endsWith(FILE_SUFFIX_JS)) { // a javascript library
        VFSMediaResource vmr = new VFSMediaResource(vfsLeaf);
View Full Code Here

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

  /**
   * @param args
   */
  public static void main(String[] args) {
    File lo = new File("c:/tmp/otemp.txt");
    VFSLeaf l = new LocalFileImpl(lo);
    VFSLeaf to = new LocalFileImpl(new File("c:/tmp/output.txt"));
    System.out.println(buildUsageAndTimeStats(l, to));
  }
View Full Code Here

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

  }
   
  protected void doIndex(SearchResourceContext resourceContext, OlatFullIndexer indexWriter, File cpRoot)
  throws IOException,InterruptedException  {
    VFSContainer container = new LocalFolderImpl(cpRoot);
    VFSLeaf fManifest = (VFSLeaf)container.resolve("imsmanifest.xml");
    if(fManifest != null) {
      Element rootElement =  IMSLoader.loadIMSDocument(fManifest).getRootElement();
      Document manfiestDoc = createManifestDocument(fManifest, rootElement, resourceContext);
      indexWriter.addDocument(manfiestDoc);
     
View Full Code Here

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

      VFSContainer mediaCtn = rootContainer.createChildContainer(WikiContainer.MEDIA_FOLDER_NAME);
      if (rootContainer.createChildContainer(VERSION_FOLDER_NAME) == null) throwError(ores);
      if (wikiCtn == null) throwError(ores);
      // copy files to wiki and media folder
      for (Iterator iter = files.iterator(); iter.hasNext();) {
        VFSLeaf leaf = ((VFSLeaf) iter.next());
        if (leaf.getName().endsWith(WikiManager.WIKI_FILE_SUFFIX) || leaf.getName().endsWith(WikiManager.WIKI_PROPERTIES_SUFFIX)) {
          wikiCtn.copyFrom(leaf);
        } else {
          if (leaf.getName().contains(WikiManager.WIKI_FILE_SUFFIX+"-") || leaf.getName().contains(WikiManager.WIKI_PROPERTIES_SUFFIX+"-")) {
            leaf.delete(); // delete version history
          } else
          mediaCtn.copyFrom(leaf);
        }
      }
      unzippedDir.delete();
      List zipFiles = rootContainer.getItems(new VFSItemSuffixFilter(new String[] { "zip" }));
      // delete all zips
      for (Iterator iter = zipFiles.iterator(); iter.hasNext();) {
        VFSLeaf element = (VFSLeaf) iter.next();
        element.delete();
      }
      //reset forum key and author references keys back to default as users and forums may not exist
      List propertyLeafs = wikiCtn.getItems(new VFSItemSuffixFilter(new String[] { WikiManager.WIKI_PROPERTIES_SUFFIX }));
      for (Iterator iter = propertyLeafs.iterator(); iter.hasNext();) {
        VFSLeaf element = (VFSLeaf) iter.next();
        WikiPage page = Wiki.assignPropertiesToPage(element);
        page.setForumKey(0);
        page.setInitalAuthor(0);
        page.setModifyAuthor(0);
        page.setModificationTime(0);
View Full Code Here

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

        // folders should be present, create the wiki
        wiki = new Wiki(getWikiRootContainer(ores));
        // filter for xyz.properties files
        List wikiLeaves = folder.getItems(new VFSItemSuffixFilter(new String[] { WikiManager.WIKI_PROPERTIES_SUFFIX }));
        for (Iterator iter = wikiLeaves.iterator(); iter.hasNext();) {
          VFSLeaf propertiesFile = (VFSLeaf) iter.next();
          WikiPage page = Wiki.assignPropertiesToPage(propertiesFile);
          if (page == null) {
            // broken pages get automatically cleaned from filesystem
            String contentFileToBeDeleted = (propertiesFile.getName().substring(0,
                propertiesFile.getName().length() - WikiManager.WIKI_PROPERTIES_SUFFIX.length()) + WikiManager.WIKI_FILE_SUFFIX);
            folder.resolve(contentFileToBeDeleted).delete();
            propertiesFile.delete();
            continue;
          }
          // index and menu page are loaded by default
          if (page.getPageName().equals(WikiPage.WIKI_INDEX_PAGE) || page.getPageName().equals(WikiPage.WIKI_MENU_PAGE)) {
            VFSLeaf leaf = (VFSLeaf) folder.resolve(page.getPageId() + "." + WikiManager.WIKI_FILE_SUFFIX);
            page.setContent(FileUtils.load(leaf.getInputStream(), "utf-8"));
          }

          // due to a bug we have to rename some pages that start with an non
          // ASCII lowercase letter
          String idOutOfFileName = propertiesFile.getName().substring(0, propertiesFile.getName().indexOf("."));
          if (!page.getPageId().equals(idOutOfFileName)) {
            // rename corrupt prop file
            propertiesFile.rename(page.getPageId() + "." + WikiManager.WIKI_PROPERTIES_SUFFIX);
            // load content and delete corrupt content file
            VFSLeaf contentFile = (VFSLeaf) folder.resolve(idOutOfFileName + "." + WikiManager.WIKI_FILE_SUFFIX);
            contentFile.rename(page.getPageId() + "." + WikiManager.WIKI_FILE_SUFFIX);
          }

          wiki.addPage(page);
        }
        // if index and menu page not present create the first page and save it
View Full Code Here

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

        copiedItem.rename(fileName);
      }
      item.delete();
    }
    // store recent content file
    VFSLeaf leaf = wikiContentContainer.createChildLeaf(page.getPageId() + "." + WIKI_FILE_SUFFIX);
    if(leaf == null) throw new AssertException("Tried to save wiki page with id ("+page.getPageId()+") and Olatresource: "+ores.getResourceableId()+" but page already existed!");
    FileUtils.save(leaf.getOutputStream(false), page.getContent(), "utf-8");

    // store recent properties file
    leaf = wikiContentContainer.createChildLeaf(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
    if (leaf == null) throw new AssertException("could not create file for wiki page "+page.getPageId()+", ores: "+ores.getResourceableTypeName()+":"+ores.getResourceableId()+", wikicontainer:"+wikiContentContainer);
    if (incrementVersion) page.incrementVersion();
    // update modification time
    if (!page.getContent().equals("")) page.setModificationTime(System.currentTimeMillis());
    Properties p = getPageProperties(page);
    try {
      OutputStream os = leaf.getOutputStream(false);
      p.store(os, "wiki page meta properties");
      os.close();
      // if (incrementVersion) page.incrementVersion();
    } catch (IOException e) {
      throw new OLATRuntimeException(WikiManager.class, "failed to save wiki page properties for page with id: " + page.getPageId() + " and olatresource: " + ores.getResourceableId(), e);
View Full Code Here

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

   
    //delete all version files of the page
    List leafs = versionsContainer.getItems(new VFSLeafFilter());
    if (leafs.size() > 0) {
      for (Iterator iter = leafs.iterator(); iter.hasNext();) {
        VFSLeaf leaf = (VFSLeaf) iter.next();
        String filename = leaf.getName();
        if (filename.startsWith(page.getPageId())) {
          leaf.delete();
        }
      }
    }
    log.audit("Deleted wiki page with name: " + page.getPageName() + " from resourcable id: "+ ores.getResourceableId());
    if (wikiCache!=null) {
View Full Code Here

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

  }


  private void saveWikiPageProperties(OLATResourceable ores, WikiPage page) {
    VFSContainer wikiContentContainer = getWikiContainer(ores, WIKI_RESOURCE_FOLDER_NAME);
    VFSLeaf leaf = (VFSLeaf) wikiContentContainer.resolve(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
    if (leaf == null) leaf = wikiContentContainer.createChildLeaf(page.getPageId() + "." + WIKI_PROPERTIES_SUFFIX);
    Properties p = getPageProperties(page);
    try {
      p.store(leaf.getOutputStream(false), "wiki page meta properties");
    } catch (IOException e) {
      throw new OLATRuntimeException(WikiManager.class, "failed to save wiki page properties for page with id: " + page.getPageId() +" and olatresource: " + ores.getResourceableId(), e);
    }
  }
View Full Code Here

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

      // attachment delete button may have been pressed
      Object userObj = activeLink.getUserObject();
      if (userObj != null) {
        setEditPermissions(ureq, message);
        if (userObj instanceof VFSLeaf) {
          VFSLeaf file = (VFSLeaf) userObj;
          if (forumCallback.mayEditMessageAsModerator() || ((userIsMsgCreator) && (msgHasChildren == false))) {
            delAttCtr = activateYesNoDialog(ureq, null, translate("reallydeleteAtt"), delAttCtr);
            delAttCtr.setUserObject(file);
          } else {
            if ((userIsMsgCreator) && (msgHasChildren == true)) {
View Full Code Here
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.