» JeaseCMS » Блог

Как экспортировать файлы из Jease обратно в файловую систему?

If you have stored lots of files within Jease (think of an music or image library) and want to export them back to a file-system, you can use something like the following script.

It simply descends all File-Objects (and derived classes) from the Root-Node, creates according directories along the way down and copies the files-contents into these directories. The script uses a temporary directory to which all the content is exported. This directory is printed on screen after the script is executed.

To use the following script, simply create a Script-Object within Jease and copy&paste the contents below into it. That's it. You can also use a traditional JSP in the filesystem of your Jease-Instance if you like.

Have fun.

<%@page import="jease.cmf.service.*"%>
<%
 java.io.File exportDirectory = jfix.util.Files.createTempDirectory();
 for (jease.cms.domain.File file : Nodes.getRoot().getDescendants(jease.cms.domain.File.class)) {
  java.io.File directory = new java.io.File(exportDirectory, file.getParent().getPath());
  directory.mkdirs();
  jfix.util.Files.copy(file.getFile(), new java.io.File(directory, file.getId()));
}
%>
Data was exported to following directory: <%= exportDirectory.getAbsolutePath() %>

Last modified on 2012-04-23 by Maik Jablonski