-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnZipDocument.java
More file actions
129 lines (104 loc) · 3.99 KB
/
UnZipDocument.java
File metadata and controls
129 lines (104 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// This file was generated by Mendix Studio Pro.
//
// WARNING: Only the following code will be retained when actions are regenerated:
// - the import list
// - the code between BEGIN USER CODE and END USER CODE
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
// Other code you write will be lost the next time you deploy the project.
// Special characters, e.g., é, ö, à, etc. are supported in comments.
package ziphandling.actions;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import com.mendix.core.Core;
import com.mendix.systemwideinterfaces.core.IContext;
import com.mendix.webui.CustomJavaAction;
import com.mendix.systemwideinterfaces.core.IMendixObject;
/**
* This Java action will Unzip the file that is used as input parameter. It returns a list of FileDocuments (unzipped), be aware that the unzipped documents are committed. To prevent full disks delete the list after use.
*/
public class UnZipDocument extends CustomJavaAction<java.util.List<IMendixObject>>
{
/** @deprecated use ZipFile.getMendixObject() instead. */
@java.lang.Deprecated(forRemoval = true)
private final IMendixObject __ZipFile;
private final system.proxies.FileDocument ZipFile;
public UnZipDocument(
IContext context,
IMendixObject _zipFile
)
{
super(context);
this.__ZipFile = _zipFile;
this.ZipFile = _zipFile == null ? null : system.proxies.FileDocument.initialize(getContext(), _zipFile);
}
@java.lang.Override
public java.util.List<IMendixObject> executeAction() throws Exception
{
// BEGIN USER CODE
InputStream zipInputStream = Core.getFileDocumentContent(getContext(), ZipFile.getMendixObject());
List<IMendixObject> returnList = new ArrayList<IMendixObject>();
final ZipInputStream zip = new ZipInputStream(zipInputStream);
ZipEntry entry;
String fileName;
int fileCheck = 1;
entry = zip.getNextEntry();
while (fileCheck ==1) {
if (!entry.isDirectory()) {
fileName = entry.getName();
IMendixObject mendixObject = Core.instantiate(getContext(), "System.FileDocument");
mendixObject.setValue(getContext(), "Name" , fileName );
ByteArrayOutputStream fout = new ByteArrayOutputStream();
for (int c = zip.read(); c != -1; c = zip.read()) {
fout.write(c);
}
zip.closeEntry();
fout.close();
ByteArrayInputStream inStream = new ByteArrayInputStream( fout.toByteArray() );
Core.storeFileDocumentContent(getContext(), mendixObject,inStream);
returnList.add(mendixObject);
try {
entry = zip.getNextEntry();
if (entry == null) {
fileCheck=0; // EOF reached
}
}
catch (IOException e)
{
fileCheck=0; // EOF reached
}
}
else
{ try {
entry = zip.getNextEntry();
if (entry == null) {
fileCheck=0; // EOF reached
}
}
catch (IOException e)
{
fileCheck=0; // EOF reached
}
}
}
zip.close();
return returnList;
// END USER CODE
}
/**
* Returns a string representation of this action
* @return a string representation of this action
*/
@java.lang.Override
public java.lang.String toString()
{
return "UnZipDocument";
}
// BEGIN EXTRA CODE
// END EXTRA CODE
}