Example usage for org.apache.commons.lang StringUtils trim

List of usage examples for org.apache.commons.lang StringUtils trim

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils trim.

Prototype

public static String trim(String str) 

Source Link

Document

Removes control characters (char <= 32) from both ends of this String, handling null by returning null.

Usage

From source file:com.clt.systemmanger.controller.UserAction.java

/**
 * @Description: ??/*  w w w  . j a  va2 s.co m*/
 * @param resp
 *            void ??
 * @author hjx
 * @create_date 2015410 ?3:33:44
 */
@ApiOperation(value = "??", notes = "????????????? ??", position = 5)
@RequestMapping(value = "/passwordReset", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> passwordReset(
        @ApiParam(value = "??", required = true) @RequestParam("userId") String userId,
        @ApiParam(value = "??", required = true) @RequestParam("phoneNo") String phoneNo,
        @ApiParam(value = "?", required = true) @RequestParam("passwrod") String passwrod,
        @ApiParam(value = "??", required = true) @RequestParam("code") String code,

        HttpServletResponse resp) {
    // TUser user = userService.getByid( userId );

    TUser user;
    try {
        user = userService.getByAccount(userId);
        if (null == user) {

            return AjaxUtil.getMap(false, "????");
        }
    } catch (Exception e1) {
        e1.printStackTrace();
        return AjaxUtil.getMapByException(e1);
    }
    String phone = user.getVcPhone();
    // ????
    if (phoneNo.equals(phone)) {
        try {
            // ???
            // ????????
            String codeStr = userCodeService.getCodeByTel(phone);
            if (StringUtils.isEmpty(codeStr)) {

                return AjaxUtil.getMap(false, "??????");
            }

            // ?????
            if (!StringUtils.trim(code).equals(codeStr)) {
                return AjaxUtil.getMap(false, "???");
            }
            // ??
            org.springframework.security.authentication.encoding.Md5PasswordEncoder t = new Md5PasswordEncoder();
            String tt = t.encodePassword(passwrod, user.getVcAccount());
            user.setVcPassword(tt);
            userService.updateUser(user);
            return AjaxUtil.getMap(true, "???");
        } catch (Exception e) {

            e.printStackTrace();
            return AjaxUtil.getMap(false, "??");
        }
    } else {
        return AjaxUtil.getMap(false, "??????");
    }

}

From source file:io.ecarf.core.utils.LogParser.java

/**
 * return the value in minutes// ww w. j  a va2 s  .  c o m
 * @param timer
 * @return
 */
private double parseStopwatchTime(String timer, boolean ignoreMillis) {

    String[] parts = timer.split(" ");

    TimeUnit unit = UNITS.get(StringUtils.trim(parts[1]));

    double value = Double.parseDouble(StringUtils.trim(parts[0]));

    switch (unit) {
    case DAYS:
        value = value * 24 * 60;
        break;

    case HOURS:
        value = value * 60;
        break;

    case MICROSECONDS:
        value = 0;
        break;

    case MILLISECONDS:

        if (ignoreMillis) {
            value = 0;

        } else {
            value = value / (1000 * 60);
        }

        break;

    case MINUTES:

        break;

    case NANOSECONDS:
        value = 0;
        break;

    case SECONDS:
        value = value / 60;
        break;
    default:
        throw new IllegalArgumentException("Not found" + unit);

    }

    return value;

}

From source file:com.edgenius.wiki.service.impl.ThemeServiceImpl.java

/**
 * Get theme by given space name.//from  w w w  .  jav a2 s.co m
 */
public Theme getSpaceTheme(Space space) {
    String name;
    name = getThemeName(space);

    Theme theme = null;
    Element ele = themeCache.get(name);
    if (ele == null) {
        //Load the default value of this theme from file system
        theme = getSystemDefaultTheme(space.getSetting().getTheme());

        //Then, merge PageTheme from space default setting as well.
        SpaceSetting setting = space.getSetting();
        if (setting.isCustomizedTheme() && setting.getPageThemes() != null
                && setting.getPageThemes().size() > 0) {

            List<PageTheme> spaceLevelPageThemes = theme.getPageThemes();
            for (PageTheme pt : setting.getPageThemes()) {
                if (PageTheme.SCOPE_DEFAULT.equalsIgnoreCase(StringUtils.trim(pt.getScope()))
                        || PageTheme.SCOPE_HOME.equalsIgnoreCase(StringUtils.trim(pt.getScope()))) {
                    //replace
                    spaceLevelPageThemes.remove(pt); // PageTheme only compare scope, so it is OK to do remove here. 
                    spaceLevelPageThemes.add(pt);
                } else {
                    //add
                    spaceLevelPageThemes.add(pt);
                }
            }
            ele = new Element(WikiConstants.CONST_NONSPACE_RESOURCE_PREFIX + space.getUnixName(), theme);
            themeCache.put(ele);
        }
    } else {
        theme = (Theme) ele.getObjectValue();
    }

    //need return clonable object, so that any change on the return object won't impact original value. 
    return (Theme) theme.clone();
}

From source file:ch.entwine.weblounge.contentrepository.impl.index.elasticsearch.ElasticSearchSearchQuery.java

/**
 * Stores <code>fieldValue</code> as a negative search term on the
 * <code>fieldName</code> field.
 * //w w w .j a va2 s. c  o m
 * @param fieldName
 *          the field name
 * @param fieldValue
 *          the field value
 * @param clean
 *          <code>true</code> to escape solr special characters in the field
 *          value
 */
protected void andNot(String fieldName, Object fieldValue, boolean clean) {

    // Fix the field name, just in case
    fieldName = StringUtils.trim(fieldName);

    // Make sure the data structures are set up accordingly
    if (negativeSearchTerms == null)
        negativeSearchTerms = new HashMap<String, Set<Object>>();
    Set<Object> termValues = negativeSearchTerms.get(fieldName);
    if (termValues == null) {
        termValues = new HashSet<Object>();
        negativeSearchTerms.put(fieldName, termValues);
    }

    // Add the term
    termValues.add(fieldValue);
}

From source file:hydrograph.ui.dataviewer.filter.FilterHelper.java

/**
 * Gets the save button listener./*from  w w  w.  j a  v  a 2 s  .c  om*/
 * 
 * @param conditionsList
 *            the conditions list
 * @param fieldsAndTypes
 *            the fields and types
 * @param groupSelectionMap
 *            the group selection map
 * @param dataset
 *            the dataset
 * @param originalFilterConditions
 *            the original filter conditions
 * @param retainRemoteFilter
 *            the retain remote filter
 * @param retainLocalFilter
 *            the retain local filter
 * @return the save button listener
 */
public SelectionListener getSaveButtonListener(final List<Condition> conditionsList,
        final Map<String, String> fieldsAndTypes, final Map<Integer, List<List<Integer>>> groupSelectionMap,
        final String dataset, final FilterConditions originalFilterConditions,
        final RetainFilter retainRemoteFilter, final RetainFilter retainLocalFilter) {
    SelectionListener listener = new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {

            StringBuffer buffer = getCondition(conditionsList, fieldsAndTypes, groupSelectionMap, false);

            logger.debug("Query String : " + buffer);
            if (dataset.equalsIgnoreCase(Messages.DOWNLOADED)) {
                localCondition = buffer.toString();
                showLocalFilteredData(StringUtils.trim(buffer.toString()));
                debugDataViewer.setLocalCondition(localCondition);
            } else {
                if (!retainLocalFilter.getRetainFilter()) {
                    if (!debugDataViewer.getLocalCondition().equals("")) {
                        MessageBox messageBox = new MessageBox(new Shell(),
                                SWT.ICON_WARNING | SWT.OK | SWT.CANCEL);
                        messageBox.setText("Warning");
                        messageBox.setMessage(Messages.NOT_RETAINED);
                        int response = messageBox.open();
                        if (response != SWT.OK) {
                            return;
                        }
                    }
                } else {
                    if (!debugDataViewer.getLocalCondition().equals("")) {
                        MessageBox messageBox = new MessageBox(new Shell(),
                                SWT.ICON_WARNING | SWT.OK | SWT.CANCEL);
                        messageBox.setText("Warning");
                        messageBox.setMessage(Messages.RETAINED);
                        int response = messageBox.open();
                        if (response != SWT.OK) {
                            return;
                        }
                    } else {
                        retainLocalFilter.setRetainFilter(false);
                    }
                }
                if (!retainLocalFilter.getRetainFilter()) {
                    originalFilterConditions.setLocalCondition("");
                    originalFilterConditions.getLocalConditions().clear();
                    filterConditionsDialog.getLocalConditionsList().clear();
                    debugDataViewer.setLocalCondition("");
                    localCondition = "";
                }
                remoteCondition = buffer.toString();
                showRemoteFilteredData(StringUtils.trim(buffer.toString()));
                debugDataViewer.setRemoteCondition(remoteCondition);
            }
            filterConditionsDialog.close();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    };
    return listener;
}

From source file:edu.mayo.cts2.framework.plugin.service.bioportal.identity.IdentityConverter.java

/**
 * Gets the urn.//w w  w  .  ja  va2 s  .  c o m
 *
 * @param xml the xml
 * @return the urn
 */
public String getUrn(String xml) {
    try {
        Node node = TransformUtils.getNamedChildWithPath(BioportalRestUtils.getDocument(xml), ONTOLOGY_BEAN);

        String urn = TransformUtils.getNamedChildText(node, URN);

        if (StringUtils.isBlank(urn)) {
            urn = TransformUtils.getNamedChildText(node, CODING_SCHEME);
        }

        urn = StringUtils.trim(urn);

        return urn;
    } catch (Exception e) {
        throw new Cts2RuntimeException(e);
    }
}

From source file:com.greenline.guahao.web.module.home.controllers.my.reservation.ReservationProcess.java

/**
 * ????/*from  www. j av  a 2  s. c  o  m*/
 * 
 * @param json
 * @param jsonMap
 * @param patient
 * @param name
 * @param msg
 */
private void checkPatientInfo(OperationJsonObject json, Map<String, String> jsonMap,
        final PatientInfoDO patient, final String name, final String msg) {
    if (null != patient && null != patient.getPatient_birthday()) {
        if (null != patient.getRelationship()) {
            // ??
            if (!RegexUtil.isIdCard(StringUtils.trim(patient.getPatient_cert_no()))) {
                json.setHasError(Boolean.TRUE);
                jsonMap.put(name + "patient_cert_no", msg + ReservationMsgConstants.ERR_MSGCERT_NO);
                json.setMessage(msg + ReservationMsgConstants.ERR_MSGCERT_NO);
            }
            // ?
            if (!json.getHasError() && !RegexUtil.isMobile(StringUtils.trim(patient.getPatient_mobile()))) {
                json.setHasError(Boolean.TRUE);
                jsonMap.put(name + "patient_mobile", msg + ReservationMsgConstants.ERR_MSG_MOBILE);
                json.setMessage(msg + ReservationMsgConstants.ERR_MSG_MOBILE);
            }
        }
        if (!json.getHasError()) {
            if (DateUtil.getDatebyString(patient.getPatient_birthday()).after(new Date())) {
                json.setHasError(Boolean.TRUE);
                json.setMessage(msg + ReservationMsgConstants.BIRDAYISERROR);
            }
        }
    }
}

From source file:com.openteach.diamond.service.DiamondServiceFactory.java

/**
 * /*from   ww  w.j a va2s  .co m*/
 * @param properties
 * @param repositoryClient
 * @return
 */
private static ServiceRouter newServiceRouter(Properties properties, AddressingService addressingService,
        RouterPlugin plugin) {
    String factoryClassName = StringUtils.trim(properties.getProperty(ROUTER_FACTORY));
    if (StringUtils.isBlank(factoryClassName)) {
        throw new IllegalArgumentException(String.format("Please set %s", ROUTER_FACTORY));
    }
    try {
        Class<?> clazz = Class.forName(factoryClassName);
        ServiceRouterFactory factory = (ServiceRouterFactory) clazz.newInstance();
        return factory.newServiceRouter(addressingService, plugin);
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException("OOPS, new router failed", e);
    } catch (InstantiationException e) {
        throw new IllegalArgumentException("OOPS, new router failed", e);
    } catch (IllegalAccessException e) {
        throw new IllegalArgumentException("OOPS, new router failed", e);
    }
}

From source file:gov.nih.nci.caarray.magetab.sdrf.SdrfDocument.java

private void handleLine(List<String> values) {
    currentLine = values;/*from ww w  .ja  v a2s . co m*/
    if (!isComment(values)) {
        for (int i = 0; i < values.size(); i++) {
            currentColumnNumber = i + 1;
            try {
                String value = NCICommonsUtils.performXSSFilter(StringUtils.trim(values.get(i)), true, true);
                handleValue(columns.getColumns().get(i), value);
            } catch (Exception e) {
                StringWriter sw = new StringWriter();
                e.printStackTrace(new PrintWriter(sw));
                addError(e.toString() + ": " + sw.toString());
            }
        }
        handleDataFileToDesignMap(currentArrayDataFiles, currentArrayDesign);
        currentNode = null;
        currentHybridization = null;
        currentScan = null;
        currentNormalization = null;
        currentFile = null;
        currentCommentable = null;
        currentArrayDesign = null;
        currentArrayDataFiles.clear();
        lineNodeCache.clear();
    }
}