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

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

Introduction

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

Prototype

public static String chomp(String str, String separator) 

Source Link

Document

Removes separator from the end of str if it's there, otherwise leave it alone.

Usage

From source file:org.objectstyle.cayenne.map.ObjAttribute.java

/**
 * Sets the dbAttributeName./*from   w w  w  .  j  av  a 2  s . c  om*/
 * @param dbAttributeName The dbAttributeName to set
 */
public void setDbAttributeName(String dbAttributeName) {
    if (dbAttributePath == null || dbAttributeName == null) {
        dbAttributePath = dbAttributeName;
        return;
    }
    int lastPartStart = dbAttributePath.lastIndexOf('.');
    String newPath = (lastPartStart > 0 ? StringUtils.chomp(dbAttributePath, ".") : "");
    newPath += (newPath.length() > 0 ? "." : "") + dbAttributeName;
    this.dbAttributePath = newPath;
}

From source file:org.pdfsam.guiclient.commons.panels.JVisualPdfPageSelectionPanel.java

/**
 * @param pages input selection set/*from   w  ww.j  av  a  2s. c o m*/
 * @return a String version of the input Set, ready to be used as -u parameter for the console
 */
private String getSelectionString(Set<Integer> pages) {
    StringBuilder buffer = new StringBuilder();
    for (Integer page : pages) {
        buffer.append(page.toString()).append(",");
    }
    return StringUtils.chomp(buffer.toString(), ",");
}

From source file:org.sonar.api.utils.ServerHttpClient.java

public ServerHttpClient(String remoteServerUrl, Integer connectTimeoutMiliseconds,
        Integer readTimeoutMiliseconds) {
    this.url = StringUtils.chomp(remoteServerUrl, "/");
    if (connectTimeoutMiliseconds != null) {
        this.connectTimeoutMiliseconds = connectTimeoutMiliseconds;
    }//w  ww . j av a2s. c  o m
    if (readTimeoutMiliseconds != null) {
        this.readTimeoutMiliseconds = readTimeoutMiliseconds;
    }

}

From source file:org.wso2.carbon.identity.workflow.impl.util.WorkflowImplUtils.java

/**
 * Returns server URL of the server./*from  ww w .ja v  a  2  s  .c om*/
 *
 * @return Server URL.
 */
public static String getServerURL() {
    String serverURL = CarbonUtils.getServerURL(ServerConfiguration.getInstance(), WorkflowImplServiceDataHolder
            .getInstance().getConfigurationContextService().getServerConfigContext());
    return StringUtils.chomp(serverURL, "/");
}

From source file:pt.webdetails.cpf.repository.pentaho.PentahoLegacySolutionAccess.java

@Override
public boolean createFolder(String path, boolean isHidden) { // TODO: shouldn't this be recursive?
    path = StringUtils.chomp(path, "/"); // strip trailing / if there
    String folderName = FilenameUtils.getBaseName(getPath(path));
    String folderPath = getPath(path).substring(0, StringUtils.lastIndexOf(getPath(path), folderName));

    try {//  w ww. ja v  a2s  .  c o m
        if (getRepositoryService().createFolder(userSession, "", folderPath, folderName, "")) {
            if (isHidden) {
                String indexContent = "<index><name>" + folderName + "</name><description></description>"
                        + "<icon>reporting.png</icon><visible>false</visible><display-type>list</display-type></index>";

                String repositoryBaseURL = PentahoSystem.getApplicationContext().getSolutionPath("");
                getRepository().addSolutionFile(repositoryBaseURL, folderName,
                        ISolutionRepository.INDEX_FILENAME, indexContent.getBytes(), true);
            }
            return true;
        } else {
            return false;
        }

    } catch (IOException ex) {
        logger.error(ex);
        return false;
    }
}

From source file:pt.webdetails.cpf.repository.pentaho.unified.UnifiedRepositoryAccess.java

private RepositoryFile getOrCreateFolder(IUnifiedRepository repo, String path, boolean isHidden) {
    // full path, no slash at end
    String fullPath = StringUtils.chomp(getFullPath(path), "/");
    // backtrack path to get list of folders to create
    List<String> foldersToCreate = new ArrayList<String>();
    while (!rawPathExists(repo, fullPath)) {
        // "a / b / c"
        // path<-|^|-> to create
        // accepts '/'
        int sepIdx = FilenameUtils.indexOfLastSeparator(fullPath);
        if (sepIdx < 0) {
            break;
        }/*from  w  w  w  . j  ava  2  s.co m*/
        foldersToCreate.add(fullPath.substring(sepIdx + 1));
        fullPath = fullPath.substring(0, sepIdx);
    }

    //in case we reached root
    if (StringUtils.isEmpty(fullPath)) {
        fullPath = RepositoryHelper.appendPath("/", fullPath);
    }

    RepositoryFile baseFolder = repo.getFile(fullPath);

    if (baseFolder == null) {
        logger.error("Path " + fullPath + " doesn't exist");
        return null;
    }
    // reverse iterate 
    if (foldersToCreate.size() > 0) {
        for (int i = foldersToCreate.size() - 1; i >= 0; i--) {
            String folder = foldersToCreate.get(i);
            baseFolder = repo.createFolder(baseFolder.getId(),
                    new RepositoryFile.Builder(folder).folder(true).hidden(isHidden).build(), null);
        }
    }
    return baseFolder;
}

From source file:ru.crazycoder.plugins.tabdir.SameFilenameTitleProviderTest.java

private CreatedType createEntry(String name, List<VirtualFile> levels, int level,
        Map<String, VirtualFile> fileSystem) throws IOException {
    VirtualFile parent = getParent(levels, level);
    CreatedType type = CreatedType.DIRECTORY;
    VirtualFile created;//from www .  j  a v a2  s.c  om
    if (name.endsWith("/")) {
        created = parent.createChildDirectory(this, StringUtils.chomp(name, "/"));
        levels.add(created);
    } else {
        created = createFile(parent, name);
        type = CreatedType.FILE;
    }
    String absolutePath = created.getPath();
    fileSystem.put(StringUtils.removeStart(absolutePath, myProject.getBasePath() + "/"), created);
    return type;
}

From source file:ubc.pavlab.aspiredb.server.util.CrudUtilsImpl.java

/**
 * @param target The object that might have the method (e.g., a service)
 * @param argument The single argument the method is expected to take. (e.g., an entity)
 * @param possibleNames An array of names of the methods (e.g., "create", "save").
 * @return/*from www  . j  av  a  2  s.  com*/
 */
Method getMethodForNames(Object target, Object argument, String[] possibleNames) {
    String argInterfaceName = StringUtils.chomp(argument.getClass().getName(), "Impl");

    Class<?>[] argArray = null;
    try {
        Class<?> entityInterface = Class.forName(argInterfaceName);
        argArray = new Class[] { entityInterface };
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    for (String methodName : possibleNames) {
        try {
            return target.getClass().getMethod(methodName, argArray);
        } catch (Exception e1) {
            // okay keep trying
        }
    }
    log.warn(
            target.getClass().getSimpleName() + " does not have method with " + argInterfaceName + " argument");
    return null;
}

From source file:ubic.gemma.analysis.report.DatabaseViewGeneratorImpl.java

@Override
public void generateDatasetView(int limit) throws FileNotFoundException, IOException {

    log.info("Generating dataset summary view");

    /*/*from ww w.  j av  a 2  s  .  c  om*/
     * Get handle to output file
     */
    File file = getViewFile(DATASET_SUMMARY_VIEW_BASENAME);
    log.info("Writing to " + file);
    Writer writer = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(file)));

    /*
     * Load all the data sets
     */
    Collection<ExpressionExperiment> vos = expressionExperimentService.loadAll();

    writer.write("GemmaDsId\tSource\tSourceAccession\tShortName\tName\tDescription\ttaxon\tManufacturer\n");

    /*
     * Print out their names etc.
     */
    int i = 0;
    for (ExpressionExperiment vo : vos) {
        vo = expressionExperimentService.thawLite(vo);
        log.info("Processing: " + vo.getShortName());

        String acc = "";
        String source = "";

        if (vo.getAccession() != null && vo.getAccession().getAccession() != null) {
            acc = vo.getAccession().getAccession();
            source = vo.getAccession().getExternalDatabase().getName();
        }

        Long gemmaId = vo.getId();
        String shortName = vo.getShortName();
        String name = vo.getName();
        String description = vo.getDescription();
        description = StringUtils.replaceChars(description, '\t', ' ');
        description = StringUtils.replaceChars(description, '\n', ' ');
        description = StringUtils.replaceChars(description, '\r', ' ');

        Taxon taxon = expressionExperimentService.getTaxon(vo);

        if (taxon == null)
            continue;

        Collection<ArrayDesign> ads = expressionExperimentService.getArrayDesignsUsed(vo);
        StringBuffer manufacturers = new StringBuffer();

        // TODO could cache the arrayDesigns to make faster, thawing ad is time consuming
        for (ArrayDesign ad : ads) {
            ad = arrayDesignService.thawLite(ad);
            if (ad.getDesignProvider() == null) {
                log.debug("Array Design: " + ad.getShortName()
                        + " has no design provoider assoicated with it. Skipping");
                continue;
            }
            manufacturers.append(ad.getDesignProvider().getName() + ",");
        }

        writer.write(String.format("%d\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", gemmaId, source, acc, shortName, name,
                description, taxon.getCommonName(), StringUtils.chomp(manufacturers.toString(), ",")));

        if (limit > 0 && ++i > limit)
            break;

    }

    writer.close();
}

From source file:ubic.gemma.analysis.report.DatabaseViewGeneratorImpl.java

@Override
public void generateDifferentialExpressionView(int limit) throws FileNotFoundException, IOException {
    log.info("Generating dataset diffex view");

    /*/*from www .  jav a  2 s.  c o  m*/
     * Get handle to output file
     */
    File file = getViewFile(DATASET_DIFFEX_VIEW_BASENAME);
    log.info("Writing to " + file);
    Writer writer = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(file)));

    /*
     * Load all the data sets
     */Collection<ExpressionExperiment> experiments = expressionExperimentService.loadAll();

    /*
     * For each gene that is differentially expressed, print out a line per contrast
     */
    writer.write(
            "GemmaDsId\tEEShortName\tGeneNCBIId\tGemmaGeneId\tFactor\tFactorURI\tBaseline\tContrasting\tDirection\n");
    int i = 0;
    for (ExpressionExperiment ee : experiments) {
        ee = expressionExperimentService.thawLite(ee);

        Collection<DifferentialExpressionAnalysis> results = differentialExpressionAnalysisService
                .getAnalyses(ee);
        if (results == null || results.isEmpty()) {
            log.warn("No differential expression results found for " + ee);
            continue;
        }

        if (results.size() > 1) {
            /*
             * FIXME. Should probably skip for this purpose.
             */
        }

        log.info("Processing: " + ee.getShortName());

        for (DifferentialExpressionAnalysis analysis : results) {

            for (ExpressionAnalysisResultSet ears : analysis.getResultSets()) {

                ears = differentialExpressionResultService.thaw(ears);

                FactorValue baselineGroup = ears.getBaselineGroup();

                if (baselineGroup == null) {
                    // log.warn( "No baseline defined for " + ee ); // interaction
                    continue;
                }

                if (ExperimentalDesignUtils.isBatch(baselineGroup.getExperimentalFactor())) {
                    continue;
                }

                String baselineDescription = ExperimentalDesignUtils.prettyString(baselineGroup);

                // Get the factor category name
                String factorName = "";
                String factorURI = "";

                for (ExperimentalFactor ef : ears.getExperimentalFactors()) {
                    factorName += ef.getName() + ",";
                    if (ef.getCategory() instanceof VocabCharacteristic) {
                        factorURI += ((VocabCharacteristic) ef.getCategory()).getCategoryUri() + ",";
                    }
                }
                factorName = StringUtils.chomp(factorName, ",");
                factorURI = StringUtils.chomp(factorURI, ",");

                if (ears.getResults() == null || ears.getResults().isEmpty()) {
                    log.warn("No  differential expression analysis results found for " + ee);
                    continue;
                }

                // Generate probe details
                for (DifferentialExpressionAnalysisResult dear : ears.getResults()) {

                    if (dear == null) {
                        log.warn("Missing results for " + ee + " skipping to next. ");
                        continue;
                    }

                    if (dear.getCorrectedPvalue() == null || dear.getCorrectedPvalue() > THRESH_HOLD)
                        continue;

                    String formatted = formatDiffExResult(ee, dear, factorName, factorURI, baselineDescription);

                    if (StringUtils.isNotBlank(formatted))
                        writer.write(formatted);

                } // dear loop
            } // ears loop
        } // analysis loop

        if (limit > 0 && ++i > limit)
            break;

    } // EE loop
    writer.close();
}