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.manydesigns.elements.fields.search.AbstractDateSearchField.java

@Override
public void readFromRequest(HttpServletRequest req) {
    minStringValue = StringUtils.trimToNull(req.getParameter(minInputName));
    try {//from   www . j  a  va 2s  . c  o m
        minValue = toDate(Util.parseDateTime(dateTimeFormatter, minStringValue, containsTime));
    } catch (Throwable e) {
        minValue = null;
    }

    maxStringValue = StringUtils.trimToNull(req.getParameter(maxInputName));
    try {
        maxValue = toDate(Util.parseDateTime(dateTimeFormatter, maxStringValue, containsTime));
    } catch (Throwable e) {
        maxValue = null;
    }

    searchNullValue = (NULL_VALUE.equals(minStringValue) || NULL_VALUE.equals(maxStringValue));
}

From source file:net.duckling.falcon.api.boostrap.SQLReader.java

/**
 * ??SQL/*from   w w w  .  j a  v  a2 s  .c  om*/
 * @return   ?SQLSQLnull
 */
public String next() {
    if (!isClosed()) {
        StringBuilder buffer = new StringBuilder();

        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                line = line.trim();
                if (isDelimiter(line)) {
                    changeDelimiter(line);
                } else if (!isComment(line)) {
                    if (line.endsWith(delimeter)) {
                        line = line.substring(0, line.length() - delimeter.length());
                        buffer.append(line);
                        buffer.append("\n");
                        return StringUtils.trimToNull(buffer.toString());
                    } else {
                        buffer.append(line);
                        buffer.append("\n");
                    }
                }
            }
        } catch (IOException e) {
            LOG.error(e.getMessage());
            LOG.debug("", e);
            close();
        }
        if (line == null) {
            close();
        }
        return StringUtils.trimToNull(buffer.toString());
    }
    return null;
}

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

public String getFind() {
    return StringUtils.trimToNull(find);
}

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

/**
 * Adds the button for adding the text currently in the input field to the list of values.
 * //from   w ww.  j  a v  a 2  s  . c  om
 * @param path
 *            the path in the lowest containing parent
 * @param rootPath
 *            the path from the top-most container, with references to all relevant repeaters
 * @return
 */
private Element getTriggerAdd(@SuppressWarnings("unused") String path, String rootPath) {

    ModelElementBindSimple inputBind = parent.getInputBind();
    ModelElementBindSimple storeBind = parent.getStoreBind();
    String inputNodeset = inputBind.getNodeset();
    String storeNodeset = storeBind.getNodeset();

    if ((StringUtils.trimToNull(rootPath) == null)
            && (rootPath.startsWith("instance('minstance')/") == false)) {
        inputNodeset = "instance('minstance')/" + inputNodeset;
    }

    Element trigger = XFormsGenerator.createTriggerWithLabelImage(XFormsGenerator.IMG_ADD, "Add item");
    Element action = XFormsGenerator.createElement("action", XFormsGenerator.NAMESPACE_XFORMS);

    // <xf:action ev:event="DOMActivate"
    // if="(instance('ComBluexmlDataRubriqueListInstance1')/SELECTEDID ne '') and not(parentchildOf[com.bluexml.data.Rubrique/BXDSID = instance('ComBluexmlDataRubriqueListInstance1')/SELECTEDID])">
    action.setAttribute("event", "DOMActivate", XFormsGenerator.NAMESPACE_EVENTS);
    String iftest = "(" + inputNodeset + " ne '')";
    action.setAttribute("if", iftest);

    Element insertAction = XFormsGenerator.createElement("insert", XFormsGenerator.NAMESPACE_XFORMS);
    insertAction.setAttribute("at", "last()");
    insertAction.setAttribute("position", "after");
    action.addContent(insertAction);
    storeBind.addLinkedElement(insertAction);

    Element setvalueId = XFormsGenerator.createElement("setvalue", XFormsGenerator.NAMESPACE_XFORMS);
    String pathItem = storeNodeset + "[last() - 1]" + "/" + MsgId.INT_INSTANCE_INPUT_MULT_VALUE;
    setvalueId.setAttribute("ref", pathItem);
    setvalueId.setAttribute("value", inputNodeset);
    action.addContent(setvalueId);

    trigger.addContent(action);
    return trigger;
}

From source file:com.bluexml.side.Integration.eclipse.branding.enterprise.wizards.migration.ModelMigrationWizard.java

protected void execute(GeneralProjectMigration page, String libraryId, IProgressMonitor monitor2)
        throws Exception {

    IProject target = ToolingUtils.importLibrary(libraryId);
    IProject project2Update = this.project;
    // copy projects before as requested
    Boolean projectCopy = page.getFieldValueBoolean(GeneralProjectMigration.Fields.copybefore.toString());
    if (projectCopy) {
        project2Update = null;//from   ww  w .j a  v a  2 s  . com
        String newNameParam = page.getFieldValueString(GeneralProjectMigration.Fields.newName.toString());

        if (StringUtils.trimToNull(newNameParam) == null) {
            newNameParam = GeneralProjectMigration.DEFAULT_VALUE_NEWNAME;
        }

        IProjectDescription description = project.getDescription();
        String newName = newNameParam;
        description.setName(newName);
        description.setLocationURI(null);
        System.out.println(
                "ModelMigrationWizard.execute() rename project " + project.getName() + " -> " + newName);
        project.copy(description, true, monitor2);
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
        project2Update = project;

    }

    // execute models conversion
    ModelMigrationHelper modelMigrationHelper = new ModelMigrationHelper();
    modelMigrationHelper.updateProject(project2Update, target, libraryId, projectCopy, monitor2);
    monitor2.subTask("Refresh project");
    IFileHelper.refreshFolder(project2Update);
    monitor2.done();
}

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

protected void onActivate() {
    String paramValue = StringUtils.trimToNull(request.getParameter(PASSWORD_ID_PARAMETER));

    if (paramValue != null) {
        passwordID = paramValue;//from   ww w . j a  v  a2  s .  com
    }

    paramValue = StringUtils.trimToNull(request.getParameter(PASSWORD_LENGTH_PARAMETER));

    if (paramValue != null) {
        passwordLength = NumberUtils.toInt(paramValue);

        if (passwordLength <= 0) {
            /*
             * Fallback to default for the user
             */
            passwordLength = null;
        }
    }
}

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

private String getExpectedMediaType(HttpServletRequest request) {
    String mediaType = null;/*from w ww . j  a v a 2s.c  om*/
    String acceptHeader = request.getHeader("Accept");
    if (acceptHeader != null) {
        mediaType = StringUtils
                .trimToNull(MIMEParse.bestMatch(Collections.singleton(MEDIA_TYPE_SVG), acceptHeader));
    }

    return mediaType;
}

From source file:com.hmsinc.epicenter.webapp.remoting.OptionsService.java

/**
 * @param prefs/*from w  ww .j  a v  a2s  . c  o m*/
 * @return
 */
@Secured("ROLE_USER")
@Transactional
@RemoteMethod
public EpiCenterUser updatePreferences(final Map<String, String> prefs) {

    Validate.notNull(prefs);
    final EpiCenterUser user = getPrincipal();
    user.getPreferences().putAll(prefs);

    logger.debug("New prefs: {}", prefs);

    final Set<String> emptyKeys = new HashSet<String>();
    for (Map.Entry<String, String> entry : user.getPreferences().entrySet()) {
        final String value = StringUtils.trimToNull(entry.getValue());
        if (value == null) {
            emptyKeys.add(entry.getKey());
        } else {
            entry.setValue(value);
        }
    }

    for (String empty : emptyKeys) {
        user.getPreferences().remove(empty);
    }
    logger.debug("Cleaned prefs: {}", user.getPreferences());

    logger.trace("Prefs for user {}: {}", user.getUsername(), user.getPreferences());

    permissionRepository.save(user);

    return user;

}

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

/**
 * Creates and initializes the DOM section for a field.
 * //  www. j a v a2  s .  c o  m
 * @param doc
 * @param fieldType
 * @return
 */
private Element getSearchFieldNode(Document doc, SearchFieldType fieldType) {
    String fieldName = fieldType.getName();
    Element fieldElt = doc.createElement(fieldName);

    Element opElt = doc.createElement(MsgId.INT_INSTANCE_SEARCH_OPCODE.getText());
    fieldElt.appendChild(opElt);
    opElt.setTextContent(fieldType.getPick()); // set the default operator

    String dataType = fieldType.getType();
    boolean isTyped = (StringUtils.trimToNull(dataType) != null);
    if (isTyped && dataType.equalsIgnoreCase("datetime")) {
        dataType = "Date";
    }

    if (hasSingleInput(fieldType) == true) {
        Element valueElt = doc.createElement(MsgId.INT_INSTANCE_SEARCH_VALUE.getText());
        if (isTyped) {
            valueElt.setTextContent(createXFormsInitialValue(dataType, null, null, null));
        }
        fieldElt.appendChild(valueElt);
    } else {
        // when more than two inputs become supported, test for the number of inputs
        Element valueLoElt = doc.createElement(MsgId.INT_INSTANCE_SEARCH_VALUE_LO.getText());
        if (isTyped) {
            valueLoElt.setTextContent(createXFormsInitialValue(dataType, null, null, null));
        }
        fieldElt.appendChild(valueLoElt);
        Element valueHiElt = doc.createElement(MsgId.INT_INSTANCE_SEARCH_VALUE_HI.getText());
        if (isTyped) {
            valueHiElt.setTextContent(createXFormsInitialValue(dataType, null, null, null));
        }
        fieldElt.appendChild(valueHiElt);
    }

    return fieldElt;
}

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

public void readFromRequest(HttpServletRequest req) {
    Class type = accessor.getType();

    minStringValue = StringUtils.trimToNull(req.getParameter(minInputName));
    try {/*from  ww w .j  av a  2  s  . c o m*/
        minValue = OgnlUtils.convertValue(minStringValue, type);
    } catch (Throwable e) {
        minValue = null;
    }

    maxStringValue = StringUtils.trimToNull(req.getParameter(maxInputName));
    try {
        maxValue = OgnlUtils.convertValue(maxStringValue, type);
    } catch (Throwable e) {
        maxValue = null;
    }

    searchNullValue = (NULL_VALUE.equals(minStringValue) || NULL_VALUE.equals(maxStringValue));
}