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.position.WebPositionsResource.java

private FlexiBean createSearchResultData(PagingRequest pr, String identifier, String minQuantityStr,
        String maxQuantityStr, List<String> positionIdStrs, List<String> tradeIdStrs) {
    minQuantityStr = StringUtils.defaultString(minQuantityStr).replace(",", "");
    maxQuantityStr = StringUtils.defaultString(maxQuantityStr).replace(",", "");
    FlexiBean out = createRootData();/*  ww w .j a  va 2 s  . co m*/

    PositionSearchRequest searchRequest = new PositionSearchRequest();
    searchRequest.setPagingRequest(pr);
    searchRequest.setSecurityIdValue(StringUtils.trimToNull(identifier));
    if (NumberUtils.isNumber(minQuantityStr)) {
        searchRequest.setMinQuantity(NumberUtils.createBigDecimal(minQuantityStr));
    }
    if (NumberUtils.isNumber(maxQuantityStr)) {
        searchRequest.setMaxQuantity(NumberUtils.createBigDecimal(maxQuantityStr));
    }
    for (String positionIdStr : positionIdStrs) {
        searchRequest.addPositionObjectId(ObjectId.parse(positionIdStr));
    }
    for (String tradeIdStr : tradeIdStrs) {
        searchRequest.addPositionObjectId(ObjectId.parse(tradeIdStr));
    }
    out.put("searchRequest", searchRequest);

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

From source file:com.egt.core.util.JS.java

public static String getOpenFileWindowJavaScript(String spec) {
    Bitacora.trace(JS.class, "getOpenFileWindowJavaScript", spec);
    VelocityContext context = new VelocityContext();
    context.put("url", StringUtils.trimToNull(spec));
    context.put("msg", "Recurso no disponible"); /* TODO: obtener de una tabla de mensajes */
    if (StringUtils.isNotBlank(spec)) {
        RandomAccessFile input;//from ww  w.  j  a va  2  s  . c o  m
        try {
            URL url = new URL(spec); // throws MalformedURLException
            File file = new File(Utils.getAttachedFileName(url));
            if (file.exists()) {
                input = new RandomAccessFile(file, "r"); // throws FileNotFoundException
                ImageInfo imageInfo = new ImageInfo();
                imageInfo.setInput(input); // input can be InputStream or RandomAccessFile
                imageInfo.setDetermineImageNumber(false); // default is false
                imageInfo.setCollectComments(false); // default is false
                if (imageInfo.check()) {
                    context.put("imageInfo", imageInfo);
                }
                input.close(); // throws IOException
            }
        } catch (MalformedURLException ex) {
            Bitacora.logFatal(ex);
        } catch (FileNotFoundException ex) {
            Bitacora.logFatal(ex);
        } catch (IOException ex) {
            Bitacora.logFatal(ex);
        }
    }
    return merge("js-open-window", context);
}

From source file:ch.entwine.weblounge.kernel.runtime.EnvironmentService.java

/**
 * {@inheritDoc}/*from   ww  w.  j a  va2  s  . c o m*/
 * 
 * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
 */
@SuppressWarnings("rawtypes")
public void updated(Dictionary properties) throws ConfigurationException {
    if (properties == null)
        return;

    // Environment
    Environment env = null;
    String environmentValue = StringUtils.trimToNull((String) properties.get(OPT_ENVIRONMENT));
    if (StringUtils.isNotBlank(environmentValue)) {
        try {
            env = Environment.valueOf(StringUtils.capitalize(environmentValue));
            logger.debug("Configured value for the default runtime environment is '{}'",
                    env.toString().toLowerCase());
        } catch (IllegalArgumentException e) {
            throw new ConfigurationException(OPT_ENVIRONMENT, environmentValue);
        }
    } else {
        env = DEFAULT_ENVIRONMENT;
        logger.debug("Using default value '{}' for runtime environment", env.toString().toLowerCase());
    }

    // Did the setting change?
    if (!env.equals(environment)) {
        this.environment = env;
        if (registration != null) {
            try {
                registration.unregister();
            } catch (IllegalStateException e) {
                // Never mind, the service has been unregistered already
            } catch (Throwable t) {
                logger.error("Unregistering runtime environment failed: {}", t.getMessage());
            }
        }
        registration = bundleContext.registerService(Environment.class.getName(), environment, null);
        logger.info("Runtime environment set to '{}'", environment.toString().toLowerCase());
    }
}

From source file:net.bulletin.pdi.xero.step.XeroGetStepMeta.java

public void setXmlFieldName(String xmlFieldName) {
    this.xmlFieldName = StringUtils.trimToNull(xmlFieldName);
}

From source file:com.opengamma.web.exchange.WebExchangesResource.java

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)/*from   w w  w .j  av  a  2s. c  o  m*/
public Response postHTML(@FormParam("name") String name, @FormParam("idscheme") String idScheme,
        @FormParam("idvalue") String idValue, @FormParam("regionscheme") String regionScheme,
        @FormParam("regionvalue") String regionValue) {
    name = StringUtils.trimToNull(name);
    idScheme = StringUtils.trimToNull(idScheme);
    idValue = StringUtils.trimToNull(idValue);
    regionScheme = StringUtils.trimToNull(regionScheme);
    regionValue = StringUtils.trimToNull(regionValue);
    if (name == null || idScheme == null || idValue == null) {
        FlexiBean out = createRootData();
        if (name == null) {
            out.put("err_nameMissing", true);
        }
        if (idScheme == null) {
            out.put("err_idschemeMissing", true);
        }
        if (idValue == null) {
            out.put("err_idvalueMissing", true);
        }
        if (regionScheme == null) {
            out.put("err_regionschemeMissing", true);
        }
        if (regionValue == null) {
            out.put("err_regionvalueMissing", true);
        }
        String html = getFreemarker().build(HTML_DIR + "exchanges-add.ftl", out);
        return Response.ok(html).build();
    }
    URI uri = createExchange(name, idScheme, idValue, regionScheme, regionValue);
    return Response.seeOther(uri).build();
}

From source file:com.opengamma.web.security.WebSecuritiesResource.java

private FlexiBean createSearchResultData(PagingRequest pr, SecuritySearchSortOrder so, String name,
        String identifier, String type, List<String> securityIdStrs, UriInfo uriInfo) {
    FlexiBean out = createRootData();//from   w ww  .  ja v a2  s . co  m

    SecuritySearchRequest searchRequest = new SecuritySearchRequest();
    searchRequest.setPagingRequest(pr);
    searchRequest.setSortOrder(so);
    searchRequest.setName(StringUtils.trimToNull(name));
    searchRequest.setExternalIdValue(StringUtils.trimToNull(identifier));
    searchRequest.setSecurityType(StringUtils.trimToNull(type));
    for (String securityIdStr : securityIdStrs) {
        searchRequest.addObjectId(ObjectId.parse(securityIdStr));
    }
    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);
    }
    out.put("searchRequest", searchRequest);

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

From source file:com.bluexml.side.Integration.alfresco.xforms.webscript.XmlBuilder.java

private static Element buildAssociation(Document doc, AssociationBean associationBean) {
    // association
    Element association = doc.createElement(ENTRY_ASSOCIATION_NODE);
    association.setAttribute(ENTRY_QUALIFIEDNAME, associationBean.getAssociationName());
    if (associationBean.getAssoType().equals(AssoType.Simple)) {
        association.setAttribute(ENTRY_ASSOCIATION_TYPE, ENTRY_ASSOCIATION_TYPE_SIMPLE);
    } else {//  ww w .  j  av a 2s .c o m
        association.setAttribute(ENTRY_ASSOCIATION_TYPE, ENTRY_ASSOCIATION_TYPE_COMPOSITION);
    }
    // target
    String targetValue = associationBean.getTargetId();
    String targetLabel = associationBean.getTargetLabel();

    String targetNodeType = associationBean.getTargetQualifiedName();
    Element target = doc.createElement(ENTRY_ASSOCIATION_TARGET_NODE);
    target.setAttribute(ENTRY_QUALIFIEDNAME, targetNodeType);
    target.setTextContent(targetValue);
    if (StringUtils.trimToNull(targetLabel) != null) {
        target.setAttribute("label", targetLabel);
    }
    association.appendChild(target);

    return association;
}

From source file:com.bluexml.side.portal.alfresco.reverse.reverser.EclipseReverser.java

public void handleComponent(Page page, Component component) throws Exception {
    String portletName = component.getRegionId();
    String componentURL = component.getUrl();
    String sourceId = component.getSourceId();
    String scope = component.getScope() != null ? component.getScope() : "template";
    Map<String, String> props = new TreeMap<String, String>();
    if (StringUtils.trimToNull(componentURL) != null) {
        props.put("url", componentURL);
    }//  w  w w  .  j  a  v a 2s.c om
    props.put("scope", scope);

    Properties properties = component.getProperties();

    handleProperties(props, properties);

    Portlet createPortlet = PortalHelper.createPortlet(rootObject, portletName, props);
    createPortlet.setTitle(page.getID() + "." + portletName);
    handleSubComponents(component, portletName, createPortlet);

    PortalHelper.createHavePortlet(portalLayout, getMatchingColumn(portletName), 1, page, createPortlet);
}

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

private void initDeleteAttributes() {
    deleteAttributes = new LinkedList<String>();

    String[] deletes = getValues(getConfiguration().getChildren(Parameter.DELETE.name));

    if (deletes != null) {
        for (String delete : deletes) {
            delete = StringUtils.trimToNull(delete);

            if (delete == null) {
                continue;
            }//from   ww  w  . ja v  a2s. c o  m

            deleteAttributes.add(delete);
        }
    }
}

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

@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)/* w w w  .  j  a v a  2s . c om*/
public Response putJSON(@FormParam("name") String name) {
    PortfolioDocument doc = data().getPortfolio();
    if (doc.isLatest() == false) {
        return Response.status(Status.FORBIDDEN).entity(getHTML()).build();
    }
    name = StringUtils.trimToNull(name);
    updatePortfolioNode(name, doc);
    return Response.ok().build();
}