Script - Exporter

Repository export execution based on crontab task.

import com.openkm.util.FileLogger;
import com.openkm.bean.ContentInfo;
import com.openkm.api.*;
import com.openkm.util.impexp.*;
import java.io.*;
import java.text.*;
import com.openkm.core.Config;
import java.util.*;
import com.openkm.module.db.stuff.*;
 
// Configuration parameters
String token = DbSessionManager.getInstance().getSystemToken();
String LOG_FILE_NAME = "CrontabRepositoryExporter";
String repoPath = "/okm:root";
String fsPath = "F:\\Restore_OKM";
boolean metadata = false;
boolean history = false;
 
// Start
FileWriter fw = null;
try {
    FileLogger.info(LOG_FILE_NAME, "Started");
    // Open outputstream
    String fileDate = new SimpleDateFormat("yyyyMMdd").format(new Date());
    String fileName = Config.LOG_DIR + File.separator + LOG_FILE_NAME + "_" + fileDate + ".log";
    File file = new File(fileName);
    fw = new FileWriter(file);
    // Starting the process
    ContentInfo cInfo = OKMFolder.getInstance().getContentInfo(token, repoPath);
    FileLogger.info(LOG_FILE_NAME, "Files & directories to export:"+(cInfo.getDocuments() + cInfo.getFolders()));
    File dir = new File(fsPath);
    ImpExpStats stats = RepositoryExporter.exportDocuments(token, repoPath, dir, metadata, history, fw, new HTMLInfoDecorator((int) cInfo.getDocuments() + (int) cInfo.getFolders()));
    FileLogger.info("CrontabRepositoryExporter", "Finished");
} catch (Exception e) {
    try {        if (fw != null) {
            fw.close();        }
    } catch (IOException e1) {        // Ignore
    }
}