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.cloudbees.jenkins.plugins.amazonecs.ECSTaskTemplate.java

@DataBoundSetter
public void setTaskrole(String taskRoleArn) {
    this.taskrole = StringUtils.trimToNull(taskRoleArn);
}

From source file:com.bluexml.xforms.controller.mapping.MappingToolSearch.java

/**
 * Builds a JSON string for the search options provided by the XForms engine
 * in the node.//from  w w  w.  j  av a 2s  . c  o  m
 * 
 * @param formName
 * @param instance
 * @return
 * @throws ServletException
 */
public String transformSearchForm(String formName, Node instance, boolean shortPropertyNames,
        Map<String, String> initParams) throws ServletException {
    SearchFormType sfType = getSearchFormType(formName);
    if (sfType == null) {
        if (logger.isErrorEnabled()) {
            logger.error("No search form found with id '" + formName + "'");
        }
        throw new ServletException("The search form '" + formName + "' was not found in the mapping.xml file.");
    }
    Element rootElt = getRootElement(formName, instance);

    StringBuffer buf = new StringBuffer(1024);
    String propName = "";
    String typeName = "";

    ClassType classType = resolveClassType(sfType);

    String packageName = classType.getPackage();

    String namespaceClassType = MappingToolCommon.getNameSpaceFromPrefix(getRootPackage(packageName));

    buf.append("{"); // open JSON string

    // the title
    buf.append("type:\"");
    typeName = "{" + namespaceClassType + "}" + classType.getAlfrescoName();
    buf.append(typeName);
    buf.append("\"");

    // the combination operator
    buf.append(",operator:\"");
    buf.append(sfType.getOperator());
    buf.append("\"");

    // the properties
    buf.append(",fields:{"); // open fields
    boolean first = true;
    for (SearchFieldType fieldType : sfType.getField()) {
        // find the corresponding attribute
        AttributeType refAttribute = null;
        String fieldName = fieldType.getName();
        for (AttributeType attribute : getAllAttibutes(classType)) {
            if (attribute.getName().equals(fieldName)) {
                refAttribute = attribute;
                break;
            }
        }
        if (refAttribute == null) {
            logger.error("The attribute for search field '" + fieldName
                    + "' was not found! Since this should never happen, the mapping file is most obviously not correct.");
            throw new ServletException("The processing of this search form could not complete.");
        }

        Element fieldElt = DOMUtil.getChild(rootElt, fieldName);
        Element opElt = DOMUtil.getChild(fieldElt, MsgId.INT_INSTANCE_SEARCH_OPCODE.getText());
        String operator = opElt.getTextContent();

        if (StringUtils.trimToNull(operator) == null) {
            continue;
        }
        if (operator.equals(MsgId.INT_SEARCH_OPERATOR_IGNORE.getText()) == false) {
            if (first == false) {
                buf.append(",");
            }

            String att_package = "";
            if (refAttribute.getAspectType() != null) {
                att_package = refAttribute.getAspectType().getPackage();
            } else if (refAttribute.getClassType() != null) {
                att_package = refAttribute.getClassType().getPackage();
            }

            String namespaceAttribute = MappingToolCommon.getNameSpaceFromPrefix(getRootPackage(att_package));

            propName = "{";
            propName += namespaceAttribute;
            propName += "}";
            propName += refAttribute.getAlfrescoName();
            if (shortPropertyNames) {
                propName = StringUtils.replace(propName, typeName, "");
            }
            buf.append("\"");
            buf.append(propName);
            buf.append("\":");
            buf.append("{"); // open field

            buf.append("type:\"");
            String type;
            if (isEnumerated(fieldType)) {
                type = MsgId.INT_SEARCH_JSON_TYPE_ENUMS.getText();
            } else if (refAttribute.getType().equalsIgnoreCase("object")) {
                type = "String";
            } else {
                type = refAttribute.getType();
            }
            buf.append(type);
            buf.append("\"");

            buf.append(",operator:\"");
            buf.append(operator);
            buf.append("\"");

            buf.append(",values:["); // open values
            if (hasSingleInput(fieldType)) {
                Element valElt = DOMUtil.getChild(fieldElt, MsgId.INT_INSTANCE_SEARCH_VALUE.getText());
                String value = valElt.getTextContent();
                if (isEnumerated(fieldType)) {
                    value = convertSelectInputValuesToSearchFormat(value, fieldType.getEnum(), initParams);
                }
                buf.append("\"");
                buf.append(value);
                buf.append("\"");
            } else {
                Element valEltLo = DOMUtil.getChild(fieldElt, MsgId.INT_INSTANCE_SEARCH_VALUE_LO.getText());
                String valueLo = valEltLo.getTextContent();
                buf.append("\"");
                buf.append(valueLo);
                buf.append("\"");
                Element valEltHi = DOMUtil.getChild(fieldElt, MsgId.INT_INSTANCE_SEARCH_VALUE_HI.getText());
                String valueHi = valEltHi.getTextContent();
                buf.append(",\"");
                buf.append(valueHi);
                buf.append("\"");
            }
            buf.append("]"); // close values
            buf.append("}"); // close field
            first = false;
        }
    }
    buf.append("}"); // close fields

    buf.append("}"); // close the JSON string

    return buf.toString();
}

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

public void execute(WebScriptRequest webscriptrequest, WebScriptResponse webscriptresponse) throws IOException {
    // WebScriptServletRequest webScriptServletRequest = (WebScriptServletRequest) webscriptrequest;
    // HttpServletRequest httpServletRequest = webScriptServletRequest.getHttpServletRequest();
    // String remoteAddr = httpServletRequest.getRemoteAddr();
    // String localAddr = httpServletRequest.getLocalAddr();
    // if (StringUtils.equalsIgnoreCase(remoteAddr, "127.0.0.1")
    // || StringUtils.equalsIgnoreCase(remoteAddr, localAddr)) {

    String username = webscriptrequest.getParameter("username");
    if (StringUtils.trimToNull(username) == null) {
        throw new RuntimeException("No user name provided.");
    }//from w  w w .  j av  a2s .c  o  m
    webscriptresponse.setContentType("text/xml");
    String contentEncoding = "UTF-8";
    webscriptresponse.setContentEncoding(contentEncoding);

    dictionaryService = serviceRegistry.getDictionaryService();
    namespacePrefixResolver = serviceRegistry.getNamespaceService();

    XFormsQueryType queryType = getQueryType(webscriptrequest);

    Map<String, String> parameters = getParameters(webscriptrequest);

    String result = AuthenticationUtil.runAs(new XFormsWork(this, queryType, parameters, getServiceRegistry()),
            username);

    OutputStream outputStream = webscriptresponse.getOutputStream();
    outputStream.write(result.getBytes("UTF-8"));
    //}
}

From source file:com.fiveamsolutions.nci.commons.mojo.copywebfiles.CopyWebFilesMojo.java

/**
 * {@inheritDoc}/*from   www . j  a v  a2  s.  c  o m*/
 */
public void execute() throws MojoExecutionException, MojoFailureException {

    if (ArrayUtils.isEmpty(srcDirectories)) {
        getLog().info("No values given for srcDirectories, no files will be copied.");
        return;
    }

    if (deployDirectory == null || !deployDirectory.isDirectory()) {
        throw new MojoExecutionException(
                "The deployDirectory configuration parameter must be set to a directory.");
    }

    if (ArrayUtils.isEmpty(fileTypes)) {
        fileTypes = defaultFileTypes;
    }

    deployDirectoryPattern = StringUtils.trimToNull(deployDirectoryPattern);

    Collection<File> latestDeployDirectories = getLatestDeploymentDirectories();

    for (File latestDeployDirectory : latestDeployDirectories) {
        IOFileFilter fileFilter = getFilefilter(latestDeployDirectory);
        copyFiles(latestDeployDirectory, fileFilter);
    }
}

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

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)/* w w w .  j  av a 2  s  .c om*/
public Response postJSON(@FormParam("idscheme") String idScheme, @FormParam("idvalue") String idValue) {
    idScheme = StringUtils.trimToNull(idScheme);
    idValue = StringUtils.trimToNull(idValue);
    if (idScheme == null || idValue == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    ExternalScheme scheme = ExternalScheme.of(idScheme);
    Collection<ExternalIdBundle> requestBundles = buildSecurityRequest(scheme, idValue);
    SecurityLoader securityLoader = data().getSecurityLoader();
    Map<ExternalIdBundle, UniqueId> loadedSecurities = securityLoader.loadSecurities(requestBundles);
    FlexiBean out = createPostJSONOutput(loadedSecurities, requestBundles, scheme);
    return Response.ok(getFreemarker().build(JSON_DIR + "securities-added.ftl", out)).build();
}

From source file:com.cloudbees.jenkins.plugins.amazonecs.ECSTaskTemplate.java

@DataBoundSetter
public void setEntrypoint(String entrypoint) {
    this.entrypoint = StringUtils.trimToNull(entrypoint);
}

From source file:com.siberhus.web.ckeditor.CkeditorConfigurationHolder.java

private String getProperty(String name) {
    return StringUtils.trimToNull(properties.getProperty(name));
}

From source file:com.zimbra.cs.servlet.ContextPathBasedThreadPoolBalancerFilter.java

protected void parse(String input) throws ServletException {
    rulesByContextPath.clear();/* w  w  w.j  ava  2  s. c  o  m*/
    for (String str : new StrTokenizer(input, ",").getTokenArray()) {
        String[] array = str.split(":");
        if (array.length != 2) {
            throw new ServletException("Malformed rules: " + input);
        }
        String key = StringUtils.trimToNull(array[0]);
        String value = StringUtils.trimToNull(array[1]);
        if (key == null || value == null) {
            throw new ServletException("Malformed rules: " + input);
        }
        Rules rules = Rules.parse(value);
        rulesByContextPath.put(key, rules);
    }
}

From source file:com.opengamma.web.historicaltimeseries.WebAllHistoricalTimeSeriesResource.java

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.TEXT_HTML)//from  w w  w  .  ja  va 2  s  .c om
public Response postHTML(@FormParam("dataProvider") String dataProvider,
        @FormParam("dataField") String dataField, @FormParam("start") String start,
        @FormParam("end") String end, @FormParam("idscheme") String idScheme,
        @FormParam("idvalue") String idValue) {
    idScheme = StringUtils.trimToNull(idScheme);
    idValue = StringUtils.trimToNull(idValue);
    dataField = StringUtils.trimToNull(dataField);
    start = StringUtils.trimToNull(start);
    end = StringUtils.trimToNull(end);
    dataProvider = StringUtils.trimToNull(dataProvider);

    FlexiBean out = createRootData();
    LocalDate startDate = null;
    boolean validStartDate = true;
    if (start != null) {
        try {
            startDate = LocalDate.parse(start);
        } catch (DateTimeException e) {
            out.put("err_startInvalid", true);
            validStartDate = false;
        }
    }
    LocalDate endDate = null;
    boolean validEndDate = true;
    if (end != null) {
        try {
            endDate = LocalDate.parse(end);
        } catch (DateTimeException e) {
            out.put("err_endInvalid", true);
            validEndDate = false;
        }
    }

    if (dataField == null || idValue == null || !validStartDate || !validEndDate) {
        //data for repopulating the form
        out.put("scheme", idScheme);
        out.put("dataField", dataField);
        out.put("idValue", idValue);
        out.put("dataProvider", dataProvider);
        out.put("start", start);
        out.put("end", end);

        if (dataField == null) {
            out.put("err_iddatafieldMissing", true);
        }
        if (idValue == null) {
            out.put("err_idvalueMissing", true);
        }
        String html = getFreemarker().build(HTML_DIR + "timeseries-add.ftl", out);
        return Response.ok(html).build();
    }

    ExternalScheme scheme = ExternalScheme.of(idScheme);
    Set<ExternalId> identifiers = buildSecurityRequest(scheme, idValue);
    Map<ExternalId, UniqueId> added = addTimeSeries(dataProvider, dataField, identifiers, startDate, endDate);

    URI uri = null;
    if (!identifiers.isEmpty()) {
        if (identifiers.size() == 1) {
            ExternalId requestIdentifier = identifiers.iterator().next();
            UniqueId uniqueId = added.get(requestIdentifier);
            if (uniqueId != null) {
                uri = data().getUriInfo().getAbsolutePathBuilder().path(uniqueId.toString()).build();
            } else {
                s_logger.warn("No time-series added for {} ", requestIdentifier);
                uri = uri(data());
            }
        } else {
            uri = uri(data(), identifiers);
        }
    }
    return Response.seeOther(uri).build();
}

From source file:com.opengamma.web.position.WebPositionsResource.java

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)/*from w w  w. jav a 2 s  . c o  m*/
public Response postJSON(@FormParam("quantity") String quantityStr, @FormParam("idscheme") String idScheme,
        @FormParam("idvalue") String idValue, @FormParam("tradesJson") String tradesJson) {

    quantityStr = StringUtils.replace(StringUtils.trimToNull(quantityStr), ",", "");
    BigDecimal quantity = quantityStr != null && NumberUtils.isNumber(quantityStr) ? new BigDecimal(quantityStr)
            : null;
    idScheme = StringUtils.trimToNull(idScheme);
    idValue = StringUtils.trimToNull(idValue);
    tradesJson = StringUtils.trimToNull(tradesJson);

    if (quantity == null || idScheme == null || idValue == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }

    ExternalIdBundle id = ExternalIdBundle.of(ExternalId.of(idScheme, idValue));
    UniqueId secUid = getSecurityUniqueId(id);
    if (secUid == null) {
        throw new DataNotFoundException("invalid " + idScheme + "~" + idValue);
    }
    Collection<ManageableTrade> trades = null;
    if (tradesJson != null) {
        trades = parseTrades(tradesJson);
    } else {
        trades = Collections.<ManageableTrade>emptyList();
    }
    URI uri = addPosition(quantity, secUid, trades);
    return Response.created(uri).build();
}