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:info.magnolia.nodebuilder.ContentOps.java

public static NodeOperation setBinaryNodeData(final String name, final String fileName, final long size,
        final InputStream inputStream) {
    return new AbstractNodeOperation() {

        @Override// w  w w . j  a v  a2s .  com
        protected Content doExec(Content context, ErrorHandler errorHandler) throws RepositoryException {
            NodeData binary = context.setNodeData(name, inputStream);
            binary.setAttribute(FileProperties.PROPERTY_FILENAME,
                    StringUtils.substringBeforeLast(fileName, "."));
            binary.setAttribute(FileProperties.PROPERTY_EXTENSION,
                    StringUtils.substringAfterLast(fileName, "."));
            binary.setAttribute(FileProperties.PROPERTY_SIZE, Long.toString(size));
            return context;
        }
    };
}

From source file:com.google.gdt.eclipse.designer.uibinder.model.util.UiBinderTagResolver.java

private void resolveTag(XmlObjectInfo object, Class<?> clazz, String[] namespace, String[] tag)
        throws Exception {
    if (tag[0] == null && UiBinderDescriptionProcessor.isUiBinder(object)) {
        String className = clazz.getName();
        namespace[0] = getNamespace(className);
        tag[0] = StringUtils.substringAfterLast(className, ".");
    }/*from w  w w .  j  ava 2 s.  c  o m*/
}

From source file:info.magnolia.cms.beans.runtime.MultipartForm.java

public void addDocument(String atomName, String fileName, String type, File file) {
    if (StringUtils.isEmpty(fileName)) {
        return;/*from   w  w w .  ja  va2s. co m*/
    }
    Document document = new Document();
    document.setAtomName(atomName);
    document.setType(type);
    document.setFile(file);
    if (!StringUtils.contains(fileName, ".")) { //$NON-NLS-1$
        document.setExtention(StringUtils.EMPTY);
        document.setFileName(fileName);
    } else {
        document.setExtention(StringUtils.substringAfterLast(fileName, ".")); //$NON-NLS-1$
        document.setFileName(StringUtils.substringBeforeLast(fileName, ".")); //$NON-NLS-1$
    }
    this.documents.put(atomName, document);
}

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

public static void printManifestInfo(String extension, boolean details, URL url) throws IOException {
    InputStream stream = url.openStream();
    if (stream == null) {
        return;/*from   w  ww  .j  a  v a 2 s  . c o m*/
    }
    //      String file = url.getFile();
    String path = StringUtils.removeEndIgnoreCase(url.getPath(), "!/" + JarFile.MANIFEST_NAME);
    String name = StringUtils.substringAfterLast(path, "/");
    Manifest manifest = new Manifest(stream);
    if (!extensionNameMatches(manifest, extension)) {
        return;
    }
    //      out.println(file);
    printManifestInfo(path, name, details, manifest);
}

From source file:net.shopxx.plugin.ftpStorage.FtpStoragePlugin.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 {// ww  w.  j  a  v a2 s.  c om
            inputStream = new BufferedInputStream(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 (SocketException e) {
            throw new RuntimeException(e.getMessage(), e);
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        } finally {
            IOUtils.closeQuietly(inputStream);
            try {
                if (ftpClient.isConnected()) {
                    ftpClient.disconnect();
                }
            } catch (IOException e) {
            }
        }
    }
}

From source file:com.gooddata.md.ExportImportServiceAT.java

@Test(groups = "exportimport", dependsOnMethods = "partialExportMetric")
public void partialImportMetric() throws Exception {
    gd.getExportImportService().partialImport(importProject, partialMdExportToken).get();
    final Metric importedMetric = gd.getMetadataService().getObjById(importProject,
            StringUtils.substringAfterLast(metric.getUri(), "/"), Metric.class);

    assertThat(importedMetric, notNullValue());
}

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

/**
 * @param workspace the workspace that contains path
 * @param path the path to the node that is to be backed up.
 * @param info indicates if an info message should be displayed.
 */// w ww.j a va  2 s  .  co  m
public BackupTask(String workspace, String path, boolean info) {
    super("Backup", "Does a backup of the node path '" + path + "' in the " + workspace + " workspace.");
    this.workspace = workspace;
    this.path = path;
    this.info = info;

    final String parentPath = StringUtils.substringBeforeLast(path, "/");
    final String backupParentPath = getBackupPath() + parentPath;
    this.backupPath = backupParentPath + "/" + StringUtils.substringAfterLast(path, "/");
    final CreateNodePathTask backupParent = new CreateNodePathTask("Create node",
            "Creates the " + path + " backup location.", workspace, backupParentPath);
    final MoveNodeTask moveNodeToBackupPath = new MoveNodeTask("Move node",
            "Moves " + path + " to the " + backupPath + " backup location.", workspace, path, backupPath, true);
    addTask(backupParent);
    addTask(moveNodeToBackupPath);
}

From source file:de.awtools.basic.file.FindFilesTest.java

@Test
public void testStringUtilsSubstring() {
    String fileName = "findmy.txt";
    String relativePath = StringUtils.substringBeforeLast(fileName, "/");
    String realFileName = StringUtils.substringAfterLast(fileName, "/");

    Assert.assertTrue(!(StringUtils.isBlank(relativePath)));
    Assert.assertEquals(fileName, relativePath);
    Assert.assertTrue(StringUtils.isBlank(realFileName));
}

From source file:com.hangum.tadpole.engine.sql.util.sqlscripts.scripts.MySqlDDLScript.java

@Override
public String getViewScript(String strName) throws Exception {
    SqlMapClient client = TadpoleSQLManager.getInstance(userDB);

    Map srcList = (HashMap) client.queryForObject("getViewScript", strName);
    String strSource = "" + srcList.get("Create View");
    strSource = StringUtils.substringAfterLast(strSource, "VIEW");

    return "CREATE VIEW " + strSource;
}

From source file:info.magnolia.voting.voters.ExtensionVoter.java

@Override
protected boolean boolVote(Object value) {
    String extension;//ww w . j  av a  2 s  .  c  o m
    if (value instanceof String) {
        extension = StringUtils.substringAfterLast((String) value, ".");
    } else {
        extension = MgnlContext.getAggregationState().getExtension();
    }

    if (StringUtils.isEmpty(MIMEMapping.getMIMEType(extension))) {
        return false; // check for MIMEMapping, extension must exist
    }

    if (allow != null && allow.length > 0 && !ArrayUtils.contains(allow, extension)) {
        return false;
    }

    if (deny != null && deny.length > 0 && ArrayUtils.contains(deny, extension)) {
        return false;
    }

    return true;
}