Subversion Repositories XServices

Rev

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

Rev 64 Rev 65
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
 
-
 
18
import java.io.BufferedInputStream;
17
 
19
import java.io.File;
-
 
20
import java.io.FileInputStream;
18
import java.io.File;
21
import java.io.FileNotFoundException;
19
import java.io.FileNotFoundException;
22
import java.io.FileOutputStream;
20
import java.io.FileOutputStream;
23
import java.io.IOException;
21
import java.io.IOException;
24
import java.io.InputStream;
22
import java.io.InputStream;
25
import java.io.UnsupportedEncodingException;
-
 
26
import java.util.Iterator;
-
 
27
import java.util.List;
23
import java.util.List;
28
 
24
 
29
import javax.activation.DataHandler;
25
import javax.activation.DataHandler;
30
import javax.jws.WebMethod;
26
import javax.jws.WebMethod;
31
import javax.jws.WebParam;
27
import javax.jws.WebParam;
32
import javax.jws.WebService;
28
import javax.jws.WebService;
33
 
-
 
34
import net.brutex.xservices.types.AntProperty;
29
 
35
import net.brutex.xservices.types.ArchiveResource;
30
import net.brutex.xservices.types.ArchiveResource;
36
import net.brutex.xservices.types.AttachmentType;
31
import net.brutex.xservices.types.AttachmentType;
37
import net.brutex.xservices.types.FileResource;
32
import net.brutex.xservices.types.FileResource;
38
import net.brutex.xservices.types.FileSetResource;
33
import net.brutex.xservices.types.FileSetResource;
39
import net.brutex.xservices.types.ReplacePattern;
34
import net.brutex.xservices.types.ReplacePattern;
40
import net.brutex.xservices.types.ResourceInterface;
-
 
41
import net.brutex.xservices.types.ReturnCode;
35
import net.brutex.xservices.types.ReturnCode;
42
import net.brutex.xservices.util.BrutexNamespaces;
36
import net.brutex.xservices.util.BrutexNamespaces;
43
import net.brutex.xservices.util.RunTask;
37
import net.brutex.xservices.util.RunTask;
44
import net.brutex.xservices.ws.FileService;
38
import net.brutex.xservices.ws.FileService;
45
import net.brutex.xservices.ws.XServicesFault;
39
import net.brutex.xservices.ws.XServicesFault;
46
 
-
 
47
import org.apache.commons.codec.binary.Base64;
-
 
48
import org.apache.commons.codec.binary.Base64InputStream;
40
 
49
import org.apache.cxf.aegis.type.mtom.StreamDataSource;
41
import org.apache.cxf.aegis.type.mtom.StreamDataSource;
50
import org.apache.tools.ant.BuildException;
42
import org.apache.tools.ant.BuildException;
51
import org.apache.tools.ant.taskdefs.Basename;
43
import org.apache.tools.ant.taskdefs.Basename;
52
import org.apache.tools.ant.taskdefs.Chmod;
44
import org.apache.tools.ant.taskdefs.Chmod;
53
import org.apache.tools.ant.taskdefs.Copy;
45
import org.apache.tools.ant.taskdefs.Copy;
54
import org.apache.tools.ant.taskdefs.Echo;
46
import org.apache.tools.ant.taskdefs.Echo;
55
import org.apache.tools.ant.taskdefs.LoadResource;
47
import org.apache.tools.ant.taskdefs.LoadResource;
56
import org.apache.tools.ant.taskdefs.Replace;
48
import org.apache.tools.ant.taskdefs.Replace;
57
import org.apache.tools.ant.taskdefs.optional.ReplaceRegExp;
49
import org.apache.tools.ant.taskdefs.optional.ReplaceRegExp;
58
import org.apache.tools.ant.taskdefs.optional.unix.Chgrp;
50
import org.apache.tools.ant.taskdefs.optional.unix.Chgrp;
59
import org.apache.tools.ant.taskdefs.optional.unix.Chown;
51
import org.apache.tools.ant.taskdefs.optional.unix.Chown;
60
import org.apache.tools.ant.types.FileSet;
52
import org.apache.tools.ant.types.FileSet;
61
import org.apache.tools.ant.types.Resource;
-
 
62
import org.apache.tools.ant.types.ResourceCollection;
-
 
63
 
53
 
64
/**
54
/**
65
 * 
55
 * 
66
 * @author Brian Rosenberger, bru@brutex.de
56
 * @author Brian Rosenberger, bru@brutex.de
67
 */
57
 */
68
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.FileService", serviceName = "FileService")
58
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.FileService", serviceName = "FileService")
69
public class FileServiceImpl implements FileService {
59
public class FileServiceImpl implements FileService {
70
 
60
 
71
	/*
61
	/*
72
	 * (non-Javadoc)
62
	 * (non-Javadoc)
73
	 * 
63
	 * 
74
	 * @see net.brutex.xservices.ws.impl.FileService#basename(java.lang.String,
64
	 * @see net.brutex.xservices.ws.impl.FileService#basename(java.lang.String,
75
	 * java.lang.String)
65
	 * java.lang.String)
76
	 */
66
	 */
77
	@Override
67
	@Override
78
	@WebMethod(operationName = "basename")
-
 
79
	public String basename(@WebParam(name = "file") String filename,
68
	public String basename(String filename, String suffix) {
80
			@WebParam(name = "suffix") String suffix) {
-
 
81
		final String BASENAME_VALUE = "basename.value";
69
		final String BASENAME_VALUE = "basename.value";
82
		Basename basename = new Basename();
70
		Basename basename = new Basename();
83
		RunTask runner = new RunTask(basename);
71
		RunTask runner = new RunTask(basename);
84
		basename.setFile(new File(filename));
72
		basename.setFile(new File(filename));
85
		if (suffix != null && !suffix.equals("")) {
73
		if (suffix != null && !suffix.equals("")) {
86
			basename.setSuffix(suffix);
74
			basename.setSuffix(suffix);
87
		}
75
		}
88
		basename.setProperty("BASENAME_VALUE");
76
		basename.setProperty(BASENAME_VALUE);
89
		ReturnCode r = runner.postTask();
77
		ReturnCode r = runner.postTask();
90
		return r.getProperty("BASENAME_VALUE");
78
		return r.getProperty(BASENAME_VALUE);
91
	}
79
	}
92
 
-
 
93
	@WebMethod(operationName = "replaceInFile")
80
 
94
	public ReturnCode replaceInFile(
-
 
95
			@WebParam(name = "file") FileResource res,
-
 
96
			@WebParam(name = "search") String search,
81
	public ReturnCode replaceInFile(FileResource res, String search,
97
			@WebParam(name = "replace") String replace) {
82
			String replace) throws XServicesFault {
98
		ReturnCode r = null;
83
		ReturnCode r = null;
99
		Replace rep = new Replace();
84
		Replace rep = new Replace();
100
		rep.setTaskName("Replace");
85
		rep.setTaskName("Replace");
101
		RunTask runner = new RunTask(rep);
86
		RunTask runner = new RunTask(rep);
102
		rep.addConfigured(res.getAntResource(rep.getProject()));
87
		rep.addConfigured(res.getAntResource(rep.getProject()));
103
		rep.setToken(search);
88
		rep.setToken(search);
104
		rep.setValue(replace);
89
		rep.setValue(replace);
-
 
90
		try {
105
		r = runner.postTask();
91
			r = runner.postTask();
-
 
92
		} catch (BuildException e) {
-
 
93
			throw new XServicesFault(e);
-
 
94
		}
106
		return r;
95
		return r;
107
	}
96
	}
108
	
-
 
109
	@WebMethod(operationName = "replaceInFile2")
97
 
110
	public ReturnCode replaceInFile2(
-
 
111
			@WebParam(name = "file") FileResource res,
98
	public ReturnCode replaceInFile2(FileResource res,
112
			@WebParam(name = "patternList") List<ReplacePattern> patternList) {
99
			List<ReplacePattern> patternList) throws XServicesFault {
113
		ReturnCode r = null;
100
		ReturnCode r = null;
114
		for (ReplacePattern pat : patternList) {
101
		for (ReplacePattern pat : patternList) {
115
			Replace rep = new Replace();
102
			Replace rep = new Replace();
116
			rep.setTaskName("Replace");
103
			rep.setTaskName("Replace");
117
			RunTask runner = new RunTask(rep);
104
			RunTask runner = new RunTask(rep);
118
			rep.addConfigured(res.getAntResource(rep.getProject()));
105
			rep.addConfigured(res.getAntResource(rep.getProject()));
119
			rep.setToken(pat.search);
106
			rep.setToken(pat.search);
120
			rep.setValue(pat.replace);
107
			rep.setValue(pat.replace);
-
 
108
			try {
121
			r = runner.postTask();
109
				r = runner.postTask();
-
 
110
			} catch (BuildException e) {
-
 
111
				throw new XServicesFault(e);
-
 
112
			}
122
		}
113
		}
123
		return r;
114
		return r;
124
	}
115
	}
125
	
-
 
126
	@WebMethod(operationName = "replaceInFileRegEx")
116
 
127
	public ReturnCode replaceInFileRegEx(
-
 
128
			@WebParam(name = "file") FileResource res,
-
 
129
			@WebParam(name = "search") String search,
-
 
130
			@WebParam(name = "replace") String replace,
117
	public ReturnCode replaceInFileRegEx(FileResource res, String search,
131
			@WebParam(name = "flags") String flags) {		
118
			String replace, String flags) throws XServicesFault {
132
		ReplaceRegExp rep = new ReplaceRegExp();
119
		ReplaceRegExp rep = new ReplaceRegExp();
133
		rep.setTaskName("ReplaceRegExp");
120
		rep.setTaskName("ReplaceRegExp");
134
		RunTask runner = new RunTask(rep);
121
		RunTask runner = new RunTask(rep);
135
		File infile = new File(res.uri);
122
		File infile = new File(res.uri);
136
		rep.setFile(infile);
123
		rep.setFile(infile);
137
		rep.setMatch(search);
124
		rep.setMatch(search);
138
		rep.setReplace(replace);
125
		rep.setReplace(replace);
139
		rep.setFlags(flags);
126
		rep.setFlags(flags);
-
 
127
		try {
140
		ReturnCode r = runner.postTask();		
128
			ReturnCode r = runner.postTask();
141
		return r;
129
			return r;
-
 
130
		} catch (BuildException e) {
-
 
131
			throw new XServicesFault(e);
-
 
132
		}
142
	}
133
	}
143
	
-
 
144
	
134
 
145
	/*
135
	/*
146
	 * (non-Javadoc)
136
	 * (non-Javadoc)
147
	 * 
137
	 * 
148
	 * @see
138
	 * @see
149
	 * net.brutex.xservices.ws.impl.FileService#base64Encode(net.brutex.xservices
139
	 * net.brutex.xservices.ws.impl.FileService#base64Encode(net.brutex.xservices
150
	 * .types.FileSetResource)
140
	 * .types.FileSetResource)
151
	 */
141
	 */
152
	@Override
142
	@Override
153
	@WebMethod(operationName = "downloadFile")
-
 
154
	public AttachmentType downloadFile(@WebParam(name = "file") FileResource res) {
143
	public AttachmentType downloadFile(FileResource res) throws XServicesFault {
155
		InputStream is = null;
144
		InputStream is = null;
156
		try {
145
		try {
157
			is = res.getAntResource(null).getInputStream();
146
			is = res.getAntResource(null).getInputStream();
158
		} catch (IOException e) {
-
 
159
			// TODO Auto-generated catch block
147
			StreamDataSource ssource = new StreamDataSource(
160
			e.printStackTrace();
148
					"application/binary", is);
161
		}
-
 
162
		DataHandler h = new DataHandler(new StreamDataSource(
149
			DataHandler h = new DataHandler(ssource);
163
				"application/binary", is));
-
 
164
		AttachmentType t = new AttachmentType();
150
			AttachmentType t = new AttachmentType();
165
		t.setContent(h);
151
			t.setContent(h);
166
		t.setFilename(res.getAntResource(null).getName());
152
			t.setFilename(res.getAntResource(null).getName());
167
		return t;
153
			return t;
-
 
154
		} catch (IOException e) {
-
 
155
			throw new XServicesFault(e);
-
 
156
		}
168
	}
157
	}
169
 
158
 
170
	/*
159
	/*
171
	 * (non-Javadoc)
160
	 * (non-Javadoc)
172
	 * 
161
	 * 
173
	 * @see
162
	 * @see
174
	 * net.brutex.xservices.ws.impl.FileService#base64Decode(net.brutex.xservices
163
	 * net.brutex.xservices.ws.impl.FileService#base64Decode(net.brutex.xservices
175
	 * .types.AttachmentType)
164
	 * .types.AttachmentType)
176
	 */
165
	 */
177
	@Override
166
	@Override
178
	@WebMethod(operationName = "uploadFile")
-
 
179
	public String uploadFile(@WebParam(name = "file") AttachmentType file) {
167
	public String uploadFile(AttachmentType file) throws XServicesFault {
180
		DataHandler h =  file.getContent();
168
		DataHandler h = file.getContent();
181
		File f = new File(file.getFilename());
169
		File f = new File(file.getFilename());
182
		FileOutputStream fout;
170
		FileOutputStream fout;
183
		try {
171
		try {
184
			fout = new FileOutputStream(f);
172
			fout = new FileOutputStream(f);
185
			/*
-
 
186
			 * InputStream in = h.getInputStream();
-
 
187
			int b;
-
 
188
			while( (b=in.read())!= -1 ) {
-
 
189
				fout.write(b);
-
 
190
			}
-
 
191
			*/
-
 
192
			h.writeTo(fout);
173
			h.writeTo(fout);
193
			fout.flush();
174
			fout.flush();
194
			fout.close();
175
			fout.close();
195
			//in.close();
-
 
196
		} catch (FileNotFoundException e) {
176
		} catch (FileNotFoundException e) {
197
			throw new BuildException(e);
177
			throw new XServicesFault(e);
198
		} catch (IOException e) {
178
		} catch (IOException e) {
199
			throw new BuildException(e);
179
			throw new XServicesFault(e);
200
		}
180
		}
201
		return file.getFilename();
181
		return file.getFilename();
202
	}
182
	}
203
 
183
 
204
	/*
184
	/*
205
	 * (non-Javadoc)
185
	 * (non-Javadoc)
206
	 * 
186
	 * 
207
	 * @see
187
	 * @see
208
	 * net.brutex.xservices.ws.impl.FileService#copy(net.brutex.xservices.types
188
	 * net.brutex.xservices.ws.impl.FileService#copy(net.brutex.xservices.types
209
	 * .FileSetResource, java.lang.String, boolean, boolean, java.lang.String)
189
	 * .FileSetResource, java.lang.String, boolean, boolean, java.lang.String)
210
	 */
190
	 */
211
	@Override
191
	@Override
-
 
192
	public ReturnCode copy(FileSetResource src, String todir, boolean plm,
-
 
193
			boolean overwrite, String encoding) throws XServicesFault {
-
 
194
		Copy copy = new Copy();
212
	@WebMethod(operationName = "copy")
195
		copy.setTaskName("Copy");
-
 
196
		RunTask runner = new RunTask(copy);
213
	public ReturnCode copy(@WebParam(name = "fileset") FileSetResource src,
197
		FileSet set = src.getAntResource(copy.getProject());
-
 
198
		copy.add(set);
214
			@WebParam(name = "todir") String todir,
199
		File dst = new File(todir);
-
 
200
		if (dst.isDirectory()) {
-
 
201
			copy.setTodir(dst);
-
 
202
		}
-
 
203
		if (dst.isFile()) {
-
 
204
			copy.setTofile(dst);
-
 
205
		}
-
 
206
		copy.setOverwrite(overwrite);
215
			@WebParam(name = "preservelastmodified") boolean plm,
207
		copy.setPreserveLastModified(plm);
216
			@WebParam(name = "overwrite") boolean overwrite,
208
		if (encoding != null && !encoding.equals("")) {
217
			@WebParam(name = "encoding") String encoding) throws XServicesFault {
209
			copy.setOutputEncoding(encoding);
-
 
210
		} else {
218
		return copy(src, new File(todir), plm, overwrite, encoding);
211
			copy.setOutputEncoding(System.getProperty("file.encoding"));
-
 
212
		}
-
 
213
		return runner.postTask();
219
	}
214
	}
220
	
215
 
221
	@Override
216
	@Override
222
	public ReturnCode copyFile(String fromFile, 
217
	public ReturnCode copyFile(String fromFile, String tofile, boolean overwrite)
223
								String tofile,
-
 
224
								boolean overwrite) throws XServicesFault {
218
			throws XServicesFault {
225
		Copy copy = new Copy();
219
		Copy copy = new Copy();
226
		copy.setTaskName("Copy");
220
		copy.setTaskName("Copy");
227
		RunTask runner = new RunTask(copy);
221
		RunTask runner = new RunTask(copy);
228
		File f = new File(fromFile);
222
		File f = new File(fromFile);
-
 
223
		if (!f.isFile())
229
		if( ! f.isFile() ) throw new XServicesFault("File '"+fromFile+"' not found.");
224
			throw new XServicesFault("File '" + fromFile + "' not found.");
230
		copy.setFile( new File( fromFile ));
225
		copy.setFile(new File(fromFile));
231
		copy.setTofile(new File(tofile));
226
		copy.setTofile(new File(tofile));
232
		copy.setOverwrite(overwrite);
227
		copy.setOverwrite(overwrite);
233
		return runner.postTask();
228
		return runner.postTask();
234
	}
229
	}
235
 
230
 
236
	/*
231
	/*
237
	 * (non-Javadoc)
232
	 * (non-Javadoc)
238
	 * 
233
	 * 
239
	 * @see
234
	 * @see
240
	 * net.brutex.xservices.ws.impl.FileService#loadRes(net.brutex.xservices
235
	 * net.brutex.xservices.ws.impl.FileService#loadRes(net.brutex.xservices
241
	 * .types.FileResource, java.lang.String)
236
	 * .types.FileResource, java.lang.String)
242
	 */
237
	 */
243
	@Override
238
	@Override
244
	@WebMethod(operationName = "loadResource")
-
 
245
	public String loadRes(@WebParam(name = "resource") FileResource res,
239
	public String loadRes(FileResource res, String encoding)
246
			@WebParam(name = "encoding") String encoding) {
240
			throws XServicesFault {
247
		if (encoding == null || encoding.equals("")) {
241
		if (encoding == null || encoding.equals("")) {
248
			encoding = System.getProperty("file.encoding");
242
			encoding = System.getProperty("file.encoding");
249
		}
243
		}
250
		LoadResource lr = new LoadResource();
244
		LoadResource lr = new LoadResource();
251
		lr.setTaskName("LoadResource");
245
		lr.setTaskName("LoadResource");
252
		RunTask runner = new RunTask(lr);
246
		RunTask runner = new RunTask(lr);
253
		lr.addConfigured(res.getAntResource(lr.getProject()));
247
		lr.addConfigured(res.getAntResource(lr.getProject()));
254
		lr.setEncoding(encoding);
248
		lr.setEncoding(encoding);
255
		System.out.println("Using encoding: " + encoding);
249
		System.out.println("Using encoding: " + encoding);
256
		lr.setProperty("LoadResource.out");
250
		lr.setProperty("LoadResource.out");
257
		ReturnCode r = runner.postTask();
251
		ReturnCode r = runner.postTask();
258
		return r.getProperty("LoadResource.out");
252
		return r.getProperty("LoadResource.out");
259
	}
253
	}
260
 
254
 
261
	/*
255
	/*
262
	 * (non-Javadoc)
256
	 * (non-Javadoc)
263
	 * 
257
	 * 
264
	 * @see
258
	 * @see
265
	 * net.brutex.xservices.ws.impl.FileService#loadResFromArchive(net.brutex
259
	 * net.brutex.xservices.ws.impl.FileService#loadResFromArchive(net.brutex
266
	 * .xservices.types.ArchiveResource, java.lang.String)
260
	 * .xservices.types.ArchiveResource, java.lang.String)
267
	 */
261
	 */
268
	@Override
262
	@Override
269
	@WebMethod(operationName = "loadResourceFromArchive")
-
 
270
	public String loadResFromArchive(
263
	public String loadResFromArchive(ArchiveResource res, String encoding) {
271
			@WebParam(name = "archiveresource") ArchiveResource res,
-
 
272
			@WebParam(name = "encoding") String encoding) {
-
 
273
		if (encoding == null || encoding.equals("")) {
264
		if (encoding == null || encoding.equals("")) {
274
			encoding = System.getProperty("file.encoding");
265
			encoding = System.getProperty("file.encoding");
275
		}
266
		}
276
		LoadResource lr = new LoadResource();
267
		LoadResource lr = new LoadResource();
277
		lr.setTaskName("LoadResource");
268
		lr.setTaskName("LoadResource");
278
		RunTask runner = new RunTask(lr);
269
		RunTask runner = new RunTask(lr);
279
		lr.addConfigured(res.getAntResource(lr.getProject()));
270
		lr.addConfigured(res.getAntResource(lr.getProject()));
280
		lr.setEncoding(encoding);
271
		lr.setEncoding(encoding);
281
		System.out.println("Using encoding: " + encoding);
272
		System.out.println("Using encoding: " + encoding);
282
		lr.setProperty("LoadResource.out");
273
		lr.setProperty("LoadResource.out");
283
		ReturnCode r = runner.postTask();
274
		ReturnCode r = runner.postTask();
284
		return r.getProperty("LoadResource.out");
275
		return r.getProperty("LoadResource.out");
285
		
276
 
286
	}
277
	}
287
 
278
 
288
	/*
279
	/*
289
	 * (non-Javadoc)
280
	 * (non-Javadoc)
290
	 * 
281
	 * 
291
	 * @see net.brutex.xservices.ws.impl.FileService#echo2file(java.lang.String,
282
	 * @see net.brutex.xservices.ws.impl.FileService#echo2file(java.lang.String,
292
	 * java.lang.String, java.lang.String, boolean)
283
	 * java.lang.String, java.lang.String, boolean)
293
	 */
284
	 */
294
	@Override
285
	@Override
-
 
286
	public ReturnCode echo2file(String message, String file, String encoding,
-
 
287
			boolean append) throws XServicesFault {
-
 
288
 
-
 
289
		Echo echo = new Echo();
295
	@WebMethod(operationName = "echoToFile")
290
		echo.setTaskName("toFile");
-
 
291
		RunTask runTask = new RunTask(echo);
-
 
292
		echo.addText(message);
-
 
293
		echo.setEncoding(encoding);
-
 
294
		File f = new File(file);
-
 
295
		try {
-
 
296
			if (!f.canWrite())
-
 
297
 
296
	public ReturnCode echo2file(@WebParam(name = "message") String message,
298
				throw new XServicesFault("Cannot write to file: "
-
 
299
						+ f.getCanonicalPath());
-
 
300
 
-
 
301
			echo.setFile(f);
-
 
302
			echo.setAppend(append);
297
			@WebParam(name = "file") String file,
303
			ReturnCode c = runTask.postTask();
-
 
304
			return c;
-
 
305
		} catch (BuildException e) {
298
			@WebParam(name = "encoding") String encoding,
306
			throw new XServicesFault("Error in echo2file.", e);
299
			@WebParam(name = "append") boolean append) {
307
		} catch (IOException e) {
300
		return echo(message, new File(file), encoding, append);
308
			throw new XServicesFault("Cannot write to file.", e);
-
 
309
		}
301
	}
310
	}
302
 
311
 
303
	/*
312
	/*
304
	 * (non-Javadoc)
313
	 * (non-Javadoc)
305
	 * 
314
	 * 
306
	 * @see
315
	 * @see
307
	 * net.brutex.xservices.ws.impl.FileService#changeOwner(net.brutex.xservices
316
	 * net.brutex.xservices.ws.impl.FileService#changeOwner(net.brutex.xservices
308
	 * .types.FileSetResource, java.lang.String)
317
	 * .types.FileSetResource, java.lang.String)
309
	 */
318
	 */
310
	@Override
319
	@Override
311
	@WebMethod(operationName = "changeOwner")
320
	public ReturnCode changeOwner(FileSetResource res, String owner) {
312
	public ReturnCode changeOwner(
321
		Chown chown = new Chown();
-
 
322
		chown.setTaskName("Chown");
313
			@WebParam(name = "fileset") FileSetResource res,
323
		RunTask runner = new RunTask(chown);
314
			@WebParam(name = "owner") String owner) {
324
		chown.setOwner(owner);
-
 
325
		FileSet set = res.getAntResource(chown.getProject());
-
 
326
		chown.add(set);
-
 
327
		chown.setMaxParallel(300);
315
		return chown(res, owner);
328
		return runner.postTask();
316
	}
329
	}
317
 
330
 
318
	/*
331
	/*
319
	 * (non-Javadoc)
332
	 * (non-Javadoc)
320
	 * 
333
	 * 
321
	 * @see
334
	 * @see
322
	 * net.brutex.xservices.ws.impl.FileService#changeGroup(net.brutex.xservices
335
	 * net.brutex.xservices.ws.impl.FileService#changeGroup(net.brutex.xservices
323
	 * .types.FileSetResource, java.lang.String)
336
	 * .types.FileSetResource, java.lang.String)
324
	 */
337
	 */
325
	@Override
338
	@Override
326
	@WebMethod(operationName = "changeGroup")
339
	public ReturnCode changeGroup(FileSetResource res, String group) {
327
	public ReturnCode changeGroup(
340
		Chgrp chgrp = new Chgrp();
-
 
341
		chgrp.setTaskName("Chgrp");
328
			@WebParam(name = "fileset") FileSetResource res,
342
		RunTask runner = new RunTask(chgrp);
329
			@WebParam(name = "group") String group) {
343
		chgrp.setGroup(group);
-
 
344
		FileSet set = res.getAntResource(chgrp.getProject());
-
 
345
		chgrp.add(set);
-
 
346
		chgrp.setMaxParallel(300);
330
		return chgrp(res, group);
347
		return runner.postTask();
331
	}
348
	}
332
 
349
 
333
	/*
350
	/*
334
	 * (non-Javadoc)
351
	 * (non-Javadoc)
335
	 * 
352
	 * 
336
	 * @see
353
	 * @see
337
	 * net.brutex.xservices.ws.impl.FileService#changeMode(net.brutex.xservices
354
	 * net.brutex.xservices.ws.impl.FileService#changeMode(net.brutex.xservices
338
	 * .types.FileSetResource, java.lang.String)
355
	 * .types.FileSetResource, java.lang.String)
339
	 */
356
	 */
340
	@Override
357
	@Override
341
	@WebMethod(operationName = "changeMode")
-
 
342
	public ReturnCode changeMode(
-
 
343
			@WebParam(name = "fileset") FileSetResource res,
-
 
344
			@WebParam(name = "permissions") String perm) {
-
 
345
		return chmod(res, perm);
-
 
346
	}
-
 
347
 
-
 
348
	@WebMethod(exclude = true)
-
 
349
	private ReturnCode echo(String msg, File file, String encoding,
-
 
350
			boolean append) {
-
 
351
		Echo echo = new Echo();
-
 
352
		echo.setTaskName("toFile");
-
 
353
		RunTask runTask = new RunTask(echo);
-
 
354
		echo.addText(msg);
-
 
355
		echo.setEncoding(encoding);
-
 
356
		echo.setFile(file);
-
 
357
		echo.setAppend(append);
-
 
358
		return runTask.postTask();
-
 
359
	}
-
 
360
 
-
 
361
	@WebMethod(exclude = true)
-
 
362
	private ReturnCode copy(FileSetResource src, File dst,
-
 
363
			boolean preservelastmodified, boolean overwrite, String encoding) {
-
 
364
		Copy copy = new Copy();
-
 
365
		copy.setTaskName("Copy");
-
 
366
		RunTask runner = new RunTask(copy);
-
 
367
		FileSet set = src.getAntResource(copy.getProject());
-
 
368
		copy.add(set);
-
 
369
 
-
 
370
		if (dst.isDirectory()) {
-
 
371
			copy.setTodir(dst);
-
 
372
		}
-
 
373
		if (dst.isFile()) {
-
 
374
			copy.setTofile(dst);
-
 
375
		}
-
 
376
		copy.setOverwrite(overwrite);
-
 
377
		copy.setPreserveLastModified(preservelastmodified);
-
 
378
		if (encoding != null && !encoding.equals("")) {
-
 
379
			copy.setOutputEncoding(encoding);
-
 
380
		} else {
-
 
381
			copy.setOutputEncoding(System.getProperty("file.encoding"));
-
 
382
		}
-
 
383
 
-
 
384
		return runner.postTask();
-
 
385
	}
-
 
386
 
-
 
387
	@WebMethod(exclude = true)
-
 
388
	private ReturnCode chown(FileSetResource src, String owner) {
-
 
389
		Chown chown = new Chown();
-
 
390
		chown.setTaskName("Chown");
-
 
391
		RunTask runner = new RunTask(chown);
-
 
392
		chown.setOwner(owner);
-
 
393
		FileSet set = src.getAntResource(chown.getProject());
-
 
394
		chown.add(set);
-
 
395
		chown.setMaxParallel(300);
-
 
396
		return runner.postTask();
-
 
397
	}
-
 
398
 
-
 
399
	@WebMethod(exclude = true)
-
 
400
	private ReturnCode chgrp(FileSetResource src, String group) {
-
 
401
		Chgrp chgrp = new Chgrp();
-
 
402
		chgrp.setTaskName("Chgrp");
-
 
403
		RunTask runner = new RunTask(chgrp);
-
 
404
		chgrp.setGroup(group);
-
 
405
		FileSet set = src.getAntResource(chgrp.getProject());
-
 
406
		chgrp.add(set);
-
 
407
		chgrp.setMaxParallel(300);
-
 
408
		return runner.postTask();
-
 
409
	}
-
 
410
 
-
 
411
	@WebMethod(exclude = true)
-
 
412
	private ReturnCode chmod(FileSetResource src, String perm) {
358
	public ReturnCode changeMode(FileSetResource res, String perm) {
413
		Chmod chmod = new Chmod();
359
		Chmod chmod = new Chmod();
414
		chmod.setTaskName("Chmod");
360
		chmod.setTaskName("Chmod");
415
		RunTask runner = new RunTask(chmod);
361
		RunTask runner = new RunTask(chmod);
416
		FileSet set = src.getAntResource(chmod.getProject());
362
		FileSet set = res.getAntResource(chmod.getProject());
417
		chmod.add(set);
363
		chmod.add(set);
418
		chmod.setMaxParallel(300);
364
		chmod.setMaxParallel(300);
419
		chmod.setPerm(perm);
365
		chmod.setPerm(perm);
420
		chmod.setVerbose(true);
366
		chmod.setVerbose(true);
421
		return runner.postTask();
367
		return runner.postTask();
422
	}
368
	}
423
 
369
 
424
}
370
}