Subversion Repositories XServices

Rev

Rev 14 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14 Rev 46
1
/*
1
/*
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
3
 *
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with the License.
5
 *   you may not use this file except in compliance with the License.
6
 *   You may obtain a copy of the License at
6
 *   You may obtain a copy of the License at
7
 *
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
10
 *   Unless required by applicable law or agreed to in writing, software
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
package net.brutex.xservices.ws;
16
package net.brutex.xservices.ws.impl;
17
 
17
 
18
import java.io.File;
18
import java.io.File;
19
import javax.jws.WebMethod;
19
import javax.jws.WebMethod;
20
import javax.jws.WebParam;
20
import javax.jws.WebParam;
21
import javax.jws.WebService;
21
import javax.jws.WebService;
22
import net.brutex.xservices.types.ArchiveResource;
22
import net.brutex.xservices.types.ArchiveResource;
23
import net.brutex.xservices.types.FileResource;
23
import net.brutex.xservices.types.FileResource;
24
import net.brutex.xservices.types.FileSetResource;
24
import net.brutex.xservices.types.FileSetResource;
25
import net.brutex.xservices.types.ResourceInterface;
25
import net.brutex.xservices.types.ResourceInterface;
26
import net.brutex.xservices.types.ReturnCode;
26
import net.brutex.xservices.types.ReturnCode;
-
 
27
import net.brutex.xservices.util.BrutexNamespaces;
27
import net.brutex.xservices.util.RunTask;
28
import net.brutex.xservices.util.RunTask;
-
 
29
import net.brutex.xservices.ws.FileService;
-
 
30
import net.brutex.xservices.ws.XServicesFault;
-
 
31
 
28
import org.apache.tools.ant.taskdefs.Basename;
32
import org.apache.tools.ant.taskdefs.Basename;
29
import org.apache.tools.ant.taskdefs.Chmod;
33
import org.apache.tools.ant.taskdefs.Chmod;
30
import org.apache.tools.ant.taskdefs.Copy;
34
import org.apache.tools.ant.taskdefs.Copy;
31
import org.apache.tools.ant.taskdefs.Echo;
35
import org.apache.tools.ant.taskdefs.Echo;
32
import org.apache.tools.ant.taskdefs.LoadResource;
36
import org.apache.tools.ant.taskdefs.LoadResource;
33
import org.apache.tools.ant.taskdefs.optional.unix.Chgrp;
37
import org.apache.tools.ant.taskdefs.optional.unix.Chgrp;
34
import org.apache.tools.ant.taskdefs.optional.unix.Chown;
38
import org.apache.tools.ant.taskdefs.optional.unix.Chown;
35
import org.apache.tools.ant.types.FileSet;
39
import org.apache.tools.ant.types.FileSet;
36
 
40
 
37
/**
41
/**
38
 *
42
 *
39
 * @author Brian Rosenberger, bru@brutex.de
43
 * @author Brian Rosenberger, bru@brutex.de
40
 */
44
 */
-
 
45
@WebService(
-
 
46
		targetNamespace = BrutexNamespaces.WS_XSERVICES, 
41
@WebService(targetNamespace = "http://ws.xservices.brutex.net", name = "FileService")
47
		endpointInterface ="net.brutex.xservices.ws.FileService", 
42
public class FileService {
48
		name = "FileService"
-
 
49
			)
-
 
50
public class FileServiceImpl implements FileService {
43
 
51
 
-
 
52
    /* (non-Javadoc)
-
 
53
	 * @see net.brutex.xservices.ws.impl.FileService#basename(java.lang.String, java.lang.String)
-
 
54
	 */
-
 
55
    @Override
44
    @WebMethod(operationName = "basename")
56
	@WebMethod(operationName = "basename")
45
    public ReturnCode basename(@WebParam(name = "file") String filename,
57
    public ReturnCode basename(@WebParam(name = "file") String filename,
46
            @WebParam(name = "suffix") String suffix) {
58
            @WebParam(name = "suffix") String suffix) {
47
        return basename(new File(filename), suffix);
59
        return basename(new File(filename), suffix);
48
    }
60
    }
-
 
61
 
-
 
62
    /* (non-Javadoc)
-
 
63
	 * @see net.brutex.xservices.ws.impl.FileService#copy(net.brutex.xservices.types.FileSetResource, java.lang.String, boolean, boolean, java.lang.String)
-
 
64
	 */
49
 
65
    @Override
50
    @WebMethod(operationName = "copy")
66
	@WebMethod(operationName = "copy")
51
    public ReturnCode copy(@WebParam(name = "fileset") FileSetResource src,
67
    public ReturnCode copy(@WebParam(name = "fileset") FileSetResource src,
52
            @WebParam(name = "todir") String todir,
68
            @WebParam(name = "todir") String todir,
53
            @WebParam(name = "preservelastmodified") boolean plm,
69
            @WebParam(name = "preservelastmodified") boolean plm,
54
            @WebParam(name = "overwrite") boolean overwrite,
70
            @WebParam(name = "overwrite") boolean overwrite,
55
            @WebParam(name = "encoding") String encoding)
71
            @WebParam(name = "encoding") String encoding)
56
            throws XServicesFault {
72
            throws XServicesFault {
57
        return copy(src, new File(todir), plm, overwrite, encoding);
73
        return copy(src, new File(todir), plm, overwrite, encoding);
58
    }
74
    }
-
 
75
 
-
 
76
    /* (non-Javadoc)
-
 
77
	 * @see net.brutex.xservices.ws.impl.FileService#loadRes(net.brutex.xservices.types.FileResource, java.lang.String)
-
 
78
	 */
59
 
79
    @Override
60
    @WebMethod(operationName = "loadResource")
80
	@WebMethod(operationName = "loadResource")
61
    public ReturnCode loadRes(@WebParam(name = "resource") FileResource res,
81
    public ReturnCode loadRes(@WebParam(name = "resource") FileResource res,
62
            @WebParam(name = "encoding") String encoding) {
82
            @WebParam(name = "encoding") String encoding) {
63
        if (encoding == null || encoding.equals("")) {
83
        if (encoding == null || encoding.equals("")) {
64
            encoding = System.getProperty("file.encoding");
84
            encoding = System.getProperty("file.encoding");
65
        }
85
        }
66
        return loadResource(res, encoding);
86
        return loadResource(res, encoding);
67
    }
87
    }
-
 
88
 
-
 
89
    /* (non-Javadoc)
-
 
90
	 * @see net.brutex.xservices.ws.impl.FileService#loadResFromArchive(net.brutex.xservices.types.ArchiveResource, java.lang.String)
-
 
91
	 */
68
 
92
    @Override
69
    @WebMethod(operationName = "loadResourceFromArchive")
93
	@WebMethod(operationName = "loadResourceFromArchive")
70
    public ReturnCode loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
94
    public ReturnCode loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
71
            @WebParam(name = "encoding") String encoding) {
95
            @WebParam(name = "encoding") String encoding) {
72
        if (encoding == null || encoding.equals("")) {
96
        if (encoding == null || encoding.equals("")) {
73
            encoding = System.getProperty("file.encoding");
97
            encoding = System.getProperty("file.encoding");
74
        }
98
        }
75
        return loadResource(res, encoding);
99
        return loadResource(res, encoding);
76
    }
100
    }
-
 
101
 
-
 
102
    /* (non-Javadoc)
-
 
103
	 * @see net.brutex.xservices.ws.impl.FileService#echo2file(java.lang.String, java.lang.String, java.lang.String, boolean)
-
 
104
	 */
77
 
105
    @Override
78
    @WebMethod(operationName = "echoToFile")
106
	@WebMethod(operationName = "echoToFile")
79
    public ReturnCode echo2file(@WebParam(name = "message") String message,
107
    public ReturnCode echo2file(@WebParam(name = "message") String message,
80
            @WebParam(name = "file") String file, @WebParam(name = "encoding") String encoding,
108
            @WebParam(name = "file") String file, @WebParam(name = "encoding") String encoding,
81
            @WebParam(name = "append") boolean append) {
109
            @WebParam(name = "append") boolean append) {
82
        return echo(message, new File(file), encoding, append);
110
        return echo(message, new File(file), encoding, append);
83
    }
111
    }
-
 
112
 
-
 
113
    /* (non-Javadoc)
-
 
114
	 * @see net.brutex.xservices.ws.impl.FileService#changeOwner(net.brutex.xservices.types.FileSetResource, java.lang.String)
-
 
115
	 */
84
 
116
    @Override
85
    @WebMethod(operationName = "changeOwner")
117
	@WebMethod(operationName = "changeOwner")
86
    public ReturnCode changeOwner(@WebParam(name = "fileset") FileSetResource res,
118
    public ReturnCode changeOwner(@WebParam(name = "fileset") FileSetResource res,
87
            @WebParam(name = "owner") String owner) {
119
            @WebParam(name = "owner") String owner) {
88
        return chown(res, owner);
120
        return chown(res, owner);
89
    }
121
    }
-
 
122
 
-
 
123
    /* (non-Javadoc)
-
 
124
	 * @see net.brutex.xservices.ws.impl.FileService#changeGroup(net.brutex.xservices.types.FileSetResource, java.lang.String)
-
 
125
	 */
90
 
126
    @Override
91
    @WebMethod(operationName = "changeGroup")
127
	@WebMethod(operationName = "changeGroup")
92
    public ReturnCode changeGroup(@WebParam(name = "fileset") FileSetResource res,
128
    public ReturnCode changeGroup(@WebParam(name = "fileset") FileSetResource res,
93
            @WebParam(name = "group") String group) {
129
            @WebParam(name = "group") String group) {
94
        return chgrp(res, group);
130
        return chgrp(res, group);
95
    }
131
    }
-
 
132
 
-
 
133
    /* (non-Javadoc)
-
 
134
	 * @see net.brutex.xservices.ws.impl.FileService#changeMode(net.brutex.xservices.types.FileSetResource, java.lang.String)
-
 
135
	 */
96
 
136
    @Override
97
    @WebMethod(operationName = "changeMode")
137
	@WebMethod(operationName = "changeMode")
98
    public ReturnCode changeMode(@WebParam(name="fileset") FileSetResource res,
138
    public ReturnCode changeMode(@WebParam(name="fileset") FileSetResource res,
99
            @WebParam(name="permissions") String perm) {
139
            @WebParam(name="permissions") String perm) {
100
        return chmod(res, perm);
140
        return chmod(res, perm);
101
    }
141
    }
102
 
142
 
103
    @WebMethod(exclude = true)
143
    @WebMethod(exclude = true)
104
    private ReturnCode basename(File file,
144
    private ReturnCode basename(File file,
105
            String suffix) {
145
            String suffix) {
106
        Basename basename = new Basename();
146
        Basename basename = new Basename();
107
        RunTask runner = new RunTask(basename);
147
        RunTask runner = new RunTask(basename);
108
        basename.setFile(file);
148
        basename.setFile(file);
109
        if (suffix != null && !suffix.equals("")) {
149
        if (suffix != null && !suffix.equals("")) {
110
            basename.setSuffix(suffix);
150
            basename.setSuffix(suffix);
111
        }
151
        }
112
        basename.setProperty("basename.value");
152
        basename.setProperty("basename.value");
113
        return runner.postTask();
153
        return runner.postTask();
114
    }
154
    }
115
 
155
 
116
    @WebMethod(exclude = true)
156
    @WebMethod(exclude = true)
117
    private ReturnCode loadResource(ResourceInterface src, String encoding) {
157
    private ReturnCode loadResource(ResourceInterface src, String encoding) {
118
        LoadResource lr = new LoadResource();
158
        LoadResource lr = new LoadResource();
119
        lr.setTaskName("LoadResource");
159
        lr.setTaskName("LoadResource");
120
        RunTask runner = new RunTask(lr);
160
        RunTask runner = new RunTask(lr);
121
        lr.addConfigured(src.getAntResource(lr.getProject()));
161
        lr.addConfigured(src.getAntResource(lr.getProject()));
122
        lr.setEncoding(encoding);
162
        lr.setEncoding(encoding);
123
        System.out.println("Using encoding: " + encoding);
163
        System.out.println("Using encoding: " + encoding);
124
        lr.setProperty("LoadResource.out");
164
        lr.setProperty("LoadResource.out");
125
        return runner.postTask();
165
        return runner.postTask();
126
    }
166
    }
127
 
167
 
128
    @WebMethod(exclude = true)
168
    @WebMethod(exclude = true)
129
    private ReturnCode echo(String msg, File file, String encoding, boolean append) {
169
    private ReturnCode echo(String msg, File file, String encoding, boolean append) {
130
        Echo echo = new Echo();
170
        Echo echo = new Echo();
131
        echo.setTaskName("toFile");
171
        echo.setTaskName("toFile");
132
        RunTask runTask = new RunTask(echo);
172
        RunTask runTask = new RunTask(echo);
133
        echo.addText(msg);
173
        echo.addText(msg);
134
        echo.setEncoding(encoding);
174
        echo.setEncoding(encoding);
135
        echo.setFile(file);
175
        echo.setFile(file);
136
        echo.setAppend(append);
176
        echo.setAppend(append);
137
        return runTask.postTask();
177
        return runTask.postTask();
138
    }
178
    }
139
 
179
 
140
    @WebMethod(exclude = true)
180
    @WebMethod(exclude = true)
141
    private ReturnCode copy(FileSetResource src, File dst, boolean preservelastmodified,
181
    private ReturnCode copy(FileSetResource src, File dst, boolean preservelastmodified,
142
            boolean overwrite, String encoding) {
182
            boolean overwrite, String encoding) {
143
        Copy copy = new Copy();
183
        Copy copy = new Copy();
144
        copy.setTaskName("Copy");
184
        copy.setTaskName("Copy");
145
        RunTask runner = new RunTask(copy);
185
        RunTask runner = new RunTask(copy);
146
        FileSet set = src.getAntFileSet(copy.getProject());
186
        FileSet set = src.getAntFileSet(copy.getProject());
147
        copy.add(set);
187
        copy.add(set);
148
 
188
 
149
        if (dst.isDirectory()) {
189
        if (dst.isDirectory()) {
150
            copy.setTodir(dst);
190
            copy.setTodir(dst);
151
        }
191
        }
152
        if (dst.isFile()) {
192
        if (dst.isFile()) {
153
            copy.setTofile(dst);
193
            copy.setTofile(dst);
154
        }
194
        }
155
        copy.setOverwrite(overwrite);
195
        copy.setOverwrite(overwrite);
156
        copy.setPreserveLastModified(preservelastmodified);
196
        copy.setPreserveLastModified(preservelastmodified);
157
        if (encoding != null && !encoding.equals("")) {
197
        if (encoding != null && !encoding.equals("")) {
158
            copy.setOutputEncoding(encoding);
198
            copy.setOutputEncoding(encoding);
159
        } else {
199
        } else {
160
            copy.setOutputEncoding(System.getProperty("file.encoding"));
200
            copy.setOutputEncoding(System.getProperty("file.encoding"));
161
        }
201
        }
162
 
202
 
163
        return runner.postTask();
203
        return runner.postTask();
164
    }
204
    }
165
 
205
 
166
    @WebMethod(exclude = true)
206
    @WebMethod(exclude = true)
167
    private ReturnCode chown(FileSetResource src, String owner) {
207
    private ReturnCode chown(FileSetResource src, String owner) {
168
        Chown chown = new Chown();
208
        Chown chown = new Chown();
169
        chown.setTaskName("Chown");
209
        chown.setTaskName("Chown");
170
        RunTask runner = new RunTask(chown);
210
        RunTask runner = new RunTask(chown);
171
        chown.setOwner(owner);
211
        chown.setOwner(owner);
172
        FileSet set = src.getAntFileSet(chown.getProject());
212
        FileSet set = src.getAntFileSet(chown.getProject());
173
        chown.add(set);
213
        chown.add(set);
174
        chown.setMaxParallel(300);
214
        chown.setMaxParallel(300);
175
        return runner.postTask();
215
        return runner.postTask();
176
    }
216
    }
177
 
217
 
178
    @WebMethod(exclude = true)
218
    @WebMethod(exclude = true)
179
    private ReturnCode chgrp(FileSetResource src, String group) {
219
    private ReturnCode chgrp(FileSetResource src, String group) {
180
        Chgrp chgrp = new Chgrp();
220
        Chgrp chgrp = new Chgrp();
181
        chgrp.setTaskName("Chgrp");
221
        chgrp.setTaskName("Chgrp");
182
        RunTask runner = new RunTask(chgrp);
222
        RunTask runner = new RunTask(chgrp);
183
        chgrp.setGroup(group);
223
        chgrp.setGroup(group);
184
        FileSet set = src.getAntFileSet(chgrp.getProject());
224
        FileSet set = src.getAntFileSet(chgrp.getProject());
185
        chgrp.add(set);
225
        chgrp.add(set);
186
        chgrp.setMaxParallel(300);
226
        chgrp.setMaxParallel(300);
187
        return runner.postTask();
227
        return runner.postTask();
188
    }
228
    }
189
 
229
 
190
    @WebMethod(exclude = true)
230
    @WebMethod(exclude = true)
191
    private ReturnCode chmod(FileSetResource src, String perm) {
231
    private ReturnCode chmod(FileSetResource src, String perm) {
192
        Chmod chmod = new Chmod();
232
        Chmod chmod = new Chmod();
193
        chmod.setTaskName("Chmod");
233
        chmod.setTaskName("Chmod");
194
        RunTask runner = new RunTask(chmod);
234
        RunTask runner = new RunTask(chmod);
195
        FileSet set = src.getAntFileSet(chmod.getProject());
235
        FileSet set = src.getAntFileSet(chmod.getProject());
196
        chmod.add(set);
236
        chmod.add(set);
197
        chmod.setMaxParallel(300);
237
        chmod.setMaxParallel(300);
198
        chmod.setPerm(perm);
238
        chmod.setPerm(perm);
199
        chmod.setVerbose(true);
239
        chmod.setVerbose(true);
200
        return runner.postTask();
240
        return runner.postTask();
201
    }
241
    }
202
 
242
 
203
}
243
}