Subversion Repositories XServices

Rev

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

Rev 49 Rev 54
Line 14... Line 14...
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;
Line 17... Line 17...
17
 
17
 
-
 
18
import java.io.File;
-
 
19
import java.io.FileInputStream;
-
 
20
import java.io.FileNotFoundException;
-
 
21
import java.io.FileOutputStream;
-
 
22
import java.io.IOException;
-
 
23
import java.io.InputStream;
-
 
24
import java.io.UnsupportedEncodingException;
-
 
25
import java.util.List;
-
 
26
 
18
import java.io.File;
27
import javax.activation.DataHandler;
19
import javax.jws.WebMethod;
28
import javax.jws.WebMethod;
20
import javax.jws.WebParam;
29
import javax.jws.WebParam;
-
 
30
import javax.jws.WebService;
-
 
31
 
21
import javax.jws.WebService;
32
import net.brutex.xservices.types.AntProperty;
-
 
33
import net.brutex.xservices.types.ArchiveResource;
22
import net.brutex.xservices.types.ArchiveResource;
34
import net.brutex.xservices.types.AttachmentType;
23
import net.brutex.xservices.types.FileResource;
35
import net.brutex.xservices.types.FileResource;
24
import net.brutex.xservices.types.FileSetResource;
36
import net.brutex.xservices.types.FileSetResource;
25
import net.brutex.xservices.types.ResourceInterface;
37
import net.brutex.xservices.types.ResourceInterface;
26
import net.brutex.xservices.types.ReturnCode;
38
import net.brutex.xservices.types.ReturnCode;
27
import net.brutex.xservices.util.BrutexNamespaces;
39
import net.brutex.xservices.util.BrutexNamespaces;
28
import net.brutex.xservices.util.RunTask;
40
import net.brutex.xservices.util.RunTask;
29
import net.brutex.xservices.ws.FileService;
41
import net.brutex.xservices.ws.FileService;
Line -... Line 42...
-
 
42
import net.brutex.xservices.ws.XServicesFault;
-
 
43
 
-
 
44
import org.apache.commons.codec.binary.Base64;
-
 
45
import org.apache.commons.codec.binary.Base64InputStream;
30
import net.brutex.xservices.ws.XServicesFault;
46
import org.apache.cxf.aegis.type.mtom.StreamDataSource;
31
 
47
import org.apache.tools.ant.BuildException;
32
import org.apache.tools.ant.taskdefs.Basename;
48
import org.apache.tools.ant.taskdefs.Basename;
33
import org.apache.tools.ant.taskdefs.Chmod;
49
import org.apache.tools.ant.taskdefs.Chmod;
34
import org.apache.tools.ant.taskdefs.Copy;
50
import org.apache.tools.ant.taskdefs.Copy;
35
import org.apache.tools.ant.taskdefs.Echo;
51
import org.apache.tools.ant.taskdefs.Echo;
36
import org.apache.tools.ant.taskdefs.LoadResource;
52
import org.apache.tools.ant.taskdefs.LoadResource;
37
import org.apache.tools.ant.taskdefs.optional.unix.Chgrp;
53
import org.apache.tools.ant.taskdefs.optional.unix.Chgrp;
Line 38... Line 54...
38
import org.apache.tools.ant.taskdefs.optional.unix.Chown;
54
import org.apache.tools.ant.taskdefs.optional.unix.Chown;
39
import org.apache.tools.ant.types.FileSet;
55
import org.apache.tools.ant.types.FileSet;
40
 
56
 
41
/**
57
/**
42
 *
-
 
43
 * @author Brian Rosenberger, bru@brutex.de
-
 
44
 */
58
 * 
45
@WebService(
-
 
46
		targetNamespace = BrutexNamespaces.WS_XSERVICES, 
-
 
47
		endpointInterface ="net.brutex.xservices.ws.FileService", 
59
 * @author Brian Rosenberger, bru@brutex.de
Line -... Line 60...
-
 
60
 */
48
		serviceName = "FileService"
61
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES, endpointInterface = "net.brutex.xservices.ws.FileService", serviceName = "FileService")
-
 
62
public class FileServiceImpl implements FileService {
49
			)
63
 
-
 
64
	/*
50
public class FileServiceImpl implements FileService {
65
	 * (non-Javadoc)
51
 
66
	 * 
52
    /* (non-Javadoc)
67
	 * @see net.brutex.xservices.ws.impl.FileService#basename(java.lang.String,
53
	 * @see net.brutex.xservices.ws.impl.FileService#basename(java.lang.String, java.lang.String)
68
	 * java.lang.String)
54
	 */
69
	 */
55
    @Override
70
	@Override
56
	@WebMethod(operationName = "basename")
71
	@WebMethod(operationName = "basename")
57
    public ReturnCode basename(@WebParam(name = "file") String filename,
72
	public ReturnCode basename(@WebParam(name = "file") String filename,
-
 
73
			@WebParam(name = "suffix") String suffix) {
58
            @WebParam(name = "suffix") String suffix) {
74
		return basename(new File(filename), suffix);
-
 
75
	}
-
 
76
 
59
        return basename(new File(filename), suffix);
77
	/*
-
 
78
	 * (non-Javadoc)
60
    }
79
	 * 
-
 
80
	 * @see
-
 
81
	 * net.brutex.xservices.ws.impl.FileService#base64Encode(net.brutex.xservices
-
 
82
	 * .types.FileSetResource)
-
 
83
	 */
-
 
84
	@Override
-
 
85
	@WebMethod(operationName = "downloadFile")
-
 
86
	public AttachmentType downloadFile(@WebParam(name = "file") FileResource res) {
-
 
87
		InputStream is = null;
-
 
88
		try {
-
 
89
			is = res.getAntResource(null).getInputStream();
-
 
90
		} catch (IOException e) {
-
 
91
			// TODO Auto-generated catch block
-
 
92
			e.printStackTrace();
-
 
93
		}
-
 
94
		DataHandler h = new DataHandler(new StreamDataSource(
-
 
95
				"application/binary", is));
-
 
96
		AttachmentType t = new AttachmentType();
-
 
97
		t.setContent(h);
-
 
98
		return t;
-
 
99
	}
-
 
100
 
-
 
101
	/*
-
 
102
	 * (non-Javadoc)
-
 
103
	 * 
-
 
104
	 * @see
-
 
105
	 * net.brutex.xservices.ws.impl.FileService#base64Decode(net.brutex.xservices
-
 
106
	 * .types.AttachmentType)
-
 
107
	 */
-
 
108
	@Override
-
 
109
	@WebMethod(operationName = "uploadFile")
-
 
110
	public String uploadFile(@WebParam(name = "file") AttachmentType file) {
-
 
111
		DataHandler h =  file.getContent();
-
 
112
		File f = new File(file.getFilename());
-
 
113
		FileOutputStream fout;
-
 
114
		try {
-
 
115
			fout = new FileOutputStream(f);
-
 
116
			/*
-
 
117
			 * InputStream in = h.getInputStream();
-
 
118
			int b;
-
 
119
			while( (b=in.read())!= -1 ) {
-
 
120
				fout.write(b);
-
 
121
			}
-
 
122
			*/
-
 
123
			h.writeTo(fout);
-
 
124
			fout.flush();
-
 
125
			fout.close();
-
 
126
			//in.close();
-
 
127
		} catch (FileNotFoundException e) {
-
 
128
			throw new BuildException(e);
-
 
129
		} catch (IOException e) {
-
 
130
			throw new BuildException(e);
-
 
131
		}
-
 
132
		return file.getFilename();
-
 
133
	}
-
 
134
 
-
 
135
	/*
-
 
136
	 * (non-Javadoc)
-
 
137
	 * 
61
 
138
	 * @see
62
    /* (non-Javadoc)
139
	 * net.brutex.xservices.ws.impl.FileService#copy(net.brutex.xservices.types
63
	 * @see net.brutex.xservices.ws.impl.FileService#copy(net.brutex.xservices.types.FileSetResource, java.lang.String, boolean, boolean, java.lang.String)
140
	 * .FileSetResource, java.lang.String, boolean, boolean, java.lang.String)
64
	 */
141
	 */
65
    @Override
142
	@Override
66
	@WebMethod(operationName = "copy")
143
	@WebMethod(operationName = "copy")
67
    public ReturnCode copy(@WebParam(name = "fileset") FileSetResource src,
144
	public ReturnCode copy(@WebParam(name = "fileset") FileSetResource src,
68
            @WebParam(name = "todir") String todir,
-
 
69
            @WebParam(name = "preservelastmodified") boolean plm,
145
			@WebParam(name = "todir") String todir,
70
            @WebParam(name = "overwrite") boolean overwrite,
146
			@WebParam(name = "preservelastmodified") boolean plm,
71
            @WebParam(name = "encoding") String encoding)
147
			@WebParam(name = "overwrite") boolean overwrite,
-
 
148
			@WebParam(name = "encoding") String encoding) throws XServicesFault {
72
            throws XServicesFault {
149
		return copy(src, new File(todir), plm, overwrite, encoding);
-
 
150
	}
-
 
151
 
73
        return copy(src, new File(todir), plm, overwrite, encoding);
152
	/*
-
 
153
	 * (non-Javadoc)
74
    }
154
	 * 
75
 
155
	 * @see
76
    /* (non-Javadoc)
156
	 * net.brutex.xservices.ws.impl.FileService#loadRes(net.brutex.xservices
77
	 * @see net.brutex.xservices.ws.impl.FileService#loadRes(net.brutex.xservices.types.FileResource, java.lang.String)
157
	 * .types.FileResource, java.lang.String)
78
	 */
158
	 */
79
    @Override
159
	@Override
80
	@WebMethod(operationName = "loadResource")
160
	@WebMethod(operationName = "loadResource")
81
    public ReturnCode loadRes(@WebParam(name = "resource") FileResource res,
161
	public ReturnCode loadRes(@WebParam(name = "resource") FileResource res,
82
            @WebParam(name = "encoding") String encoding) {
162
			@WebParam(name = "encoding") String encoding) {
83
        if (encoding == null || encoding.equals("")) {
163
		if (encoding == null || encoding.equals("")) {
84
            encoding = System.getProperty("file.encoding");
164
			encoding = System.getProperty("file.encoding");
-
 
165
		}
85
        }
166
		return loadResource(res, encoding);
-
 
167
	}
-
 
168
 
86
        return loadResource(res, encoding);
169
	/*
-
 
170
	 * (non-Javadoc)
87
    }
171
	 * 
88
 
172
	 * @see
89
    /* (non-Javadoc)
173
	 * net.brutex.xservices.ws.impl.FileService#loadResFromArchive(net.brutex
-
 
174
	 * .xservices.types.ArchiveResource, java.lang.String)
90
	 * @see net.brutex.xservices.ws.impl.FileService#loadResFromArchive(net.brutex.xservices.types.ArchiveResource, java.lang.String)
175
	 */
91
	 */
176
	@Override
92
    @Override
177
	@WebMethod(operationName = "loadResourceFromArchive")
93
	@WebMethod(operationName = "loadResourceFromArchive")
178
	public ReturnCode loadResFromArchive(
94
    public ReturnCode loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
179
			@WebParam(name = "archiveresource") ArchiveResource res,
95
            @WebParam(name = "encoding") String encoding) {
180
			@WebParam(name = "encoding") String encoding) {
96
        if (encoding == null || encoding.equals("")) {
181
		if (encoding == null || encoding.equals("")) {
97
            encoding = System.getProperty("file.encoding");
182
			encoding = System.getProperty("file.encoding");
-
 
183
		}
98
        }
184
		return loadResource(res, encoding);
-
 
185
	}
99
        return loadResource(res, encoding);
186
 
-
 
187
	/*
100
    }
188
	 * (non-Javadoc)
101
 
189
	 * 
102
    /* (non-Javadoc)
190
	 * @see net.brutex.xservices.ws.impl.FileService#echo2file(java.lang.String,
103
	 * @see net.brutex.xservices.ws.impl.FileService#echo2file(java.lang.String, java.lang.String, java.lang.String, boolean)
191
	 * java.lang.String, java.lang.String, boolean)
-
 
192
	 */
104
	 */
193
	@Override
105
    @Override
194
	@WebMethod(operationName = "echoToFile")
106
	@WebMethod(operationName = "echoToFile")
195
	public ReturnCode echo2file(@WebParam(name = "message") String message,
107
    public ReturnCode echo2file(@WebParam(name = "message") String message,
196
			@WebParam(name = "file") String file,
108
            @WebParam(name = "file") String file, @WebParam(name = "encoding") String encoding,
197
			@WebParam(name = "encoding") String encoding,
-
 
198
			@WebParam(name = "append") boolean append) {
109
            @WebParam(name = "append") boolean append) {
199
		return echo(message, new File(file), encoding, append);
-
 
200
	}
-
 
201
 
110
        return echo(message, new File(file), encoding, append);
202
	/*
-
 
203
	 * (non-Javadoc)
111
    }
204
	 * 
112
 
205
	 * @see
113
    /* (non-Javadoc)
206
	 * net.brutex.xservices.ws.impl.FileService#changeOwner(net.brutex.xservices
-
 
207
	 * .types.FileSetResource, java.lang.String)
114
	 * @see net.brutex.xservices.ws.impl.FileService#changeOwner(net.brutex.xservices.types.FileSetResource, java.lang.String)
208
	 */
115
	 */
209
	@Override
116
    @Override
210
	@WebMethod(operationName = "changeOwner")
117
	@WebMethod(operationName = "changeOwner")
211
	public ReturnCode changeOwner(
118
    public ReturnCode changeOwner(@WebParam(name = "fileset") FileSetResource res,
212
			@WebParam(name = "fileset") FileSetResource res,
-
 
213
			@WebParam(name = "owner") String owner) {
119
            @WebParam(name = "owner") String owner) {
214
		return chown(res, owner);
-
 
215
	}
-
 
216
 
120
        return chown(res, owner);
217
	/*
-
 
218
	 * (non-Javadoc)
121
    }
219
	 * 
122
 
220
	 * @see
123
    /* (non-Javadoc)
221
	 * net.brutex.xservices.ws.impl.FileService#changeGroup(net.brutex.xservices
-
 
222
	 * .types.FileSetResource, java.lang.String)
124
	 * @see net.brutex.xservices.ws.impl.FileService#changeGroup(net.brutex.xservices.types.FileSetResource, java.lang.String)
223
	 */
125
	 */
224
	@Override
126
    @Override
225
	@WebMethod(operationName = "changeGroup")
127
	@WebMethod(operationName = "changeGroup")
226
	public ReturnCode changeGroup(
128
    public ReturnCode changeGroup(@WebParam(name = "fileset") FileSetResource res,
227
			@WebParam(name = "fileset") FileSetResource res,
-
 
228
			@WebParam(name = "group") String group) {
129
            @WebParam(name = "group") String group) {
229
		return chgrp(res, group);
-
 
230
	}
-
 
231
 
130
        return chgrp(res, group);
232
	/*
-
 
233
	 * (non-Javadoc)
131
    }
234
	 * 
132
 
235
	 * @see
133
    /* (non-Javadoc)
236
	 * net.brutex.xservices.ws.impl.FileService#changeMode(net.brutex.xservices
Line 238... Line 342...
238
        chmod.setPerm(perm);
342
		chmod.setPerm(perm);