13,9 → 13,11 |
* See the License for the specific language governing permissions and |
* limitations under the License. |
*/ |
|
package net.brutex.xservices.ws; |
|
import java.io.File; |
import java.util.Map; |
import javax.jws.WebMethod; |
import javax.jws.WebParam; |
import javax.jws.WebService; |
23,14 → 25,11 |
import net.brutex.xservices.types.FileResource; |
import net.brutex.xservices.types.FileSetResource; |
import net.brutex.xservices.types.ResourceInterface; |
import net.brutex.xservices.types.ReturnCode; |
import net.brutex.xservices.util.RunTask; |
import org.apache.tools.ant.taskdefs.Basename; |
import org.apache.tools.ant.taskdefs.Copy; |
import org.apache.tools.ant.taskdefs.Echo; |
import org.apache.tools.ant.taskdefs.LoadResource; |
import org.apache.tools.ant.taskdefs.optional.unix.Chgrp; |
import org.apache.tools.ant.taskdefs.optional.unix.Chown; |
import org.apache.tools.ant.types.FileSet; |
|
/** |
37,27 → 36,31 |
* |
* @author Brian Rosenberger, bru@brutex.de |
*/ |
@WebService(targetNamespace = "http://ws.xservices.brutex.net", name = "FileService") |
@WebService(targetNamespace="http://ws.xservices.brutex.net", name="FileService") |
public class FileService { |
|
@WebMethod(operationName = "basename") |
public ReturnCode basename(@WebParam(name = "file") String filename, |
public String basename(@WebParam(name = "file") String filename, |
@WebParam(name = "suffix") String suffix) { |
return basename(new File(filename), suffix); |
} |
|
@WebMethod(operationName = "copy") |
public ReturnCode copy(@WebParam(name = "fileset") FileSetResource src, |
@WebParam(name = "todir") String todir, |
@WebParam(name = "preservelastmodified") boolean plm, |
@WebParam(name = "overwrite") boolean overwrite, |
@WebParam(name = "encoding") String encoding) |
throws XServicesFault { |
return copy(src, new File(todir), plm, overwrite, encoding); |
public void copy(@WebParam(name="fileset") FileSetResource src, |
@WebParam(name="todir") String todir, |
@WebParam(name="preservelastmodified") boolean plm, |
@WebParam(name="overwrite") boolean overwrite, |
@WebParam(name="encoding") String encoding) |
throws XServicesFault { |
try { |
copy(src, new File(todir), plm, overwrite, encoding); |
} catch (Exception ex) { |
throw new XServicesFault(ex.getMessage(), ex); |
} |
} |
|
@WebMethod(operationName = "loadResource") |
public ReturnCode loadRes(@WebParam(name = "resource") FileResource res, |
public String loadRes(@WebParam(name = "resource") FileResource res, |
@WebParam(name = "encoding") String encoding) { |
if (encoding == null || encoding.equals("")) { |
encoding = System.getProperty("file.encoding"); |
66,7 → 69,7 |
} |
|
@WebMethod(operationName = "loadResourceFromArchive") |
public ReturnCode loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res, |
public String loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res, |
@WebParam(name = "encoding") String encoding) { |
if (encoding == null || encoding.equals("")) { |
encoding = System.getProperty("file.encoding"); |
75,26 → 78,14 |
} |
|
@WebMethod(operationName = "echoToFile") |
public ReturnCode echo2file(@WebParam(name = "message") String message, |
@WebParam(name = "file") String file, @WebParam(name = "encoding") String encoding, |
@WebParam(name = "append") boolean append) { |
public String echo2file(@WebParam(name="message") String message, |
@WebParam(name="file")String file, @WebParam(name="encoding") String encoding, |
@WebParam(name="append")boolean append) { |
return echo(message, new File(file), encoding, append); |
} |
|
@WebMethod(operationName = "changeOwner") |
public ReturnCode changeOwner(@WebParam(name = "fileset") FileSetResource res, |
@WebParam(name = "owner") String owner) { |
return chown(res, owner); |
} |
|
@WebMethod(operationName = "changeGroup") |
public ReturnCode changeGroup(@WebParam(name = "fileset") FileSetResource res, |
@WebParam(name = "group") String group) { |
return chgrp(res, group); |
} |
|
@WebMethod(exclude = true) |
private ReturnCode basename(File file, |
private String basename(File file, |
String suffix) { |
Basename basename = new Basename(); |
RunTask runner = new RunTask(basename); |
103,11 → 94,11 |
basename.setSuffix(suffix); |
} |
basename.setProperty("basename.value"); |
return runner.postTask(); |
Map<String, String> result = runner.postTask(); |
return result.get("basename.value"); |
} |
|
@WebMethod(exclude = true) |
private ReturnCode loadResource(ResourceInterface src, String encoding) { |
@WebMethod(exclude = true) |
private String loadResource(ResourceInterface src, String encoding) { |
LoadResource lr = new LoadResource(); |
lr.setTaskName("LoadResource"); |
RunTask runner = new RunTask(lr); |
115,11 → 106,12 |
lr.setEncoding(encoding); |
System.out.println("Using encoding: " + encoding); |
lr.setProperty("LoadResource.out"); |
return runner.postTask(); |
Map<String, String> result = runner.postTask(); |
return result.get("LoadResource.out"); |
} |
|
@WebMethod(exclude = true) |
private ReturnCode echo(String msg, File file, String encoding, boolean append) { |
private String echo(String msg, File file, String encoding, boolean append) { |
Echo echo = new Echo(); |
echo.setTaskName("toFile"); |
RunTask runTask = new RunTask(echo); |
127,11 → 119,12 |
echo.setEncoding(encoding); |
echo.setFile(file); |
echo.setAppend(append); |
return runTask.postTask(); |
Map<String, String> result = runTask.postTask(); |
return "complete"; |
} |
|
@WebMethod(exclude = true) |
private ReturnCode copy(FileSetResource src, File dst, boolean preservelastmodified, |
@WebMethod(exclude=true) |
private void copy(FileSetResource src, File dst, boolean preservelastmodified, |
boolean overwrite, String encoding) { |
Copy copy = new Copy(); |
copy.setTaskName("Copy"); |
139,42 → 132,16 |
FileSet set = src.getAntFileSet(copy.getProject()); |
copy.add(set); |
|
if (dst.isDirectory()) { |
copy.setTodir(dst); |
} |
if (dst.isFile()) { |
copy.setTofile(dst); |
} |
if(dst.isDirectory()) copy.setTodir(dst); |
if(dst.isFile()) copy.setTofile(dst); |
copy.setOverwrite(overwrite); |
copy.setPreserveLastModified(preservelastmodified); |
if (encoding != null && !encoding.equals("")) { |
if(encoding!=null && !encoding.equals("") ) { |
copy.setOutputEncoding(encoding); |
} else { |
copy.setOutputEncoding(System.getProperty("file.encoding")); |
} |
|
return runner.postTask(); |
Map<String, String> result = runner.postTask(); |
} |
|
@WebMethod(exclude = true) |
private ReturnCode chown(FileSetResource src, String owner) { |
Chown chown = new Chown(); |
chown.setTaskName("Chown"); |
RunTask runner = new RunTask(chown); |
chown.setOwner(owner); |
FileSet set = src.getAntFileSet(chown.getProject()); |
chown.add(set); |
return runner.postTask(); |
} |
|
@WebMethod(exclude = true) |
private ReturnCode chgrp(FileSetResource src, String group) { |
Chgrp chgrp = new Chgrp(); |
chgrp.setTaskName("Chgrp"); |
RunTask runner = new RunTask(chgrp); |
chgrp.setGroup(group); |
FileSet set = src.getAntFileSet(chgrp.getProject()); |
chgrp.add(set); |
return runner.postTask(); |
} |
} |