Subversion Repositories XServices

Rev

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

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