Subversion Repositories XServices

Rev

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

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