Difference between revisions of "Export folder to server as zip"
From OpenKM Documentation
(Created page with "The script export all contents of OpenKM folder compressed as zip file into OpenKM server <source lang="java"> import java.io.File; import java.io.FileOutputStream; import ja...") |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | The script export all contents of OpenKM folder compressed as zip file into OpenKM server | + | The script export all contents of OpenKM folder, compressed as zip file, into OpenKM server |
<source lang="java"> | <source lang="java"> | ||
Line 8: | Line 8: | ||
import com.openkm.util.impexp.RepositoryExporter; | import com.openkm.util.impexp.RepositoryExporter; | ||
import com.openkm.util.impexp.TextInfoDecorator; | import com.openkm.util.impexp.TextInfoDecorator; | ||
+ | import com.openkm.util.ArchiveUtils; | ||
+ | import org.apache.commons.io.IOUtils; | ||
+ | // Destination | ||
File file = new File("/home/openkm/import/folderExport.zip"); | File file = new File("/home/openkm/import/folderExport.zip"); | ||
+ | // OpenKM folder contents to be exported | ||
String fldPath = "/okm:root/Permisos de circulación/import"; | String fldPath = "/okm:root/Permisos de circulación/import"; | ||
+ | |||
FileOutputStream os = new FileOutputStream(file); | FileOutputStream os = new FileOutputStream(file); | ||
− | |||
StringWriter out = new StringWriter(); | StringWriter out = new StringWriter(); | ||
File tmp = FileUtils.createTempDir(); | File tmp = FileUtils.createTempDir(); | ||
RepositoryExporter.exportDocuments(null, fldPath, tmp, false, false, out, new TextInfoDecorator(fldPath)); | RepositoryExporter.exportDocuments(null, fldPath, tmp, false, false, out, new TextInfoDecorator(fldPath)); | ||
− | |||
− | |||
ArchiveUtils.createZip(tmp, "import", os); | ArchiveUtils.createZip(tmp, "import", os); | ||
− | |||
− | |||
org.apache.commons.io.FileUtils.deleteDirectory(tmp); | org.apache.commons.io.FileUtils.deleteDirectory(tmp); | ||
− | |||
IOUtils.closeQuietly(out); | IOUtils.closeQuietly(out); | ||
− | |||
os.flush(); | os.flush(); | ||
os.close(); | os.close(); |
Latest revision as of 11:52, 22 August 2013
The script export all contents of OpenKM folder, compressed as zip file, into OpenKM server
import java.io.File;
import java.io.FileOutputStream;
import java.io.StringWriter;
import com.openkm.util.FileUtils;
import com.openkm.util.impexp.RepositoryExporter;
import com.openkm.util.impexp.TextInfoDecorator;
import com.openkm.util.ArchiveUtils;
import org.apache.commons.io.IOUtils;
// Destination
File file = new File("/home/openkm/import/folderExport.zip");
// OpenKM folder contents to be exported
String fldPath = "/okm:root/Permisos de circulación/import";
FileOutputStream os = new FileOutputStream(file);
StringWriter out = new StringWriter();
File tmp = FileUtils.createTempDir();
RepositoryExporter.exportDocuments(null, fldPath, tmp, false, false, out, new TextInfoDecorator(fldPath));
ArchiveUtils.createZip(tmp, "import", os);
org.apache.commons.io.FileUtils.deleteDirectory(tmp);
IOUtils.closeQuietly(out);
os.flush();
os.close();