Example usage for org.apache.commons.httpclient.util URIUtil getName

List of usage examples for org.apache.commons.httpclient.util URIUtil getName

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.util URIUtil getName.

Prototype

public static String getName(String uri) 

Source Link

Document

Get the basename of an URI.

Usage

From source file:com.opoopress.maven.plugins.plugin.PluginMojo.java

@Override
protected void executeInternal(ConfigImpl config) throws MojoExecutionException, MojoFailureException {
    String pluginDir = config.get("plugin_dir");
    File plugins = new File(config.getBasedir(), pluginDir);

    URL url = null;//w  w  w. j a v a  2s.c  om

    if (plugin != null) {
        String str = plugin.toLowerCase();
        //url
        if (str.startsWith("http://") || str.startsWith("https://")) {
            try {
                url = new URL(plugin);
            } catch (MalformedURLException e) {
                throw new MojoFailureException("Not a valid url: " + plugin, e);
            }
        } else {
            //groupId:artifactId:version[:packaging][:classifier]
            String[] tokens = StringUtils.split(plugin, ":");
            if (tokens.length < 3 || tokens.length > 5) {
                throw new MojoFailureException(
                        "Invalid plugin artifact, you must specify groupId:artifactId:version[:packaging][:classifier] "
                                + plugin);
            }
            groupId = tokens[0];
            artifactId = tokens[1];
            version = tokens[2];
            if (tokens.length >= 4) {
                type = tokens[3];
            }
            if (tokens.length == 5) {
                classifier = tokens[4];
            } else {
                classifier = null;
            }
        }
    }

    //url
    if (url != null) {
        String filename = URIUtil.getName(plugin);
        File pluginFile = new File(plugins, filename);
        if (pluginFile.exists()) {
            getLog().info("Plugin already exists: " + pluginFile);
            return;
        }

        try {
            new ProgressURLDownloader().setQuiet(false).download(url, pluginFile);
        } catch (IOException e) {
            throw new MojoFailureException("Download plugin file failed: " + e.getMessage(), e);
        }
        return;
    }

    //artifact
    if (StringUtils.isBlank(groupId) || StringUtils.isBlank(artifactId)) {

        if (version != null) {
            String filename = artifactId + "-" + version + (classifier != null ? "-" + classifier : "") + "."
                    + type;

            File pluginFile = new File(plugins, filename);
            if (pluginFile.exists()) {
                getLog().info("Plugin already exists: " + pluginFile);
                return;
            }
        }

        ArtifactDownloader downloader = new DefaultArtifactDownloader(getLog(), artifactFactory,
                artifactResolver, localRepository, remoteArtifactRepositories, remoteRepositories,
                repositoryLayouts, artifactRepositoryFactory, artifactMetadataSource, enableOpooPressRepos);

        File file = downloader.download(groupId, artifactId, version, classifier, type);

        File pluginFile = new File(plugins, file.getName());
        if (pluginFile.exists()) {
            getLog().info("Plugin already exists: " + pluginFile);
        } else {
            getLog().info("Install plugin: " + pluginFile);
            try {
                FileUtils.copyFile(file, pluginFile);
            } catch (IOException e) {
                throw new MojoFailureException("Copy plugin file failed: " + e.getMessage(), e);
            }
        }
    }
}

From source file:com.opoopress.maven.plugins.plugin.ThemeMojo.java

private void processParameters() throws MojoFailureException {
    if (name != null) {
        if (name.startsWith(OP_THEME_ARTIFACT_PREFIX)) {
            if (artifactId == null) {
                artifactId = name;/*ww w.j  ava 2s  .com*/
            }
            name = name.substring(OP_THEME_ARTIFACT_PREFIX_LENGTH);
        } else {
            if (artifactId == null) {
                artifactId = OP_THEME_ARTIFACT_PREFIX + name;
            }
        }
    }

    //        URL url = null;

    if (theme != null) {
        String str = theme.toLowerCase();
        //url
        if (str.startsWith("http://") || str.startsWith("https://")) {
            try {
                url = new URL(theme);
            } catch (MalformedURLException e) {
                throw new MojoFailureException("Not a valid url: " + theme, e);
            }
            if (name == null) {
                String filename = URIUtil.getName(theme);
                name = FilenameUtils.removeExtension(filename);
            }
        } else {
            //groupId:artifactId:version[:packaging][:classifier]
            String[] tokens = StringUtils.split(theme, ":");
            if (tokens.length < 3 || tokens.length > 5) {
                throw new MojoFailureException(
                        "Invalid theme artifact, you must specify groupId:artifactId:version[:packaging][:classifier] "
                                + theme);
            }
            groupId = tokens[0];
            artifactId = tokens[1];
            version = tokens[2];
            if (tokens.length >= 4) {
                type = tokens[3];
            }
            if (tokens.length == 5) {
                classifier = tokens[4];
            } else {
                classifier = null;
            }

            if (name == null) {
                if (artifactId.startsWith(OP_THEME_ARTIFACT_PREFIX)) {
                    name = artifactId.substring(OP_THEME_ARTIFACT_PREFIX_LENGTH);
                } else {
                    name = artifactId;
                }
            }
        }
    }
}

From source file:org.apache.webdav.cmd.Client.java

void get(String path, String filename) {

    filename = getLocalTragetFileName(path, filename);

    try {/*  w  w  w  . j  a  v  a  2s .  c  om*/
        // The resource on the remote.
        String src = checkUri(path);
        // The file on the local.
        String dest = (filename != null) ? filename
                : URIUtil.getName(src.endsWith("/") ? src.substring(0, src.length() - 1) : src);

        out.println("get " + src + " " + dest);

        // For the overwrite operation;
        String y = "y";
        File file = new File(dest);
        // Checking the local file.
        if (file.exists()) {

            // FIXME: interactive ?
            out.print("Aleady exists. " + "Do you want to overwrite it(y/n)? ");
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            y = in.readLine();
        }
        if (y.trim().equalsIgnoreCase("y") || (y != null && y.length() == 0)) {
            out.print("Downloading  '" + src + "' to '" + dest + "': ");
            if (webdavResource.getMethod(src, file)) {
                out.println("succeeded.");
            } else {
                out.println("failed.");
                out.println(webdavResource.getStatusMessage());
            }
        }
    } catch (Exception ex) {
        handleException(ex);
    }
}

From source file:org.apache.webdav.lib.WebdavResource.java

private static String getName(String uri, boolean decode) {
    String escapedName = URIUtil.getName(uri.endsWith("/") ? uri.substring(0, uri.length() - 1) : uri);
    if (decode) {
        try {// w  ww  .j ava2  s  . c om
            return URIUtil.decode(escapedName);
        } catch (URIException e) {
            // Oh well
        }
    }
    return escapedName;
}

From source file:org.apache.webdav.lib.WebdavFile.java

public String getName() {
    if (relPath != null)
        return relPath;
    String escapedPath = httpUrl.getEscapedPath();
    String escapedName = URIUtil.getName(
            escapedPath.endsWith("/") ? escapedPath.substring(0, escapedPath.length() - 1) : escapedPath);
    try {//  w  ww .  j  a  v  a  2  s.co m
        return URIUtil.decode(escapedName);
    } catch (URIException e) {
        return escapedName;
    }
}

From source file:org.cloudfoundry.identity.uaa.provider.oauth.XOAuthAuthenticationFilter.java

public boolean authenticationWasSuccessful(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    String origin = URIUtil.getName(request.getServletPath());
    String code = request.getParameter("code");
    String idToken = request.getParameter("id_token");
    String accessToken = request.getParameter("access_token");
    String redirectUrl = request.getRequestURL().toString();
    XOAuthCodeToken codeToken = new XOAuthCodeToken(code, origin, redirectUrl, idToken, accessToken);
    codeToken.setDetails(new UaaAuthenticationDetails(request));
    try {/*from w  w  w  .ja va  2s . c o  m*/
        Authentication authentication = xOAuthAuthenticationManager.authenticate(codeToken);
        SecurityContextHolder.getContext().setAuthentication(authentication);
        ofNullable(successHandler)
                .ifPresent(handler -> handler.setSavedAccountOptionCookie(request, response, authentication));
    } catch (Exception ex) {
        logger.error("XOauth Authentication exception", ex);
        String message = ex.getMessage();
        if (!hasText(message)) {
            message = ex.getClass().getSimpleName();
        }
        String errorMessage = URLEncoder.encode(
                "There was an error when authenticating against the external identity provider: " + message,
                "UTF-8");
        response.sendRedirect(request.getContextPath() + "/oauth_error?error=" + errorMessage);
        return false;
    }
    return true;
}

From source file:org.pengyou.client.lib.DavResource.java

private static String getName(String uri) {
    String escapedName = URIUtil.getName(uri.endsWith("/") ? uri.substring(0, uri.length() - 1) : uri);
    try {/*from w  w  w.  j  a va2  s .c o m*/
        return URIUtil.decode(escapedName);
    } catch (URIException e) {
        return escapedName;
    }
}