FileDocCategorySizeDatePackage
URLResolver.javaAPI DocApache Ant 1.703923Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs.optional.extension.resolvers

URLResolver

public class URLResolver extends Object implements org.apache.tools.ant.taskdefs.optional.extension.ExtensionResolver
Resolver that just returns s specified location.

Fields Summary
private File
destfile
private File
destdir
private URL
url
Constructors Summary
Methods Summary
private java.io.FilegetDest()

        File result;
        if (null != destfile) {
            result = destfile;
        } else {
            final String file = url.getFile();
            String filename;
            if (null == file || file.length() <= 1) {
                filename = "default.file";
            } else {
                int index = file.lastIndexOf('/");
                if (-1 == index) {
                    index = 0;
                }
                filename = file.substring(index);
            }
            result = new File(destdir, filename);
        }
        return result;
    
public java.io.Fileresolve(org.apache.tools.ant.taskdefs.optional.extension.Extension extension, org.apache.tools.ant.Project project)
Returns the file resolved from URL and directory

param
extension the extention
param
project the project
return
file the file resolved
throws
BuildException if the URL is invalid

        validate();

        final File file = getDest();

        final Get get = new Get();
        get.setProject(project);
        get.setDest(file);
        get.setSrc(url);
        get.execute();

        return file;
    
public voidsetDestdir(java.io.File destdir)
Sets the destination directory

param
destdir the destination directory

        this.destdir = destdir;
    
public voidsetDestfile(java.io.File destfile)
Sets the destination file

param
destfile the destination file

        this.destfile = destfile;
    
public voidsetUrl(java.net.URL url)
Sets the URL

param
url the url

        this.url = url;
    
public java.lang.StringtoString()
Returns a string representation of the URL

return
the string representation

        return "URL[" + url + "]";
    
private voidvalidate()

        if (null == url) {
            final String message = "Must specify URL";
            throw new BuildException(message);
        }

        if (null == destdir && null == destfile) {
            final String message = "Must specify destination file or directory";
            throw new BuildException(message);
        } else if (null != destdir && null != destfile) {
            final String message = "Must not specify both destination file or directory";
            throw new BuildException(message);
        }