Exemplo n.º 1
0
  private File reversedOriginFile(VFSItem versionXml) {
    String path =
        File.separatorChar + versionXml.getName().substring(0, versionXml.getName().length() - 4);
    for (VFSContainer parent = versionXml.getParentContainer();
        parent != null && !parent.isSame(getRootVersionsContainer());
        parent = parent.getParentContainer()) {
      path = File.separatorChar + parent.getName() + path;
    }

    return new File(getCanonicalRoot(), path);
  }
  /**
   * @see org.olat.course.nodes.GenericCourseNode#archiveNodeData(java.util.Locale,
   *     org.olat.course.ICourse, java.io.File, java.lang.String)
   */
  @Override
  public boolean archiveNodeData(
      final Locale locale, final ICourse course, final File exportDirectory, final String charset) {
    final String repoRef = (String) this.getModuleConfiguration().get("reporef");
    final OLATResourceable ores =
        RepositoryManager.getInstance()
            .lookupRepositoryEntryBySoftkey(repoRef, true)
            .getOlatResource();

    if (WikiManager.getInstance().getOrLoadWiki(ores).getAllPagesWithContent().size() > 0) {
      // OK, there is somthing to archive
      final VFSContainer exportContainer = new LocalFolderImpl(exportDirectory);
      VFSContainer wikiExportContainer =
          (VFSContainer) exportContainer.resolve(WikiManager.WIKI_RESOURCE_FOLDER_NAME);
      if (wikiExportContainer == null) {
        wikiExportContainer =
            exportContainer.createChildContainer(WikiManager.WIKI_RESOURCE_FOLDER_NAME);
      }
      final String exportDirName =
          getShortTitle()
              + "_"
              + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
      final VFSContainer destination = wikiExportContainer.createChildContainer(exportDirName);
      if (destination == null) {
        Tracing.logError(
            "archiveNodeData: Could not create destination directory: wikiExportContainer="
                + wikiExportContainer
                + ", exportDirName="
                + exportDirName,
            getClass());
      }

      final VFSContainer container =
          WikiManager.getInstance().getWikiContainer(ores, WikiManager.WIKI_RESOURCE_FOLDER_NAME);
      if (container
          != null) { // the container could be null if the wiki is an old empty one - so nothing to
                     // archive
        final VFSContainer parent = container.getParentContainer();
        final VFSLeaf wikiZip = WikiToZipUtils.getWikiAsZip(parent);
        destination.copyFrom(wikiZip);
      }
      return true;
    }
    // empty wiki, no need to archive
    return false;
  }