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

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

Introduction

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

Prototype

public static String abbreviate(String str, int offset, int maxWidth) 

Source Link

Document

Abbreviates a String using ellipses.

Usage

From source file:StringUtilsExampleV1.java

public static void main(String args[]) {

    System.err.println(StringUtils.abbreviate("Take time off working", 0, 10));
}

From source file:com.rslakra.java.string.TestApacheStringUtils.java

public static void main(String args[]) {

    System.err.println(StringUtils.abbreviate("Take time off working", 0, 10));
    System.err.println(StringUtils.capitalize("vanderLust"));
    System.err.println(StringUtils.center("MTV", 7, '='));
    System.err.println(StringUtils.chomp("temperature", "ure"));
    System.err.println(StringUtils.chop("Dane"));
    System.err.println(StringUtils.contains("Dorothy", "oro"));
    System.err.println(StringUtils.containsNone("r u m t", new char[] { 'r', 'o' }));
    System.err.println(StringUtils.containsOnly("r u m t", new char[] { 'r', 'o' }));
    System.err.println(StringUtils.countMatches("arthur", "r"));
    System.err.println(StringUtils.deleteWhitespace("f f f f"));
    System.err.println(StringUtils.difference("govern", "government"));
    System.err.println(StringUtils.getLevenshteinDistance("govern", "government"));

}

From source file:ac.elements.parser.ExtendedFunctions.java

/**
 * The main method.//from  w w w .  j a v a2  s  .  c  o m
 * 
 * @param args
 *            the arguments
 */
public static void main(String[] args) {

    java.math.BigInteger myInt = new java.math.BigInteger("1223");
    System.out.println(myInt);
    System.out.println(ExtendedFunctions.timePeriod(myInt));
    myInt = new java.math.BigInteger("59000");
    System.out.println(myInt);
    System.out.println(ExtendedFunctions.timePeriod(myInt));
    myInt = new java.math.BigInteger("59900");
    System.out.println(myInt);
    System.out.println(ExtendedFunctions.timePeriod(myInt));
    myInt = new java.math.BigInteger("5990000");
    System.out.println(myInt);
    System.out.println(ExtendedFunctions.timePeriod(myInt));
    myInt = new java.math.BigInteger("599000000");
    System.out.println(myInt);
    System.out.println(ExtendedFunctions.timePeriod(myInt));
    myInt = new java.math.BigInteger("59900000000");
    System.out.println(myInt);
    System.out.println(ExtendedFunctions.timePeriod(myInt));

    String sql = "select * from domain where `this`='test' and this2=\"test\"";

    System.out.println(ExtendedFunctions.escapeSql(sql));

    String unformattedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><QueryMessage\n"
            + "        xmlns=\"http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message\"\n"
            + "        xmlns:query=\"http://www.SDMX.org/resources/SDMXML/schemas/v2_0/query\">\n"
            + "    <Query>\n" + "        <query:CategorySchemeWhere>\n"
            + "   \t\t\t\t\t         <query:AgencyID>ECB\n\n\n\n</query:AgencyID>\n"
            + "        </query:CategorySchemeWhere>\n" + "    </Query>\n\n\n\n\n" + "</QueryMessage>";

    System.out.println(ExtendedFunctions.formatXml(unformattedXml));

    String company = "international business MACHINES. iag is here.";
    System.out.println(ExtendedFunctions.capitalize(company));

    String url = "\u1087\u1088\u1077\u1076\u1089";

    System.out.println(url);
    System.out.println(ExtendedFunctions.escUniJs(url));
    System.out.println(ExtendedFunctions.toUnicodeHTML(url));
    ExtendedFunctions.trim(url);
    url = "http://news.google.com/news?hl=en&client=safari&rls=en-us&q=get%20part%20of%20paragraph%20words%20google%20algorithm&um=1&ie=UTF-8&sa=N&tab=wn";
    System.out.println(ExtendedFunctions.chopUrl(url, 30));
    url = "http://www.pcplus.co.uk/node/3061/";
    System.out.println(ExtendedFunctions.chopUrl(url, 30));
    url = "http://www.opent.net/forum/security-problem-with-ot-script-on-ssl-t159.html";
    System.out.println(ExtendedFunctions.chopUrl(url, 30));
    System.out.println(ExtendedFunctions.escapeJavaScript("escapeJavas'\"cript"));
    System.err.println(StringUtils.abbreviate("Take time off working", 0, 10));
    System.err.println(StringUtils.capitalize("how is vandersar doing?"));
    String unescapedJava = "Are you \" for real?";
    System.err.println(StringEscapeUtils.escapeJava(unescapedJava));

    String unescapedJavaScript = "What's in a name?";
    System.err.println(ExtendedFunctions.escapeJavaScript(unescapedJavaScript));

    String unescapedSql = "Mc'Williams";
    System.err.println(StringEscapeUtils.escapeSql(unescapedSql));

    String unescapedXML = "<data>";
    System.err.println(StringEscapeUtils.escapeXml(unescapedXML));

    String unescapedHTML = "the data is <data>";
    System.err.println(StringEscapeUtils.escapeHtml(unescapedHTML));
    System.err.println(WordUtils.capitalize(unescapedHTML));
    System.err.println(WordUtils.swapCase(unescapedHTML));
}

From source file:com.hangum.tadpole.engine.sql.util.tables.SQLResultLabelProvider.java

@SuppressWarnings("unchecked")
public String getColumnText(Object element, int columnIndex) {
    HashMap<Integer, Object> rsResult = (HashMap<Integer, Object>) element;

    Object obj = rsResult.get(columnIndex);
    if (rsDAO != null) {
        if (isPretty & RDBTypeToJavaTypeUtils.isNumberType(rsDAO.getColumnType().get(columnIndex)))
            return addComma(obj);
    }//ww w  .j a v a 2  s.c o  m
    String showValue = "";
    try {
        int intShowWidth = Integer.parseInt(getRDBShowInTheColumn());
        if (intShowWidth != -1)
            showValue = StringUtils.abbreviate(obj.toString(), 0, intShowWidth);
        else
            showValue = obj.toString();
    } catch (Exception e) {
    }

    return obj == null ? PublicTadpoleDefine.DEFINE_NULL_VALUE : showValue;
}

From source file:com.hangum.tadpole.rdb.core.editors.main.composite.direct.SQLResultLabelProvider.java

@SuppressWarnings("unchecked")
public String getColumnText(Object element, int columnIndex) {
    HashMap<Integer, Object> rsResult = (HashMap<Integer, Object>) element;

    Object obj = rsResult.get(columnIndex);
    if (rsDAO != null && rsDAO.getColumnType().get(columnIndex) != null && queryMode == QUERY_MODE.QUERY) {
        if (isPretty & RDBTypeToJavaTypeUtils.isNumberType(rsDAO.getColumnType().get(columnIndex)))
            return addComma(obj);
    }/*from   w w  w .  j a  v  a  2  s.  c o m*/

    if (obj == null) {
        return PublicTadpoleDefine.DEFINE_NULL_VALUE;
    } else {
        if (getRDBShowInTheColumn() == -1) {
            return obj.toString();
        }
        return queryMode == QUERY_MODE.QUERY
                ? StringUtils.abbreviate(obj.toString(), 0, getRDBShowInTheColumn())
                : obj.toString();
    }
}

From source file:io.cloudslang.lang.cli.services.SyncTriggerEventListener.java

public static Map<String, Serializable> extractNotEmptyOutputs(Map<String, Serializable> data) {

    Map<String, Serializable> originalOutputs = (Map<String, Serializable>) data.get(LanguageEventData.OUTPUTS);
    Map<String, Serializable> extractedOutputs = new HashMap<>();

    if (MapUtils.isNotEmpty(originalOutputs)) {
        for (Map.Entry<String, Serializable> output : originalOutputs.entrySet()) {
            if (output.getValue() != null && !(StringUtils.isEmpty(output.getValue().toString()))) {
                extractedOutputs.put(output.getKey(),
                        StringUtils.abbreviate(output.getValue().toString(), 0, OUTPUT_VALUE_LIMIT));
            }/*w  ww. ja va  2  s  .  c o  m*/
        }
        return extractedOutputs;
    }
    return new HashMap<>();
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.export.template.AbstractSheetGenerator.java

/**
 * creates the cells in header and preheader row.
 * // w  w  w  .  ja va2 s  .  c o  m
 * @param featureExpression
 * @param displayName
 * @return the cell in the PREHEADER row.
 */
protected Cell addColumnHeaderCells(FeatureExpression<?> featureExpression, String displayName) {
    int columnCount = sheetContext.getColumnCount();

    Cell headerCell = headerRow.createCell(columnCount);
    headerCell.setCellStyle(wbContext.getStyles().get(IteraExcelStyle.HEADER));
    headerCell.setCellValue(displayName);
    addHeaderHyperlink(featureExpression, headerCell);

    sheetContext.getSheet().autoSizeColumn(columnCount);
    sheetContext.addColumn(featureExpression, headerCell);

    Cell preHeaderCell = preHeaderRow.createCell(columnCount);
    preHeaderCell.setCellStyle(wbContext.getStyles().get(IteraExcelStyle.HEADER));

    if (featureExpression instanceof EnumerationPropertyExpression) {
        String joinedLiteralList = StringUtils.join(
                ExcelGeneratorUtils.getListOfLiterals((EnumerationPropertyExpression) featureExpression), ";");
        String values = StringUtils.abbreviate(joinedLiteralList, 0, 255);
        preHeaderCell.setCellValue(values);
    }

    return preHeaderCell;
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.elasticExcel.export.ExcelExportServiceImpl.java

/**
 * @param literals//from   ww w . j ava 2  s  . c  o  m
 * @return a String with all enum literals, separeted by ';'
 */
private String joinEnumLiterals(Collection<EnumerationLiteralExpression> literals) {
    List<String> literalNames = new ArrayList<String>();
    for (EnumerationLiteralExpression e : literals) {
        literalNames.add(e.getPersistentName());
    }
    return StringUtils.abbreviate(StringUtils.join(literalNames, ";"), 0, 255);
}

From source file:org.caleydo.core.view.opengl.layout2.dnd.TextDragInfo.java

@Override
public String getLabel() {
    return StringUtils.abbreviate(text, 0, 20);
}

From source file:org.jenkinsci.plugins.shortwspath.ShortWsLocator.java

@Override
public FilePath locate(TopLevelItem item, Node node) {
    if (!(node instanceof Slave)) {
        // noop on master. The path is configurable and rather tricky to replace safely
        return null;
    }/* w ww.ja v a  2  s .co m*/
    Slave slave = (Slave) node;

    FilePath def = getDefaultPath(item, slave);
    if (def == null)
        return null; // No idea what the path is going to look like - do not touch

    int usabeSpace = getUsableSpace(def, node);
    if (usabeSpace > BUILD_PATH_LENGTH)
        return null; // There is plenty of room

    String iName = item.getName();

    LOGGER.info("Strip default.texts : " + STRIP_DEFAULT_TEXT);
    // Replace common text from build ,good to have when naming schema on jenkins dictates that jobs should be named in a certain way
    if (STRIP_DEFAULT_TEXT != null && !STRIP_DEFAULT_TEXT.equals("")) {
        if (iName.contains(STRIP_DEFAULT_TEXT)) {
            iName = iName.replace(STRIP_DEFAULT_TEXT, "");
        }
    }
    LOGGER.info("Remove Blanks : " + REMOVE_BLANKS);
    if (REMOVE_BLANKS) {
        //Replace any spaces in path to make resulting path more descriptive
        iName = iName.replace(" ", "");

    }

    String itemName = StringUtils.abbreviate(iName, 0, 16);

    // Replace the ellipsis with dashes to avoid problems with msbuild
    // prior to version 4.6.2.  It used its own path normalization (vs. built in .NET)
    // which doesn't recognize ... as a valid path.
    LOGGER.info("Initial prefix to add : " + INITIAL_PREFIX);
    // adding prefix in the beginning of the build job name to indicate that the item was changed
    if (INITIAL_PREFIX != null) {
        itemName = INITIAL_PREFIX + itemName;
    }
    LOGGER.info("Default text to replace : " + DEFAULT_TEXT_REPLACE);
    if (DEFAULT_TEXT_REPLACE != null) {
        LOGGER.info("Default text to replace : " + itemName + " -> "
                + itemName.replace("...", DEFAULT_TEXT_REPLACE));
        itemName = itemName.replace("...", DEFAULT_TEXT_REPLACE);
    } else {
        LOGGER.info("Default text to replace (NOTUSED): " + DEFAULT_TEXT_REPLACE);
    }

    final String digest = Util.getDigestOf(item.getFullName()).substring(0, 8);
    FilePath newPath = slave.getWorkspaceRoot().child(itemName + digest);

    return newPath.getRemote().length() < def.getRemote().length() ? newPath : null // Do nothing if it will not improve the situation
    ;
}