How to export Files from Jease back to the file-system?

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 2010-09-20 by Maik Jablonski

Java with Ease

2009-12-31

Java is a very productive development environment if you choose and combine the right tools and patterns.

Jease is the result of my personal quest bringing tools and patterns together which make the life of a web-developer as simple as it can be.