Subversion Repositories XServices

Rev

Rev 12 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12 Rev 46
Line 13... Line 13...
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
package net.brutex.xservices.ws;
16
package net.brutex.xservices.ws;
Line 17... Line -...
17
 
-
 
18
import java.io.File;
-
 
19
import java.util.Map;
17
 
20
import javax.jws.WebMethod;
18
import javax.jws.WebMethod;
21
import javax.jws.WebParam;
19
import javax.jws.WebParam;
22
import javax.jws.WebService;
20
import javax.jws.WebService;
23
import net.brutex.xservices.types.ArchiveResource;
21
import net.brutex.xservices.types.ArchiveResource;
24
import net.brutex.xservices.types.CompressionType;
22
import net.brutex.xservices.types.CompressionType;
25
import net.brutex.xservices.types.FileResource;
-
 
-
 
23
import net.brutex.xservices.types.FileResource;
26
import net.brutex.xservices.types.ResourceInterface;
24
 
27
import net.brutex.xservices.types.ReturnCode;
25
import net.brutex.xservices.types.ReturnCode;
28
import net.brutex.xservices.util.RunTask;
-
 
29
import net.brutex.xservices.util.UnRarTask;
-
 
30
import org.apache.tools.ant.taskdefs.BUnzip2;
-
 
31
import org.apache.tools.ant.taskdefs.BZip2;
-
 
32
import org.apache.tools.ant.taskdefs.Expand;
-
 
33
import org.apache.tools.ant.taskdefs.GUnzip;
-
 
34
import org.apache.tools.ant.taskdefs.GZip;
-
 
35
import org.apache.tools.ant.taskdefs.Untar;
-
 
-
 
26
import net.brutex.xservices.util.BrutexNamespaces;
Line 36... Line 27...
36
import org.apache.tools.ant.taskdefs.Zip;
27
 
37
 
28
 
38
/**
29
/**
39
 *
30
 *
40
 * @author Brian Rosenberger, bru@brutex.de
31
 * @author Brian Rosenberger, bru@brutex.de
41
 */
32
 */
Line 42... Line 33...
42
@WebService(targetNamespace = "http://ws.xservices.brutex.net", name = "ArchiveService")
33
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
43
public class ArchiveService {
34
public interface ArchiveService {
44
 
35
 
45
    public static final String WS_OPERATION_BZIP2 = "bzip2";
36
    public static final String WS_OPERATION_BZIP2 = "bzip2";
Line 58... Line 49...
58
    public static final String WS_PARAM_ENCODING = "encoding";
49
    public static final String WS_PARAM_ENCODING = "encoding";
59
    public static final String WS_PARAM_OVERWRITE = "overwrite";
50
    public static final String WS_PARAM_OVERWRITE = "overwrite";
Line 60... Line 51...
60
 
51
 
61
    @WebMethod(operationName = WS_OPERATION_BZIP2, action = WS_OPERATION_BZIP2)
52
    @WebMethod(operationName = WS_OPERATION_BZIP2, action = WS_OPERATION_BZIP2)
62
    public ReturnCode bzip2(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
53
    public ReturnCode bzip2(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
63
            @WebParam(name = WS_PARAM_DESTFILE) String file) {
-
 
64
        return bzip(src, new File(file));
-
 
Line 65... Line 54...
65
    }
54
            @WebParam(name = WS_PARAM_DESTFILE) String file);
66
 
55
 
67
    @WebMethod(operationName = WS_OPERATION_BZIP2_ARCHIVE, action = WS_OPERATION_BZIP2_ARCHIVE)
56
    @WebMethod(operationName = WS_OPERATION_BZIP2_ARCHIVE, action = WS_OPERATION_BZIP2_ARCHIVE)
68
    public ReturnCode bzip2FromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
-
 
69
            @WebParam(name = WS_PARAM_DESTFILE) String file) {
-
 
Line 70... Line 57...
70
        return bzip(src, new File(file));
57
    public ReturnCode bzip2FromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
71
    }
58
            @WebParam(name = WS_PARAM_DESTFILE) String file);
72
 
59
 
73
    @WebMethod(operationName = WS_OPERATION_GZIP, action = WS_OPERATION_GZIP)
-
 
74
    public ReturnCode gzip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
-
 
Line 75... Line 60...
75
            @WebParam(name = WS_PARAM_DESTFILE) String file) {
60
    @WebMethod(operationName = WS_OPERATION_GZIP, action = WS_OPERATION_GZIP)
76
        return gzip(src, new File(file));
61
    public ReturnCode gzip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
77
    }
62
            @WebParam(name = WS_PARAM_DESTFILE) String file);
78
 
-
 
79
    @WebMethod(operationName = WS_OPERATION_GZIP_ARCHIVE, action = WS_OPERATION_GZIP_ARCHIVE)
-
 
Line 80... Line 63...
80
    public ReturnCode gzipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
63
 
81
            @WebParam(name = WS_PARAM_DESTFILE) String file) {
64
    @WebMethod(operationName = WS_OPERATION_GZIP_ARCHIVE, action = WS_OPERATION_GZIP_ARCHIVE)
82
        return gzip(src, new File(file));
65
    public ReturnCode gzipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
83
    }
-
 
84
 
-
 
85
    @WebMethod(operationName = WS_OPERATION_GUNZIP, action = WS_OPERATION_GUNZIP)
-
 
86
    public ReturnCode gunzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
-
 
87
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
-
 
88
        File target = null;
-
 
Line 89... Line 66...
89
        if (!dest.equals("") && dest != null) {
66
            @WebParam(name = WS_PARAM_DESTFILE) String file);
90
            target = new File(dest);
67
 
91
        }
68
    @WebMethod(operationName = WS_OPERATION_GUNZIP, action = WS_OPERATION_GUNZIP)
92
        return GUnzip(new FileResource(FileResource.Type.FILE, src), target);
-
 
93
    }
-
 
94
 
-
 
95
    @WebMethod(operationName = WS_OPERATION_BUNZIP2)
-
 
96
    public ReturnCode bunzip2(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
-
 
97
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
-
 
Line 98... Line 69...
98
        File target = null;
69
    public ReturnCode gunzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
99
        if (!dest.equals("") && dest != null) {
70
            @WebParam(name = WS_PARAM_DESTDIR) String dest);
100
            target = new File(dest);
71
 
101
        }
-
 
102
        return BUnzip2(new FileResource(FileResource.Type.FILE, src), target);
-
 
103
    }
-
 
104
 
-
 
105
    @WebMethod(operationName = "gunzipFromURL")
-
 
106
    public ReturnCode gunzipFromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
-
 
Line 107... Line 72...
107
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
72
    @WebMethod(operationName = WS_OPERATION_BUNZIP2)
108
        File target = null;
73
    public ReturnCode bunzip2(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
109
        if (!dest.equals("") && dest != null) {
74
            @WebParam(name = WS_PARAM_DESTDIR) String dest);
110
            target = new File(dest);
-
 
111
        }
-
 
112
        return GUnzip(new FileResource(FileResource.Type.URL, src), target);
-
 
113
    }
-
 
114
 
-
 
115
    @WebMethod(operationName = "bunzip2FromURL")
-
 
Line 116... Line 75...
116
    public ReturnCode bunzip2FromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
75
 
117
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
76
    @WebMethod(operationName = "gunzipFromURL")
118
        File target = null;
77
    public ReturnCode gunzipFromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
119
        if (!dest.equals("") && dest != null) {
78
            @WebParam(name = WS_PARAM_DESTDIR) String dest);
120
            target = new File(dest);
79
 
121
        }
80
    @WebMethod(operationName = "bunzip2FromURL")
122
        return BUnzip2(new FileResource(FileResource.Type.URL, src), target);
-
 
123
    }
-
 
124
 
-
 
125
    @WebMethod(operationName = "zip")
-
 
126
    public ReturnCode zip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
-
 
127
            @WebParam(name = WS_PARAM_DESTFILE) String file,
-
 
128
            @WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
-
 
129
            @WebParam(name = WS_PARAM_ENCODING) String encoding,
-
 
Line 130... Line 81...
130
            @WebParam(name = "compresslevel") int level) {
81
    public ReturnCode bunzip2FromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
131
        if (level > 9) {
82
            @WebParam(name = WS_PARAM_DESTDIR) String dest);
132
            level = 9;
83
 
133
        }
84
    @WebMethod(operationName = "zip")
134
        if (level < 0) {
85
    public ReturnCode zip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
135
            level = 0;
86
            @WebParam(name = WS_PARAM_DESTFILE) String file,
136
        }
-
 
137
        return zip(src, new File(file), encoding, !overwrite, level);
-
 
Line 138... Line 87...
138
    }
87
            @WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
139
 
88
            @WebParam(name = WS_PARAM_ENCODING) String encoding,
140
    @WebMethod(operationName = "zipFromArchive")
89
            @WebParam(name = "compresslevel") int level);
141
    public ReturnCode zipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
90
 
142
            @WebParam(name = WS_PARAM_DESTFILE) String file,
91
    @WebMethod(operationName = "zipFromArchive")
143
            @WebParam(name = WS_PARAM_OVERWRITE) boolean update,
-
 
144
            @WebParam(name = WS_PARAM_ENCODING) String encoding,
-
 
Line 145... Line 92...
145
            @WebParam(name = "compresslevel") int level) {
92
    public ReturnCode zipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
146
        return zip(src, new File(file), encoding, !update, level);
93
            @WebParam(name = WS_PARAM_DESTFILE) String file,
147
    }
94
            @WebParam(name = WS_PARAM_OVERWRITE) boolean update,
148
 
-
 
149
    @WebMethod(operationName = "unzip")
-
 
Line 150... Line 95...
150
    public ReturnCode unzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
95
            @WebParam(name = WS_PARAM_ENCODING) String encoding,
151
            @WebParam(name = WS_PARAM_DESTDIR) String dest,
96
            @WebParam(name = "compresslevel") int level);
152
            @WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
97
 
153
            @WebParam(name = WS_PARAM_ENCODING) String encoding) {
98
    @WebMethod(operationName = "unzip")
154
        return unzip(new File(src), new File(dest), overwrite, encoding);
99
    public ReturnCode unzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
155
    }
-
 
156
 
-
 
157
    @WebMethod(operationName = "unrar")
-
 
158
    public ReturnCode unrar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
-
 
159
            @WebParam(name = WS_PARAM_DESTDIR) String dest) {
-
 
160
        return unrar(new File(src), new File(dest));
-
 
161
    }
-
 
162
 
-
 
163
    @WebMethod(operationName = "untar")
-
 
164
    public ReturnCode untar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
-
 
165
            @WebParam(name = WS_PARAM_DESTDIR) String dest,
-
 
166
            @WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
-
 
167
            @WebParam(name = "compression") CompressionType compression) {
-
 
168
        Untar.UntarCompressionMethod c = new Untar.UntarCompressionMethod();
-
 
169
        switch (compression) {
-
 
170
            case GZIP:
-
 
171
                c.setValue("gzip");
-
 
172
                break;
-
 
173
            case BZIP2:
-
 
174
                c.setValue("bzip2");
-
 
175
                break;
-
 
176
            default:
-
 
177
                c.setValue("none");
-
 
178
                break;
-
 
179
        }
-
 
180
        return untar(new File(src), new File(dest), overwrite, c);
-
 
181
    }
-
 
182
 
-
 
183
    @WebMethod(exclude = true)
-
 
184
    private ReturnCode bzip(ResourceInterface src, File dst) {
-
 
185
        if (dst.exists() && dst.isFile()) {
-
 
186
            dst.delete();
-
 
187
        }
-
 
188
        BZip2 bzip = new BZip2();
-
 
189
        bzip.setTaskName("BZip2");
-
 
190
        RunTask runner = new RunTask(bzip);
-
 
191
        bzip.setSrcResource(src.getAntResource(bzip.getProject()));
-
 
192
        bzip.setDestfile(dst);
-
 
193
 
-
 
194
        return runner.postTask();
-
 
195
    }
-
 
196
 
-
 
197
    @WebMethod(exclude = true)
-
 
198
    private ReturnCode gzip(ResourceInterface src, File dst) {
-
 
199
        if (dst.exists() && dst.isFile()) {
-
 
200
            dst.delete();
-
 
201
        }
-
 
202
        GZip gzip = new GZip();
-
 
203
        gzip.setTaskName("GZip");
-
 
204
        RunTask runner = new RunTask(gzip);
-
 
205
        gzip.addConfigured(src.getAntResource(gzip.getProject()));
-
 
206
        gzip.setDestfile(dst);
-
 
207
        return runner.postTask();
-
 
208
    }
-
 
209
 
-
 
210
    @WebMethod(exclude = true)
-
 
211
    private ReturnCode zip(ResourceInterface src, File dst, String encoding, boolean update, int compresslevel) {
-
 
212
        Zip zip = new Zip();
-
 
213
        zip.setTaskName("Zip");
-
 
214
        RunTask runner = new RunTask(zip);
-
 
215
        zip.add(src.getAntResource(zip.getProject()));
-
 
216
        zip.setDestFile(dst);
-
 
217
        if (encoding != null && !encoding.equals("")) {
-
 
218
            zip.setEncoding(encoding);
-
 
219
        }
-
 
220
        zip.setUpdate(update);
-
 
221
        zip.setLevel(compresslevel);
-
 
222
        return runner.postTask();
-
 
223
    }
-
 
224
 
-
 
225
    @WebMethod(exclude = true)
-
 
226
    private ReturnCode GUnzip(ResourceInterface src, File dst) {
-
 
227
        GUnzip uz = new GUnzip();
-
 
228
        uz.setTaskName("GUnzip");
-
 
229
        RunTask runner = new RunTask(uz);
-
 
230
        uz.setSrcResource(src.getAntResource(uz.getProject()));
-
 
231
        if (dst != null) {
-
 
232
            uz.setDest(dst);
-
 
233
        }
-
 
234
        return runner.postTask();
-
 
235
    }
-
 
236
 
-
 
237
    @WebMethod(exclude = true)
-
 
238
    private ReturnCode BUnzip2(ResourceInterface src, File dst) {
-
 
239
        BUnzip2 uz = new BUnzip2();
-
 
240
        uz.setTaskName("BUnzip2");
-
 
241
        RunTask runner = new RunTask(uz);
-
 
242
        uz.setSrcResource(src.getAntResource(uz.getProject()));
-
 
243
        if (dst != null) {
-
 
244
            uz.setDest(dst);
-
 
245
        }
-
 
246
        return runner.postTask();
-
 
247
    }
-
 
248
 
-
 
249
    @WebMethod(exclude = true)
-
 
250
    private ReturnCode unzip(File src, File dest, boolean overwrite, String encoding) {
-
 
251
        Expand unzip = new Expand();
-
 
252
        unzip.setTaskName("UnZip");
-
 
253
        RunTask runner = new RunTask(unzip);
-
 
254
        unzip.setSrc(src);
-
 
255
        unzip.setDest(dest);
-
 
256
        unzip.setOverwrite(overwrite);
-
 
257
        if (encoding != null && !encoding.equals("")) {
-
 
258
            unzip.setEncoding(encoding);
-
 
259
        }
-
 
260
        return runner.postTask();
-
 
261
    }
-
 
262
 
-
 
263
    @WebMethod(exclude = true)
-
 
264
    private ReturnCode untar(File src, File dest, boolean overwrite, Untar.UntarCompressionMethod compression) {
-
 
265
        Untar unzip = new Untar();
-
 
266
        unzip.setTaskName("Untar");
-
 
267
        RunTask runner = new RunTask(unzip);
-
 
268
        unzip.setSrc(src);
-
 
269
        unzip.setDest(dest);
-
 
270
        unzip.setOverwrite(overwrite);
-
 
271
        unzip.setCompression(compression);
100
            @WebParam(name = WS_PARAM_DESTDIR) String dest,