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

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

Introduction

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

Prototype

public static String trimToNull(String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String returning null if the String is empty ("") after the trim or if it is null.

Usage

From source file:cz.vutbr.fit.xzelin15.dp.consumer.WSDynamicClientFactory.java

private String downloadWsdl(String wsdlURL, String userName, String password, WiseProperties wiseProperties)
        throws WiseConnectionException {
    if (StringUtils.trimToNull(userName) == null || StringUtils.trimToNull(password) == null) {
        return this.transferWSDL(wsdlURL, null, wiseProperties);
    } else {//from w w w.  j  ava  2  s.  c o m
        return this.transferWSDL(wsdlURL, new StringBuffer(userName).append(":").append(password).toString(),
                wiseProperties);
    }
}

From source file:mitm.common.dlp.impl.FileWordSkipper.java

private void loadFile() throws IOException {
    if (!file.exists()) {
        throw new IOException("File " + file.getAbsolutePath() + " does not exist.");
    }//  w w w.  ja  v a 2  s  .  com

    /*
     * Read the file using a Unicode aware reader
     */
    UnicodeReader unicodeReader = new UnicodeReader(new FileInputStream(file), CharEncoding.UTF_8);

    LineIterator lineIterator = new LineIterator(unicodeReader);

    while (lineIterator.hasNext()) {
        String line = StringUtils.trimToNull(lineIterator.nextLine());

        if (line == null || line.startsWith("#")) {
            continue;
        }

        words.add(line.toLowerCase());
    }
}

From source file:com.bluexml.xforms.generator.forms.renderable.forms.field.RenderableChoiceInputSearch.java

private void addSelector(XFormsGenerator generationManager, ChoiceField choiceField) {
    SelectBean selectBean = new SelectBean();

    com.bluexml.side.common.ModelElement ref;

    ref = choiceField.getRef();//from   w ww.ja  v  a  2 s.co m
    ref = (com.bluexml.side.common.ModelElement) generationManager.getFormGenerator().getRealObject(ref);

    Attribute attributeRef = (Attribute) ref;
    selectBean.setEnumeration(attributeRef.getValueList());
    selectBean.setLabel(choiceField.getLabel());
    selectBean.setMultiple(choiceField.isMultiple());
    selectBean.setLimited(true);

    AssociationBean associationBean = new AssociationBean();

    associationBean.setCreateEditForms(null);
    associationBean.setDestinationRenderable(null);
    associationBean.setDestinationSelect(selectBean);
    associationBean.setName(FormGeneratorsManager.getUniqueName(choiceField));
    associationBean.setTitle(choiceField.getLabel());
    associationBean.setHint(choiceField.getHelp_text());
    associationBean.setShowingActions(false);
    String lsize = "" + choiceField.getField_size();
    if (StringUtils.trimToNull(lsize) != null) {
        associationBean.setFieldSize(lsize);
    }
    associationBean.setMandatory(choiceField.isMandatory());

    // custom configuration parameters
    FormGeneratorsManager formGenerator = getFormGenerator();
    associationBean.setDataSourceUri(formGenerator.getXtensionDataSourceUri(choiceField));
    associationBean.setFeatureMode(formGenerator.getXtensionFeatureMode(choiceField));
    associationBean.setLuceneQuery(formGenerator.getXtensionLuceneQuery(choiceField));
    associationBean.setNoAutoSearch(formGenerator.getXtensionNoAutoSearch(choiceField));
    associationBean.setNoStatsOutput(formGenerator.getXtensionNoStatsOutput(choiceField));

    RenderableSelector selector = new RenderableSelector(associationBean);
    add(new RenderableSSingle(associationBean, selector));
    throw new RuntimeException("This class is deprecated");
}

From source file:com.bluexml.xforms.generator.forms.renderable.common.association.inline.RenderableIMultiple.java

@Override
public Rendered render(String path, Stack<Renderable> parents, Stack<Rendered> renderedParents,
        boolean isInIMultRepeater) {
    // ** #1310/*from   w  w  w  . java 2 s.co m*/
    String finalPath = path;
    String completePath = null;

    Rendered rendered = new RenderedParentGroup(renderedParents);
    if (isInIMultRepeater) {
        completePath = getRootPath(renderedParents);
    }

    if (StringUtils.trimToNull(completePath) != null) {
        finalPath = "instance('minstance')/" + completePath + path;
    }
    // ** #1310

    String nodeSetActions = computeNodeSetActions(finalPath);
    String nodeSetItems = computeNodeSetItems(nodeSetActions);

    // the bind used by actions: e.g. Article1310/field_2/modelcyvel.Paragraphe
    ModelElementBindSimple bindActions = getBindActions();
    bindActions.setNodeset(nodeSetActions);
    bindActions.setRepeaterRootBind(true); // #1241

    ModelElementBindHolder bindRepeater = getBindRepeater(); // we shadow the class field!
    bindRepeater.setNodeset(nodeSetItems);
    rendered.setOptionalData(XFormsGenerator.getId(bean.getName() + "Repeater"));

    rendered.addModelElement(bindRepeater);
    rendered.addModelElement(bindActions);
    rendered.setRepeater(bindRepeater);
    return rendered;
}

From source file:com.opengamma.web.portfolio.WebPortfolioNodeResource.java

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)/*from www  .ja  va2 s  .com*/
public Response postHTML(@FormParam("name") String name) {
    name = StringUtils.trimToNull(name);
    if (name == null) {
        FlexiBean out = createRootData();
        out.put("err_nameMissing", true);
        String html = getFreemarker().build(HTML_DIR + "portfolionode-add.ftl", out);
        return Response.ok(html).build();
    }
    URI uri = createPortfolioNode(name);
    return Response.seeOther(uri).build();
}

From source file:mitm.djigzo.web.pages.portal.secure.Login.java

protected void onActivate() {
    if (email == null) {
        email = EmailAddressUtils.canonicalize(StringUtils.trimToNull(request.getParameter("email")));
    }
}

From source file:com.excilys.ebi.gatling.recorder.ui.component.ConfigurationValidatorListener.java

public void actionPerformed(ActionEvent e) {

    boolean hasError = false;
    Border defaultBorder = frame.txtProxyHost.getBorder();

    Configuration config = Configuration.getInstance();

    if (frame.txtProxyHost.getText().equals(frame.txtProxyHost.getName()))
        frame.txtProxyHost.setText(EMPTY);
    if (frame.txtProxyPort.getText().equals(frame.txtProxyPort.getName()))
        frame.txtProxyPort.setText(EMPTY);
    if (frame.txtProxySslPort.getText().equals(frame.txtProxySslPort.getName()))
        frame.txtProxySslPort.setText(EMPTY);

    frame.tblFilters.validateCells();//from   w  w w .j av  a  2s. c  om

    // Parse local proxy port
    try {
        config.setPort(Integer.parseInt(frame.txtPort.getText()));
        frame.txtPort.setBorder(defaultBorder);
    } catch (NumberFormatException nfe) {
        logger.error("Error, while parsing proxy port...");
        frame.txtPort.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.red));
        hasError = true;
    }

    config.getProxy().setHost(StringUtils.trimToNull(frame.txtProxyHost.getText()));

    // Parse local ssl proxy port
    try {
        config.setSslPort(Integer.parseInt(frame.txtSslPort.getText()));
        frame.txtSslPort.setBorder(defaultBorder);
    } catch (NumberFormatException nfe) {
        logger.error("Error, while parsing proxy SSL port...");
        frame.txtSslPort.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.red));
        hasError = true;
    }

    config.getProxy().setHost(StringUtils.trimToNull(frame.txtProxyHost.getText()));

    // Parse outgoing proxy port
    if (!StringUtils.isEmpty(config.getProxy().getHost())) {
        try {
            config.getProxy().setPort(Integer.parseInt(frame.txtProxyPort.getText()));
            frame.txtProxyPort.setBorder(defaultBorder);
        } catch (NumberFormatException nfe) {
            logger.error("Error, while parsing outgoing proxy port... !");
            frame.txtProxyPort.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.red));
            hasError = true;
        }
    }

    // Parse outgoing ssl proxy port
    if (!StringUtils.isEmpty(config.getProxy().getHost())) {
        try {
            config.getProxy().setSslPort(Integer.parseInt(frame.txtProxySslPort.getText()));
            frame.txtProxySslPort.setBorder(defaultBorder);
        } catch (NumberFormatException nfe) {
            logger.error("Error, while parsing outgoing proxy SSL port... !");
            frame.txtProxySslPort.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.red));
            hasError = true;
        }
    }

    config.setFilterStrategy((FilterStrategy) frame.cbFilterStrategies.getSelectedItem());
    // Set urls filters into a list
    config.setPatterns(new ArrayList<Pattern>());
    for (int i = 0; i < frame.tblFilters.getRowCount(); i++)
        config.getPatterns().add((Pattern) frame.tblFilters.getPattern(i));

    // Check if a directory was entered
    config.setOutputFolder(StringUtils.trimToNull(frame.txtOutputFolder.getText()));
    if (config.getOutputFolder() == null) {
        logger.error("Error, no directory selected for results.");
        frame.txtOutputFolder.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.red));
        hasError = true;
    } else
        frame.txtOutputFolder.setBorder(defaultBorder);

    // Set selected results type into a list
    config.setResultTypes(new ArrayList<ResultType>());
    boolean tmp = false;
    for (JCheckBox cb : frame.resultTypes) {
        if (cb.isSelected()) {
            tmp = true;
            config.getResultTypes().add(ResultType.getByLabel(cb.getText()));
        }
    }

    config.setSaveConfiguration(frame.chkSavePref.isSelected());

    // set selected encoding
    config.setEncoding(Charset.class.cast(frame.cbOutputEncoding.getSelectedItem()).name());

    // If nothing was selected we add by default 'text'
    if (!tmp)
        config.getResultTypes().add(ResultType.TEXT);

    if (hasError)
        return;

    if (frame.chkSavePref.isSelected())
        ConfigurationHelper.saveToDisk();

    logConfiguration();

    getEventBus().post(new ShowRunningFrameEvent());
}

From source file:com.metasoft.claim.service.impl.claim.ClaimImportServiceImpl.java

@Override
@Transactional//from   w w  w  . jav a  2 s .  c  o m
public List<ImportError> saveFromFile(UploadedFile uploadedFile, SecUser user) throws Exception {
    List<ImportError> errorClaimNumbers = new ArrayList<ImportError>();
    XSSFWorkbook workbook = null;
    try {
        InputStream input = new ByteArrayInputStream(uploadedFile.bytes);
        Date today = new Date();

        // Using XSSF for xlsx format, for xls use HSSF
        workbook = new XSSFWorkbook(input);

        Sheet sheet = workbook.getSheetAt(0);

        Iterator<Row> rowIterator = sheet.iterator();
        Row row = rowIterator.next();
        // iterating over each row
        int i = 1;
        int rowAt = 1;
        while (rowIterator.hasNext()) {
            i = 1;
            TblClaimRecovery claim = new TblClaimRecovery();

            row = rowIterator.next();
            try {
                //                  ?   ?   ?   ?      ?             
                claim.setClaimNumber(StringUtils.trimToNull(row.getCell(i++).getStringCellValue()));
                claim.setPolicyNo(StringUtils.trimToNull(row.getCell(i++).getStringCellValue()));
                claim.setLicenseNumber(StringUtils.trimToNull(row.getCell(i++).getStringCellValue()));
                claim.setPartyLicenseNumber(StringUtils.trimToNull(row.getCell(i++).getStringCellValue()));
                claim.setAccidentDate(row.getCell(i++).getDateCellValue());
                claim.setMaturityDate(row.getCell(i++).getDateCellValue());
            } catch (Exception e) {
                ImportError importError = new ImportError();
                importError.setReason("? " + rowAt
                        + "  " + i + " ?");
                importError.setClaimNumber(StringUtils.isEmpty(claim.getClaimNumber())
                        ? ""
                        : claim.getClaimNumber());
                errorClaimNumbers.add(importError);
                continue;
            }

            String partyInsuranceName = StringUtils.trimToNull(row.getCell(i++).getStringCellValue());
            if (partyInsuranceName != null) {
                claim.setPartyInsurance(insuranceDao.findByName(partyInsuranceName));
            }

            claim.setClaimInsuranceAmount((float) row.getCell(i++).getNumericCellValue());

            if (claim.getClaimNumber() != null && claim.getPartyInsurance() != null) {
                if (!claimDao.checkDupClaimNumber(claim.getClaimNumber())) {
                    claim.setCreateDate(today);
                    claim.setCreateBy(user);

                    claim.setJobDate(today);
                    claim.setJobStatus(JobStatus.RECEIVED);

                    List<TblUserInsurance> tblUserInsurances = userInsuranceDao
                            .searchByInsuranceId(claim.getPartyInsurance().getId());
                    if (tblUserInsurances != null && !tblUserInsurances.isEmpty()) {
                        claim.setAgent(userDao.findById(tblUserInsurances.get(0).getId().getUserId()));
                    }

                    claimDao.save(claim);

                    claim.setJobNo(DateToolsUtil.convertToString(today,
                            DateToolsUtil.DATE_PATTERN_VIEW_YYYYMMDD, DateToolsUtil.LOCALE_TH) + claim.getId());

                    claimDao.save(claim);
                } else {
                    ImportError importError = new ImportError();
                    importError.setReason("");
                    importError.setClaimNumber(claim.getClaimNumber());
                    errorClaimNumbers.add(importError);
                }
            } else if (claim.getClaimNumber() != null && claim.getPartyInsurance() == null) {
                ImportError importError = new ImportError();
                importError.setReason("?");
                importError.setClaimNumber(claim.getClaimNumber());
                errorClaimNumbers.add(importError);
            }

            rowAt++;
        }

        input.close();
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    } finally {
        if (workbook != null) {
            try {
                workbook.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    return errorClaimNumbers;
}

From source file:com.bluexml.side.util.dependencies.MavenTmpProject.java

/**
 * build pom dependency fragment from ModuleConstraint
 * /* w w  w .  j  a v  a 2  s. com*/
 * @param n
 * @return
 */
private Element buildPomDependency(Namespace n, ModuleConstraint mc) {
    Element depends = new Element("dependency", n.getURI()); //$NON-NLS-1$
    Element groupId = new Element("groupId", n.getURI()).setText(mc.getGroupId()); //$NON-NLS-1$
    Element artifactId = new Element("artifactId", n.getURI()).setText(mc.getArtifactId()); //$NON-NLS-1$
    Element version = new Element("version", n.getURI()).setText(mc.getVersionRange()); //$NON-NLS-1$
    Element type = new Element("type", n.getURI()).setText(mc.getModuleType()); //$NON-NLS-1$

    depends.addContent(groupId);
    depends.addContent(artifactId);
    depends.addContent(version);
    depends.addContent(type);

    String classifierString = mc.getClassifier();
    if (StringUtils.trimToNull(classifierString) != null) {
        Element classifier = new Element("classifier", n.getURI()).setText(classifierString); //$NON-NLS-1$
        depends.addContent(classifier);
    }
    return depends;
}

From source file:nc.noumea.mairie.appock.core.security.AppUser.java

public void setLogin(String login) {
    this.login = StringUtils.trimToNull(StringUtils.lowerCase(login));
}