Subversion Repositories XServices

Rev

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

Rev 6 Rev 12
Line 11... Line 11...
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
 
-
 
17
package net.brutex.xservices.ws;
16
package net.brutex.xservices.ws;
Line 18... Line 17...
18
 
17
 
19
import java.io.File;
-
 
20
import java.util.Map;
18
import java.io.File;
21
import javax.jws.WebMethod;
19
import javax.jws.WebMethod;
22
import javax.jws.WebParam;
20
import javax.jws.WebParam;
23
import javax.jws.WebService;
21
import javax.jws.WebService;
24
import net.brutex.xservices.types.ArchiveResource;
22
import net.brutex.xservices.types.ArchiveResource;
25
import net.brutex.xservices.types.FileResource;
23
import net.brutex.xservices.types.FileResource;
26
import net.brutex.xservices.types.FileSetResource;
24
import net.brutex.xservices.types.FileSetResource;
-
 
25
import net.brutex.xservices.types.ResourceInterface;
27
import net.brutex.xservices.types.ResourceInterface;
26
import net.brutex.xservices.types.ReturnCode;
28
import net.brutex.xservices.util.RunTask;
27
import net.brutex.xservices.util.RunTask;
29
import org.apache.tools.ant.taskdefs.Basename;
28
import org.apache.tools.ant.taskdefs.Basename;
30
import org.apache.tools.ant.taskdefs.Copy;
29
import org.apache.tools.ant.taskdefs.Copy;
31
import org.apache.tools.ant.taskdefs.Echo;
30
import org.apache.tools.ant.taskdefs.Echo;
-
 
31
import org.apache.tools.ant.taskdefs.LoadResource;
-
 
32
import org.apache.tools.ant.taskdefs.optional.unix.Chgrp;
32
import org.apache.tools.ant.taskdefs.LoadResource;
33
import org.apache.tools.ant.taskdefs.optional.unix.Chown;
Line 33... Line 34...
33
import org.apache.tools.ant.types.FileSet;
34
import org.apache.tools.ant.types.FileSet;
34
 
35
 
35
/**
36
/**
36
 *
37
 *
37
 * @author Brian Rosenberger, bru@brutex.de
38
 * @author Brian Rosenberger, bru@brutex.de
38
 */
39
 */
Line 39... Line 40...
39
@WebService(targetNamespace="http://ws.xservices.brutex.net", name="FileService")
40
@WebService(targetNamespace = "http://ws.xservices.brutex.net", name = "FileService")
40
public class FileService {
41
public class FileService {
41
 
42
 
42
    @WebMethod(operationName = "basename")
43
    @WebMethod(operationName = "basename")
43
    public String basename(@WebParam(name = "file") String filename,
44
    public ReturnCode basename(@WebParam(name = "file") String filename,
Line 44... Line 45...
44
            @WebParam(name = "suffix") String suffix) {
45
            @WebParam(name = "suffix") String suffix) {
45
        return basename(new File(filename), suffix);
46
        return basename(new File(filename), suffix);
46
    }
47
    }
47
 
48
 
48
    @WebMethod(operationName = "copy")
49
    @WebMethod(operationName = "copy")
49
    public void copy(@WebParam(name="fileset") FileSetResource src,
50
    public ReturnCode copy(@WebParam(name = "fileset") FileSetResource src,
50
            @WebParam(name="todir") String todir,
51
            @WebParam(name = "todir") String todir,
51
            @WebParam(name="preservelastmodified") boolean plm,
-
 
52
            @WebParam(name="overwrite") boolean overwrite,
52
            @WebParam(name = "preservelastmodified") boolean plm,
53
            @WebParam(name="encoding") String encoding)
-
 
54
    throws XServicesFault {
-
 
55
        try {
-
 
56
            copy(src, new File(todir), plm, overwrite, encoding);
53
            @WebParam(name = "overwrite") boolean overwrite,
Line 57... Line 54...
57
        } catch (Exception ex) {
54
            @WebParam(name = "encoding") String encoding)
58
            throw new XServicesFault(ex.getMessage(), ex);
55
            throws XServicesFault {
59
        }
56
        return copy(src, new File(todir), plm, overwrite, encoding);
60
    }
57
    }
61
 
58
 
62
    @WebMethod(operationName = "loadResource")
59
    @WebMethod(operationName = "loadResource")
63
    public String loadRes(@WebParam(name = "resource") FileResource res,
60
    public ReturnCode loadRes(@WebParam(name = "resource") FileResource res,
64
            @WebParam(name = "encoding") String encoding) {
61
            @WebParam(name = "encoding") String encoding) {
Line 65... Line 62...
65
        if (encoding == null || encoding.equals("")) {
62
        if (encoding == null || encoding.equals("")) {
66
            encoding = System.getProperty("file.encoding");
63
            encoding = System.getProperty("file.encoding");
67
        }
64
        }
68
        return loadResource(res, encoding);
65
        return loadResource(res, encoding);
69
    }
66
    }
70
 
67
 
71
    @WebMethod(operationName = "loadResourceFromArchive")
68
    @WebMethod(operationName = "loadResourceFromArchive")
72
    public String loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
69
    public ReturnCode loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
Line 73... Line 70...
73
            @WebParam(name = "encoding") String encoding) {
70
            @WebParam(name = "encoding") String encoding) {
74
        if (encoding == null || encoding.equals("")) {
71
        if (encoding == null || encoding.equals("")) {
75
            encoding = System.getProperty("file.encoding");
72
            encoding = System.getProperty("file.encoding");
76
        }
73
        }
77
        return loadResource(res, encoding);
74
        return loadResource(res, encoding);
78
    }
75
    }
Line -... Line 76...
-
 
76
 
-
 
77
    @WebMethod(operationName = "echoToFile")
-
 
78
    public ReturnCode echo2file(@WebParam(name = "message") String message,
-
 
79
            @WebParam(name = "file") String file, @WebParam(name = "encoding") String encoding,
-
 
80
            @WebParam(name = "append") boolean append) {
-
 
81
        return echo(message, new File(file), encoding, append);
-
 
82
    }
-
 
83
 
-
 
84
    @WebMethod(operationName = "changeOwner")
-
 
85
    public ReturnCode changeOwner(@WebParam(name = "fileset") FileSetResource res,
-
 
86
            @WebParam(name = "owner") String owner) {
-
 
87
        return chown(res, owner);
79
 
88
    }
80
    @WebMethod(operationName = "echoToFile")
89
 
81
    public String echo2file(@WebParam(name="message") String message,
90
    @WebMethod(operationName = "changeGroup")
82
            @WebParam(name="file")String file, @WebParam(name="encoding") String encoding,
91
    public ReturnCode changeGroup(@WebParam(name = "fileset") FileSetResource res,
83
            @WebParam(name="append")boolean append) {
92
            @WebParam(name = "group") String group) {
84
        return echo(message, new File(file), encoding, append);
93
        return chgrp(res, group);
85
    }
94
    }
86
 
95
 
87
    @WebMethod(exclude = true)
96
    @WebMethod(exclude = true)
88
    private String basename(File file,
97
    private ReturnCode basename(File file,
89
            String suffix) {
-
 
90
        Basename basename = new Basename();
98
            String suffix) {
91
        RunTask runner = new RunTask(basename);
99
        Basename basename = new Basename();
-
 
100
        RunTask runner = new RunTask(basename);
92
        basename.setFile(file);
101
        basename.setFile(file);
93
        if (suffix != null && !suffix.equals("")) {
102
        if (suffix != null && !suffix.equals("")) {
94
            basename.setSuffix(suffix);
103
            basename.setSuffix(suffix);
95
        }
104
        }
96
        basename.setProperty("basename.value");
105
        basename.setProperty("basename.value");
97
        Map<String, String> result = runner.postTask();
106
        return runner.postTask();
98
        return result.get("basename.value");
107
    }
99
    }
108
 
100
        @WebMethod(exclude = true)
109
    @WebMethod(exclude = true)
101
    private String loadResource(ResourceInterface src, String encoding) {
110
    private ReturnCode loadResource(ResourceInterface src, String encoding) {
102
        LoadResource lr = new LoadResource();
-
 
103
        lr.setTaskName("LoadResource");
111
        LoadResource lr = new LoadResource();
Line 104... Line 112...
104
        RunTask runner = new RunTask(lr);
112
        lr.setTaskName("LoadResource");
105
        lr.addConfigured(src.getAntResource(lr.getProject()));
113
        RunTask runner = new RunTask(lr);
106
        lr.setEncoding(encoding);
114
        lr.addConfigured(src.getAntResource(lr.getProject()));
107
        System.out.println("Using encoding: " + encoding);
115
        lr.setEncoding(encoding);
108
        lr.setProperty("LoadResource.out");
116
        System.out.println("Using encoding: " + encoding);
109
        Map<String, String> result = runner.postTask();
117
        lr.setProperty("LoadResource.out");
110
        return result.get("LoadResource.out");
118
        return runner.postTask();
111
    }
119
    }
112
 
120
 
113
    @WebMethod(exclude = true)
-
 
114
    private String echo(String msg, File file, String encoding, boolean append) {
121
    @WebMethod(exclude = true)
115
        Echo echo = new Echo();
122
    private ReturnCode echo(String msg, File file, String encoding, boolean append) {
Line 116... Line 123...
116
        echo.setTaskName("toFile");
123
        Echo echo = new Echo();
117
        RunTask runTask = new RunTask(echo);
124
        echo.setTaskName("toFile");
118
        echo.addText(msg);
125
        RunTask runTask = new RunTask(echo);
119
        echo.setEncoding(encoding);
126
        echo.addText(msg);
120
        echo.setFile(file);
127
        echo.setEncoding(encoding);
121
        echo.setAppend(append);
128
        echo.setFile(file);
122
        Map<String, String> result = runTask.postTask();
129
        echo.setAppend(append);
123
        return "complete";
130
        return runTask.postTask();
Line 124... Line 131...
124
    }
131
    }
-
 
132
 
-
 
133
    @WebMethod(exclude = true)
-
 
134
    private ReturnCode copy(FileSetResource src, File dst, boolean preservelastmodified,
125
 
135
            boolean overwrite, String encoding) {
-
 
136
        Copy copy = new Copy();
126
    @WebMethod(exclude=true)
137
        copy.setTaskName("Copy");
127
    private void copy(FileSetResource src, File dst, boolean preservelastmodified,
138
        RunTask runner = new RunTask(copy);
128
            boolean overwrite, String encoding) {
139
        FileSet set = src.getAntFileSet(copy.getProject());
129
        Copy copy = new Copy();
140
        copy.add(set);
130
        copy.setTaskName("Copy");
141
 
131
        RunTask runner = new RunTask(copy);
142
        if (dst.isDirectory()) {
132
        FileSet set = src.getAntFileSet(copy.getProject());
143
            copy.setTodir(dst);
Line 133... Line 144...
133
        copy.add(set);
144
        }
-
 
145
        if (dst.isFile()) {
-
 
146
            copy.setTofile(dst);
-
 
147
        }
-
 
148
        copy.setOverwrite(overwrite);
-
 
149
        copy.setPreserveLastModified(preservelastmodified);
-
 
150
        if (encoding != null && !encoding.equals("")) {
-
 
151
            copy.setOutputEncoding(encoding);
-
 
152
        } else {
-
 
153
            copy.setOutputEncoding(System.getProperty("file.encoding"));
-
 
154
        }
-
 
155
 
-
 
156
        return runner.postTask();
-
 
157
    }
-
 
158
 
-
 
159
    @WebMethod(exclude = true)
-
 
160
    private ReturnCode chown(FileSetResource src, String owner) {
-
 
161
        Chown chown = new Chown();
-
 
162
        chown.setTaskName("Chown");
-
 
163
        RunTask runner = new RunTask(chown);
-
 
164
        chown.setOwner(owner);
-
 
165
        FileSet set = src.getAntFileSet(chown.getProject());
-
 
166
        chown.add(set);
134
 
167
        return runner.postTask();
135
        if(dst.isDirectory()) copy.setTodir(dst);
168
    }