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

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

Introduction

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

Prototype

public static String left(String str, int len) 

Source Link

Document

Gets the leftmost len characters of a String.

Usage

From source file:org.sonar.server.component.index.ComponentIndexSearchFeature.java

protected MatchQueryBuilder partialTermQuery(String queryTerm) {
    // We will truncate the search to the maximum length of nGrams in the index.
    // Otherwise the search would for sure not find any results.
    String truncatedQuery = StringUtils.left(queryTerm, DefaultIndexSettings.MAXIMUM_NGRAM_LENGTH);

    return matchQuery(SEARCH_GRAMS_ANALYZER.subField(FIELD_NAME), truncatedQuery);
}

From source file:org.sonar.server.es.textsearch.ComponentTextSearchFeature.java

protected MatchQueryBuilder partialTermQuery(String queryTerm, String fieldName) {
    // We will truncate the search to the maximum length of nGrams in the index.
    // Otherwise the search would for sure not find any results.
    String truncatedQuery = StringUtils.left(queryTerm, DefaultIndexSettings.MAXIMUM_NGRAM_LENGTH);
    return matchQuery(SEARCH_GRAMS_ANALYZER.subField(fieldName), truncatedQuery);
}

From source file:org.sonar.server.es.textsearch.ComponentTextSearchFeatureRepertoire.java

protected MatchQueryBuilder tokenQuery(String queryTerm, String fieldName,
        DefaultIndexSettingsElement analyzer) {
    // We will truncate the search to the maximum length of nGrams in the index.
    // Otherwise the search would for sure not find any results.
    String truncatedQuery = StringUtils.left(queryTerm, DefaultIndexSettings.MAXIMUM_NGRAM_LENGTH);
    return matchQuery(analyzer.subField(fieldName), truncatedQuery);
}

From source file:org.springframework.cassandra.test.unit.core.cql.generator.KeyspaceOperationCqlGeneratorTest.java

public String randomKeyspaceName() {
    String name = getClass().getSimpleName() + "_" + UUID.randomUUID().toString().replace("-", "");
    return StringUtils.left(name, 47).toLowerCase();
}

From source file:org.trustedanalytics.datasetpublisher.boundary.MetadataMapper.java

/**
 * Converts table name to valid string according to database engine and driver constraints.
 * @param string table name/*  www  .j  a v  a2  s.c  om*/
 * @return valid name
 */
private String toValidTableName(String string) {
    final Function<String, String> lowercase = String::toLowerCase;

    return lowercase
            // prefix must be a letter
            .andThen(s -> s.matches("^[a-zA-Z].*") ? s : "x" + s)
            // replace non alphanumeric characters
            .andThen(s -> s.replaceAll("\\W", "_"))
            // add underscore after name that is Impala reserved word
            .andThen(s -> isValidKeyword(s) ? s : s + "_")
            // limit identifier length
            .andThen(s -> StringUtils.left(s, IDENTIFIER_MAX_LEN))
            // apply initial name
            .apply(string);
}

From source file:org.xaloon.wicket.component.repository.util.RepositoryHelper.java

public static String getFileName(String nodePath) {
    final String nstr = StringUtils.left(nodePath, nodePath.lastIndexOf("/"));
    return StringUtils.substring(nstr, nstr.lastIndexOf("/") + 1);
}

From source file:org.zanata.webtrans.server.rpc.GetGlossaryHandler.java

@Override
public GetGlossaryResult execute(GetGlossary action, ExecutionContext context) throws ActionException {
    identity.checkLoggedIn();//  w ww  . ja  v  a 2 s .c o  m

    String searchText = action.getQuery();
    ShortString abbrev = new ShortString(searchText);
    SearchType searchType = action.getSearchType();
    log.debug("Fetching Glossary matches({}) for \"{}\"", searchType, abbrev);

    LocaleId localeId = action.getLocaleId();
    ArrayList<GlossaryResultItem> results;

    String projQualifiedName = ProjectService
            .getGlossaryQualifiedName(action.getProjectIterationId().getProjectSlug());
    try {
        List<Object[]> projMatches = glossaryDAO.getSearchResult(searchText, searchType,
                action.getSrcLocaleId(), MAX_RESULTS, projQualifiedName);

        List<Object[]> globalMatches = glossaryDAO.getSearchResult(searchText, searchType,
                action.getSrcLocaleId(), MAX_RESULTS, GlossaryUtil.GLOBAL_QUALIFIED_NAME);

        Map<GlossaryKey, GlossaryResultItem> matchesMap = Maps.newLinkedHashMap();

        processMatches(globalMatches, matchesMap, searchText, localeId, GlossaryUtil.GLOBAL_QUALIFIED_NAME);

        processMatches(projMatches, matchesMap, searchText, localeId, projQualifiedName);

        results = Lists.newArrayList(matchesMap.values());
    } catch (ParseException e) {
        if (e.getCause() instanceof BooleanQuery.TooManyClauses) {
            log.warn("BooleanQuery.TooManyClauses, query too long to parse '" + StringUtils.left(searchText, 80)
                    + "...'");
        } else {
            if (searchType == SearchType.FUZZY) {
                log.warn("Can't parse fuzzy query '" + searchText + "'");
            } else {
                // escaping failed!
                log.error("Can't parse query '" + searchText + "'", e);
            }
        }
        results = new ArrayList<>(0);
    }
    Collections.sort(results, COMPARATOR);
    log.debug("Returning {} Glossary matches for \"{}\"", results.size(), abbrev);
    return new GetGlossaryResult(action, results);
}

From source file:pl.otros.logview.api.gui.LogDataTableModel.java

public Object getValueAt(int rowIndex, int columnIndex) {
    LogData ld = getLogData(rowIndex);// w w  w . java2  s  .  co m
    if (ld == null) {
        System.err.println("LogDataTableModel.getValueAt() null form row " + rowIndex);
        dumpInfo();
    }
    Object result = null;
    TableColumns selectColumn = TableColumns.getColumnById(columnIndex);
    assert ld != null;
    switch (selectColumn) {
    case ID:
        result = ld.getId();
        break;
    case TIME:
        result = ld.getDate();
        break;
    case DELTA:
        result = new TimeDelta(ld.getDate());
        break;
    case LEVEL:
        result = ld.getLevel();
        break;
    case MESSAGE:
        result = ld.getMessage();
        break;
    case CLASS:
        String clazz = ld.getClazz();
        if (!classWrapperCache.containsKey(clazz)) {
            classWrapperCache.put(clazz, new ClassWrapper(clazz));
        }
        result = classWrapperCache.get(clazz);
        break;
    case METHOD:
        int maximumMessageLength = 2000;
        result = StringUtils.left(ld.getMethod(), maximumMessageLength);
        break;
    case THREAD:
        result = ld.getThread();
        break;
    case MARK:
        result = ld.getMarkerColors();
        break;
    case NOTE:
        result = ld.getNote();
        if (result == null) {
            result = EMPTY_NOTE;
        }
        break;
    case FILE:
        result = ld.getFile();
        break;
    case LINE:
        result = ld.getLine();
        break;
    case NDC:
        result = ld.getNDC();
        break;
    case PROPERTIES:
        result = getProperties(ld);
        break;
    case LOGGER_NAME:
        final String loggerName = ld.getLoggerName();
        if (!classWrapperCache.containsKey(loggerName)) {
            classWrapperCache.put(loggerName, new ClassWrapper(loggerName));
        }
        result = classWrapperCache.get(loggerName);
        break;
    case LOG_SOURCE:
        result = ld.getLogSource();
        break;
    default:
        break;
    }
    return result;
}

From source file:pl.otros.logview.gui.LogDataTableModel.java

public Object getValueAt(int rowIndex, int columnIndex) {
    LogData ld = getLogData(rowIndex);//from   www. j  a  v a 2  s . com
    if (ld == null) {
        System.err.println("LogDataTableModel.getValueAt() null form row " + rowIndex);
        dumpInfo();
    }
    Object result = null;
    TableColumns selecteColumn = TableColumns.getColumnById(columnIndex);
    switch (selecteColumn) {
    case ID:
        result = ld.getId();
        break;
    case TIME:
        result = ld.getDate();
        break;
    case DELTA:
        result = new TimeDelta(ld.getDate());
        break;
    case LEVEL:
        result = ld.getLevel();
        break;
    case MESSAGE:
        result = ld.getMessage();
        break;
    case CLASS:
        String clazz = ld.getClazz();
        if (!classWrapperCache.containsKey(clazz)) {
            classWrapperCache.put(clazz, new ClassWrapper(clazz));
        }
        result = classWrapperCache.get(clazz);
        break;
    case METHOD:
        result = StringUtils.left(ld.getMethod(), maximumMessageLength);
        break;
    case THREAD:
        result = ld.getThread();
        break;
    case MARK:
        result = ld.getMarkerColors();
        break;
    case NOTE:
        result = ld.getNote();
        if (result == null) {
            result = EMPTY_NOTE;
        }
        break;
    case FILE:
        result = ld.getFile();
        break;
    case LINE:
        result = ld.getLine();
        break;
    case NDC:
        result = ld.getNDC();
        break;
    case PROPERTIES:
        result = getProperties(ld);
        break;
    case LOGGER_NAME:
        final String loggerName = ld.getLoggerName();
        if (!classWrapperCache.containsKey(loggerName)) {
            classWrapperCache.put(loggerName, new ClassWrapper(loggerName));
        }
        result = classWrapperCache.get(loggerName);
        break;
    case LOG_SOURCE:
        result = ld.getLogSource();
        break;
    default:
        break;
    }
    return result;
}

From source file:pl.otros.logview.gui.message.update.LogDataFormatter.java

public java.util.List<TextChunkWithStyle> format() throws Exception {

    LOGGER.finer("Start do in background");

    String s1 = "Date:    " + dateFormat.format(ld.getDate()) + NEW_LINE;
    chunks.add(new TextChunkWithStyle(s1, mainStyle));
    s1 = "Class:   " + ld.getClazz() + NEW_LINE;
    chunks.add(new TextChunkWithStyle(s1, classMethodStyle));
    s1 = "Method:  " + ld.getMethod() + NEW_LINE;
    chunks.add(new TextChunkWithStyle(s1, classMethodStyle));
    s1 = "Level:   ";
    chunks.add(new TextChunkWithStyle(s1, classMethodStyle));
    Icon levelIcon = LevelRenderer.getIconByLevel(ld.getLevel());
    if (levelIcon != null) {
        chunks.add(new TextChunkWithStyle(levelIcon));
    }// w w  w. j av a2s . c  o m
    s1 = " " + ld.getLevel().getName() + NEW_LINE;
    chunks.add(new TextChunkWithStyle(s1, classMethodStyle));

    chunks.add(new TextChunkWithStyle("Thread: " + ld.getThread() + NEW_LINE, classMethodStyle));

    if (StringUtils.isNotBlank(ld.getFile())) {
        s1 = "File: " + ld.getFile();
        if (StringUtils.isNotBlank(ld.getLine())) {
            s1 = s1 + ":" + ld.getLine();
        }
        chunks.add(new TextChunkWithStyle(s1 + NEW_LINE, mainStyle));
    }

    if (StringUtils.isNotBlank(ld.getNDC())) {
        chunks.add(new TextChunkWithStyle("NDC: " + ld.getNDC() + NEW_LINE, mainStyle));
    }

    if (StringUtils.isNotBlank(ld.getLoggerName())) {
        chunks.add(new TextChunkWithStyle("Logger name: " + ld.getLoggerName() + NEW_LINE, mainStyle));
    }

    Map<String, String> properties = ld.getProperties();
    if (properties != null && properties.size() > 0) {
        chunks.add(new TextChunkWithStyle("Properties:\n", boldArialStyle));
        ArrayList<String> keys = new ArrayList(properties.keySet());
        Collections.sort(keys);
        for (String key : keys) {
            chunks.add(new TextChunkWithStyle(key + "=", propertyNameStyle));
            chunks.add(new TextChunkWithStyle(properties.get(key) + "\n", propertyValueStyle));
        }
    }

    s1 = "Message: ";
    chunks.add(new TextChunkWithStyle(s1, boldArialStyle));
    s1 = ld.getMessage();
    if (s1.length() > maximumMessageSize) {
        int removedCharsSize = s1.length() - maximumMessageSize;
        s1 = StringUtils.left(s1, maximumMessageSize)
                + String.format("%n...%n...(+%,d chars)", removedCharsSize);
    }

    Collection<MessageFormatter> formatters = formattersContainer.getElements();
    int charsBeforeMessage = countCharsBeforeMessage(chunks);
    for (MessageFormatter messageFormatter : formatters) {
        if (cancelStatus.isCancelled()) {
            return chunks;
        }
        s1 = messageUtils.formatMessageWithTimeLimit(s1, messageFormatter, 5);
        s1 = StringUtils.remove(s1, '\r');
    }
    chunks.add(new TextChunkWithStyle(s1, mainStyle));

    Collection<MessageColorizer> colorizers = colorizersContainer.getElements();
    ArrayList<MessageFragmentStyle> messageFragmentStyles = new ArrayList<MessageFragmentStyle>();
    for (MessageColorizer messageColorizer : colorizers) {
        if (messageColorizer.getPluginableId().equals(SearchResultColorizer.class.getName())) {
            continue;
        }
        messageFragmentStyles
                .addAll(messageUtils.colorizeMessageWithTimeLimit(s1, charsBeforeMessage, messageColorizer, 5));
    }

    for (MessageFragmentStyle messageFragmentStyle : messageFragmentStyles) {
        chunks.add(new TextChunkWithStyle(null, messageFragmentStyle));
    }

    chunks.add(new TextChunkWithStyle("\nMarked: ", boldArialStyle));
    if (ld.isMarked()) {
        MarkerColors markerColors = ld.getMarkerColors();
        chunks.add(new TextChunkWithStyle(" " + markerColors.name() + NEW_LINE,
                getStyleForMarkerColor(markerColors)));
    } else {
        chunks.add(new TextChunkWithStyle("false\n", boldArialStyle));
    }

    Note note = ld.getNote();
    if (note != null && note.getNote() != null && note.getNote().length() > 0) {
        s1 = "Note: " + note.getNote();
        chunks.add(new TextChunkWithStyle(s1, boldArialStyle));
    }

    return chunks;
}