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:com.opengamma.web.exchange.WebExchangesResource.java

private FlexiBean createSearchResultData(PagingRequest pr, ExchangeSearchSortOrder so, String name,
        List<String> exchangeIdStrs, UriInfo uriInfo) {
    FlexiBean out = createRootData();// w  w w  .  j  av a  2 s. co  m

    ExchangeSearchRequest searchRequest = new ExchangeSearchRequest();
    searchRequest.setPagingRequest(pr);
    searchRequest.setSortOrder(so);
    searchRequest.setName(StringUtils.trimToNull(name));
    MultivaluedMap<String, String> query = uriInfo.getQueryParameters();
    for (int i = 0; query.containsKey("idscheme." + i) && query.containsKey("idvalue." + i); i++) {
        ExternalId id = ExternalId.of(query.getFirst("idscheme." + i), query.getFirst("idvalue." + i));
        searchRequest.addExternalId(id);
    }
    for (String exchangeIdStr : exchangeIdStrs) {
        searchRequest.addObjectId(ObjectId.parse(exchangeIdStr));
    }
    out.put("searchRequest", searchRequest);

    if (data().getUriInfo().getQueryParameters().size() > 0) {
        ExchangeSearchResult searchResult = data().getExchangeMaster().search(searchRequest);
        out.put("searchResult", searchResult);
        out.put("paging", new WebPaging(searchResult.getPaging(), uriInfo));
    }
    return out;
}

From source file:com.manydesigns.elements.fields.search.TextSearchField.java

public void readFromRequest(HttpServletRequest req) {
    value = StringUtils.trimToNull(req.getParameter(inputName));
    if (showMatchMode) {
        String matchModeStr = req.getParameter(matchModeParam);
        matchMode = TextMatchMode.CONTAINS; // default
        for (TextMatchMode m : TextMatchMode.values()) {
            if (m.getStringValue().equals(matchModeStr)) {
                matchMode = m;/* www .  ja  v a 2 s.  c  om*/
            }
        }
    }
}

From source file:com.enonic.cms.core.structure.SitePropertiesServiceImpl.java

private String getProperty(String key, SiteKey siteKey) {
    SiteProperties props = doGetSiteProperties(siteKey);
    if (props == null) {
        throw new IllegalArgumentException("No properties for site " + siteKey);
    }//from w  w  w .  j ava 2s  .  c  o m

    return StringUtils.trimToNull(props.getProperty(key));
}

From source file:com.galeoconsulting.leonardinius.servlet.ScriptRunnerSessionServlet.java

private Map<String, String> getConfiguredTemplates() {
    if (configuredTemplates == null) {
        String parameterValue = checkNotNull(getInitParameter(VELOCITY_TEMPLATES_CONFIG_PARAMETER),
                VELOCITY_TEMPLATES_CONFIG_PARAMETER + " servlet configuration parameter");

        Collection<String> entries = new LinkedHashSet<String>(
                Arrays.asList(StringUtils.split(parameterValue, ';')));

        entries = Collections2.filter(entries, new Predicate<String>() {
            @Override/* w  w  w.java  2  s .  c o  m*/
            public boolean apply(@Nullable String s) {
                return StringUtils.isNotBlank(s);
            }
        });

        Map<String, String> result = Maps.newHashMap();
        for (String entry : entries) {
            String data[] = StringUtils.split(entry, '|');
            result.put(StringUtils.trimToNull(data[0]), StringUtils.trimToNull(data[1]));
        }

        configuredTemplates = ImmutableMap.copyOf(result);
    }

    return configuredTemplates;
}

From source file:com.novartis.pcs.ontology.rest.servlet.TermsServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String mediaType = getExpectedMediaType(request);
    String pathInfo = StringUtils.trimToNull(request.getPathInfo());
    if (mediaType == null || !MEDIA_TYPE_JSON.equals(mediaType)) {
        response.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
        response.setContentLength(0);//from ww  w. java 2 s.c  o m
    } else if (pathInfo != null && pathInfo.length() > 1) {
        String referenceId = pathInfo.substring(1);
        serialize(referenceId, response);
    } else {
        // perform search using query string params
        String name = StringUtils.trimToNull(request.getParameter("name"));
        String ontology = StringUtils.trimToNull(request.getParameter("ontology"));
        boolean includeSynonyms = Boolean.parseBoolean(request.getParameter("synonyms"));
        int maxResults = Integer.MAX_VALUE;

        try {
            maxResults = Integer.parseInt(request.getParameter("max"));
            if (maxResults <= 0) {
                maxResults = Integer.MAX_VALUE;
            }
        } catch (Exception e) {
            maxResults = Integer.MAX_VALUE;
        }

        serialize(name, ontology, includeSynonyms, maxResults, response);
    }
}

From source file:com.opengamma.web.orgs.WebOrganizationsResource.java

private FlexiBean createSearchResultData(final PagingRequest pr, final String shortName,
        final String obligorTicker, final String obligorREDCode, final List<String> organizationIdStrs,
        final UriInfo uriInfo) {
    FlexiBean out = createRootData();/*from www  .  j  a va 2 s. c o  m*/

    OrganizationSearchRequest searchRequest = new OrganizationSearchRequest();
    searchRequest.setPagingRequest(pr);
    searchRequest.setObligorShortName(StringUtils.trimToNull(shortName));
    searchRequest.setObligorTicker(StringUtils.trimToNull(obligorTicker));
    searchRequest.setObligorREDCode(StringUtils.trimToNull(obligorREDCode));
    for (String organizationIdStr : organizationIdStrs) {
        searchRequest.addOrganizationObjectId(ObjectId.parse(organizationIdStr));
    }
    out.put("searchRequest", searchRequest);

    if (data().getUriInfo().getQueryParameters().size() > 0) {
        OrganizationSearchResult searchResult = data().getOrganizationMaster().search(searchRequest);
        out.put("searchResult", searchResult);
        out.put("paging", new WebPaging(searchResult.getPaging(), uriInfo));
    }
    return out;
}

From source file:mitm.application.djigzo.james.mailets.DKIMSign.java

@Override
protected void initMailet() throws MessagingException {
    convertTo7Bit = getBooleanInitParameter(Parameter.CONVERT_TO_7BIT.name, true);

    foldSignature = getBooleanInitParameter(Parameter.FOLD_SIGNATURE.name, false);

    dkimHeader = getInitParameter(Parameter.DKIM_HEADER.name, DKIMCommon.DEFAULT_DKIM_HEADER);

    signatureTemplate = StringUtils.trimToNull(getInitParameter(Parameter.SIGNATURE_TEMPLATE.name));

    if (signatureTemplate == null) {
        throw new MessagingException("signatureTemplate is missing.");
    }//from w w  w .  j  a v  a2  s .com

    loadPrivateKey();
}

From source file:com.opengamma.web.holiday.WebHolidaysResource.java

private FlexiBean createSearchResultData(PagingRequest pr, HolidaySearchSortOrder sort, String name,
        String type, String currencyISO, List<String> holidayIdStrs, UriInfo uriInfo) {
    FlexiBean out = createRootData();//from  w w  w .j  ava  2 s .  c o  m

    HolidaySearchRequest searchRequest = new HolidaySearchRequest();
    searchRequest.setPagingRequest(pr);
    searchRequest.setSortOrder(sort);
    searchRequest.setName(StringUtils.trimToNull(name));
    if (StringUtils.isNotEmpty(type)) {
        searchRequest.setType(HolidayType.valueOf(type));
    }
    if (currencyISO != null) {
        searchRequest.setCurrency(Currency.of(currencyISO));
    }
    MultivaluedMap<String, String> query = uriInfo.getQueryParameters();
    for (int i = 0; query.containsKey("idscheme." + i) && query.containsKey("idvalue." + i); i++) {
        ExternalId id = ExternalId.of(query.getFirst("idscheme." + i), query.getFirst("idvalue." + i));
        if (HolidayType.BANK.name().equals(type)) {
            searchRequest.addRegionExternalId(id);
        } else { // assume settlement/trading
            searchRequest.addExchangeExternalId(id);
        }
    }
    for (String holidayIdStr : holidayIdStrs) {
        searchRequest.addHolidayObjectId(ObjectId.parse(holidayIdStr));
    }
    out.put("searchRequest", searchRequest);

    if (data().getUriInfo().getQueryParameters().size() > 0) {
        HolidaySearchResult searchResult = data().getHolidayMaster().search(searchRequest);
        out.put("searchResult", searchResult);
        out.put("paging", new WebPaging(searchResult.getPaging(), uriInfo));
    }
    return out;
}

From source file:mitm.application.djigzo.james.mailets.DKIMVerify.java

protected static PublicKey parseKey(String pkcs8) throws MessagingException {
    PublicKey key = null;// ww  w  .j a va  2  s.c  o m

    pkcs8 = StringUtils.trimToNull(pkcs8);

    if (pkcs8 != null) {
        PEMReader pem = new PEMReader(new StringReader(pkcs8));

        Object o;

        try {
            o = pem.readObject();
        } catch (IOException e) {
            throw new MessagingException("Unable to read PEM encoded private key", e);
        }

        if (o instanceof PublicKey) {
            key = (PublicKey) o;
        } else if (o instanceof KeyPair) {
            key = ((KeyPair) o).getPublic();
        } else if (o == null) {
            throw new MessagingException("The PEM encoded blob did not return any object.");
        } else {
            throw new MessagingException("The PEM input is not a PublicKey or KeyPair but a " + o.getClass());
        }
    }

    return key;
}

From source file:com.hmsinc.epicenter.integrator.service.event.AbstractHL7EventHandler.java

protected Integer extractAge(HL7Message message, PatientDetail detail) throws HL7Exception {

    Integer age = null;/*from   w  ww.j  ava  2 s . c  o  m*/

    // Set the age using PID-7-2 if necessary
    if (detail.getDateOfBirth() == null) {

        // Check PID-7-2 for Age
        final String ageStr = StringUtils.trimToNull(message.getTerser().get("/PID-7-2"));

        if (ageStr == null) {
            logger.error("No date of birth or age set in message");
        } else if (StringUtils.isNumeric(ageStr)) {
            Integer ageAtInteraction = Integer.valueOf(ageStr);
            if (ageAtInteraction < 200) {
                age = ageAtInteraction;
            } else {
                logger.error("Age out of range: {}", ageAtInteraction);
            }
            logger.debug("Using age from PID-7-2: {}", ageAtInteraction);
        } else {
            logger.error("Non-numeric age specified in message");
        }
    }
    return age;
}