Browse Source

add unzipFile function

master
Larry L 1 year ago
parent
commit
1d2f8a96eb
  1. 36
      core/src/main/java/com/mcaps/core/workflows/ScormExtractor.java

36
core/src/main/java/com/mcaps/core/workflows/ScormExtractor.java

@ -1,9 +1,15 @@
package com.mcaps.core.workflows;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.jcr.Node;
import javax.jcr.Session;
@ -40,14 +46,15 @@ public class ScormExtractor implements WorkflowProcess {
@Override
public void execute(WorkItem arg0, WorkflowSession arg1, MetaDataMap arg2) throws WorkflowException {
log.warn("The string I got was ..." + arg2.get("PROCESS_ARGS", "string").toString());
log.warn("SCORM WORKFLOW: MetaDataMap args: " + arg2.get("PROCESS_ARGS", "string").toString());
String[] params = arg2.get("PROCESS_ARGS", "string").toString().split(",");
String attachmentsPath = params[0];
String saveToLocation = params[1];
log.warn("The payload path is " + arg0.getContentPath());
log.warn("SCORM WORKFLOW: payload path: " + arg0.getContentPath());
String payloadPath = arg0.getWorkflowData().getPayload().toString();
Map<String, String> map = new HashMap<String, String> ();
map.put("path", payloadPath + "/" + attachmentsPath);
unzipFile(saveToLocation, payloadPath);
//File saveLocationFolder = new File(saveToLocation);
//if (!saveLocationFolder.exists()) {
// saveLocationFolder.mkdirs();
@ -56,4 +63,29 @@ public class ScormExtractor implements WorkflowProcess {
map.put("type", "nt:file");
//throw new UnsupportedOperationException("Unimplemented method 'execute'");
}
private void unzipFile(String filePath, String outputFolder) {
try (ZipInputStream zipIn = new ZipInputStream(new FileInputStream(filePath))) {
ZipEntry entry = zipIn.getNextEntry();
while (entry != null) {
String zipFilePath = outputFolder + File.separator + entry.getName();
log.warn("SCORM WORKFLOW: zipFilePath: " + zipFilePath);
if (!entry.isDirectory()) {
try (FileOutputStream fos = new FileOutputStream(filePath)) {
byte[] buffer = new byte[1024];
int length;
while ((length = zipIn.read(buffer)) >= 0) {
fos.write(buffer, 0, length);
}
}
}
zipIn.closeEntry();
entry = zipIn.getNextEntry();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Loading…
Cancel
Save