15,6 → 15,8 |
*/ |
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; |
21,17 → 23,24 |
import net.brutex.xservices.types.ArchiveResource; |
import net.brutex.xservices.types.CompressionType; |
import net.brutex.xservices.types.FileResource; |
|
import net.brutex.xservices.types.ResourceInterface; |
import net.brutex.xservices.types.ReturnCode; |
import net.brutex.xservices.util.BrutexNamespaces; |
import net.brutex.xservices.util.RunTask; |
import net.brutex.xservices.util.UnRarTask; |
import org.apache.tools.ant.taskdefs.BUnzip2; |
import org.apache.tools.ant.taskdefs.BZip2; |
import org.apache.tools.ant.taskdefs.Expand; |
import org.apache.tools.ant.taskdefs.GUnzip; |
import org.apache.tools.ant.taskdefs.GZip; |
import org.apache.tools.ant.taskdefs.Untar; |
import org.apache.tools.ant.taskdefs.Zip; |
|
|
/** |
* |
* @author Brian Rosenberger, bru@brutex.de |
*/ |
@WebService(targetNamespace = BrutexNamespaces.WS_XSERVICES) |
public interface ArchiveService { |
@WebService(targetNamespace = "http://ws.xservices.brutex.net", name = "ArchiveService") |
public class ArchiveService { |
|
public static final String WS_OPERATION_BZIP2 = "bzip2"; |
public static final String WS_OPERATION_BZIP2_ARCHIVE = "bzip2FromArchive"; |
51,35 → 60,67 |
|
@WebMethod(operationName = WS_OPERATION_BZIP2, action = WS_OPERATION_BZIP2) |
public ReturnCode bzip2(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src, |
@WebParam(name = WS_PARAM_DESTFILE) String file); |
@WebParam(name = WS_PARAM_DESTFILE) String file) { |
return bzip(src, new File(file)); |
} |
|
@WebMethod(operationName = WS_OPERATION_BZIP2_ARCHIVE, action = WS_OPERATION_BZIP2_ARCHIVE) |
public ReturnCode bzip2FromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src, |
@WebParam(name = WS_PARAM_DESTFILE) String file); |
@WebParam(name = WS_PARAM_DESTFILE) String file) { |
return bzip(src, new File(file)); |
} |
|
@WebMethod(operationName = WS_OPERATION_GZIP, action = WS_OPERATION_GZIP) |
public ReturnCode gzip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src, |
@WebParam(name = WS_PARAM_DESTFILE) String file); |
@WebParam(name = WS_PARAM_DESTFILE) String file) { |
return gzip(src, new File(file)); |
} |
|
@WebMethod(operationName = WS_OPERATION_GZIP_ARCHIVE, action = WS_OPERATION_GZIP_ARCHIVE) |
public ReturnCode gzipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src, |
@WebParam(name = WS_PARAM_DESTFILE) String file); |
@WebParam(name = WS_PARAM_DESTFILE) String file) { |
return gzip(src, new File(file)); |
} |
|
@WebMethod(operationName = WS_OPERATION_GUNZIP, action = WS_OPERATION_GUNZIP) |
public ReturnCode gunzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src, |
@WebParam(name = WS_PARAM_DESTDIR) String dest); |
@WebParam(name = WS_PARAM_DESTDIR) String dest) { |
File target = null; |
if (!dest.equals("") && dest != null) { |
target = new File(dest); |
} |
return GUnzip(new FileResource(FileResource.Type.FILE, src), target); |
} |
|
@WebMethod(operationName = WS_OPERATION_BUNZIP2) |
public ReturnCode bunzip2(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src, |
@WebParam(name = WS_PARAM_DESTDIR) String dest); |
@WebParam(name = WS_PARAM_DESTDIR) String dest) { |
File target = null; |
if (!dest.equals("") && dest != null) { |
target = new File(dest); |
} |
return BUnzip2(new FileResource(FileResource.Type.FILE, src), target); |
} |
|
@WebMethod(operationName = "gunzipFromURL") |
public ReturnCode gunzipFromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src, |
@WebParam(name = WS_PARAM_DESTDIR) String dest); |
@WebParam(name = WS_PARAM_DESTDIR) String dest) { |
File target = null; |
if (!dest.equals("") && dest != null) { |
target = new File(dest); |
} |
return GUnzip(new FileResource(FileResource.Type.URL, src), target); |
} |
|
@WebMethod(operationName = "bunzip2FromURL") |
public ReturnCode bunzip2FromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src, |
@WebParam(name = WS_PARAM_DESTDIR) String dest); |
@WebParam(name = WS_PARAM_DESTDIR) String dest) { |
File target = null; |
if (!dest.equals("") && dest != null) { |
target = new File(dest); |
} |
return BUnzip2(new FileResource(FileResource.Type.URL, src), target); |
} |
|
@WebMethod(operationName = "zip") |
public ReturnCode zip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src, |
86,7 → 127,15 |
@WebParam(name = WS_PARAM_DESTFILE) String file, |
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite, |
@WebParam(name = WS_PARAM_ENCODING) String encoding, |
@WebParam(name = "compresslevel") int level); |
@WebParam(name = "compresslevel") int level) { |
if (level > 9) { |
level = 9; |
} |
if (level < 0) { |
level = 0; |
} |
return zip(src, new File(file), encoding, !overwrite, level); |
} |
|
@WebMethod(operationName = "zipFromArchive") |
public ReturnCode zipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src, |
93,21 → 142,143 |
@WebParam(name = WS_PARAM_DESTFILE) String file, |
@WebParam(name = WS_PARAM_OVERWRITE) boolean update, |
@WebParam(name = WS_PARAM_ENCODING) String encoding, |
@WebParam(name = "compresslevel") int level); |
@WebParam(name = "compresslevel") int level) { |
return zip(src, new File(file), encoding, !update, level); |
} |
|
@WebMethod(operationName = "unzip") |
public ReturnCode unzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src, |
@WebParam(name = WS_PARAM_DESTDIR) String dest, |
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite, |
@WebParam(name = WS_PARAM_ENCODING) String encoding); |
@WebParam(name = WS_PARAM_ENCODING) String encoding) { |
return unzip(new File(src), new File(dest), overwrite, encoding); |
} |
|
@WebMethod(operationName = "unrar") |
public ReturnCode unrar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src, |
@WebParam(name = WS_PARAM_DESTDIR) String dest); |
@WebParam(name = WS_PARAM_DESTDIR) String dest) { |
return unrar(new File(src), new File(dest)); |
} |
|
@WebMethod(operationName = "untar") |
public ReturnCode untar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src, |
@WebParam(name = WS_PARAM_DESTDIR) String dest, |
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite, |
@WebParam(name = "compression") CompressionType compression); |
@WebParam(name = "compression") CompressionType compression) { |
Untar.UntarCompressionMethod c = new Untar.UntarCompressionMethod(); |
switch (compression) { |
case GZIP: |
c.setValue("gzip"); |
break; |
case BZIP2: |
c.setValue("bzip2"); |
break; |
default: |
c.setValue("none"); |
break; |
} |
return untar(new File(src), new File(dest), overwrite, c); |
} |
|
@WebMethod(exclude = true) |
private ReturnCode bzip(ResourceInterface src, File dst) { |
if (dst.exists() && dst.isFile()) { |
dst.delete(); |
} |
BZip2 bzip = new BZip2(); |
bzip.setTaskName("BZip2"); |
RunTask runner = new RunTask(bzip); |
bzip.setSrcResource(src.getAntResource(bzip.getProject())); |
bzip.setDestfile(dst); |
|
return runner.postTask(); |
} |
|
@WebMethod(exclude = true) |
private ReturnCode gzip(ResourceInterface src, File dst) { |
if (dst.exists() && dst.isFile()) { |
dst.delete(); |
} |
GZip gzip = new GZip(); |
gzip.setTaskName("GZip"); |
RunTask runner = new RunTask(gzip); |
gzip.addConfigured(src.getAntResource(gzip.getProject())); |
gzip.setDestfile(dst); |
return runner.postTask(); |
} |
|
@WebMethod(exclude = true) |
private ReturnCode zip(ResourceInterface src, File dst, String encoding, boolean update, int compresslevel) { |
Zip zip = new Zip(); |
zip.setTaskName("Zip"); |
RunTask runner = new RunTask(zip); |
zip.add(src.getAntResource(zip.getProject())); |
zip.setDestFile(dst); |
if (encoding != null && !encoding.equals("")) { |
zip.setEncoding(encoding); |
} |
zip.setUpdate(update); |
zip.setLevel(compresslevel); |
return runner.postTask(); |
} |
|
@WebMethod(exclude = true) |
private ReturnCode GUnzip(ResourceInterface src, File dst) { |
GUnzip uz = new GUnzip(); |
uz.setTaskName("GUnzip"); |
RunTask runner = new RunTask(uz); |
uz.setSrcResource(src.getAntResource(uz.getProject())); |
if (dst != null) { |
uz.setDest(dst); |
} |
return runner.postTask(); |
} |
|
@WebMethod(exclude = true) |
private ReturnCode BUnzip2(ResourceInterface src, File dst) { |
BUnzip2 uz = new BUnzip2(); |
uz.setTaskName("BUnzip2"); |
RunTask runner = new RunTask(uz); |
uz.setSrcResource(src.getAntResource(uz.getProject())); |
if (dst != null) { |
uz.setDest(dst); |
} |
return runner.postTask(); |
} |
|
@WebMethod(exclude = true) |
private ReturnCode unzip(File src, File dest, boolean overwrite, String encoding) { |
Expand unzip = new Expand(); |
unzip.setTaskName("UnZip"); |
RunTask runner = new RunTask(unzip); |
unzip.setSrc(src); |
unzip.setDest(dest); |
unzip.setOverwrite(overwrite); |
if (encoding != null && !encoding.equals("")) { |
unzip.setEncoding(encoding); |
} |
return runner.postTask(); |
} |
|
@WebMethod(exclude = true) |
private ReturnCode untar(File src, File dest, boolean overwrite, Untar.UntarCompressionMethod compression) { |
Untar unzip = new Untar(); |
unzip.setTaskName("Untar"); |
RunTask runner = new RunTask(unzip); |
unzip.setSrc(src); |
unzip.setDest(dest); |
unzip.setOverwrite(overwrite); |
unzip.setCompression(compression); |
return runner.postTask(); |
} |
|
@WebMethod(exclude = true) |
private ReturnCode unrar(File src, File dst) { |
UnRarTask unrar = new UnRarTask(); |
unrar.setTaskName("UnRar"); |
RunTask runner = new RunTask(unrar); |
unrar.setSrc(src); |
unrar.setDst(dst); |
return runner.postTask(); |
} |
} |