Example usage for org.apache.commons.lang3 StringUtils substringBefore

List of usage examples for org.apache.commons.lang3 StringUtils substringBefore

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substringBefore.

Prototype

public static String substringBefore(final String str, final String separator) 

Source Link

Document

Gets the substring before the first occurrence of a separator.

Usage

From source file:org.hbird.business.groundstation.hamlib.protocol.HamlibProtocolHelper.java

public static Map<String, String> toMap(String response) {
    String[] lines = StringUtils.split(response, "\n");

    Map<String, String> map = new HashMap<String, String>();
    for (String line : lines) {
        if (StringUtils.isBlank(line)) {
            // skip the blank lines
            continue;
        }//from www  . ja  v a 2 s .c om
        String key;
        String value;
        if (line.startsWith(HamlibProtocolConstants.RESPONSE_END_MARKER)) {
            key = HamlibProtocolConstants.RESPONSE_END_MARKER;
            value = StringUtils.substringAfter(line, HamlibProtocolConstants.RESPONSE_END_MARKER);
        } else {
            key = StringUtils.substringBefore(line, ":");
            value = StringUtils.substringAfter(line, ":");
        }
        map.put(key.trim(), value.trim());
    }
    return map;
}

From source file:org.igov.service.business.action.task.core.ActionTaskService.java

private String addCalculatedFields(String saFieldsCalc, TaskInfo curTask, String currentRow) {
    HistoricTaskInstance details = oHistoryService.createHistoricTaskInstanceQuery().includeProcessVariables()
            .taskId(curTask.getId()).singleResult();
    LOG.info("Process variables of the task {}:{}: {}", curTask.getId(), saFieldsCalc,
            details.getProcessVariables());
    if (details != null && details.getProcessVariables() != null) {
        Set<String> headersExtra = new HashSet<>();
        for (String key : details.getProcessVariables().keySet()) {
            if (!key.startsWith("sBody")) {
                headersExtra.add(key);/* w  w  w  .  j  a  v a  2  s .c om*/
            }
        }
        saFieldsCalc = StringUtils.substringAfter(saFieldsCalc, "\"");
        saFieldsCalc = StringUtils.substringBeforeLast(saFieldsCalc, "\"");
        for (String expression : saFieldsCalc.split(";")) {
            LOG.info("Processing expression: {}", expression);
            String variableName = StringUtils.substringBefore(expression, "=");
            String condition = StringUtils.substringAfter(expression, "=");
            LOG.info("Checking variable with (name={}, condition={}, expression={}) ", variableName, condition,
                    expression);
            try {
                Object conditionResult = getObjectResultofCondition(headersExtra, details, details, condition);
                currentRow = currentRow + ";" + conditionResult;
                LOG.info("Adding calculated field {} with the value {}", variableName, conditionResult);
            } catch (Exception oException) {
                LOG.error("Error: {}, occured while processing (variable={}) ", oException.getMessage(),
                        variableName);
                LOG.debug("FAIL:", oException);
            }
        }
    }
    return currentRow;
}

From source file:org.igov.service.business.action.task.core.ActionTaskService.java

protected void processExtractFieldsParameter(Set<String> headersExtra, HistoricTaskInstance currTask,
        String saFields, Map<String, Object> line) {
    HistoricTaskInstance details = oHistoryService.createHistoricTaskInstanceQuery().includeProcessVariables()
            .taskId(currTask.getId()).singleResult();
    LOG.info("Process variables of the task {}:{}", currTask.getId(), details.getProcessVariables());
    if (details.getProcessVariables() != null) {
        LOG.info("(Cleaned saFields={})", saFields);
        String[] expressions = saFields.split(";");
        if (expressions != null) {
            for (String expression : expressions) {
                String variableName = StringUtils.substringBefore(expression, "=");
                String condition = StringUtils.substringAfter(expression, "=");
                LOG.info("Checking variable with (name={}, condition={}, expression={})", variableName,
                        condition, expression);
                try {
                    Object conditionResult = getObjectResultofCondition(headersExtra, currTask, details,
                            condition);/* ww  w.j a  va  2s .co  m*/
                    line.put(variableName, conditionResult);
                } catch (Exception oException) {
                    LOG.error("Error: {}, occured while processing variable {}", oException.getMessage(),
                            variableName);
                    LOG.debug("FAIL:", oException);
                }
            }
        }
    }
}

From source file:org.igov.service.business.action.task.core.ActionTaskService.java

public String formHeader(String saFields, List<HistoricTaskInstance> foundHistoricResults,
        String saFieldsCalc) {//from ww  w. j ava2  s  .c  o  m
    String res = null;
    if (saFields != null && !"".equals(saFields.trim())) {
        LOG.info("Fields have custom header names");
        StringBuilder sb = new StringBuilder();
        String[] fields = saFields.split(";");
        LOG.info("fields: " + fields);
        for (int i = 0; i < fields.length; i++) {
            if (fields[i].contains("\\=")) {
                sb.append(StringUtils.substringBefore(fields[i], "\\="));
                LOG.info("if (fields[i].contains(\"\\\\=\"))_sb: " + sb);
            } else {
                sb.append(fields[i]);
                LOG.info("else_sb: " + sb);
            }
            if (i < fields.length - 1) {
                sb.append(";");
                LOG.info("(i < fields.length - 1)_sb: " + sb);
            }
        }
        res = sb.toString();
        res = res.replaceAll("\\$\\{", "");
        res = res.replaceAll("\\}", "");
        LOG.info("Formed header from list of fields: {}", res);
    } else {
        if (foundHistoricResults != null && !foundHistoricResults.isEmpty()) {
            HistoricTaskInstance historicTask = foundHistoricResults.get(0);
            Set<String> keys = historicTask.getProcessVariables().keySet();
            StringBuilder sb = new StringBuilder();
            Iterator<String> iter = keys.iterator();
            while (iter.hasNext()) {
                sb.append(iter.next());
                if (iter.hasNext()) {
                    sb.append(";");
                }
            }
            res = sb.toString();
            LOG.info("res: " + res);
        }
        LOG.info("Formed header from all the fields of a task: {}", res);
    }
    if (saFieldsCalc != null) {
        saFieldsCalc = StringUtils.substringAfter(saFieldsCalc, "\"");
        saFieldsCalc = StringUtils.substringBeforeLast(saFieldsCalc, "\"");
        String[] params = saFieldsCalc.split(";");
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < params.length; i++) {
            String currParam = params[i];
            String cutHeader = StringUtils.substringBefore(currParam, "=");
            LOG.info("Adding header to the csv file from saFieldsCalc: {}", cutHeader);
            sb.append(cutHeader);
            if (i < params.length - 1) {
                sb.append(";");
            }
        }
        res = res + ";" + sb.toString();
        LOG.info("Header with calculated fields: {}", res);
    }
    return res;
}

From source file:org.imsglobal.lti.toolProvider.mediaType.SecurityContract.java

/**
 * Class constructor./*from w w w.java 2  s .c  om*/
 *
 * @param ToolProvider toolProvider  Tool Provider instance
 * @param string secret Shared secret
 */
public SecurityContract(ToolProvider toolProvider, String secret) {

    tcContexts = new HashMap<String, String>(); //toolConsumer contexts from JSON-LD spec
    for (JSONContext context : toolProvider.getConsumer().getProfile().getContexts()) {
        tcContexts.putAll(context.getTerms());
        //PHP: $tcContexts = array_merge(get_object_vars($context), $tcContexts);
        //context here is a JSON-LD Context, it contains rewrite rules and ontology refs for a JSON schema
    }

    this.setSharedSecret(secret);

    toolServices = new HashMap<String, ToolService>();
    for (ToolService requiredService : toolProvider.getRequiredServices()) {
        for (String format : requiredService.getFormats()) {
            ServiceDefinition service = toolProvider.findService(format, requiredService.getActions());
            if ((service != null) && toolServices.containsKey(service.getId())) {
                String id = service.getId();
                String part1 = StringUtils.substringBefore(id, ":");
                String part2 = StringUtils.substringAfter(id, ":");
                if (StringUtils.isNotEmpty(part2)) {
                    if (tcContexts.containsKey(part1)) {
                        id = tcContexts.get(part1) + part2;
                    }
                }
                ToolService toolService = new ToolService();
                toolService.setType("RestServiceProfile");
                toolService.setService(id);
                toolService.setActions(requiredService.getActions());
                toolServices.put(service.getId(), toolService);
            }
        }
    }
    for (ToolService optionalService : toolProvider.getOptionalServices()) {
        for (String format : optionalService.getFormats()) {
            ServiceDefinition service = toolProvider.findService(format, optionalService.getActions());
            if ((service != null) && toolServices.containsKey(service.getId())) {
                String id = service.getId();
                String part1 = StringUtils.substringBefore(id, ":");
                String part2 = StringUtils.substringAfter(id, ":");
                if (StringUtils.isNotEmpty(part2)) {
                    if (tcContexts.containsKey(part1)) {
                        id = tcContexts.get(part1) + part2;
                    }
                }
                ToolService toolService = new ToolService();
                toolService.setType("RestServiceProfile");
                toolService.setService(id);
                toolService.setActions(optionalService.getActions());
                toolServices.put(service.getId(), toolService);
            }
        }
    }
}

From source file:org.ingini.mongodb.jongo.example.util.ImportQuotes.java

public static void main(String[] args) throws IOException, URISyntaxException {
    Jongo jongo = new Jongo(new MongoClient("127.0.0.1", 27017).getDB("movie_db"));
    MongoCollection quoteCollection = jongo.getCollection("quotes");

    URI uri = ImportQuotes.class.getClassLoader().getResource("raw/quotes.list").toURI();
    Stream<String> lines = Files.lines(Paths.get(uri), forName("windows-1252"));

    List<List<String>> quotesList = new ArrayList<>();

    lines.skip(14).forEach(s -> {//from  w  w  w  .  jav a2s.c  o m
        List<String> quotes = new ArrayList<>();
        if (quotesList.size() == 0) {
            quotesList.add(quotes);
        }
        quotes = quotesList.get(quotesList.size() - 1);

        if (s.isEmpty() && quotes.get(quotes.size() - 1).isEmpty()) {
            quotesList.add(new ArrayList<>());
        }

        quotes.add(s);
    });

    System.out.println("Quotes lists: " + quotesList.size());

    List<FilmQuote> filmQuotes = new ArrayList<>();
    for (List<String> quotes : quotesList) {
        Set<ActorQuote> actorQuotes = new LinkedHashSet<>();
        Iterator<String> iterator = quotes.subList(1, quotes.size()).iterator();

        String actorName = null;
        String quote = null;
        while (iterator.hasNext()) {
            String s = iterator.next();
            if (s.contains(":")) {
                if (actorName != null && quote != null) {
                    actorQuotes.add(new ActorQuote(actorName, quote));
                }
                actorName = StringUtils.substringBefore(s, ":");
                quote = StringUtils.substringAfter(s, ":");
            } else if (s.isEmpty()) {
                actorQuotes.add(new ActorQuote(actorName, quote));
            } else {
                quote += StringUtils.substringAfter(s, " ");
            }

        }
        FilmQuote filmQuote = new FilmQuote("english", quotes.get(0), actorQuotes);
        filmQuotes.add(filmQuote);
        quoteCollection.insert(filmQuote);
    }

    System.out.println("Film Quotes lists: " + filmQuotes.size());

}

From source file:org.jasig.cas.support.oauth.web.BaseOAuthWrapperController.java

/**
 * Return the method to call according to the url.
 *
 * @param request the incoming http request
 * @return the method to call according to the url
 */// w  w  w. ja  va 2 s  .  c  o  m
private String getMethod(final HttpServletRequest request) {
    String method = request.getRequestURI();
    if (method.indexOf('?') >= 0) {
        method = StringUtils.substringBefore(method, "?");
    }
    final int pos = method.lastIndexOf('/');
    if (pos >= 0) {
        method = method.substring(pos + 1);
    }
    return method;
}

From source file:org.kawanfw.commons.client.http.HttpHostPartsExtractor.java

/**
 * Returns the host name.//from  w ww  .  j  ava  2 s.c  o  m
 *
 * @return the host name (IP or DNS name)
 */
public String getHostName() {

    String hostname = StringUtils.substringAfter(httpHost, "://");

    if (hostname.contains(":")) {
        hostname = StringUtils.substringBefore(hostname, ":");
    }

    return hostname;
}

From source file:org.kawanfw.commons.client.http.HttpHostPartsExtractor.java

/**
 * Returns the scheme name ("http" or "https")
 *
 * @return "http" or "https"//from   w ww. j av a2  s  .  com
 */
public String getSchemeName() {
    String shemeName = StringUtils.substringBefore(httpHost, "://");
    return shemeName;
}

From source file:org.kawanfw.commons.server.util.FileJoiner.java

/**
 * Delete all previous existing chunks starting at 2.
 * @param filePart   the chunk that may be a fist chunk
 *///from   w w  w . java  2  s. c  om
public void deleteExistingChunks(String filePart) {

    if (!isFirstChunk(filePart)) {
        return;
    }

    // Delete all chunks
    String rawFilename = StringUtils.substringBefore(filePart, ".1.kawanfw.chunk");

    int count = 2;
    while (true) {
        File chunk = new File(getFilePart(rawFilename, count));
        if (chunk.exists()) {
            chunk.delete();
        } else {
            break;
        }

        count++;
    }
}