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.google.code.configprocessor.processing.AddAction.java

public String getAfter() {
    return StringUtils.trimToNull(after);
}

From source file:com.edgenius.wiki.render.handler.PageIndexHandler.java

public List<RenderPiece> handle(RenderContext renderContext, Map<String, String> values)
        throws RenderHandlerException {
    if (indexer == null) {
        log.warn("Unable to find valid page for index");
        throw new RenderHandlerException("Unable to find valid page for index");
    }/* www . jav a 2 s  .c  o  m*/

    List<String> filters = getFilterList(values != null ? StringUtils.trimToNull(values.get("filter")) : null);
    List<String> filtersOut = getFilterList(
            values != null ? StringUtils.trimToNull(values.get("filterout")) : null);

    //temporary cache for indexer after filter out
    TreeMap<Character, Integer> indexerFiltered = new TreeMap<Character, Integer>();
    List<RenderPiece> listPieces = new ArrayList<RenderPiece>();
    //render each character list
    Character indexKey = null;
    boolean requireEndOfMacroPageIndexList = false;
    for (Entry<String, LinkModel> entry : indexMap.entrySet()) {
        String title = entry.getKey();

        if (filters.size() > 0) {
            boolean out = false;
            for (String filter : filters) {
                if (!FilenameUtils.wildcardMatch(title.toLowerCase(), filter.toLowerCase())) {
                    out = true;
                    break;
                }
            }
            if (out)
                continue;
        }

        if (filtersOut.size() > 0) {
            boolean out = false;
            for (String filterOut : filtersOut) {
                if (FilenameUtils.wildcardMatch(title.toLowerCase(), filterOut.toLowerCase())) {
                    out = true;
                    break;
                }
            }
            if (out)
                continue;
        }

        Character first = Character.toUpperCase(title.charAt(0));
        if (!first.equals(indexKey)) {
            if (requireEndOfMacroPageIndexList) {
                listPieces.add(new TextModel("</div>")); //macroPageIndexList
            }
            Integer anchorIdx = indexer.get(first);
            indexKey = first;
            if (anchorIdx != null) {
                indexerFiltered.put(first, anchorIdx);
                listPieces.add(new TextModel(new StringBuilder().append(
                        "<div class=\"macroPageIndexList\"><div class=\"macroPageIndexKey\" id=\"pageindexanchor-")
                        .append(anchorIdx).append("\">").append(first).toString()));
                requireEndOfMacroPageIndexList = true;
                //up image line to return top
                if (RenderContext.RENDER_TARGET_PAGE.equals(renderContext.getRenderTarget())) {
                    LinkModel back = new LinkModel();
                    back.setAnchor("pageindexanchor-0");
                    back.setAid("Go back index character list");
                    back.setView(renderContext.buildSkinImageTag("render/link/up.png", NameConstants.AID,
                            SharedConstants.NO_RENDER_TAG));
                    listPieces.add(back);
                }

                listPieces.add(new TextModel("</div>"));//macroPageIndexKey
            } else {
                log.error("Unable to page indexer for {}", indexKey);
            }
        }
        listPieces.add(new TextModel("<div class=\"macroPageIndexLink\">"));
        LinkModel link = entry.getValue();
        link.setLinkTagStr(renderContext.buildURL(link));
        listPieces.add(link);
        listPieces.add(new TextModel("</div>"));//macroPageIndexLink

    }
    if (requireEndOfMacroPageIndexList) {
        listPieces.add(new TextModel("</div>")); //macroPageIndexList
    }

    //render sum of characters - although it display before page list, however, as filter may hide some characters, so display later than
    //other
    List<RenderPiece> pieces = new ArrayList<RenderPiece>();

    StringBuffer sbuf = new StringBuffer("<div aid=\"pageindex\" class=\"macroPageIndex ")
            .append(WikiConstants.mceNonEditable).append("\"");
    if (values != null && values.size() > 0) {
        sbuf.append(" wajax=\"")
                .append(RichTagUtil.buildWajaxAttributeString(this.getClass().getName(), values)).append("\" ");
    }
    sbuf.append("><div id=\"pageindexanchor-0\" class=\"macroPageIndexKeys\">");

    pieces.add(new TextModel(sbuf.toString()));
    for (Entry<Character, Integer> entry : indexerFiltered.entrySet()) {
        LinkModel anchor = new LinkModel();
        anchor.setView(entry.getKey().toString());
        anchor.setAnchor("pageindexanchor-" + entry.getValue());
        anchor.setLinkTagStr(renderContext.buildURL(anchor));
        pieces.add(anchor);
    }
    pieces.add(new TextModel("</div>")); //macroPageIndexKeys
    pieces.addAll(listPieces);
    pieces.add(new TextModel("</div>")); //macroPageIndex

    return pieces;

}

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

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)/*w  w  w  . jav a 2 s.  c om*/
public Response postJSON(@FormParam("uid") String uniqueIdStr) {
    PortfolioDocument doc = data().getPortfolio();
    if (doc.isLatest() == false) {
        return Response.status(Status.FORBIDDEN).entity(new WebPortfolioNodeResource(this).getHTML()).build();
    }
    uniqueIdStr = StringUtils.trimToNull(uniqueIdStr);
    if (uniqueIdStr == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    UniqueId positionId = null;
    try {
        positionId = UniqueId.parse(uniqueIdStr);
        data().getPositionMaster().get(positionId); // validate position exists
    } catch (Exception ex) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    URI uri = addPosition(doc, positionId);
    return Response.created(uri).build();
}

From source file:eionet.meta.service.data.VocabularyFilter.java

public void setBaseUri(String baseUri) {
    this.baseUri = StringUtils.trimToNull(baseUri);
}

From source file:$.DirectCallController.java

@RequestMapping(value = "/directCall", method = RequestMethod.POST)
    public String processCallForm(@ModelAttribute("model") ModelMap modelMap, @RequestParam("body") String body,
            @RequestParam("uri") String uri, @RequestParam("senderRef") String senderRef,
            @RequestParam("soapAction") @Nullable String soapAction, @RequestParam("header") String header) {

        Assert.hasText(body, "the body must not be empty");
        Assert.hasText(uri, "the uri must not be empty");
        Assert.hasText(senderRef, "the senderRef must not be empty");

        // generate unique ID
        String callId = UUID.randomUUID().toString();

        // save params into registry
        DirectCallParams params = new DirectCallParams(body, uri, senderRef, soapAction,
                StringUtils.trimToNull(header));
        callRegistry.addParams(callId, params);

        // call external system via internal servlet route
        try {/*  ww  w  . java 2s .  co  m*/
            Log.debug("Calling external system with callId=" + callId + ", params: " + params);

            String res = directCall.makeCall(callId);

            modelMap.put(CALL_RESULT_ATTR, MessageController.prettyPrintXML(res));
        } catch (Exception ex) {
            // error occurred
            StringWriter strOut = new StringWriter();
            PrintWriter resStr = new PrintWriter(strOut);
            ExceptionUtils.printRootCauseStackTrace(ex, resStr);

            modelMap.put(CALL_RESULT_ERR_ATTR, strOut.toString());
        }

        modelMap.put("header", header);
        modelMap.put("body", body);
        modelMap.put("uri", uri);
        modelMap.put("senderRef", senderRef);
        modelMap.put("soapAction", soapAction);

        return VIEW_NAME;
    }

From source file:com.google.code.configprocessor.processing.AddAction.java

public String getBefore() {
    return StringUtils.trimToNull(before);
}

From source file:net.hillsdon.reviki.configuration.PropertiesDeploymentConfiguration.java

private String getTrimToNullProperty(final String key) {
    return StringUtils.trimToNull(_properties.get(key));
}

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

protected static PrivateKey parseKey(String pkcs8) throws MessagingException {
    PrivateKey key = null;/*from www  .  j  av  a 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 PrivateKey) {
            key = (PrivateKey) o;
        } else if (o instanceof KeyPair) {
            key = ((KeyPair) o).getPrivate();
        } 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 PrivateKey or KeyPair but a " + o.getClass());
        }
    }

    return key;
}

From source file:com.opengamma.web.region.WebRegionsResource.java

private FlexiBean createSearchResultData(PagingRequest pr, String name, RegionClassification classification,
        List<String> regionIdStrs, UriInfo uriInfo) {
    FlexiBean out = createRootData();//from  w w w . j  ava2 s . c o m

    RegionSearchRequest searchRequest = new RegionSearchRequest();
    searchRequest.setPagingRequest(pr);
    searchRequest.setName(StringUtils.trimToNull(name));
    searchRequest.setClassification(classification);
    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 regionIdStr : regionIdStrs) {
        searchRequest.addObjectId(ObjectId.parse(regionIdStr));
    }
    out.put("searchRequest", searchRequest);

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

From source file:ips1ap101.lib.core.db.util.VistaFuncionWrapper.java

public VistaFuncionWrapper(long vista, EnumFormatoGuardar formato, EnumTipoInforme tipo, String select)
        throws ExcepcionAplicacion {
    _id = vista;//w  ww  .  j a v  a  2 s.  c  o  m
    _nombre = Global.PREFIJO_STRING_ID_RECURSO + vista;
    _formato = formato != null ? formato : EnumFormatoGuardar.INFORME;
    _tipo = tipo != null ? tipo : EnumTipoInforme.DETALLE;
    if (_formato.equals(EnumFormatoGuardar.ARCHIVO) && _tipo.equals(EnumTipoInforme.GRAFICO)) {
        throw new ExcepcionAplicacion(Bitacora.getTextoMensaje(CBM.GRAFICO_NO_DISPONIBLE));
    }
    _select = StringUtils.trimToNull(select);
    if (_select == null) {
        throw new ExcepcionAplicacion(Bitacora.getTextoMensaje(CBM.ERROR_COMANDO_SELECT));
    }
    init();
}