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

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

Introduction

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

Prototype

public static String removeEnd(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

Usage

From source file:edu.cornell.med.icb.goby.reads.ReadsReader.java

/**
 * Return the basename corresponding to the input reads filename.  Note
 * that if the filename does have the extension known to be a compact read
 * the returned value is the original filename
 *
 * @param filename The name of the file to get the basename for
 * @return basename for the alignment file
 *///from   www .j  a v  a  2 s  .co m
public static String getBasename(final String filename) {
    for (final String ext : FileExtensionHelper.COMPACT_READS_FILE_EXTS) {
        if (StringUtils.endsWith(filename, ext)) {
            return StringUtils.removeEnd(filename, ext);
        }
    }

    // perhaps the input was a basename already.
    return filename;
}

From source file:it.geosolutions.opensdi2.configurations.controller.OSDIModuleController.java

protected String getPathFragment(HttpServletRequest req, int index) {
    String path = req.getPathInfo();
    if (path == null) {
        throw new IllegalArgumentException(
                "The path found in the request is null... this should never happen...");
    }/*w ww.j a v  a 2 s.  c om*/
    LOGGER.debug("Extracting part of the following path '" + path + "' in order to get the module name...");
    path = StringUtils.removeStart(path, "/");
    path = StringUtils.removeEnd(path, "/");

    String[] parts = path.split("/");
    if (parts == null || parts.length <= index || parts[index] == null) {
        throw new IllegalArgumentException("no fragment is found... this should never happen...");
    }
    if (StringUtils.isNotEmpty(parts[index])) {
        return parts[index];
    }
    for (int i = index; i < parts.length; i++) {
        if (StringUtils.isNotEmpty(parts[i])) {
            return parts[i];
        }
    }
    return null;
}

From source file:com.vecna.taglib.processor.JspAnnotationsProcessor.java

/**
 * Scan a classloader for classes under the given package.
 * @param pkg package name// w  w w  .  ja  va  2  s  . c  o m
 * @param loader classloader
 * @param lookInsideJars whether to consider classes inside jars or only "unpacked" class files
 * @return matching class names (will not attemp to actually load these classes)
 */
private Collection<String> scanClasspath(String pkg, ClassLoader loader, boolean lookInsideJars) {
    Collection<String> classes = Lists.newArrayList();

    Enumeration<URL> resources;
    String packageDir = pkg.replace(PACKAGE_SEPARATOR, JAR_PATH_SEPARATOR) + JAR_PATH_SEPARATOR;

    try {
        resources = loader.getResources(packageDir);
    } catch (IOException e) {
        s_log.warn("couldn't scan package", e);
        return classes;
    }

    while (resources.hasMoreElements()) {
        URL resource = resources.nextElement();
        String path = resource.getPath();
        s_log.debug("processing path {}", path);

        if (path.startsWith(FILE_URL_PREFIX)) {
            if (lookInsideJars) {
                String jarFilePath = StringUtils.substringBetween(path, FILE_URL_PREFIX,
                        NESTED_FILE_URL_SEPARATOR);
                try {
                    JarFile jarFile = new JarFile(jarFilePath);
                    Enumeration<JarEntry> entries = jarFile.entries();
                    while (entries.hasMoreElements()) {
                        String entryName = entries.nextElement().getName();
                        if (entryName.startsWith(packageDir) && entryName.endsWith(CLASS_NAME_SUFFIX)) {
                            String potentialClassName = entryName.substring(packageDir.length(),
                                    entryName.length() - CLASS_NAME_SUFFIX.length());
                            if (!potentialClassName.contains(JAR_PATH_SEPARATOR)) {
                                classes.add(pkg + PACKAGE_SEPARATOR + potentialClassName);
                            }
                        }
                    }
                } catch (IOException e) {
                    s_log.warn("couldn't open jar file", e);
                }
            }
        } else {
            File dir = new File(path);
            if (dir.exists() && dir.isDirectory()) {
                String[] files = dir.list();
                for (String file : files) {
                    s_log.debug("file {}", file);
                    if (file.endsWith(CLASS_NAME_SUFFIX)) {
                        classes.add(pkg + PACKAGE_SEPARATOR + StringUtils.removeEnd(file, CLASS_NAME_SUFFIX));
                    }
                }
            }
        }
    }
    return classes;
}

From source file:gov.nasa.jpl.mudrod.main.MudrodEngine.java

private String decompressSVMWithSGDModel(String archiveName) throws IOException {

    URL scmArchive = getClass().getClassLoader().getResource(archiveName);
    if (scmArchive == null) {
        throw new IOException("Unable to locate " + archiveName + " as a classpath resource.");
    }/*from   www  .j  ava2s . c om*/
    File tempDir = Files.createTempDirectory("mudrod").toFile();
    assert tempDir.setWritable(true);
    File archiveFile = new File(tempDir, archiveName);
    FileUtils.copyURLToFile(scmArchive, archiveFile);

    // Decompress archive
    int BUFFER_SIZE = 512000;
    ZipInputStream zipIn = new ZipInputStream(new FileInputStream(archiveFile));
    ZipEntry entry;
    while ((entry = zipIn.getNextEntry()) != null) {
        File f = new File(tempDir, entry.getName());
        // If the entry is a directory, create the directory.
        if (entry.isDirectory() && !f.exists()) {
            boolean created = f.mkdirs();
            if (!created) {
                LOG.error("Unable to create directory '{}', during extraction of archive contents.",
                        f.getAbsolutePath());
            }
        } else if (!entry.isDirectory()) {
            boolean created = f.getParentFile().mkdirs();
            if (!created && !f.getParentFile().exists()) {
                LOG.error("Unable to create directory '{}', during extraction of archive contents.",
                        f.getParentFile().getAbsolutePath());
            }
            int count;
            byte data[] = new byte[BUFFER_SIZE];
            FileOutputStream fos = new FileOutputStream(new File(tempDir, entry.getName()), false);
            try (BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) {
                while ((count = zipIn.read(data, 0, BUFFER_SIZE)) != -1) {
                    dest.write(data, 0, count);
                }
            }
        }
    }

    return new File(tempDir, StringUtils.removeEnd(archiveName, ".zip")).toURI().toString();
}

From source file:de.devboost.emfcustomize.EcoreModelRefactorer.java

public Set<Method> getAnnotatedMethods(Class customClass) {
    Set<Method> annotatedMethods = new HashSet<Method>();

    List<Method> methods = customClass.getMethods();
    for (Method method : methods) {
        List<String> comments = method.getComments();
        if (comments != null && comments.size() > 0) {
            for (String comment : comments) {
                String[] lines = comment.split("[\\r\\n]+");
                for (String line : lines) {
                    String deleteWhitespace = StringUtils.deleteWhitespace(line);
                    if (StringUtils.endsWith(deleteWhitespace, MODEL_ANNOTATION)) {
                        String difference = StringUtils.removeEnd(deleteWhitespace, MODEL_ANNOTATION);
                        if (StringUtils.containsOnly(difference, VALID_PREFIX_CHARACTERS)
                                || difference.isEmpty()) {
                            annotatedMethods.add(method);
                        }//from  w  w w .j  ava  2 s. c o  m
                    }
                }
            }
        }
    }
    return annotatedMethods;
}

From source file:hydrograph.ui.engine.ui.converter.impl.OutputTeradataUiConverter.java

/**
 *  Appends update keys using a comma/*from  w  ww.ja v  a 2 s.c  om*/
 * @param update
 */
private String getLoadTypeUpdateKeyUIValue(TypeUpdateKeys update) {
    StringBuffer buffer = new StringBuffer();
    if (update != null && update.getUpdateByKeys() != null) {
        TypeKeyFields keyFields = update.getUpdateByKeys();
        for (TypeFieldName fieldName : keyFields.getField()) {
            buffer.append(fieldName.getName());
            buffer.append(",");
        }
    }
    return StringUtils.removeEnd(buffer.toString(), ",");
}

From source file:com.hangum.tadpole.manager.core.dialogs.api.APIServiceDialog.java

/**
 * initialize ui//  ww  w .  j av  a 2 s .c  om
 * 
 * @param strArgument
 */
private void initData(String strArgument) {

    try {
        String strReturnResult = ""; //$NON-NLS-1$

        // velocity  if else   . 
        String strSQLs = RESTfulAPIUtils.makeTemplateTOSQL("APIServiceDialog", strSQL, strArgument); //$NON-NLS-1$
        // ? ? .
        for (String strTmpSQL : strSQLs.split(PublicTadpoleDefine.SQL_DELIMITER)) {
            if (StringUtils.trim(strTmpSQL).equals(""))
                continue;

            NamedParameterDAO dao = NamedParameterUtil.parseParameterUtils(userDB, strTmpSQL, strArgument);
            if (QueryUtils.RESULT_TYPE.JSON.name().equalsIgnoreCase(comboResultType.getText())) {
                strReturnResult += getSelect(userDB, dao.getStrSQL(), dao.getListParam()) + ","; //$NON-NLS-1$
            } else {
                strReturnResult += getSelect(userDB, dao.getStrSQL(), dao.getListParam());
            }
        }

        if (QueryUtils.RESULT_TYPE.JSON.name().equalsIgnoreCase(comboResultType.getText())) {
            strReturnResult = "[" + StringUtils.removeEnd(strReturnResult, ",") + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }

        textResult.setText(strReturnResult);

    } catch (Exception e) {
        logger.error("api exception", e); //$NON-NLS-1$

        MessageDialog.openError(getShell(), Messages.get().Error,
                Messages.get().APIServiceDialog_11 + "\n" + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
    }
}

From source file:com.hangum.tadpole.manager.core.dialogs.api.UserAPIServiceDialog.java

/**
 * initialize ui//from   ww w  .  j  a va 2  s  . co  m
 * 
 * @param strArgument
 */
private void initData(String strArgument) {

    try {
        String strAPIKEY = textAPIKey.getText();
        if (strAPIKEY.equals("")) { //$NON-NLS-1$
            MessageDialog.openWarning(getShell(), Messages.get().Warning,
                    Messages.get().UserAPIServiceDialog_10);
            textAPIKey.setFocus();

            return;
        }

        Timestamp timstampStart = new Timestamp(System.currentTimeMillis());
        UserDBDAO userDB = null;
        UserDBResourceDAO userDBResourceDao = TadpoleSystem_UserDBResource.findAPIKey(strAPIKEY);
        if (userDBResourceDao == null) {
            MessageDialog.openInformation(getShell(), Messages.get().Confirm,
                    Messages.get().UserAPIServiceDialog_12);
        } else {

            String strSQL = TadpoleSystem_UserDBResource.getResourceData(userDBResourceDao);
            if (logger.isDebugEnabled())
                logger.debug(userDBResourceDao.getName() + ", " + strSQL); //$NON-NLS-1$

            // find db
            userDB = TadpoleSystem_UserDBQuery.getUserDBInstance(userDBResourceDao.getDb_seq());

            String strReturnResult = ""; //$NON-NLS-1$

            String strSQLs = RESTfulAPIUtils.makeTemplateTOSQL("APIServiceDialog", strSQL, strArgument); //$NON-NLS-1$
            // ? ? .
            for (String strTmpSQL : strSQLs.split(PublicTadpoleDefine.SQL_DELIMITER)) {
                if (StringUtils.trim(strTmpSQL).equals(""))
                    continue;
                NamedParameterDAO dao = NamedParameterUtil.parseParameterUtils(userDB, strTmpSQL, strArgument);
                if (QueryUtils.RESULT_TYPE.JSON.name().equalsIgnoreCase(comboResultType.getText())) {
                    strReturnResult += getSelect(userDB, dao.getStrSQL(), dao.getListParam()) + ","; //$NON-NLS-1$
                } else {
                    strReturnResult += getSelect(userDB, dao.getStrSQL(), dao.getListParam());
                }
            }

            if (QueryUtils.RESULT_TYPE.JSON.name().equalsIgnoreCase(comboResultType.getText())) {
                strReturnResult = "[" + StringUtils.removeEnd(strReturnResult, ",") + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            }

            textResult.setText(strReturnResult);
        }

    } catch (Exception e) {
        logger.error("api exception", e); //$NON-NLS-1$

        MessageDialog.openError(getShell(), Messages.get().Error,
                Messages.get().APIServiceDialog_11 + "\n" + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
    }
}

From source file:hudson.ivy.IvyModule.java

public String getRelativePathToModuleRoot() {
    return StringUtils.removeEnd(relativePathToDescriptorFromWorkspace,
            StringUtils.defaultString(getRelativePathToDescriptorFromModuleRoot(), IVY_XML_PATH));
}

From source file:edu.mayo.cts2.framework.plugin.service.bprdf.dao.id.DefaultIdService.java

@Override
public String getAcronymForUri(String uri) {
    // try adding a '/' if we don't find it
    for (String addition : Arrays.asList("", "/")) {
        String acronym = this.getFromCache(this.uriToAcronym, uri + addition);
        if (acronym != null) {
            return acronym;
        }/*from   ww w. j  a v  a2 s .c o  m*/
    }

    if (uri.startsWith(BIOPORTAL_PURL_URI)) {
        uri = StringUtils.removeStart(uri, BIOPORTAL_PURL_URI);
        uri = StringUtils.removeEnd(uri, "/");
        uri = StringUtils.substringBefore(uri, "/");

        uri = StringUtils.removeEnd(uri, ":");
        uri = StringUtils.removeEnd(uri, "#");

        return uri;
    }
    if (uri.startsWith(PURL_OBO_OWL_URI)) {
        uri = StringUtils.removeStart(uri, PURL_OBO_OWL_URI);
        uri = StringUtils.removeEnd(uri, "/");
        uri = StringUtils.substringBefore(uri, "/");

        uri = StringUtils.removeEnd(uri, ":");
        uri = StringUtils.removeEnd(uri, "#");

        return uri;
    } else {
        return null;
    }
}