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.eclipse.recommenders.utils.rcp.JavaElementResolver.java

public ITypeName toRecType(IType jdtType) {
    ensureIsNotNull(jdtType);/*from  www.ja v  a 2 s  . com*/
    jdtType = JdtUtils.resolveJavaElementProxy(jdtType);
    ITypeName recType = (ITypeName) cache.inverse().get(jdtType);
    if (recType == null) {
        String fullyQualifiedName = jdtType.getFullyQualifiedName();
        fullyQualifiedName = StringUtils.substringBefore(fullyQualifiedName, "<");
        recType = VmTypeName.get("L" + fullyQualifiedName.replace('.', '/'));
        registerRecJdtElementPair(recType, jdtType);
    }
    return recType;
}

From source file:org.eclipse.recommenders.utils.Zips.java

public static IMethodName method(ZipEntry e, String suffix) {
    String name = "L" + StringUtils.substringBefore(e.getName(), suffix);
    int start = name.lastIndexOf('/');
    char[] chars = name.toCharArray();
    chars[start] = '.';
    for (int i = start + 1; i < chars.length; i++) {
        if (chars[i] == '.') {
            chars[i] = '/';
        }// ww  w  .ja va2 s .  c  om
    }
    return VmMethodName.get(new String(chars));
}

From source file:org.fabrician.enabler.DockerContainer.java

private boolean isHostPortVacant(final String varName, final String varValue) {
    String host_port_str = StringUtils.substringBefore(varValue, ":");
    int host_port = NumberUtils.createInteger(host_port_str);
    if (host_port < 1024) {
        throw new RuntimeException("Illegal Host port [" + host_port
                + "] specified in the [0-1023] well-known TCP/UDP ports range.");
    }/*ww  w.  j  av a  2s .com*/
    if (checkServerPortInUse(host_port)) {
        getEngineLogger().warning("External host port [" + host_port_str
                + "] associated with runtime context variable [" + varName + "] is already in use.");
        return false;
    }
    return true;

}

From source file:org.flowable.app.rest.service.api.repository.AppDeploymentCollectionResource.java

public Map<String, String> splitQueryString(String queryString) {
    if (StringUtils.isEmpty(queryString)) {
        return Collections.emptyMap();
    }/*from w  w  w  .  j a v a 2 s  .  co  m*/
    Map<String, String> queryMap = new HashMap<>();
    for (String param : queryString.split("&")) {
        queryMap.put(StringUtils.substringBefore(param, "="), decode(StringUtils.substringAfter(param, "=")));
    }
    return queryMap;
}

From source file:org.gbif.ipt.config.JdbcSupport.java

protected int setProperties(Properties props) {
    driver.clear();//from  w  w w  .  j a  v a  2 s  .  c o  m
    // get distinct list of driver names
    Set<String> names = new HashSet<String>();
    for (Enumeration propertyNames = props.propertyNames(); propertyNames.hasMoreElements();) {
        String name = StringUtils.substringBefore((String) propertyNames.nextElement(), ".");
        names.add(name);
    }
    // create a jdbc info object for each
    for (String name : names) {
        name = name.toLowerCase();
        LIMIT_TYPE lt = LIMIT_TYPE.valueOf(props.getProperty(name + ".limitType"));
        JdbcInfo info = new JdbcInfo(name, props.getProperty(name + ".title"),
                props.getProperty(name + ".driver"), props.getProperty(name + ".url"), lt);
        driver.put(name, info);
    }
    return driver.size();
}

From source file:org.gbif.registry.ws.util.DataCiteConverter.java

public static String truncateDescription(DOI doi, String xml, URI target) throws InvalidMetadataException {
    try {//from ww w.j av  a  2 s.c om
        DataCiteMetadata dm = DataCiteValidator.fromXml(xml);
        String description = Joiner.on("\n").join(dm.getDescriptions().getDescription().get(0).getContent());
        dm.setDescriptions(DataCiteMetadata.Descriptions.builder().addDescription()
                .withDescriptionType(DescriptionType.ABSTRACT).withLang(ENGLISH)
                .addContent(StringUtils.substringBefore(description, "constituent datasets:")
                        + String.format("constituent datasets:\nPlease see %s for full list.", target))
                .end().build());
        return DataCiteValidator.toXml(doi, dm);

    } catch (JAXBException e) {
        throw new InvalidMetadataException("Failed to deserialize datacite xml for DOI " + doi, e);
    }
}

From source file:org.goko.controller.grbl.v08.GrblControllerService.java

protected void handleConfigurationReading(String cofigurationMessage) throws GkException {
    String identifier = StringUtils.substringBefore(cofigurationMessage, "=").trim();
    String value = StringUtils.substringBetween(cofigurationMessage, "=", "(").trim();
    configuration.setValue(identifier, value);
    LOG.info("Updating setting '" + identifier + "' with value '" + value + "'");
}

From source file:org.grible.model.Table.java

public Table(File file) throws Exception {
    setFile(file);/* w  w  w.j  ava 2s.c  o m*/
    setName(StringUtils.substringBefore(file.getName(), ".json"));
    this.tableJson = new TableJson();
}

From source file:org.grible.servlets.app.imp.StorageImport.java

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
 *      response)/*from   ww w. ja  va 2 s  . co  m*/
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {
        if (Security.anyServletEntryCheckFailed(request, response)) {
            return;
        }
        String className = Streams.asString(request.getPart("class").getInputStream());

        Part filePart = request.getPart("file");
        String fileName = ServletHelper.getFilename(filePart);
        String storageName = StringUtils.substringBefore(fileName, ".xls");
        int categoryId = Integer.parseInt(request.getParameter("category"));
        String categoryPath = StringHelper
                .getFolderPathWithoutLastSeparator(request.getParameter("categorypath"));
        int productId = Integer.parseInt(request.getParameter("product"));

        InputStream filecontent = filePart.getInputStream();
        ExcelFile excelFile = new ExcelFile(filecontent, ServletHelper.isXlsx(fileName));

        Category category = null;
        if (ServletHelper.isJson()) {
            jDao = new JsonDao();
            category = new Category(categoryPath, TableType.STORAGE, productId);
        } else {
            pDao = new PostgresDao();
            category = new Category(categoryId);
        }

        if (DataManager.getInstance().getDao().isTableInProductExist(storageName, TableType.STORAGE,
                category)) {

            Table table = null;
            int currentKeysCount = 0;
            if (ServletHelper.isJson()) {
                table = jDao.getTable(storageName, TableType.STORAGE, category);
                currentKeysCount = table.getTableJson().getKeys().length;
            } else {
                table = pDao.getTable(storageName, categoryId);
                currentKeysCount = table.getKeys().length;
            }
            int importedKeysCount = excelFile.getKeys().length;

            if (currentKeysCount != importedKeysCount) {
                throw new Exception("Parameters number is different.<br>In the current storage: "
                        + currentKeysCount + ". In the Excel file: " + importedKeysCount + ".");
            }

            request.getSession(true).setAttribute("importedTable", table);
            request.getSession(false).setAttribute("importedFile", excelFile);
            String destination = "/storages/?product=" + productId + "&id=" + table.getId();
            response.sendRedirect(destination);
        } else {
            int storageId = 0;
            Key[] keys = excelFile.getKeys();
            String[][] values = excelFile.getValues();
            storageId = DataManager.getInstance().getDao().insertTable(storageName, TableType.STORAGE, category,
                    null, className, keys, values);

            String message = "";
            if (className.equals("")) {
                message = "'" + storageName
                        + "' storage was successfully imported. WARNING: Class name is empty.";
            } else if (!className.endsWith("Info")) {
                message = "'" + storageName
                        + "' storage was successfully imported. WARNING: Class name does not end with 'Info'.";
            } else {
                message = "'" + storageName + "' storage was successfully imported.";
            }

            String destination = "";
            if (storageId > 0) {
                destination = "/storages/?product=" + productId + "&id=" + storageId;
            } else {
                destination = "/storages/?product=" + productId;
            }
            request.getSession(true).setAttribute("importResult", message);
            response.sendRedirect(destination);
        }
    } catch (Exception e) {
        int productId = Integer.parseInt(request.getParameter("product"));
        String destination = "/storages/?product=" + productId;
        String message = Lang.get("error") + ": " + e.getMessage();
        e.printStackTrace();
        request.getSession(true).setAttribute("importResult", message);
        response.sendRedirect(destination);
    }
}

From source file:org.grible.servlets.app.imp.TableImport.java

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
 *      response)/*  w w w .  j  a  va2 s.  com*/
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {
        if (Security.anyServletEntryCheckFailed(request, response)) {
            return;
        }
        Part filePart = request.getPart("file");
        String fileName = ServletHelper.getFilename(filePart);
        String tableName = StringUtils.substringBefore(fileName, ".xls");
        int categoryId = Integer.parseInt(request.getParameter("category"));
        String categoryPath = StringHelper
                .getFolderPathWithoutLastSeparator(request.getParameter("categorypath"));
        int productId = Integer.parseInt(request.getParameter("product"));

        InputStream filecontent = filePart.getInputStream();
        ExcelFile excelFile = new ExcelFile(filecontent, ServletHelper.isXlsx(fileName));

        Category category = null;
        if (ServletHelper.isJson()) {
            jDao = new JsonDao();
            category = new Category(categoryPath, TableType.TABLE, productId);
        } else {
            pDao = new PostgresDao();
            category = new Category(categoryId);
        }

        if (DataManager.getInstance().getDao().isTableInProductExist(tableName, TableType.TABLE, category)) {
            Table table = null;
            int currentKeysCount = 0;
            if (ServletHelper.isJson()) {
                table = jDao.getTable(tableName, TableType.TABLE, category);
                currentKeysCount = table.getTableJson().getKeys().length;
            } else {
                table = pDao.getTable(tableName, categoryId);
                currentKeysCount = table.getKeys().length;
            }

            int importedKeysCount = excelFile.getKeys().length;
            if (currentKeysCount != importedKeysCount) {
                throw new Exception("Parameters number is different.<br>In the current table: "
                        + currentKeysCount + ". In the Excel file: " + importedKeysCount + ".");
            }

            request.getSession(true).setAttribute("importedTable", table);
            request.getSession(false).setAttribute("importedFile", excelFile);
            String destination = "/tables/?product=" + productId + "&id=" + table.getId();
            response.sendRedirect(destination);
        } else {
            Key[] keys = excelFile.getKeys();
            String[][] values = excelFile.getValues();
            int tableId = DataManager.getInstance().getDao().insertTable(tableName, TableType.TABLE, category,
                    null, null, keys, values);

            if (excelFile.hasPreconditions()) {
                Key[] precondKeys = getKeys(excelFile.getPrecondition());
                String[][] precondValues = getValues(excelFile.getPrecondition());
                DataManager.getInstance().getDao().insertTable(null, TableType.PRECONDITION, category, tableId,
                        null, precondKeys, precondValues);
            }

            if (excelFile.hasPostconditions()) {
                Key[] postcondKeys = getKeys(excelFile.getPostcondition());
                String[][] postcondValues = getValues(excelFile.getPostcondition());
                DataManager.getInstance().getDao().insertTable(null, TableType.POSTCONDITION, category, tableId,
                        null, postcondKeys, postcondValues);
            }

            String message = "'" + tableName + "' table was successfully imported.";
            request.getSession(true).setAttribute("importResult", message);
            String destination = "/tables/?product=" + productId + "&id=" + tableId;
            response.sendRedirect(destination);
        }
    } catch (Exception e) {
        int productId = Integer.parseInt(request.getParameter("product"));
        String destination = "/tables/?product=" + productId;
        String message = Lang.get("error") + ": " + e.getMessage();
        e.printStackTrace();
        request.getSession(true).setAttribute("importResult", message);
        response.sendRedirect(destination);
    }
}