Subversion Repositories XServices

Rev

Rev 14 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14 Rev 46
Line 1... Line -...
1
/*
-
 
2
 *   Copyright 2010 Brian Rosenberger (Brutex Network)
-
 
3
 *
-
 
4
 *   Licensed under the Apache License, Version 2.0 (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
-
 
7
 *
-
 
8
 *       http://www.apache.org/licenses/LICENSE-2.0
-
 
9
 *
-
 
10
 *   Unless required by applicable law or agreed to in writing, software
-
 
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
-
 
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-
 
13
 *   See the License for the specific language governing permissions and
-
 
14
 *   limitations under the License.
-
 
15
 */
-
 
16
package net.brutex.xservices.ws;
1
package net.brutex.xservices.ws;
Line 17... Line -...
17
 
-
 
18
import java.io.File;
2
 
19
import javax.jws.WebMethod;
3
import javax.jws.WebMethod;
20
import javax.jws.WebParam;
4
import javax.jws.WebParam;
-
 
5
import javax.jws.WebService;
21
import javax.jws.WebService;
6
 
22
import net.brutex.xservices.types.ArchiveResource;
7
import net.brutex.xservices.types.ArchiveResource;
23
import net.brutex.xservices.types.FileResource;
8
import net.brutex.xservices.types.FileResource;
24
import net.brutex.xservices.types.FileSetResource;
-
 
25
import net.brutex.xservices.types.ResourceInterface;
9
import net.brutex.xservices.types.FileSetResource;
26
import net.brutex.xservices.types.ReturnCode;
10
import net.brutex.xservices.types.ReturnCode;
27
import net.brutex.xservices.util.RunTask;
-
 
28
import org.apache.tools.ant.taskdefs.Basename;
-
 
29
import org.apache.tools.ant.taskdefs.Chmod;
-
 
30
import org.apache.tools.ant.taskdefs.Copy;
-
 
31
import org.apache.tools.ant.taskdefs.Echo;
-
 
32
import org.apache.tools.ant.taskdefs.LoadResource;
-
 
33
import org.apache.tools.ant.taskdefs.optional.unix.Chgrp;
-
 
34
import org.apache.tools.ant.taskdefs.optional.unix.Chown;
-
 
35
import org.apache.tools.ant.types.FileSet;
-
 
36
 
-
 
37
/**
-
 
38
 *
-
 
39
 * @author Brian Rosenberger, bru@brutex.de
-
 
40
 */
11
import net.brutex.xservices.util.BrutexNamespaces;
41
@WebService(targetNamespace = "http://ws.xservices.brutex.net", name = "FileService")
12
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES)
Line 42... Line 13...
42
public class FileService {
13
public interface FileService {
43
 
14
 
44
    @WebMethod(operationName = "basename")
15
	@WebMethod(operationName = "basename")
45
    public ReturnCode basename(@WebParam(name = "file") String filename,
16
	public abstract ReturnCode basename(
46
            @WebParam(name = "suffix") String suffix) {
-
 
Line 47... Line 17...
47
        return basename(new File(filename), suffix);
17
			@WebParam(name = "file") String filename,
-
 
18
			@WebParam(name = "suffix") String suffix);
48
    }
19
 
49
 
20
	@WebMethod(operationName = "copy")
50
    @WebMethod(operationName = "copy")
21
	public abstract ReturnCode copy(
51
    public ReturnCode copy(@WebParam(name = "fileset") FileSetResource src,
22
			@WebParam(name = "fileset") FileSetResource src,
52
            @WebParam(name = "todir") String todir,
23
			@WebParam(name = "todir") String todir,
53
            @WebParam(name = "preservelastmodified") boolean plm,
-
 
54
            @WebParam(name = "overwrite") boolean overwrite,
-
 
55
            @WebParam(name = "encoding") String encoding)
-
 
Line 56... Line 24...
56
            throws XServicesFault {
24
			@WebParam(name = "preservelastmodified") boolean plm,
-
 
25
			@WebParam(name = "overwrite") boolean overwrite,
57
        return copy(src, new File(todir), plm, overwrite, encoding);
26
			@WebParam(name = "encoding") String encoding) throws XServicesFault;
58
    }
27
 
59
 
-
 
60
    @WebMethod(operationName = "loadResource")
-
 
61
    public ReturnCode loadRes(@WebParam(name = "resource") FileResource res,
-
 
62
            @WebParam(name = "encoding") String encoding) {
-
 
63
        if (encoding == null || encoding.equals("")) {
-
 
Line 64... Line 28...
64
            encoding = System.getProperty("file.encoding");
28
	@WebMethod(operationName = "loadResource")
65
        }
29
	public abstract ReturnCode loadRes(
66
        return loadResource(res, encoding);
30
			@WebParam(name = "resource") FileResource res,
67
    }
-
 
68
 
-
 
69
    @WebMethod(operationName = "loadResourceFromArchive")
-
 
70
    public ReturnCode loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
31
			@WebParam(name = "encoding") String encoding);
71
            @WebParam(name = "encoding") String encoding) {
-
 
Line 72... Line 32...
72
        if (encoding == null || encoding.equals("")) {
32
 
-
 
33
	@WebMethod(operationName = "loadResourceFromArchive")
73
            encoding = System.getProperty("file.encoding");
34
	public abstract ReturnCode loadResFromArchive(
74
        }
35
			@WebParam(name = "archiveresource") ArchiveResource res,
75
        return loadResource(res, encoding);
36
			@WebParam(name = "encoding") String encoding);
76
    }
37
 
77
 
-
 
Line 78... Line 38...
78
    @WebMethod(operationName = "echoToFile")
38
	@WebMethod(operationName = "echoToFile")
79
    public ReturnCode echo2file(@WebParam(name = "message") String message,
39
	public abstract ReturnCode echo2file(
80
            @WebParam(name = "file") String file, @WebParam(name = "encoding") String encoding,
40
			@WebParam(name = "message") String message,
81
            @WebParam(name = "append") boolean append) {
41
			@WebParam(name = "file") String file,
82
        return echo(message, new File(file), encoding, append);
-
 
Line 83... Line 42...
83
    }
42
			@WebParam(name = "encoding") String encoding,
84
 
43
			@WebParam(name = "append") boolean append);
85
    @WebMethod(operationName = "changeOwner")
44
 
86
    public ReturnCode changeOwner(@WebParam(name = "fileset") FileSetResource res,
45
	@WebMethod(operationName = "changeOwner")
87
            @WebParam(name = "owner") String owner) {
-
 
Line 88... Line 46...
88
        return chown(res, owner);
46
	public abstract ReturnCode changeOwner(
89
    }
-
 
90
 
-
 
91
    @WebMethod(operationName = "changeGroup")
-
 
92
    public ReturnCode changeGroup(@WebParam(name = "fileset") FileSetResource res,
-
 
93
            @WebParam(name = "group") String group) {
-
 
94
        return chgrp(res, group);
-
 
95
    }
47
			@WebParam(name = "fileset") FileSetResource res,
96
 
-
 
97
    @WebMethod(operationName = "changeMode")
-
 
98
    public ReturnCode changeMode(@WebParam(name="fileset") FileSetResource res,
-
 
99
            @WebParam(name="permissions") String perm) {
-
 
100
        return chmod(res, perm);
-
 
101
    }
-
 
102
 
-
 
103
    @WebMethod(exclude = true)
-
 
104
    private ReturnCode basename(File file,
-
 
105
            String suffix) {
-
 
106
        Basename basename = new Basename();
-
 
107
        RunTask runner = new RunTask(basename);
-
 
108
        basename.setFile(file);
-
 
109
        if (suffix != null && !suffix.equals("")) {
-
 
110
            basename.setSuffix(suffix);
-
 
111
        }
-
 
112
        basename.setProperty("basename.value");
-
 
113
        return runner.postTask();
-
 
114
    }
-
 
115
 
-
 
116
    @WebMethod(exclude = true)
-
 
117
    private ReturnCode loadResource(ResourceInterface src, String encoding) {
-
 
118
        LoadResource lr = new LoadResource();
-
 
119
        lr.setTaskName("LoadResource");
-
 
120
        RunTask runner = new RunTask(lr);
-
 
121
        lr.addConfigured(src.getAntResource(lr.getProject()));
-
 
122
        lr.setEncoding(encoding);
-
 
123
        System.out.println("Using encoding: " + encoding);
-
 
124
        lr.setProperty("LoadResource.out");
-
 
125
        return runner.postTask();
-
 
126
    }
-
 
127
 
-
 
128
    @WebMethod(exclude = true)
-
 
129
    private ReturnCode echo(String msg, File file, String encoding, boolean append) {
-
 
130
        Echo echo = new Echo();
-
 
131
        echo.setTaskName("toFile");
-
 
132
        RunTask runTask = new RunTask(echo);
-
 
133
        echo.addText(msg);
-
 
134
        echo.setEncoding(encoding);
-
 
135
        echo.setFile(file);
-
 
136
        echo.setAppend(append);
-
 
137
        return runTask.postTask();
-
 
138
    }
-
 
139
 
-
 
140
    @WebMethod(exclude = true)
-
 
141
    private ReturnCode copy(FileSetResource src, File dst, boolean preservelastmodified,
-
 
142
            boolean overwrite, String encoding) {
-
 
143
        Copy copy = new Copy();
-
 
144
        copy.setTaskName("Copy");
-
 
145
        RunTask runner = new RunTask(copy);
-
 
146
        FileSet set = src.getAntFileSet(copy.getProject());
-
 
147
        copy.add(set);
-
 
148
 
-
 
149
        if (dst.isDirectory()) {
-
 
150
            copy.setTodir(dst);
-
 
151
        }
-
 
152
        if (dst.isFile()) {
-
 
153
            copy.setTofile(dst);
-
 
154
        }
-
 
155
        copy.setOverwrite(overwrite);
-
 
156
        copy.setPreserveLastModified(preservelastmodified);
-
 
157
        if (encoding != null && !encoding.equals("")) {
-
 
158
            copy.setOutputEncoding(encoding);
-
 
159
        } else {
-
 
160
            copy.setOutputEncoding(System.getProperty("file.encoding"));
-
 
161
        }
-
 
162
 
-
 
163
        return runner.postTask();
48
			@WebParam(name = "owner") String owner);
164
    }
-
 
165
 
-
 
166
    @WebMethod(exclude = true)
-
 
167
    private ReturnCode chown(FileSetResource src, String owner) {
-
 
168
        Chown chown = new Chown();
-
 
169
        chown.setTaskName("Chown");
-
 
170
        RunTask runner = new RunTask(chown);
-
 
171
        chown.setOwner(owner);
-
 
172
        FileSet set = src.getAntFileSet(chown.getProject());
-
 
173
        chown.add(set);
-
 
174
        chown.setMaxParallel(300);
-
 
175
        return runner.postTask();
-
 
176
    }
-
 
177
 
-
 
178
    @WebMethod(exclude = true)
-
 
179
    private ReturnCode chgrp(FileSetResource src, String group) {
-
 
180
        Chgrp chgrp = new Chgrp();
-
 
181
        chgrp.setTaskName("Chgrp");
-
 
182
        RunTask runner = new RunTask(chgrp);
49
 
183
        chgrp.setGroup(group);
-
 
184
        FileSet set = src.getAntFileSet(chgrp.getProject());
-
 
185
        chgrp.add(set);
-
 
186
        chgrp.setMaxParallel(300);
-
 
187
        return runner.postTask();
-
 
188
    }
-
 
189
 
-
 
190
    @WebMethod(exclude = true)
-
 
191
    private ReturnCode chmod(FileSetResource src, String perm) {
-
 
192
        Chmod chmod = new Chmod();
-
 
Line 193... Line 50...
193
        chmod.setTaskName("Chmod");
50
	@WebMethod(operationName = "changeGroup")