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

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

Introduction

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

Prototype

public static String normalizeSpace(String str) 

Source Link

Document

<p> Similar to <a href="http://www.w3.org/TR/xpath/#function-normalize-space"> http://www.w3.org/TR/xpath/#function-normalize -space</a> </p> <p> The function returns the argument string with whitespace normalized by using <code> #trim(String) </code> to remove leading and trailing whitespace and then replacing sequences of whitespace characters by a single space.

Usage

From source file:com.bahmanm.karun.PacmanConfHelper.java

/**
 * Extracts valuable info from 'pacman.conf'.
 *///w  w w  .  j a  v a 2 s. co m
private void extractInfo() throws FileNotFoundException, IOException {
    FileInputStream fis = new FileInputStream(confPath);
    DataInputStream dis = new DataInputStream(fis);
    BufferedReader br = new BufferedReader(new InputStreamReader(dis));
    String line;
    try {
        while ((line = br.readLine()) != null) {
            line = StringUtils.normalizeSpace(line);
            if (line.startsWith("#")) {
                continue;
            } else if (line.startsWith("[") && line.endsWith("]")) {
                String section = line.substring(1, line.length() - 1);
                if (!section.equals("options")) {
                    repos.add(section);
                }
            } else if (line.startsWith("DBPath")) {
                dbPath = line.split("=")[1].trim();
            } else if (line.startsWith("CacheDir")) {
                cacheDir = line.split("=")[1].trim();
            }
        }
    } catch (IOException ex) {
        Logger.getLogger(PacmanConfHelper.class.getName()).log(Level.SEVERE, null, ex);
        try {
            br.close();
            dis.close();
            fis.close();
        } catch (IOException ioex) {
            throw new IOException("Error closing stream or reader: " + ioex.getMessage());
        }
    }
}

From source file:com.haulmont.cuba.web.gui.components.mainwindow.WebFtsField.java

@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(FTS_FIELD_STYLENAME, ""));
}

From source file:com.haulmont.cuba.web.gui.components.WebButton.java

@Override
public String getStyleName() {
    if (getIcon() != null)
        return StringUtils.normalizeSpace(super.getStyleName().replace(ICON_STYLE, ""));

    return super.getStyleName();
}

From source file:com.haulmont.cuba.web.gui.components.presentations.TablePresentations.java

@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(TABLE_PREFS_STYLENAME, ""));
}

From source file:com.haulmont.cuba.web.gui.components.WebSearchField.java

@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(SEARCHSELECT_STYLENAME, ""));
}

From source file:com.haulmont.cuba.web.gui.components.WebScrollBoxLayout.java

@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(SCROLLBOX_STYLENAME, ""));
}

From source file:de.tudarmstadt.ukp.csniper.webapp.evaluation.MlPipeline.java

public String parse(EvaluationResult result, CAS cas) throws UIMAException {
    // get parse from db, or parse now
    String pennTree = "";
    CachedParse cp = repository.getCachedParse(result.getItem());
    if (cp != null && !cp.getPennTree().isEmpty()) {
        if ("ERROR".equals(cp.getPennTree())) {
            System.out.println("Unable to parse: [" + result.getItem().getCoveredText() + "] (cached)");
            return "";
        }/*from www.  j a  v  a 2  s.  c  om*/
        // write existing parse to cas for extraction
        pennTree = cp.getPennTree();
        addPennTree(cas, cp.getPennTree());
    } else {
        parser.process(cas);
        try {
            pennTree = StringUtils
                    .normalizeSpace(JCasUtil.selectSingle(cas.getJCas(), PennTree.class).getPennTree());
            repository.writeCachedParse(new CachedParse(result.getItem(), pennTree));
        } catch (IllegalArgumentException e) {
            System.out.println("Unable to parse: [" + result.getItem().getCoveredText() + "]");
            repository.writeCachedParse(new CachedParse(result.getItem(), "ERROR"));
        }
    }

    return pennTree;
}

From source file:com.dianping.puma.datahandler.AbstractDataHandler.java

protected void handleQueryEvent(BinlogEvent binlogEvent, DataHandlerResult result) {
    QueryEvent queryEvent = (QueryEvent) binlogEvent;
    String sql = StringUtils.normalizeSpace(queryEvent.getSql());
    if (StringUtils.startsWithIgnoreCase(sql, "ALTER ") || StringUtils.startsWithIgnoreCase(sql, "CREATE ")
            || StringUtils.startsWithIgnoreCase(sql, "DROP ")
            || StringUtils.startsWithIgnoreCase(sql, "RENAME ")
            || StringUtils.startsWithIgnoreCase(sql, "TRUNCATE ")) {

        handleDDlEvent(result, queryEvent, sql);

    } else if (StringUtils.equalsIgnoreCase(sql, "BEGIN")) {

        handleTransactionBeginEvent(binlogEvent, result, queryEvent);
    } else {/* ww w. j  a va2  s .com*/
        result.setEmpty(true);
        result.setFinished(true);
        // log.info("QueryEvent  sql=" + queryEvent.getSql());
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.tgrep.TGrepWriter.java

@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
    String filename;//from  w  ww  .j a v  a  2s .c  o  m
    String collectionId;
    String documentId;

    try {
        DocumentMetaData meta = DocumentMetaData.get(aJCas);
        collectionId = meta.getCollectionId();
        documentId = meta.getDocumentId();
    } catch (IllegalArgumentException e) {
        getLogger().warn("No DocumentMetaData found.");
        collectionId = "defaultCollectionId";
        documentId = "defaultDocumentId";
    }

    // if the collectionId contains inconvenient characters, remove them for the filename
    // filename = collectionId;
    filename = collectionId.replaceAll("\\W", "");

    try {
        PrintWriter pw = writers.get(filename);
        if (pw == null) {
            pw = new PrintWriter(new OutputStreamWriter(
                    new FileOutputStream(new File(outputPath, filename + EXT_CORPUS)), "UTF-8"));
            writers.put(filename, pw);
        }

        for (PennTree pt : JCasUtil.select(aJCas, PennTree.class)) {
            String tree = StringUtils.normalizeSpace(pt.getPennTree());
            // detect and handle malformed trees
            if (!isTermiteFree(tree)) {
                if (dropMalformedTrees) {
                    getLogger().warn("Dropping malformed tree: [" + tree + "].");
                    continue;
                } else {
                    throw new AnalysisEngineProcessException(
                            new IllegalArgumentException("Found malformed tree: [" + tree + "]."));
                }
            }
            // write comments and trees
            if (writeComments) {
                pw.printf("# %s,%d,%d\n", documentId, pt.getBegin(), pt.getEnd());
            }
            pw.printf("%s\n", tree);
        }
    } catch (IOException e) {
        throw new AnalysisEngineProcessException(e);
    }
}

From source file:com.haulmont.cuba.web.gui.components.WebEntityLinkField.java

@Override
public String getStyleName() {
    return StringUtils.normalizeSpace(super.getStyleName().replace(EMPTY_VALUE_STYLENAME, ""));
}