Subversion Repositories XServices

Rev

Rev 11 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11 Rev 12
Line 11... Line 11...
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
14
 *   limitations under the License.
15
 */
15
 */
16
 
-
 
17
package net.brutex.xservices.ws;
16
package net.brutex.xservices.ws;
Line 18... Line 17...
18
 
17
 
19
import java.io.File;
18
import java.io.File;
20
import java.util.Map;
19
import java.util.Map;
Line 48... Line 47...
48
    public static final String WS_OPERATION_GZIP = "gzip";
47
    public static final String WS_OPERATION_GZIP = "gzip";
49
    public static final String WS_OPERATION_GZIP_ARCHIVE = "gzipFromArchive";
48
    public static final String WS_OPERATION_GZIP_ARCHIVE = "gzipFromArchive";
50
    public static final String WS_OPERATION_UNZIP = "unzip";
49
    public static final String WS_OPERATION_UNZIP = "unzip";
51
    public static final String WS_OPERATION_GUNZIP = "gunzip";
50
    public static final String WS_OPERATION_GUNZIP = "gunzip";
52
    public static final String WS_OPERATION_BUNZIP2 = "bunzip2";
51
    public static final String WS_OPERATION_BUNZIP2 = "bunzip2";
53
 
-
 
54
    public static final String WS_PARAM_SOURCEFILE = "source";
52
    public static final String WS_PARAM_SOURCEFILE = "source";
55
    public static final String WS_PARAM_SOURCEFILE_STRING = "srcfile";
53
    public static final String WS_PARAM_SOURCEFILE_STRING = "srcfile";
56
    public static final String WS_PARAM_SOURCEURL = "srcurl";
54
    public static final String WS_PARAM_SOURCEURL = "srcurl";
57
    public static final String WS_PARAM_SOURCEARCHIVE = "archivesource";
55
    public static final String WS_PARAM_SOURCEARCHIVE = "archivesource";
58
    public static final String WS_PARAM_DESTFILE = "destfile";
56
    public static final String WS_PARAM_DESTFILE = "destfile";
59
    public static final String WS_PARAM_DESTDIR = "destdir";
57
    public static final String WS_PARAM_DESTDIR = "destdir";
60
 
-
 
61
    public static final String WS_PARAM_ENCODING = "encoding";
58
    public static final String WS_PARAM_ENCODING = "encoding";
62
    public static final String WS_PARAM_OVERWRITE= "overwrite";
59
    public static final String WS_PARAM_OVERWRITE = "overwrite";
Line 63... Line 60...
63
 
60
 
64
    @WebMethod(operationName = WS_OPERATION_BZIP2, action=WS_OPERATION_BZIP2)
61
    @WebMethod(operationName = WS_OPERATION_BZIP2, action = WS_OPERATION_BZIP2)
Line 72... Line 69...
72
            @WebParam(name = WS_PARAM_DESTFILE) String file) {
69
            @WebParam(name = WS_PARAM_DESTFILE) String file) {
73
        return bzip(src, new File(file));
70
        return bzip(src, new File(file));
74
    }
71
    }
Line 75... Line 72...
75
 
72
 
76
    @WebMethod(operationName = WS_OPERATION_GZIP, action=WS_OPERATION_GZIP)
73
    @WebMethod(operationName = WS_OPERATION_GZIP, action = WS_OPERATION_GZIP)
77
    public String gzip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
74
    public ReturnCode gzip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
78
            @WebParam(name = WS_PARAM_DESTFILE) String file) {
75
            @WebParam(name = WS_PARAM_DESTFILE) String file) {
79
        return gzip(src, new File(file));
76
        return gzip(src, new File(file));
Line 80... Line 77...
80
    }
77
    }
81
 
78
 
82
    @WebMethod(operationName = WS_OPERATION_GZIP_ARCHIVE, action=WS_OPERATION_GZIP_ARCHIVE)
79
    @WebMethod(operationName = WS_OPERATION_GZIP_ARCHIVE, action = WS_OPERATION_GZIP_ARCHIVE)
83
    public String gzipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
80
    public ReturnCode gzipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
84
            @WebParam(name = WS_PARAM_DESTFILE) String file) {
81
            @WebParam(name = WS_PARAM_DESTFILE) String file) {
Line 85... Line 82...
85
        return gzip(src, new File(file));
82
        return gzip(src, new File(file));
86
    }
83
    }
87
 
84
 
88
    @WebMethod(operationName = WS_OPERATION_GUNZIP, action=WS_OPERATION_GUNZIP)
85
    @WebMethod(operationName = WS_OPERATION_GUNZIP, action = WS_OPERATION_GUNZIP)
89
    public String gunzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
86
    public ReturnCode gunzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
90
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
87
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
91
        File target = null;
88
        File target = null;
92
        if (!dest.equals("") && dest != null) {
89
        if (!dest.equals("") && dest != null) {
93
            target = new File(dest);
90
            target = new File(dest);
Line 94... Line 91...
94
        }
91
        }
95
        return GUnzip(new FileResource(FileResource.Type.FILE, src), target);
92
        return GUnzip(new FileResource(FileResource.Type.FILE, src), target);
96
    }
93
    }
97
 
94
 
98
    @WebMethod(operationName = WS_OPERATION_BUNZIP2)
95
    @WebMethod(operationName = WS_OPERATION_BUNZIP2)
99
    public String bunzip2(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
96
    public ReturnCode bunzip2(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
100
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
97
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
101
        File target = null;
98
        File target = null;
102
        if (!dest.equals("") && dest != null) {
99
        if (!dest.equals("") && dest != null) {
Line 103... Line 100...
103
            target = new File(dest);
100
            target = new File(dest);
104
        }
101
        }
105
        return BUnzip2(new FileResource(FileResource.Type.FILE, src), target);
102
        return BUnzip2(new FileResource(FileResource.Type.FILE, src), target);
106
    }
103
    }
107
 
104
 
108
    @WebMethod(operationName = "gunzipFromURL")
105
    @WebMethod(operationName = "gunzipFromURL")
109
    public String gunzipFromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
106
    public ReturnCode gunzipFromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
110
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
107
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
111
        File target = null;
108
        File target = null;
Line 112... Line 109...
112
        if (!dest.equals("") && dest != null) {
109
        if (!dest.equals("") && dest != null) {
113
            target = new File(dest);
110
            target = new File(dest);
114
        }
111
        }
115
        return GUnzip(new FileResource(FileResource.Type.URL, src), target);
112
        return GUnzip(new FileResource(FileResource.Type.URL, src), target);
116
    }
113
    }
117
 
114
 
118
    @WebMethod(operationName = "bunzip2FromURL")
115
    @WebMethod(operationName = "bunzip2FromURL")
119
    public String bunzip2FromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
116
    public ReturnCode bunzip2FromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
120
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
117
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
Line 121... Line 118...
121
        File target = null;
118
        File target = null;
122
        if (!dest.equals("") && dest != null) {
119
        if (!dest.equals("") && dest != null) {
123
            target = new File(dest);
120
            target = new File(dest);
124
        }
121
        }
125
        return BUnzip2(new FileResource(FileResource.Type.URL, src), target);
122
        return BUnzip2(new FileResource(FileResource.Type.URL, src), target);
126
    }
123
    }
127
 
124
 
Line 139... Line 136...
139
        }
136
        }
140
        return zip(src, new File(file), encoding, !overwrite, level);
137
        return zip(src, new File(file), encoding, !overwrite, level);
141
    }
138
    }
Line 142... Line 139...
142
 
139
 
143
    @WebMethod(operationName = "zipFromArchive")
140
    @WebMethod(operationName = "zipFromArchive")
144
    public String zipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
141
    public ReturnCode zipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
145
            @WebParam(name = WS_PARAM_DESTFILE) String file,
142
            @WebParam(name = WS_PARAM_DESTFILE) String file,
146
            @WebParam(name = WS_PARAM_OVERWRITE) boolean update,
143
            @WebParam(name = WS_PARAM_OVERWRITE) boolean update,
147
            @WebParam(name = WS_PARAM_ENCODING) String encoding,
144
            @WebParam(name = WS_PARAM_ENCODING) String encoding,
148
            @WebParam(name = "compresslevel") int level) {
145
            @WebParam(name = "compresslevel") int level) {
149
        return zip(src, new File(file), encoding, !update, level);
146
        return zip(src, new File(file), encoding, !update, level);
Line 150... Line -...
150
    }
-
 
151
 
147
    }
152
 
148
 
153
    @WebMethod(operationName = "unzip")
149
    @WebMethod(operationName = "unzip")
154
    public String unzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
150
    public ReturnCode unzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
155
            @WebParam(name = WS_PARAM_DESTDIR) String dest,
151
            @WebParam(name = WS_PARAM_DESTDIR) String dest,
156
            @WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
152
            @WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
157
            @WebParam(name = WS_PARAM_ENCODING) String encoding) {
153
            @WebParam(name = WS_PARAM_ENCODING) String encoding) {
Line 158... Line 154...
158
        return unzip(new File(src), new File(dest), overwrite, encoding);
154
        return unzip(new File(src), new File(dest), overwrite, encoding);
159
    }
155
    }
160
 
156
 
161
    @WebMethod(operationName = "unrar")
157
    @WebMethod(operationName = "unrar")
162
    public String unrar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
158
    public ReturnCode unrar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
Line 163... Line 159...
163
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
159
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
164
        return unrar(new File(src), new File(dest));
160
        return unrar(new File(src), new File(dest));
165
    }
161
    }
166
 
162
 
167
    @WebMethod(operationName = "untar")
163
    @WebMethod(operationName = "untar")
168
    public String untar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
164
    public ReturnCode untar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
169
            @WebParam(name = WS_PARAM_DESTDIR) String dest,
165
            @WebParam(name = WS_PARAM_DESTDIR) String dest,
Line 193... Line 189...
193
        bzip.setTaskName("BZip2");
189
        bzip.setTaskName("BZip2");
194
        RunTask runner = new RunTask(bzip);
190
        RunTask runner = new RunTask(bzip);
195
        bzip.setSrcResource(src.getAntResource(bzip.getProject()));
191
        bzip.setSrcResource(src.getAntResource(bzip.getProject()));
196
        bzip.setDestfile(dst);
192
        bzip.setDestfile(dst);
Line 197... Line 193...
197
 
193
 
198
        Map<String, String> result = runner.postTask();
-
 
199
        return new ReturnCode(0,result.get("System.stdOut"),result.get("System.stdErr"));
194
        return runner.postTask();
Line 200... Line 195...
200
    }
195
    }
201
 
196
 
202
    @WebMethod(exclude = true)
197
    @WebMethod(exclude = true)
203
    private String gzip(ResourceInterface src, File dst) {
198
    private ReturnCode gzip(ResourceInterface src, File dst) {
204
        if (dst.exists() && dst.isFile()) {
199
        if (dst.exists() && dst.isFile()) {
205
            dst.delete();
200
            dst.delete();
206
        }
201
        }
207
        GZip gzip = new GZip();
202
        GZip gzip = new GZip();
208
        gzip.setTaskName("GZip");
203
        gzip.setTaskName("GZip");
209
        RunTask runner = new RunTask(gzip);
204
        RunTask runner = new RunTask(gzip);
210
        gzip.addConfigured(src.getAntResource(gzip.getProject()));
-
 
211
        gzip.setDestfile(dst);
205
        gzip.addConfigured(src.getAntResource(gzip.getProject()));
212
        Map<String, String> result = runner.postTask();
206
        gzip.setDestfile(dst);
Line 213... Line -...
213
        return "complete";
-
 
214
    }
-
 
215
 
207
        return runner.postTask();
216
 
208
    }
217
 
209
 
218
    @WebMethod(exclude = true)
210
    @WebMethod(exclude = true)
219
    private String zip(ResourceInterface src, File dst, String encoding, boolean update, int compresslevel) {
211
    private ReturnCode zip(ResourceInterface src, File dst, String encoding, boolean update, int compresslevel) {
220
        Zip zip = new Zip();
212
        Zip zip = new Zip();
221
        zip.setTaskName("Zip");
213
        zip.setTaskName("Zip");
222
        RunTask runner = new RunTask(zip);
214
        RunTask runner = new RunTask(zip);
223
        zip.add(src.getAntResource(zip.getProject()));
215
        zip.add(src.getAntResource(zip.getProject()));
224
        zip.setDestFile(dst);
216
        zip.setDestFile(dst);
225
        if (encoding != null && !encoding.equals("")) {
217
        if (encoding != null && !encoding.equals("")) {
226
            zip.setEncoding(encoding);
218
            zip.setEncoding(encoding);
227
        }
-
 
228
        zip.setUpdate(update);
219
        }
229
        zip.setLevel(compresslevel);
220
        zip.setUpdate(update);
Line 230... Line 221...
230
        Map<String, String> result = runner.postTask();
221
        zip.setLevel(compresslevel);
231
        return "complete";
222
        return runner.postTask();
232
    }
223
    }
233
 
224
 
234
    @WebMethod(exclude = true)
225
    @WebMethod(exclude = true)
235
    private String GUnzip(ResourceInterface src, File dst) {
226
    private ReturnCode GUnzip(ResourceInterface src, File dst) {
236
        GUnzip uz = new GUnzip();
227
        GUnzip uz = new GUnzip();
237
        uz.setTaskName("GUnzip");
228
        uz.setTaskName("GUnzip");
238
        RunTask runner = new RunTask(uz);
229
        RunTask runner = new RunTask(uz);
239
        uz.setSrcResource(src.getAntResource(uz.getProject()));
-
 
240
        if (dst != null) {
230
        uz.setSrcResource(src.getAntResource(uz.getProject()));
241
            uz.setDest(dst);
231
        if (dst != null) {
Line 242... Line 232...
242
        }
232
            uz.setDest(dst);
243
        Map<String, String> result = runner.postTask();
233
        }
244
        return "complete";
234
        return runner.postTask();
245
    }
235
    }
246
 
236
 
247
    @WebMethod(exclude = true)
237
    @WebMethod(exclude = true)
248
    private String BUnzip2(ResourceInterface src, File dst) {
238
    private ReturnCode BUnzip2(ResourceInterface src, File dst) {
249
        BUnzip2 uz = new BUnzip2();
239
        BUnzip2 uz = new BUnzip2();
250
        uz.setTaskName("BUnzip2");
240
        uz.setTaskName("BUnzip2");
251
        RunTask runner = new RunTask(uz);
-
 
252
        uz.setSrcResource(src.getAntResource(uz.getProject()));
241
        RunTask runner = new RunTask(uz);
253
        if (dst != null) {
242
        uz.setSrcResource(src.getAntResource(uz.getProject()));
Line 254... Line 243...
254
            uz.setDest(dst);
243
        if (dst != null) {
255
        }
244
            uz.setDest(dst);
256
        Map<String, String> result = runner.postTask();
245
        }
257
        return "complete";
246
        return runner.postTask();
258
    }
247
    }
259
 
248
 
260
    @WebMethod(exclude = true)
249
    @WebMethod(exclude = true)
261
    private String unzip(File src, File dest, boolean overwrite, String encoding) {
250
    private ReturnCode unzip(File src, File dest, boolean overwrite, String encoding) {
262
        Expand unzip = new Expand();
251
        Expand unzip = new Expand();
263
        unzip.setTaskName("UnZip");
252
        unzip.setTaskName("UnZip");
264
        RunTask runner = new RunTask(unzip);
253
        RunTask runner = new RunTask(unzip);
265
        unzip.setSrc(src);
-
 
266
        unzip.setDest(dest);
-
 
267
        unzip.setOverwrite(overwrite);
254
        unzip.setSrc(src);
268
        if (encoding != null && !encoding.equals("")) {
255
        unzip.setDest(dest);
Line 269... Line 256...
269
            unzip.setEncoding(encoding);
256
        unzip.setOverwrite(overwrite);
270
        }
257
        if (encoding != null && !encoding.equals("")) {
271
 
258
            unzip.setEncoding(encoding);
272
        Map<String, String> result = runner.postTask();
259
        }
273
        return "complete";
260
        return runner.postTask();
274
    }
261
    }
275
 
262
 
276
    @WebMethod(exclude = true)
263
    @WebMethod(exclude = true)
277
    private String untar(File src, File dest, boolean overwrite, Untar.UntarCompressionMethod compression) {
264
    private ReturnCode untar(File src, File dest, boolean overwrite, Untar.UntarCompressionMethod compression) {
278
        Untar unzip = new Untar();
-
 
279
        unzip.setTaskName("Untar");
265
        Untar unzip = new Untar();
280
        RunTask runner = new RunTask(unzip);
266
        unzip.setTaskName("Untar");
Line 281... Line 267...
281
        unzip.setSrc(src);
267
        RunTask runner = new RunTask(unzip);
282
        unzip.setDest(dest);
268
        unzip.setSrc(src);
283
        unzip.setOverwrite(overwrite);
269
        unzip.setDest(dest);
284
        unzip.setCompression(compression);
270
        unzip.setOverwrite(overwrite);
285
        Map<String, String> result = runner.postTask();
271
        unzip.setCompression(compression);
286
        return "complete";
272
        return runner.postTask();
287
    }
273
    }
288
 
-
 
289
    @WebMethod(exclude = true)
274
 
290
    private String unrar(File src, File dst) {
275
    @WebMethod(exclude = true)
291
        UnRarTask unrar = new UnRarTask();
-
 
292
        unrar.setTaskName("UnRar");
-
 
293
        RunTask runner = new RunTask(unrar);
276
    private ReturnCode unrar(File src, File dst) {