Example usage for org.apache.commons.lang StringUtils substringAfterLast

List of usage examples for org.apache.commons.lang StringUtils substringAfterLast

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substringAfterLast.

Prototype

public static String substringAfterLast(String str, String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:com.dp2345.plugin.ftp.FtpPlugin.java

@Override
public void upload(String path, File file, String contentType) {
    PluginConfig pluginConfig = getPluginConfig();
    if (pluginConfig != null) {
        String host = pluginConfig.getAttribute("host");
        Integer port = Integer.valueOf(pluginConfig.getAttribute("port"));
        String username = pluginConfig.getAttribute("username");
        String password = pluginConfig.getAttribute("password");
        FTPClient ftpClient = new FTPClient();
        InputStream inputStream = null;
        try {//from  ww w .  j  av a 2s . co m
            inputStream = new FileInputStream(file);
            ftpClient.connect(host, port);
            ftpClient.login(username, password);
            ftpClient.setFileTransferMode(FTP.STREAM_TRANSFER_MODE);
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
            ftpClient.enterLocalPassiveMode();
            if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
                String directory = StringUtils.substringBeforeLast(path, "/");
                String filename = StringUtils.substringAfterLast(path, "/");
                if (!ftpClient.changeWorkingDirectory(directory)) {
                    String[] paths = StringUtils.split(directory, "/");
                    String p = "/";
                    ftpClient.changeWorkingDirectory(p);
                    for (String s : paths) {
                        p += s + "/";
                        if (!ftpClient.changeWorkingDirectory(p)) {
                            ftpClient.makeDirectory(s);
                            ftpClient.changeWorkingDirectory(p);
                        }
                    }
                }
                ftpClient.storeFile(filename, inputStream);
                ftpClient.logout();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(inputStream);
            if (ftpClient.isConnected()) {
                try {
                    ftpClient.disconnect();
                } catch (IOException e) {
                }
            }
        }
    }
}

From source file:com.cloud.servlet.StaticResourceServlet.java

static String getContentType(final String fileName) {
    return contentTypes.get(StringUtils.lowerCase(StringUtils.substringAfterLast(fileName, ".")));
}

From source file:com.adobe.acs.tools.csv_asset_importer.impl.Column.java

public Column(final String raw, final int index) {
    this.index = index;
    this.raw = StringUtils.trim(raw);

    String paramsStr = StringUtils.substringBetween(raw, "{{", "}}");
    String[] params = StringUtils.split(paramsStr, ":");

    if (StringUtils.isBlank(paramsStr)) {
        this.relPropertyPath = this.getRaw();
    } else {//from   www  . ja  v  a2  s.c o m
        this.relPropertyPath = StringUtils.trim(StringUtils.substringBefore(this.getRaw(), "{{"));

        if (params.length == 2) {
            this.dataType = nameToClass(StringUtils.stripToEmpty(params[0]));
            this.multi = StringUtils.equalsIgnoreCase(StringUtils.stripToEmpty(params[1]), MULTI);
        }

        if (params.length == 1) {
            if (StringUtils.equalsIgnoreCase(MULTI, StringUtils.stripToEmpty(params[0]))) {
                this.multi = true;
            } else {
                this.dataType = nameToClass(StringUtils.stripToEmpty(params[0]));
            }
        }
    }

    if (StringUtils.contains(this.relPropertyPath, "/")) {
        this.propertyName = StringUtils.trim(StringUtils.substringAfterLast(this.relPropertyPath, "/"));
    } else {
        this.propertyName = StringUtils.trim(this.relPropertyPath);
    }

}

From source file:info.magnolia.module.delta.BootstrapConditionally.java

private static String cleanupFilename(String filename) {
    filename = StringUtils.replace(filename, "\\", "/");
    filename = StringUtils.substringAfterLast(filename, "/");
    filename = StringUtils.substringBeforeLast(filename, ".");

    return StringUtils.removeEnd(filename, DataTransporter.XML);
}

From source file:adalid.util.info.JavaInfo.java

public static void printManifestInfo(String extension, boolean details, File file) throws IOException {
    //      String absolutePath = file.getAbsolutePath();
    //      String canonicalPath = file.getCanonicalPath();
    String path = StringUtils.removeEndIgnoreCase(file.getPath(), FILE_SEP + MANIFEST_NAME);
    String name = StringUtils.substringAfterLast(path, FILE_SEP);
    InputStream stream = new FileInputStream(file);
    Manifest manifest = new Manifest(stream);
    if (!extensionNameMatches(manifest, extension)) {
        return;/*from ww w.  ja  v a  2  s .c o m*/
    }
    //      out.println(absolutePath);
    //      out.println(canonicalPath);
    printManifestInfo(path, name, details, manifest);
}

From source file:eionet.cr.filestore.ScriptTemplateDaoImpl.java

/**
 * {@inheritDoc}/*  www  .  j a v a2 s.co  m*/
 */
@Override
public ScriptTemplateDTO getScriptTemplate(String id) {
    ScriptTemplateDTO result = new ScriptTemplateDTO();
    result.setId(id);
    for (Object key : PROPERTIES.keySet()) {
        String currentId = StringUtils.substringBefore((String) key, ".");
        String property = StringUtils.substringAfterLast((String) key, ".");

        if (currentId.equals(id)) {
            if (property.equals("name")) {
                result.setName(PROPERTIES.getProperty((String) key).trim());
            }

            if (property.equals("script")) {
                result.setScript(PROPERTIES.getProperty((String) key).trim());
            }
        }
    }
    return result;
}

From source file:com.google.gwt.dev.js.JsniFieldAsMethodReferenceVisitor.java

private boolean isJsniFieldReference(String name) {
    name = StringUtils.substringAfterLast(name, "@");
    if (!StringUtils.isEmpty(name) && name.indexOf("::") != -1) {
        return !name.endsWith(")");
    }/*from  w w  w  .  jav  a2 s . c om*/
    return false;
}

From source file:com.netflix.adminresources.resources.EmbeddedContentResource.java

/**
 * The karyon admin resources can exist in the form of .jar files.
 * These .jar files contain Jersey REST resource java classes and also
 * resources for rendering like *.js, *.jpg, *.css files. The REST classes
 * are discovered by the Jersey container scanning the classpath. To get the
 * other resources, we will use this method to scan the classpath (and hence
 * the module .jar files) and return the bytes corresponding to the contents
 * of the resources files (i.e. the *.js, *.jpg, *.css files)
 *//*from  w w  w  .ja va 2  s  .c om*/
// For URIs of the form /adminres/<something>
@GET
@Path("{subResources:.*}")
public Response get() {
    // get the part after /adminres
    String path = uriInfo.getPath().substring("adminres".length());
    String ext = StringUtils.substringAfterLast(path, ".");
    String mediaType = EXT_TO_MEDIATYPE.get(ext);
    byte[] contentAsBytes = null;
    if (mediaType != null) {
        if (resourceCache.containsKey(path)) {
            contentAsBytes = resourceCache.get(path);
        } else {
            InputStream is = getClass().getResourceAsStream(path);
            if (is != null) {
                try {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
                    byte[] chunk = new byte[4096];
                    int bytesRead;
                    while ((bytesRead = is.read(chunk)) > 0) {
                        baos.write(chunk, 0, bytesRead);
                    }
                    // This is a rather costly operation as we are throwing away all content loaded in memory, but
                    // this is only the case when the same resource is requested concurrently.
                    contentAsBytes = baos.toByteArray();
                    byte[] existing = resourceCache.putIfAbsent(path, contentAsBytes);
                    if (null != existing) {
                        contentAsBytes = existing;
                    }
                } catch (IOException e) {
                    logger.error("Error loading resource with path: " + uriInfo.getPath(), e);
                } finally {
                    try {
                        is.close();
                    } catch (IOException e) {
                        logger.info("Could not close the resource stream for loading admin resource, ignoring.",
                                e);
                    }
                }
            }
        }
    }

    if (contentAsBytes == null) {
        logger.info("Could not find resource: " + uriInfo.getPath());
        throw new NotFoundException();
    } else {
        return Response.ok(contentAsBytes, mediaType).build();
    }
}

From source file:com.thalesgroup.sonar.plugins.tusar.TUSARResource.java

/**
 * File in project. Key is the path relative to project source directories. It is not the absolute path
 * and it does not include the path to source directories. Example : <code>new File("org/sonar/foo.sql")</code>. The
 * absolute path may be c:/myproject/src/main/sql/org/sonar/foo.sql. Project root is c:/myproject and source dir
 * is src/main/sql./*from   w w  w .  j av a2  s  .  c  o  m*/
 */
public TUSARResource(String key, boolean unitTest) {
    if (key == null) {
        throw new IllegalArgumentException("File key is null");
    }
    String realKey = parseKey(key);
    if (realKey != null && realKey.indexOf(Directory.SEPARATOR) >= 0) {
        this.directoryKey = Directory.parseKey(StringUtils.substringBeforeLast(key, Directory.SEPARATOR));
        this.filename = StringUtils.substringAfterLast(realKey, Directory.SEPARATOR);
        realKey = new StringBuilder().append(this.directoryKey).append(Directory.SEPARATOR).append(filename)
                .toString();

    } else {
        this.filename = key;
    }
    setKey(realKey);
    this.unitTest = unitTest;
}

From source file:info.magnolia.cms.beans.config.URI2RepositoryMapping.java

/**
 * Create a node handle based on an uri.
 *///from   w  w w.j a  va 2 s .  co  m
public String getHandle(String uri) {
    String handle;
    handle = StringUtils.removeStart(uri, this.URIPrefix);
    if (StringUtils.isNotEmpty(this.handlePrefix)) {
        StringUtils.removeStart(handle, "/");
        handle = this.handlePrefix + "/" + handle;
    }
    //remove extension (ignore . anywhere else in the uri)
    String fileName = StringUtils.substringAfterLast(handle, "/");
    String extension = StringUtils.substringAfterLast(fileName, ".");
    handle = StringUtils.removeEnd(handle, "." + extension);
    handle = cleanHandle(handle);

    try {
        final Session session = MgnlContext.getJCRSession(this.repository);
        if (!session.itemExists(handle)) {
            String maybeHandle = (this.handlePrefix.endsWith("/") ? "/" : "")
                    + StringUtils.removeStart(handle, this.handlePrefix);
            // prefix might have been prepended incorrectly. Second part of the condition is there to match links to binary nodes
            if (session.itemExists(maybeHandle) || (maybeHandle.lastIndexOf("/") > 0
                    && session.itemExists(StringUtils.substringBeforeLast(maybeHandle, "/")))) {
                return maybeHandle;
            }
        }
    } catch (RepositoryException e) {
        //Log the exception and return handle
        log.debug(e.getMessage(), e);
    }
    return handle;
}