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

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

Introduction

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

Prototype

public static String trim(final String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String, handling null by returning null .

The String is trimmed using String#trim() .

Usage

From source file:com.gitlab.anlar.lunatic.server.ServerTest.java

private void checkEmail(String from, String to, String subject, String body, Email email) {
    TestCase.assertNotNull(email);/*from w w w  . j a v a 2s.  co  m*/
    TestCase.assertEquals(from, email.getFrom());
    TestCase.assertEquals(to, email.getTo());
    TestCase.assertEquals(subject, email.getSubject());
    TestCase.assertEquals(StringUtils.trim(body), StringUtils.trim(email.getBody()));
}

From source file:com.ottogroup.bi.spqr.pipeline.component.operator.DirectResponseOperatorRuntimeEnvironment.java

/**
 * Initializes the operator runtime environment using the provided input
 * @param processingNodeId/* www .  ja  v a2 s .  com*/
 * @param pipelineId
 * @param directResponseOperator
 * @param queueConsumer
 * @param queueProducer
 */
public DirectResponseOperatorRuntimeEnvironment(final String processingNodeId, final String pipelineId,
        final DirectResponseOperator directResponseOperator, final StreamingMessageQueueConsumer queueConsumer,
        final StreamingMessageQueueProducer queueProducer) throws RequiredInputMissingException {

    /////////////////////////////////////////////////////////////
    // input validation
    if (StringUtils.isBlank(processingNodeId))
        throw new RequiredInputMissingException("Missing required processing node identifier");
    if (StringUtils.isBlank(pipelineId))
        throw new RequiredInputMissingException("Missing required pipeline identifier");
    if (directResponseOperator == null)
        throw new RequiredInputMissingException("Missing required direct response operator");
    if (queueConsumer == null)
        throw new RequiredInputMissingException("Missing required queue consumer");
    if (queueProducer == null)
        throw new RequiredInputMissingException("Missing required queue producer");
    //
    /////////////////////////////////////////////////////////////

    this.processingNodeId = StringUtils.lowerCase(StringUtils.trim(processingNodeId));
    this.pipelineId = StringUtils.lowerCase(StringUtils.trim(pipelineId));
    this.operatorId = StringUtils.lowerCase(StringUtils.trim(directResponseOperator.getId()));
    this.directResponseOperator = directResponseOperator;
    this.queueConsumer = queueConsumer;
    this.queueProducer = queueProducer;
    this.running = true;
    this.consumerQueueWaitStrategy = queueConsumer.getWaitStrategy();
    this.destinationQueueWaitStrategy = queueProducer.getWaitStrategy();

    if (logger.isDebugEnabled())
        logger.debug("direct response operator init [node=" + this.processingNodeId + ", pipeline="
                + this.pipelineId + ", operator=" + this.operatorId + "]");
}

From source file:com.ottogroup.bi.spqr.operator.json.aggregator.JsonContentAggregator.java

/**
 * @see com.ottogroup.bi.spqr.pipeline.component.MicroPipelineComponent#initialize(java.util.Properties)
 *///  w w w.  ja va 2  s . c  om
public void initialize(Properties properties)
        throws RequiredInputMissingException, ComponentInitializationFailedException {

    /////////////////////////////////////////////////////////////////////////////////////
    // assign and validate properties
    if (StringUtils.isBlank(this.id))
        throw new RequiredInputMissingException("Missing required component identifier");

    this.pipelineId = StringUtils.trim(properties.getProperty(CFG_PIPELINE_ID));
    this.documentType = StringUtils.trim(properties.getProperty(CFG_DOCUMENT_TYPE));
    if (StringUtils.equalsIgnoreCase(properties.getProperty(CFG_FORWARD_RAW_DATA), "false"))
        this.storeForwardRawData = false;

    for (int i = 1; i < Integer.MAX_VALUE; i++) {
        String name = properties.getProperty(CFG_FIELD_PREFIX + i + ".name");
        if (StringUtils.isBlank(name))
            break;

        String path = properties.getProperty(CFG_FIELD_PREFIX + i + ".path");
        String valueType = properties.getProperty(CFG_FIELD_PREFIX + i + ".type");

        this.fields.add(new JsonContentAggregatorFieldSetting(name, path.split("\\."),
                StringUtils.equalsIgnoreCase("STRING", valueType) ? JsonContentType.STRING
                        : JsonContentType.NUMERICAL));
    }
    /////////////////////////////////////////////////////////////////////////////////////

    if (logger.isDebugEnabled())
        logger.debug("json content aggregator [id=" + id + "] initialized");

}

From source file:com.school.exam.service.account.AccountService.java

public void inputUser(InputStream inputStream) {
    List<List<String>> userList = ExcelUtils.toList(inputStream);

    for (List<String> row : userList) {

        SSClassVO ssClassVO = ssClassService.findClassByClassName(row.get(0));

        if (null == ssClassVO) {
            ssClassVO = new SSClassVO();
            ssClassVO.setClassName(row.get(0));
            ssClassService.registerClass(ssClassVO);
        }/*  ww w.ja v  a 2  s. c o  m*/

        User user = userDao.findByLoginName(row.get(2) + "");
        if (null == user) {
            user = new User();
            user.setLoginName(row.get(2));
            user.setRoles("student");
            user.setPlainPassword(StringUtils.trim(row.get(3)));
            user.setName(row.get(1));
            user.setSsClass(ssClassVO);

            registerUser(user);

        }

    }

}

From source file:com.ottogroup.bi.spqr.resman.server.SPQRResourceManagerServer.java

/**
 * Reads contents from {@link ApplicationRepositoryConfiguration referenced repository} and deploys them to given
 * {@link ActorRef deployment receiver}.
 * @param cfg/*w ww. j  a v a2 s.c o m*/
 * @param jarDeploymentReceiverRef
 * @throws RequiredInputMissingException
 * @throws JsonParseException
 * @throws JsonMappingException
 * @throws IOException
 */
public ComponentRepository loadAndDeployApplicationRepository(final String repositoryPath)
        throws RequiredInputMissingException, JsonParseException, JsonMappingException, IOException {

    ////////////////////////////////////////////////////////////////////////////
    // validate provided input and ensure that folder exists
    if (StringUtils.isBlank(repositoryPath))
        throw new RequiredInputMissingException("Missing required input for parameter 'repositoryPath'");

    File repositoryFolder = new File(StringUtils.trim(repositoryPath));
    if (repositoryFolder == null || !repositoryFolder.isDirectory())
        throw new RequiredInputMissingException(
                "No repository found at provided folder '" + repositoryPath + "'");
    //
    ////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////

    final ComponentRepository library = new ComponentRepository();

    ////////////////////////////////////////////////////////////////////////////
    // find component repositories below repository folder 
    File[] repoFolders = repositoryFolder.listFiles();
    if (repoFolders == null || repoFolders.length < 1)
        return library;
    //
    ////////////////////////////////////////////////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////
    // for each entry check if it is a folder and pass it on the library
    int folderCount = 0;
    int componentsCount = 0;
    for (File folder : repoFolders) {
        if (folder.isDirectory()) {
            try {
                logger.info("Processing folder '" + folder.getAbsolutePath() + "'");
                Map<String, ComponentDescriptor> descriptors = library
                        .addComponentFolder(folder.getAbsolutePath());
                componentsCount = componentsCount + descriptors.size();
                folderCount++;
            } catch (Exception e) {
                logger.error("Failed to add folder '" + folder.getAbsolutePath()
                        + "' to component repository. Error: " + e.getMessage());
            }
        }
    }
    //
    ////////////////////////////////////////////////////////////////////////////

    logger.info("Components deployment finished [repo=" + repositoryPath + ", componentFolders=" + folderCount
            + ", componets=" + componentsCount + "]");
    return library;
}

From source file:com.ottogroup.bi.asap.resman.pipeline.PipelineManager.java

/**
 * Updates or instantiates the provided pipeline on a set of processing nodes
 * @param pipelineConfiguration/*  www  . j  av  a  2s.  com*/
 * @return
 * @throws RequiredInputMissingException
 * @throws RemoteClientConnectionFailedException 
 * @throws IOException 
 */
public PipelineDeploymentProfile updatesOrInstantiatePipeline(
        final MicroPipelineConfiguration pipelineConfiguration)
        throws RequiredInputMissingException, PipelineAlreadyRegisteredException {

    ///////////////////////////////////////////////////////////
    // validate input
    if (pipelineConfiguration == null)
        throw new RequiredInputMissingException("Missing required pipeline configuration");
    // TODO validate pipeline configuration
    //
    ///////////////////////////////////////////////////////////

    String pid = StringUtils.lowerCase(StringUtils.trim(pipelineConfiguration.getId()));
    PipelineDeploymentProfile profile = this.pipelineDeployments.get(pid);
    if (profile != null) {
        profile.getProcessingNodes().clear();
        profile.setConfiguration(pipelineConfiguration);
    } else {
        profile = new PipelineDeploymentProfile(pipelineConfiguration.getId(), pipelineConfiguration);
    }

    profile = processingNodeManager.updateOrInstantiatePipeline(
            new PipelineDeploymentProfile(pipelineConfiguration.getId(), pipelineConfiguration));
    this.pipelineDeployments.put(StringUtils.lowerCase(StringUtils.trim(pipelineConfiguration.getId())),
            profile);

    return profile;
}

From source file:com.dominion.salud.pedicom.configuration.PEDICOMJpaConfiguration.java

@Bean(name = "MainEM")
@Autowired//from  ww  w. java 2 s.  co m
public EntityManagerFactory entityManagerFactory() throws Exception {
    HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
    adapter.setGenerateDdl(
            Boolean.getBoolean(StringUtils.trim(environment.getRequiredProperty("hibernate.generate_ddl"))));
    adapter.setShowSql(
            Boolean.getBoolean(StringUtils.trim(environment.getRequiredProperty("hibernate.show_sql"))));
    adapter.setDatabasePlatform(StringUtils.trim(environment.getRequiredProperty("hibernate.dialect")));
    LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
    factory.setDataSource(routingDataSource());
    factory.setJpaVendorAdapter(adapter);
    factory.setPackagesToScan("com.dominion.salud.pedicom.negocio.entities");
    factory.setPersistenceUnitName("MainEM");
    factory.afterPropertiesSet();
    factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
    return factory.getObject();
}

From source file:com.jeans.iservlet.controller.impl.ImportController.java

@RequestMapping(method = RequestMethod.POST, value = "/hr")
@ResponseBody//from  www  .j  av  a2s  .co m
public void importHR(@RequestParam("data") CommonsMultipartFile data, HttpServletResponse response)
        throws IOException {
    PrintWriter out = response.getWriter();
    if (null == data) {
        showError(out, "??");
        out.close();
        return;
    }
    int deptCount = 0, emplCount = 0;
    String info = null;
    try (Workbook workBook = WorkbookFactory.create(data.getInputStream())) {
        Sheet deptSheet = workBook.getSheet("");
        Sheet emplSheet = workBook.getSheet("");
        if (null == deptSheet || null == emplSheet) {
            data.getInputStream().close();
            showError(out, "????Sheet");
            out.close();
            return;
        }
        Company comp = getCurrentCompany();
        // deptSheet: 1?04?5??????
        int total = deptSheet.getLastRowNum() + emplSheet.getLastRowNum();
        double progress = 0.0;
        double step = 100.0 / (double) total;
        showProgressDialog(out, getCurrentCompany().getAlias() + "");
        int last = deptSheet.getLastRowNum();
        for (int rn = 1; rn <= last; rn++) {
            Row r = deptSheet.getRow(rn);
            // ??""???
            String flag = StringUtils
                    .trim(ExcelUtils.getCellValueAsString(r.getCell(4, Row.RETURN_BLANK_AS_NULL)));
            progress += step;
            if (!"".equals(flag)) {
                continue;
            }
            // ?name?
            String name = ExcelUtils.getCellValueAsString(r.getCell(0, Row.RETURN_BLANK_AS_NULL));
            if (StringUtils.isBlank(name)) {
                continue;
            } else {
                name = StringUtils.trim(name);
            }
            showProgress(out, "" + name, progress);// 
            // ?alias?
            String alias = ExcelUtils.getCellValueAsString(r.getCell(1, Row.RETURN_BLANK_AS_NULL));
            if (StringUtils.isBlank(alias)) {
                alias = name.substring(0, 15);
            } else {
                alias = StringUtils.trim(alias);
            }
            // ?ID(superiorId)????????
            String superior = ExcelUtils.getCellValueAsString(r.getCell(2, Row.RETURN_BLANK_AS_NULL));
            long superiorId = 0;
            if (StringUtils.isBlank(superior)) {
                superiorId = comp.getId();
            } else {
                Department suprDept = hrService.findDepartmentByName(comp, superior);
                if (null == suprDept) {
                    continue;
                } else {
                    superiorId = suprDept.getId();
                }
            }
            // ???listOrder??short999??1999
            short listOrder = 999;
            try {
                double order = (double) ExcelUtils.getCellValue(r.getCell(3, Row.RETURN_BLANK_AS_NULL));
                if (order < 1) {
                    listOrder = 1;
                } else if (order > 999) {
                    listOrder = 999;
                } else {
                    listOrder = (short) Math.round(order);
                }
            } catch (ClassCastException e) {
                log(e);
                listOrder = 999;
            }
            if (null != hrService.createDept(name, alias, superiorId, listOrder)) {
                deptCount++;
            }
        }
        // emplSheet: 1?08?9??????????????admin?
        last = emplSheet.getLastRowNum();
        for (int rn = 1; rn <= last; rn++) {
            Row r = emplSheet.getRow(rn);
            // ??""???
            String flag = StringUtils
                    .trim(ExcelUtils.getCellValueAsString(r.getCell(8, Row.RETURN_BLANK_AS_NULL)));
            progress += step;
            if (!"".equals(flag)) {
                continue;
            }
            // ???name?
            String name = ExcelUtils.getCellValueAsString(r.getCell(0, Row.RETURN_BLANK_AS_NULL));
            if (StringUtils.isBlank(name)) {
                continue;
            } else {
                name = StringUtils.trim(name);
            }
            showProgress(out, "" + name, progress); // 
            // ?ID(deptId)???
            String deptName = ExcelUtils.getCellValueAsString(r.getCell(1, Row.RETURN_BLANK_AS_NULL));
            long deptId = 0;
            if (StringUtils.isBlank(deptName)) {
                continue;
            } else {
                Department dept = hrService.findDepartmentByName(comp, deptName);
                if (null == dept) {
                    continue;
                } else {
                    deptId = dept.getId();
                }
            }
            // ???listOrder??short999??1999
            short listOrder = 999;
            try {
                double order = (double) ExcelUtils.getCellValue(r.getCell(2, Row.RETURN_BLANK_AS_NULL));
                if (order < 1) {
                    listOrder = 1;
                } else if (order > 999) {
                    listOrder = 999;
                } else {
                    listOrder = (short) Math.round(order);
                }
            } catch (ClassCastException e) {
                log(e);
                listOrder = 999;
            }
            // ???????admin?
            boolean leader = "".equals(
                    StringUtils.trim(ExcelUtils.getCellValueAsString(r.getCell(3, Row.RETURN_BLANK_AS_NULL))));
            boolean supervisor = "".equals(
                    StringUtils.trim(ExcelUtils.getCellValueAsString(r.getCell(4, Row.RETURN_BLANK_AS_NULL))));
            boolean auditor = "".equals(
                    StringUtils.trim(ExcelUtils.getCellValueAsString(r.getCell(5, Row.RETURN_BLANK_AS_NULL))));
            boolean iter = "".equals(
                    StringUtils.trim(ExcelUtils.getCellValueAsString(r.getCell(6, Row.RETURN_BLANK_AS_NULL))));
            boolean admin = "".equals(
                    StringUtils.trim(ExcelUtils.getCellValueAsString(r.getCell(7, Row.RETURN_BLANK_AS_NULL))));
            if (null != hrService.createEmpl(name, deptId, listOrder, leader, supervisor, auditor, iter,
                    admin)) {
                emplCount++;
            }
        }
        info = "?" + deptCount + "" + emplCount
                + "??";
    } catch (Exception e) {
        log(e);
        info = "????"
                + deptCount + "" + emplCount + "??";
    } finally {
        data.getInputStream().close();
        closeProgressDialog(out);
        showInfo(out, info);
        out.close();
        log(info);
    }
}

From source file:com.jeans.iservlet.action.admin.DataImportAction.java

/**
 * ??// www .j a v  a2s .  c om
 * 
 * @return
 * @throws Exception
 */
@Action(value = "hr-import", results = { @Result(name = SUCCESS, type = "json", params = { "root", "results",
        "contentType", "text/plain", "encoding", "UTF-8" }) })
public String uploadHRData() throws Exception {
    if (!checkDataFile()) {
        return SUCCESS;
    }
    int deptCount = 0, emplCount = 0;
    try (Workbook workBook = WorkbookFactory.create(data)) {
        Sheet deptSheet = workBook.getSheet("");
        Sheet emplSheet = workBook.getSheet("");
        if (null == deptSheet || null == emplSheet) {
            results.put("code", 4);
            results.put("tip", "????Sheet");
            return SUCCESS;
        }
        Company comp = getCurrentCompany();
        // deptSheet: 1?04?5??????
        int last = deptSheet.getLastRowNum();
        for (int rn = 1; rn <= last; rn++) {
            Row r = deptSheet.getRow(rn);
            // ??""???
            String flag = StringUtils
                    .trim(ExcelUtils.getCellValueAsString(r.getCell(4, Row.RETURN_BLANK_AS_NULL)));
            if (!"".equals(flag))
                continue;
            // ?name?
            String name = ExcelUtils.getCellValueAsString(r.getCell(0, Row.RETURN_BLANK_AS_NULL));
            if (StringUtils.isBlank(name))
                continue;
            else
                name = StringUtils.trim(name);
            // ?alias?
            String alias = ExcelUtils.getCellValueAsString(r.getCell(1, Row.RETURN_BLANK_AS_NULL));
            if (StringUtils.isBlank(alias))
                alias = name.substring(0, 15);
            else
                alias = StringUtils.trim(alias);
            // ?ID(superiorId)????????
            String superior = ExcelUtils.getCellValueAsString(r.getCell(2, Row.RETURN_BLANK_AS_NULL));
            long superiorId = 0;
            if (StringUtils.isBlank(superior)) {
                superiorId = comp.getId();
            } else {
                HRUnitNode suprDept = hrService.getDepartmentByName(comp, superior);
                if (null == suprDept)
                    continue;
                else
                    superiorId = suprDept.getId();
            }
            // ???listOrder??short999??1999
            short listOrder = 999;
            try {
                double order = (double) ExcelUtils.getCellValue(r.getCell(3, Row.RETURN_BLANK_AS_NULL));
                if (order < 1)
                    listOrder = 1;
                else if (order > 999)
                    listOrder = 999;
                else
                    listOrder = (short) Math.round(order);
            } catch (ClassCastException e) {
                log(e);
                listOrder = 999;
            }
            hrService.appendDept(name, alias, superiorId, listOrder);
            deptCount++;
        }
        // emplSheet: 1?08?9??????????????admin?
        last = emplSheet.getLastRowNum();
        for (int rn = 1; rn <= last; rn++) {
            Row r = emplSheet.getRow(rn);
            // ??""???
            String flag = StringUtils
                    .trim(ExcelUtils.getCellValueAsString(r.getCell(8, Row.RETURN_BLANK_AS_NULL)));
            if (!"".equals(flag))
                continue;
            // ???name?
            String name = ExcelUtils.getCellValueAsString(r.getCell(0, Row.RETURN_BLANK_AS_NULL));
            if (StringUtils.isBlank(name))
                continue;
            else
                name = StringUtils.trim(name);
            // ?ID(deptId)???
            String deptName = ExcelUtils.getCellValueAsString(r.getCell(1, Row.RETURN_BLANK_AS_NULL));
            long deptId = 0;
            if (StringUtils.isBlank(deptName)) {
                continue;
            } else {
                HRUnitNode dept = hrService.getDepartmentByName(comp, deptName);
                if (null == dept)
                    continue;
                else
                    deptId = dept.getId();
            }
            // ???listOrder??short999??1999
            short listOrder = 999;
            try {
                double order = (double) ExcelUtils.getCellValue(r.getCell(2, Row.RETURN_BLANK_AS_NULL));
                if (order < 1)
                    listOrder = 1;
                else if (order > 999)
                    listOrder = 999;
                else
                    listOrder = (short) Math.round(order);
            } catch (ClassCastException e) {
                log(e);
                listOrder = 999;
            }
            // ???????admin?
            boolean leader = "".equals(
                    StringUtils.trim(ExcelUtils.getCellValueAsString(r.getCell(3, Row.RETURN_BLANK_AS_NULL))));
            boolean supervisor = "".equals(
                    StringUtils.trim(ExcelUtils.getCellValueAsString(r.getCell(4, Row.RETURN_BLANK_AS_NULL))));
            boolean auditor = "".equals(
                    StringUtils.trim(ExcelUtils.getCellValueAsString(r.getCell(5, Row.RETURN_BLANK_AS_NULL))));
            boolean iter = "".equals(
                    StringUtils.trim(ExcelUtils.getCellValueAsString(r.getCell(6, Row.RETURN_BLANK_AS_NULL))));
            boolean admin = "".equals(
                    StringUtils.trim(ExcelUtils.getCellValueAsString(r.getCell(7, Row.RETURN_BLANK_AS_NULL))));
            hrService.appendEmpl(name, deptId, listOrder, leader, supervisor, auditor, iter, admin);
            emplCount++;
        }
        results.put("code", 0);
        results.put("tip", "???" + deptCount + "" + emplCount
                + "??");
        log("?HR??" + deptCount + "" + emplCount + "??");
        return SUCCESS;
    } catch (Exception e) {
        log(e);
        results.put("code", 4);
        results.put("tip", "???" + deptCount
                + "" + emplCount + "??");
        log("?HR??" + deptCount + "" + emplCount
                + "??");
        return SUCCESS;
    }
}

From source file:com.ottogroup.bi.asap.operator.json.aggregator.JsonContentAggregatorResult.java

/**
 * Increment aggregated value by provided <i>inc</i> value
 * @param field//from   w  ww  .j a v  a 2s .c  o m
 * @param fieldValue
 * @param inc
 * @throws RequiredInputMissingException
 */
public void incAggregatedValue(final String field, final String fieldValue, final long inc)
        throws RequiredInputMissingException {
    ///////////////////////////////////////////////////////////////////////////////////////////
    // validate provided input
    if (StringUtils.isBlank(field))
        throw new RequiredInputMissingException("Missing required input for parameter 'field'");
    if (StringUtils.isBlank(fieldValue))
        throw new RequiredInputMissingException("Missing required input for parameter 'fieldValue'");
    //
    ///////////////////////////////////////////////////////////////////////////////////////////

    String fieldKey = StringUtils.lowerCase(StringUtils.trim(field));
    String fieldValueKey = StringUtils.lowerCase(StringUtils.trim(fieldValue));
    Map<String, Long> fieldAggregationValues = this.aggregatedValues.get(fieldKey);
    if (fieldAggregationValues == null)
        fieldAggregationValues = new HashMap<>();
    long aggregationValue = (fieldAggregationValues.containsKey(fieldValueKey)
            ? fieldAggregationValues.get(fieldValueKey)
            : 0);
    aggregationValue = aggregationValue + inc;
    fieldAggregationValues.put(fieldValueKey, aggregationValue);
    this.aggregatedValues.put(fieldKey, fieldAggregationValues);
}