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:de.iteratec.iteraplan.businesslogic.exchange.timeseriesExcel.importer.TimeseriesExcelImporter.java

private AttributeType getAttributeTypeFromSheet(Sheet timeseriesSheet) {
    CellReference ref = ExcelUtils.getFullCellReference(timeseriesSheet, AT_CELL_REF);

    Row row = timeseriesSheet.getRow(ref.getRow());
    if (row == null) {
        logError(ref, "No Attribute Type name found.");
        return null;
    }/*www  .j  a  v  a 2 s.  c  o m*/

    Cell atCell = row.getCell(ref.getCol());
    if (ExcelUtils.isEmptyCell(atCell)) {
        logError(ref, "No Attribute Type name found.");
        return null;
    }

    String attributeName = StringUtils.trim(ExcelUtils.getStringCellValue(atCell));
    AttributeType at = atService.getAttributeTypeByName(attributeName);

    if (at == null) {
        logError(ref, "No attribute type with name \"{0}\" found.", attributeName);
        return null;
    }

    if (!(at instanceof TimeseriesType && ((TimeseriesType) at).isTimeseries())) {
        logError(ref, "Attribute \"{0}\" is not a timeseries attribute.", at);
    }
    return at;
}

From source file:hydrograph.ui.propertywindow.widgets.customwidgets.AbstractWidget.java

public void showHideErrorSymbol(boolean isWidgetValid) {
    if (!isWidgetValid) {
        for (CTabItem item : getTabFolder().getItems()) {
            if (StringUtils.equalsIgnoreCase(StringUtils.trim(item.getText()), getPropertyName())) {
                item.setImage(ImagePathConstant.COMPONENT_ERROR_ICON.getImageFromRegistry());
            }//  w ww . j  a  v a  2  s.co m
        }
    } else {
        for (CTabItem item : getTabFolder().getItems()) {
            if (StringUtils.equalsIgnoreCase(StringUtils.trim(item.getText()), getPropertyName())) {
                item.setImage(null);
            }
        }
    }
}

From source file:com.microsoft.alm.plugin.idea.git.ui.pullrequest.CreatePullRequestModel.java

public void setDescription(final String description) {
    synchronized (this) {
        this.description = StringUtils.trim(description);
    }/*from   w  ww .j a  v a 2 s.c  o  m*/
    setChangedAndNotify(PROP_DESCRIPTION);
}

From source file:edu.monash.merc.system.remote.FTPFileGetter.java

/**
 * Issue the FTP MDTM command (not supported by all servers to retrieve the last modification time of a file.
 * The modification string should be in the ISO 3077 form "YYYYMMDDhhmmss(.xxx)?".
 * The timestamp represented should also be in GMT, but not all FTP servers honour this.
 *
 * @param remoteFile The file path to query.
 * @return A string representing the last file modification time in YYYYMMDDhhmmss format.
 *///from w ww .ja va2  s .c o m
public String getLastModifiedTime(String remoteFile) {
    try {
        String replyCode = getModificationTime(remoteFile);
        String tempTime = StringUtils.substringAfter(replyCode, String.valueOf(FTPReply.FILE_STATUS));
        return StringUtils.trim(tempTime);
    } catch (Exception ex) {
        throw new DMFTPException(ex);
    }
}

From source file:net.poemerchant.scraper.ShopScraper.java

public List<Buyout> scrapeItemBuyouts(int noOfItems) {
    buyouts = new ArrayList<Buyout>(noOfItems);
    for (int i = 0; i < noOfItems; i++) {
        Buyout buyout = Buyout.NONE;/*from w w w.  j  a v  a 2s  .  c  om*/
        Node itemElem = doc.select("#item-fragment-" + i).first();
        Element itemElemNext = doc.select("#item-fragment-" + (i + 1)).first();
        if (itemElem != null) {
            while (!itemElem.equals(itemElemNext)) {
                itemElem = itemElem.nextSibling();

                if (itemElem == null) {
                    // case where there is no b/o set and we've reached the end of a spoiler
                    break;
                }

                if (Element.class.isAssignableFrom(itemElem.getClass()))
                    continue;
                String boRaw = StringUtils.trim(itemElem.toString());
                String[] split = StringUtils.split(boRaw);
                if (split.length == 3) {
                    BuyoutMode buyoutMode = BuyoutMode.parse(split[0]);
                    if (buyoutMode != BuyoutMode.unknown) {
                        buyout = new Buyout(boRaw);
                        break;
                    }
                }
            }
        } else {
            logger.severe(
                    "Actual item in the OP was not found. Buyout will be defaulted to NONE. Item index is "
                            + i);
        }
        buyouts.add(buyout);
    }

    return buyouts;
}

From source file:net.sf.firemox.database.Proxy.java

/**
 * @param cardModel//  w ww. j a  va2s  . com
 *          the card model.
 * @param constraints
 *          the constraints.
 * @return the string read from one of the streams of this proxy.
 * @throws IOException
 *           If some other I/O error occurs
 */
private String getStringFromStream(CardModel cardModel, Map<String, String> constraints) throws IOException {

    // Determine the best stream configuration
    int highestScore = -1;
    UrlTokenizer stream = null;
    for (int i = 0; i < streams.size(); i++) {
        int score = streams.get(i).getUrlScore(constraints);
        if (score > highestScore) {
            highestScore = score;
            stream = streams.get(i);
        }
    }

    // No stream available for this proxy + card
    if (stream == null) {
        return null;
    }

    // read stream from the built URL
    final URL mainPage = new URL(streamBaseUrl + stream.getUrl(cardModel, constraints, this));
    final StringBuilder res = new StringBuilder(2000);
    final InputStream proxyStream;
    try {
        proxyStream = MToolKit.getHttpConnection(mainPage).getInputStream();
    } catch (Throwable e) {
        // Error during the IP get
        throw new IOException(LanguageManager.getString("error.stream.null"));
    }
    if (proxyStream == null) {
        // Error during the IP get
        throw new IOException(LanguageManager.getString("error.stream.null"));
    }
    final BufferedReader br = new BufferedReader(new InputStreamReader(proxyStream, encoding));
    String line = null;
    while ((line = br.readLine()) != null) {
        res.append(StringUtils.trim(line));
    }
    return res.toString();
}

From source file:com.openteach.diamond.rpc.impl.DefaultRPCProtocolProvider.java

/**
 * //from   w w w . j a va2  s  .c  om
 * @param protocol
 * @return
 */
private RPCProtocol4Client loadRPCProtocol4Client(String protocol) {
    try {
        String factoryClassName = StringUtils
                .trim(properties.getProperty(String.format("%s.client.factory", protocol)));
        if (StringUtils.isBlank(factoryClassName)) {
            return null;
        }
        Class clazz = Class.forName(factoryClassName);
        if (!RPCProtocol4ClientFactory.class.isAssignableFrom(clazz)) {
            throw new IllegalArgumentException(
                    String.format("RPC protocol 4 client factory:%s must implements %s", factoryClassName,
                            RPCProtocol4ClientFactory.class.getName()));
        }
        RPCProtocol4ClientFactory factory = (RPCProtocol4ClientFactory) clazz.newInstance();
        return factory.newProtocol();
    } catch (ClassNotFoundException e) {
        throw new IllegalArgumentException(e);
    } catch (InstantiationException e) {
        throw new IllegalArgumentException(e);
    } catch (IllegalAccessException e) {
        throw new IllegalArgumentException(e);
    }
}

From source file:$.MessageLogParser.java

@Nullable
    private String getRequestId(String line) {
        // 2013-05-23 20:22:36,754 [MACHINE_IS_UNDEFINED, ajp-bio-8009-exec-19, /esb/ws/account/v1, 10.10.0.95:72cab819:13ecdbd371c:-7eff, ] DEBUG

        String logHeader = StringUtils.substringBetween(line, "[", "]");
        if (logHeader == null) {
            // no match - the line doesn't contain []
            return null;
        }//  www .j  av a 2s .com
        String[] headerParts = StringUtils.split(logHeader, ",");
        String requestId = StringUtils.trim(headerParts[3]);

        // note: if request starts from scheduled job, then there is request ID information
        // 2013-05-27 16:37:25,633 [MACHINE_IS_UNDEFINED, DefaultQuartzScheduler-camelContext_Worker-8, , , ]
        //  WARN  c.c.c.i.c.a.d.RepairMessageServiceDbImpl${symbol_dollar}2 - The message (msg_id = 372, correlationId = ...

        return StringUtils.trimToNull(requestId);
    }

From source file:com.adobe.acs.commons.contentfinder.querybuilder.impl.viewhandler.GQLToQueryBuilderConverter.java

/**
 * Returns a single value for a query parameter key
 *
 * @param request//from   www.  j  a  v a2s .  c o  m
 * @param key
 * @return
 */
public static String get(SlingHttpServletRequest request, String key) {
    return StringUtils.trim(request.getRequestParameter(key).toString());
}

From source file:com.hangum.tadpole.manager.core.dialogs.api.UserAPIServiceDialog.java

/**
 * initialize ui/*  w w w  .ja  va2 s  .  c om*/
 * 
 * @param strArgument
 */
private void initData(String strArgument) {

    try {
        String strAPIKEY = textAPIKey.getText();
        if (strAPIKEY.equals("")) { //$NON-NLS-1$
            MessageDialog.openWarning(getShell(), Messages.get().Warning,
                    Messages.get().UserAPIServiceDialog_10);
            textAPIKey.setFocus();

            return;
        }

        Timestamp timstampStart = new Timestamp(System.currentTimeMillis());
        UserDBDAO userDB = null;
        UserDBResourceDAO userDBResourceDao = TadpoleSystem_UserDBResource.findAPIKey(strAPIKEY);
        if (userDBResourceDao == null) {
            MessageDialog.openInformation(getShell(), Messages.get().Confirm,
                    Messages.get().UserAPIServiceDialog_12);
        } else {

            String strSQL = TadpoleSystem_UserDBResource.getResourceData(userDBResourceDao);
            if (logger.isDebugEnabled())
                logger.debug(userDBResourceDao.getName() + ", " + strSQL); //$NON-NLS-1$

            // find db
            userDB = TadpoleSystem_UserDBQuery.getUserDBInstance(userDBResourceDao.getDb_seq());

            String strReturnResult = ""; //$NON-NLS-1$

            String strSQLs = RESTfulAPIUtils.makeTemplateTOSQL("APIServiceDialog", strSQL, strArgument); //$NON-NLS-1$
            // ? ? .
            for (String strTmpSQL : strSQLs.split(PublicTadpoleDefine.SQL_DELIMITER)) {
                if (StringUtils.trim(strTmpSQL).equals(""))
                    continue;
                NamedParameterDAO dao = NamedParameterUtil.parseParameterUtils(userDB, strTmpSQL, strArgument);
                if (QueryUtils.RESULT_TYPE.JSON.name().equalsIgnoreCase(comboResultType.getText())) {
                    strReturnResult += getSelect(userDB, dao.getStrSQL(), dao.getListParam()) + ","; //$NON-NLS-1$
                } else {
                    strReturnResult += getSelect(userDB, dao.getStrSQL(), dao.getListParam());
                }
            }

            if (QueryUtils.RESULT_TYPE.JSON.name().equalsIgnoreCase(comboResultType.getText())) {
                strReturnResult = "[" + StringUtils.removeEnd(strReturnResult, ",") + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            }

            textResult.setText(strReturnResult);
        }

    } catch (Exception e) {
        logger.error("api exception", e); //$NON-NLS-1$

        MessageDialog.openError(getShell(), Messages.get().Error,
                Messages.get().APIServiceDialog_11 + "\n" + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
    }
}