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

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

Introduction

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

Prototype

public static String removeEnd(String str, String remove) 

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

Usage

From source file:com.ewcms.content.resource.service.operator.FileOperator.java

/**
 * ?//from   w w w .  j a va  2 s  . c o m
 * 
 * @param uri ?
 * @return
 */
private File getLocalFile(String uri) {
    String root = rootDirPath;
    root = StringUtils.removeStart(root, "/");
    root = StringUtils.removeEnd(root, "/");
    String path = StringUtils.isBlank(root) ? uri : ("/" + root + uri);
    logger.debug("Resource path is {}", path);
    return new File(path);
}

From source file:com.hangum.tadpole.rdb.core.actions.object.rdb.object.ObjectExplorerSelectionAction.java

@Override
public void run(IStructuredSelection selection, UserDBDAO userDB, OBJECT_TYPE actionType) {
    if (selection.isEmpty())
        return;//w  ww.  ja v  a2 s  .  c o  m

    String strObjectName = "";
    Object[] arryObj = selection.toArray();

    // table dao
    if (arryObj[0] instanceof TableDAO) {
        for (int i = 0; i < arryObj.length; i++) {
            TableDAO tcDAO = (TableDAO) arryObj[i];
            strObjectName += tcDAO.getFullName() + ", "; //$NON-NLS-1$
        }
        // column dao
    } else {
        for (int i = 0; i < arryObj.length; i++) {
            TableColumnDAO tcDAO = (TableColumnDAO) arryObj[i];
            strObjectName += tcDAO.getField() + ", "; //$NON-NLS-1$
        }
    }
    strObjectName = StringUtils.removeEnd(strObjectName, ", "); //$NON-NLS-1$

    FindEditorAndWriteQueryUtil.runAtPosition(strObjectName);
}

From source file:com.gemstone.gemfire.management.internal.cli.parser.preprocessor.PreprocessorUtils.java

/**
 * /*w  ww  .  jav  a  2 s  . c  om*/
 * This function will trim the given input string. It will not only remove the
 * spaces and tabs at the end but also compress multiple spaces and tabs to a
 * single space
 * 
 * @param input
 *          The input string on which the trim operation needs to be performed
 * @param retainLineSeparator
 *          whether to retain the line separator.
 * 
 * @return String
 */
public static TrimmedInput trim(final String input, final boolean retainLineSeparator) {
    if (input != null) {
        String inputCopy = input;
        StringBuffer output = new StringBuffer();
        // First remove the trailing white spaces, we do not need those
        inputCopy = StringUtils.stripEnd(inputCopy, null);
        // As this parser is for optionParsing, we also need to remove
        // the trailing optionSpecifiers provided it has previous
        // options. Remove the trailing LONG_OPTION_SPECIFIERs
        // in a loop. It is necessary to check for previous options for
        // the case of non-mandatory arguments.
        // "^(.*)(\\s-+)$" - something that ends with a space followed by a series of hyphens.
        while (Pattern.matches("^(.*)(\\s-+)$", inputCopy)) {
            inputCopy = StringUtils.removeEnd(inputCopy, SyntaxConstants.SHORT_OPTION_SPECIFIER);

            // Again we need to trim the trailing white spaces
            // As we are in a loop
            inputCopy = StringUtils.stripEnd(inputCopy, null);
        }
        // Here we made use of the String class function trim to remove the
        // space and tabs if any at the
        // beginning and the end of the string
        int noOfSpacesRemoved = 0;
        {
            int length = inputCopy.length();
            inputCopy = inputCopy.trim();
            noOfSpacesRemoved += length - inputCopy.length();
        }
        // Now we need to compress the multiple spaces and tabs to single space
        // and tabs but we also need to ignore the white spaces inside the
        // quotes and parentheses

        StringBuffer buffer = new StringBuffer();

        boolean startWhiteSpace = false;
        for (int i = 0; i < inputCopy.length(); i++) {
            char ch = inputCopy.charAt(i);
            buffer.append(ch);
            if (PreprocessorUtils.isWhitespace(ch)) {
                if (PreprocessorUtils.isSyntaxValid(buffer.toString())) {
                    if (startWhiteSpace) {
                        noOfSpacesRemoved++;
                    } else {
                        startWhiteSpace = true;
                        if (ch == '\n') {
                            if (retainLineSeparator) {
                                output.append("\n");
                            }
                        } else {
                            output.append(" ");
                        }
                    }
                    buffer.delete(0, buffer.length());
                } else {
                    output.append(ch);
                }
            } else {
                startWhiteSpace = false;
                output.append(ch);
            }
        }
        return new TrimmedInput(output.toString(), noOfSpacesRemoved);
    } else {
        return null;
    }
}

From source file:com.lingxiang2014.plugin.ftp.FtpController.java

@RequestMapping(value = "/update", method = RequestMethod.POST)
public String update(String host, Integer port, String username, String password, String urlPrefix,
        @RequestParam(defaultValue = "false") Boolean isEnabled, Integer order,
        RedirectAttributes redirectAttributes) {
    PluginConfig pluginConfig = ftpPlugin.getPluginConfig();
    pluginConfig.setAttribute("host", host);
    pluginConfig.setAttribute("port", port.toString());
    pluginConfig.setAttribute("username", username);
    pluginConfig.setAttribute("password", password);
    pluginConfig.setAttribute("urlPrefix", StringUtils.removeEnd(urlPrefix, "/"));
    pluginConfig.setIsEnabled(isEnabled);
    pluginConfig.setOrder(order);/*from w ww  .  j a  v a 2s  .c  o m*/
    pluginConfigService.update(pluginConfig);
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:/admin/storage_plugin/list.jhtml";
}

From source file:com.tlabs.eve.api.EveRequest.java

protected final void putParam(String p, long[] values) {
    if (null == values) {
        this.params.put(p, null);
        return;//from w ww.j a  v  a  2 s  .c o m
    }

    String s = "";
    for (long v : values) {
        s = s + Long.toString(v) + ",";
    }
    this.params.put(p, StringUtils.removeEnd(s, ","));
}

From source file:mitm.common.util.StandardHttpURLBuilder.java

@Override
public void setBaseURL(String baseURL) throws URLBuilderException {
    Check.notNull(baseURL, "baseURL");

    this.baseURL = StringUtils.removeEnd(baseURL.trim(), "/");
}

From source file:com.hangum.tadpole.engine.query.sql.DBSystemSchema.java

/**
 * get view List/* www  .j  a  v  a 2  s  .c  om*/
 * 
 * @param userDB
 * @return
 * @throws TadpoleSQLManagerException
 * @throws SQLException
 */
public static List<TableDAO> getViewList(final UserDBDAO userDB)
        throws TadpoleSQLManagerException, SQLException {
    if (userDB.getDBDefine() == DBDefine.TAJO_DEFAULT || userDB.getDBDefine() == DBDefine.HIVE_DEFAULT
            || userDB.getDBDefine() == DBDefine.HIVE2_DEFAULT)
        return new ArrayList<TableDAO>();

    List<TableDAO> listTblView = new ArrayList<TableDAO>();

    SqlMapClient sqlClient = TadpoleSQLManager.getInstance(userDB);
    if (userDB.getDBDefine() == DBDefine.POSTGRE_DEFAULT) {
        List<TableDAO> listView = sqlClient.queryForList("viewList", userDB.getDb());
        // ?  ?? . ' " ???.
        StringBuffer strViewList = new StringBuffer();
        for (TableDAO td : listView) {
            td.setSysName(SQLUtil.makeIdentifierName(userDB, td.getName()));
            strViewList.append(
                    MakeContentAssistUtil.makeObjectPattern(td.getSchema_name(), td.getSysName(), "View")); //$NON-NLS-1$
        }
        userDB.setTableListSeparator(
                StringUtils.removeEnd(strViewList.toString(), MakeContentAssistUtil._PRE_GROUP)); //$NON-NLS-1$

        return listView;
    } else {
        List<String> listView = sqlClient.queryForList("viewList", userDB.getDb());
        // 1. ?  ?? . ' " ???.
        // 2. keyword  .
        StringBuffer strViewList = new StringBuffer();
        for (String strView : listView) {
            TableDAO tblDao = new TableDAO();
            tblDao.setName(strView);
            tblDao.setSysName(SQLUtil.makeIdentifierName(userDB, strView));

            listTblView.add(tblDao);

            strViewList.append(MakeContentAssistUtil.makeObjectPattern(tblDao.getSchema_name(),
                    tblDao.getSysName(), "View")); //$NON-NLS-1$
        }
        userDB.setViewListSeparator(
                StringUtils.removeEnd(strViewList.toString(), MakeContentAssistUtil._PRE_GROUP)); //$NON-NLS-1$

        return listTblView;
    }
}

From source file:ips1ap101.lib.core.web.app.EJBL.java

public static Object lookup(Class<?> interfaz) {
    Bitacora.trace(EJBL.class, "lookup", interfaz);
    String key = EAC.JNDI_EJB_LOOKUP_PATTERN;
    String pattern = EA.getString(key);
    String base = interfaz.getSimpleName();
    String bean = StringUtils.removeEnd(base, "Base") + "Bean";
    String jndi = MessageFormat.format(pattern, bean, interfaz.getName());
    Bitacora.trace(key + "=" + pattern);
    Bitacora.trace(key + "=" + jndi);
    try {//from  ww w  . j  a v a 2s . com
        Object facade = InitialContext.doLookup(jndi);
        boolean assignable = facade != null && interfaz.isAssignableFrom(facade.getClass());
        Bitacora.trace(bean + "=" + facade);
        Bitacora.trace(base + "=" + assignable);
        return facade;
    } catch (NamingException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:net.shopxx.plugin.ftpStorage.FtpStorageController.java

@RequestMapping(value = "/update", method = RequestMethod.POST)
public String update(String host, Integer port, String username, String password, String urlPrefix,
        @RequestParam(defaultValue = "false") Boolean isEnabled, Integer order,
        RedirectAttributes redirectAttributes) {
    PluginConfig pluginConfig = ftpStoragePlugin.getPluginConfig();
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("host", host);
    attributes.put("port", String.valueOf(port));
    attributes.put("username", username);
    attributes.put("password", password);
    attributes.put("urlPrefix", StringUtils.removeEnd(urlPrefix, "/"));
    pluginConfig.setAttributes(attributes);
    pluginConfig.setIsEnabled(isEnabled);
    pluginConfig.setOrder(order);/*from   ww  w.ja  va 2  s. c o  m*/
    pluginConfigService.update(pluginConfig);
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:/admin/storage_plugin/list.jhtml";
}

From source file:net.shopxx.plugin.ossStorage.OssStorageController.java

@RequestMapping(value = "/update", method = RequestMethod.POST)
public String update(String endpoint, String accessId, String accessKey, String bucketName, String urlPrefix,
        @RequestParam(defaultValue = "false") Boolean isEnabled, Integer order,
        RedirectAttributes redirectAttributes) {
    PluginConfig pluginConfig = ossStoragePlugin.getPluginConfig();
    Map<String, String> attributes = new HashMap<String, String>();
    attributes.put("endpoint", endpoint);
    attributes.put("accessId", accessId);
    attributes.put("accessKey", accessKey);
    attributes.put("bucketName", bucketName);
    attributes.put("urlPrefix", StringUtils.removeEnd(urlPrefix, "/"));
    pluginConfig.setAttributes(attributes);
    pluginConfig.setIsEnabled(isEnabled);
    pluginConfig.setOrder(order);//from w ww .  j  a v a  2s. c o  m
    pluginConfigService.update(pluginConfig);
    addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
    return "redirect:/admin/storage_plugin/list.jhtml";
}