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

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

Introduction

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

Prototype

public static String strip(String str) 

Source Link

Document

Strips whitespace from the start and end of a String.

Usage

From source file:pt.webdetails.cte.CteSettings.java

protected List<String> initBlacklistedFolders() {

    List<String> blacklistedFolders = new ArrayList<String>();
    List<Element> xmlElements = getSettingsXmlSection(Constants.SETTINGS_XPATH_BLACKLISTED_FOLDERS);

    if (xmlElements != null) {

        for (Element xmlElement : xmlElements) {

            String value = StringUtils.strip(xmlElement.getTextTrim());

            if (StringUtils.isEmpty(value)) {
                logger.error("Invalid empty path. Skipping..");
                continue;
            }//from w  w w  . jav  a 2 s .  c  om

            blacklistedFolders.add(value);
        }
    }

    return blacklistedFolders;
}

From source file:pt.webdetails.cte.CteSettings.java

protected List<String> initBlacklistedPlugins() {

    List<String> blacklistedPlugins = new ArrayList<String>();
    List<Element> xmlElements = getSettingsXmlSection(Constants.SETTINGS_XPATH_BLACKLISTED_PLUGINS);

    if (xmlElements != null) {

        for (Element xmlElement : xmlElements) {

            String value = StringUtils.strip(xmlElement.getTextTrim());

            if (StringUtils.isEmpty(value)) {
                logger.error("Invalid empty plugin id. Skipping..");
                continue;
            }/*from   www . j a  v a2  s.c om*/

            blacklistedPlugins.add(value);
        }
    }

    return blacklistedPlugins;
}

From source file:ru.org.linux.spring.AddMessageForm.java

public String getTagsHTML() {
    return tags == null ? "" : StringUtils.strip(tags);
}

From source file:tw.com.useful.util.JSONUtil.java

private JSON processArrayElement(Element element, String defaultType) {

    JSONObject jsonObj = new JSONObject();

    // process children (including text)
    int childCount = element.getChildCount();
    //System.out.println("processArrayElement() -"+element.getQualifiedName()+", size="+childCount);

    for (int i = 0; i < childCount; i++) {
        Node child = element.getChild(i);
        if (child instanceof Text) {
            Text text = (Text) child;
            //System.out.println("..."+text.getValue());
            if (StringUtils.isNotBlank(StringUtils.strip(text.getValue()))) {
                jsonObj.element("#text", text.getValue());
            }/*from   w ww .  j a v a2s. c  o m*/
        } else if (child instanceof Element) {
            setValue(jsonObj, (Element) child, defaultType);
        }
    }

    String key = removeNamespacePrefix(element.getQualifiedName());

    //System.out.println("key="+element.getQualifiedName() +", size="+jsonObj.size() +", =>"+jsonObj.toString());
    if (jsonObj.isEmpty())
        return JSONNull.getInstance();

    //JSON json = new JSONObject().element( key, jsonObj );
    return jsonObj;
    //return json;
}

From source file:tw.com.useful.util.JSONUtil.java

private JSON processObjectElement(Element element, String defaultType) {
    if (isNullObject(element)) {
        return JSONNull.getInstance();
    }/*from  w w w.j av a2  s . com*/

    //System.out.println("process object element, element="+element.getQualifiedName());

    JSONObject jsonObject = new JSONObject();

    if (!skipNamespaces) {
        for (int j = 0; j < element.getNamespaceDeclarationCount(); j++) {
            String prefix = element.getNamespacePrefix(j);
            String uri = element.getNamespaceURI(prefix);
            if (StringUtils.isBlank(uri)) {
                continue;
            }
            if (!StringUtils.isBlank(prefix)) {
                prefix = ":" + prefix;
            }
            setOrAccumulate(jsonObject, "@xmlns" + prefix, trimSpaceFromValue(uri));
        }
    }

    // process attributes first
    int attrCount = element.getAttributeCount();
    for (int i = 0; i < attrCount; i++) {
        Attribute attr = element.getAttribute(i);
        String attrname = attr.getQualifiedName();
        if (isTypeHintsEnabled() && (addJsonPrefix("class").compareToIgnoreCase(attrname) == 0
                || addJsonPrefix("type").compareToIgnoreCase(attrname) == 0)) {
            continue;
        }
        String attrvalue = attr.getValue();
        setOrAccumulate(jsonObject, ATTRIBUTE_PREFIX + removeNamespacePrefix(attrname),
                trimSpaceFromValue(attrvalue));
    }

    // process children (including text)
    int childCount = element.getChildCount();
    for (int i = 0; i < childCount; i++) {
        Node child = element.getChild(i);
        if (child instanceof Text) {
            Text text = (Text) child;
            if (StringUtils.isNotBlank(StringUtils.strip(text.getValue()))) {
                setOrAccumulate(jsonObject, "#text", trimSpaceFromValue(text.getValue()));
            }
        } else if (child instanceof Element) {
            setValue(jsonObject, (Element) child, defaultType);
        }
    }

    return jsonObject;
}

From source file:ubc.pavlab.aspiredb.server.CytobandFileLoaderImpl.java

private FileRow parseFileRow(String row) {
    // Row format (tab delimited): chromosome, start, end, cytoband, staining agent
    final int CHROMOSOME = 0;
    final int START = 1;
    final int END = 2;
    final int CYTOBAND = 3;
    final int STAINING_AGENT = 4;

    row = StringUtils.strip(row);
    String[] fields = row.split("\t");

    FileRow parsedRow = new FileRow();
    parsedRow.chromosome = fields[CHROMOSOME].replaceAll("chr", ""); // trim 'chr' part
    parsedRow.start = Integer.parseInt(fields[START]);
    parsedRow.end = Integer.parseInt(fields[END]);
    parsedRow.cytoband = fields[CYTOBAND];
    parsedRow.staining = fields[STAINING_AGENT];

    return parsedRow;
}

From source file:ubic.basecode.bio.geneset.GeneAnnotations.java

/**
 * @param bis//  w  w  w.  j ava  2  s.  c  o  m
 * @param object
 */
protected void readAffyCsv(InputStream bis, Set<String> activeGenes) throws IOException {
    if (bis == null) {
        throw new IOException("Inputstream was null");
    }
    BufferedReader dis = new BufferedReader(new InputStreamReader(bis));
    Collection<String> probeIds = new ArrayList<String>();
    String classIds = null;

    String header = dis.readLine();

    if (header == null) {
        throw new IOException("File had no header");
    }

    int numFields = getAffyNumFields(header);
    int probeIndex = getAffyProbeIndex(header);
    int goBpIndex = getAffyBpIndex(header);
    int goCcIndex = getAffyCcIndex(header);
    int goMfIndex = getAffyMfIndex(header);
    int geneNameIndex = getAffyGeneNameIndex(header);
    int geneSymbolIndex = getAffyGeneSymbolIndex(header);

    int alternateGeneSymbolIndex = getAffyAlternateGeneSymbolIndex(header);

    if (probeIndex < 0) {
        throw new IllegalStateException("Invalid AFFY file format: could not find the probe set id column");
    }
    if (geneNameIndex < 0) {
        throw new IllegalStateException("Invalid AFFY file format: could not find the gene name column");
    }
    if (geneSymbolIndex < 0) {
        throw new IllegalStateException("Invalid AFFY file format: could not find the gene symbol column");
    }

    if (goBpIndex < 0) {
        throw new IllegalStateException("Invalid AFFY file format: No biological process data were found");
    } else if (goCcIndex < 0) {
        throw new IllegalStateException("Invalid AFFY file format: No cellular component data were found");
    } else if (goMfIndex < 0) {
        throw new IllegalStateException("Invalid AFFY file format: No molecular function data were found");
    }

    log.debug("Read header");

    tick();
    assert (numFields > probeIndex + 1 && numFields > geneSymbolIndex + 1);
    Pattern pat = Pattern.compile("[0-9]+");
    // loop through rows. Makes hash map of probes to go, and map of go to
    // probes.
    int n = 0;
    String line = "";

    log.debug("File opened okay, parsing Affy CSV");

    while ((line = dis.readLine()) != null) {

        if (Thread.currentThread().isInterrupted()) {
            dis.close();
            throw new CancellationException();
        }

        String[] fields = StringUtil.csvSplit(line);
        if (fields.length < probeIndex + 1 || fields.length < geneSymbolIndex + 1) {
            continue; // skip lines that don't meet criteria.
        }

        String probe = fields[probeIndex];
        String gene = fields[geneSymbolIndex];

        if (StringUtils.isBlank(probe) || probe.equals("---")) {
            throw new IllegalStateException("Probe name was missing or invalid at line " + n
                    + "; it is possible the file format is not readable; contact the developers.");
        }

        if (StringUtils.isBlank(gene) || gene.equals("---")) {
            gene = fields[alternateGeneSymbolIndex];
            if (StringUtils.isBlank(gene) || gene.equals("---")) {
                throw new IllegalStateException("Gene name was missing or invalid at line " + n
                        + "; it is possible the file format is not readable; contact the developers.");
            }
        }

        if (activeGenes != null && !activeGenes.contains(gene)) {
            continue;
        }

        // log.debug("Probe=" + probe + " Gene=" + gene); // PP temporary for user problems.

        storeProbeAndGene(probeIds, probe, gene);

        /* read gene description */

        String description = fields[geneNameIndex].intern();
        if (!description.startsWith("GO:")) {
            this.probeToDescription.put(probe.intern(), description.intern());
        } else {
            this.probeToDescription.put(probe.intern(), NO_DESCRIPTION);
        }

        /*
         * Each field is like this: 0000166 // nucleotide binding // inferred from electronic annotation
         */

        classIds = " // " + fields[goBpIndex] + " // " + fields[goMfIndex] + " // " + fields[goCcIndex];
        String[] goinfo = classIds.split("/+");
        for (String element : goinfo) {
            if (StringUtils.isBlank(element)) {
                continue;
            }
            element = StringUtils.strip(element);
            parseGoTerm(probe, pat, element);
        }

        if (messenger != null && n % 5000 == 0) {
            messenger.showStatus("Read " + n + " probes");
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                dis.close();
                throw new RuntimeException("Interrupted");
            }
        }
        n++;

    }

    /* Fill in the genegroupreader and the classmap */
    dis.close();
    tick();
    resetSelectedProbes();

    if (this.probeToGeneName.size() == 0 || this.geneSetToProbeMap.size() == 0) {
        throw new IllegalArgumentException(
                "The gene annotations had invalid information. Please check the format.");
    }

}

From source file:ubic.gemma.apps.ExpressionExperimentLoadSpacesMasterCLI.java

/**
 * Submits the task to the space and retrieves the result.
 *//*from w  w  w  . j a  v a  2 s.co m*/
protected void start() {

    log.debug("Got accession(s) from command line " + accessions);

    TaskResult res = null;
    if (accessions != null) {
        String[] accsToRun = StringUtils.split(accessions, ',');

        for (String accession : accsToRun) {

            log.info("processing accession " + accession);
            StopWatch stopwatch = new StopWatch();
            stopwatch.start();

            accession = StringUtils.strip(accession);

            if (StringUtils.isBlank(accession)) {
                continue;
            }

            /* configure this client to receive notifications */
            try {
                // FIXME: JMS migration
                // template.addNotifyDelegatorListener( this, new SpacesProgressEntry(), null, true, Lease.FOREVER,
                // NotifyModifiers.NOTIFY_ALL );

            } catch (Exception e) {
                throw new RuntimeException(e);
            }

            // if ( !spacesUtil.canServiceTask( ExpressionExperimentLoadTask.class.getName() ) ) continue;

            ExpressionExperimentLoadTaskCommand command = new ExpressionExperimentLoadTaskCommand(platformOnly,
                    !doMatching, accession, true, false, null);

            // res = proxy.execute( command );

            stopwatch.stop();
            long wt = stopwatch.getTime();
            log.info("Job with id " + res.getTaskId() + " completed in " + wt
                    + " ms.  Number of expression experiments persisted: " + res.getAnswer() + ".");

        }

        /*
         * Terminate the VM after you get the result. This is needed else the VM will wait for the timeout millis
         * that is set in the spring context.
         */
        System.exit(0);
    }
}

From source file:ubic.gemma.apps.GenericGenelistDesignGenerator.java

/**
 * @return//from   www  .  jav  a 2  s .co m
 */
private String generateShortName() {
    String ncbiIdSuffix = useNCBIIds ? "_ncbiIds" : "";
    String ensemblIdSuffix = useEnsemblIds ? "_ensemblIds" : "";
    String shortName = "";
    if (StringUtils.isBlank(taxon.getCommonName())) {
        shortName = "Generic_" + StringUtils.strip(taxon.getScientificName()).replaceAll(" ", "_")
                + ncbiIdSuffix;
    } else {
        shortName = "Generic_" + StringUtils.strip(taxon.getCommonName()).replaceAll(" ", "_") + ncbiIdSuffix
                + ensemblIdSuffix;
    }
    return shortName;
}

From source file:ubic.gemma.apps.LoadExpressionDataCli.java

@Override
protected Exception doWork(String[] args) {
    Exception err = processCommandLine("Expression Data loader", args);
    if (err != null) {
        return err;
    }//w ww.j a  v  a 2 s .  c  o  m
    try {

        GeoService geoService = this.getBean(GeoService.class);
        geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGenerator());

        if (accessions == null && accessionFile == null) {
            return new IllegalArgumentException(
                    "You must specific either a file or accessions on the command line");
        }

        if (accessions != null) {
            log.info("Got accession(s) from command line " + accessions);
            String[] accsToRun = StringUtils.split(accessions, ',');

            for (String accession : accsToRun) {

                accession = StringUtils.strip(accession);

                if (StringUtils.isBlank(accession)) {
                    continue;
                }

                if (platformOnly) {
                    Collection<?> designs = geoService.fetchAndLoad(accession, true, true, false, false, true,
                            true);
                    for (Object object : designs) {
                        assert object instanceof ArrayDesign;
                        successObjects.add(((Describable) object).getName() + " (" + ((ArrayDesign) object)
                                .getExternalReferences().iterator().next().getAccession() + ")");
                    }
                } else {
                    processAccession(geoService, accession);
                }
            }

        }

        if (accessionFile != null) {
            log.info("Loading accessions from " + accessionFile);
            InputStream is = new FileInputStream(accessionFile);
            BufferedReader br = new BufferedReader(new InputStreamReader(is));

            String accession = null;
            while ((accession = br.readLine()) != null) {

                if (StringUtils.isBlank(accession)) {
                    continue;
                }

                processAccession(geoService, accession);

            }
        }
        summarizeProcessing();
    } catch (Exception e) {
        log.error(e);
        return e;
    }
    return null;
}