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.antsdb.saltedfish.sql.mysql.InstructionGenerator.java

@SuppressWarnings("unchecked")
static public Generator<ParseTree> getGenerator(ParseTree ctx) throws OrcaException {
    Class<?> klass = ctx.getClass();
    Generator<ParseTree> generator = _generatorByName.get(klass);
    if (generator == null) {
        String key = StringUtils.removeStart(klass.getSimpleName(), "MysqlParser$");
        key = StringUtils.removeEnd(key, "Context");
        key += "Generator";
        try {//from  w  w w.  ja  va2 s  .co m
            key = InstructionGenerator.class.getPackage().getName() + "." + key;
            Class<?> generatorClass = Class.forName(key);
            generator = (Generator<ParseTree>) generatorClass.newInstance();
            _generatorByName.put(klass, generator);
        } catch (Exception x) {
            throw new OrcaException("instruction geneartor is not found: " + key, x);
        }
    }
    return generator;
}

From source file:com.gzj.tulip.load.vfs.FileSystemManager.java

public synchronized FileObject resolveFile(URL url) throws IOException {
    try {/*from  www.  j  a  va  2s  .c o  m*/
        if (traceEnabled) {
            logger.trace("[fs] resolveFile ... by url '" + url + "'");
        }
        String urlString = url.toString();
        FileObject object = cached.get(urlString);

        if (object != null) {
            if (traceEnabled) {
                logger.trace("[fs] found cached file for url '" + urlString + "'");
            }
            return object;
        }
        if (ResourceUtils.isJarURL(url)) {
            if (!urlString.endsWith("/")) {
                object = resolveFile(urlString + "/");
            }
            if (object == null || !object.exists()) {
                object = new JarFileObject(this, url);
                if (traceEnabled) {
                    logger.trace("[fs] create jarFileObject for '" + urlString + "'");
                }
            }
        } else {
            File file = ResourceUtils.getFile(url);
            if (file.isDirectory()) {
                if (!urlString.endsWith("/")) {
                    urlString = urlString + "/";
                    url = new URL(urlString);
                }
            } else if (file.isFile()) {
                if (urlString.endsWith("/")) {
                    urlString = StringUtils.removeEnd(urlString, "/");
                    url = new URL(urlString);
                }
            }
            object = new SimpleFileObject(this, url);
            if (traceEnabled) {
                logger.trace("[fs] create simpleFileObject for '" + urlString + "'");
            }
        }
        if (object.exists()) {
            cached.put(urlString, object);
        }
        return object;
    } catch (IOException e) {
        logger.error(e.getMessage() + ":" + url, e);
        throw e;
    }
}

From source file:info.magnolia.cms.beans.config.URI2RepositoryMapping.java

/**
 * Create a node handle based on an uri.
 *//*from   w w w . j  a  v  a 2s  .  c  o m*/
public String getHandle(String uri) {
    String handle;
    handle = StringUtils.removeStart(uri, this.URIPrefix);
    if (StringUtils.isNotEmpty(this.handlePrefix)) {
        StringUtils.removeStart(handle, "/");
        handle = this.handlePrefix + "/" + handle;
    }
    //remove extension (ignore . anywhere else in the uri)
    String fileName = StringUtils.substringAfterLast(handle, "/");
    String extension = StringUtils.substringAfterLast(fileName, ".");
    handle = StringUtils.removeEnd(handle, "." + extension);
    handle = cleanHandle(handle);

    try {
        final Session session = MgnlContext.getJCRSession(this.repository);
        if (!session.itemExists(handle)) {
            String maybeHandle = (this.handlePrefix.endsWith("/") ? "/" : "")
                    + StringUtils.removeStart(handle, this.handlePrefix);
            // prefix might have been prepended incorrectly. Second part of the condition is there to match links to binary nodes
            if (session.itemExists(maybeHandle) || (maybeHandle.lastIndexOf("/") > 0
                    && session.itemExists(StringUtils.substringBeforeLast(maybeHandle, "/")))) {
                return maybeHandle;
            }
        }
    } catch (RepositoryException e) {
        //Log the exception and return handle
        log.debug(e.getMessage(), e);
    }
    return handle;
}

From source file:com.fortify.processrunner.RunProcessRunnerFromCLI.java

/**
 * Get the default log file name. If the current jar name that we are running 
 * from is known, the log file will have the same name as the jar name but 
 * with '.log' extension. If the jar name is not known, the default log file 
 * name will be 'processrunner.log'./*www.  j  ava  2 s. co m*/
 *  
 * @return Default log file name
 */
protected static final String getDefaultLogFileName() {
    String result = "processrunner.log";
    String jarName = getJarName();
    if (jarName != null) {
        result = StringUtils.removeEnd(jarName, ".jar") + ".log";
    }
    return result;
}

From source file:hr.fer.zemris.vhdllab.platform.gui.dialog.AbstractOptionPaneDialogManager.java

@Override
protected String alterSimpleClassName(String simpleClassName) {
    return StringUtils.removeEnd(simpleClassName, DIALOG_MANAGER_SUFFIX);
}

From source file:de.iteratec.iteraplan.presentation.dialog.GuiController.java

protected void init(ModelMap model, HttpSession session, HttpServletRequest request) {
    model.addAttribute("componentMode", "READ");

    // Store application URL in model map
    String applicationURL = URLBuilder.getApplicationURL(request);
    if (applicationURL != null) {
        model.addAttribute(SessionConstants.APPLICATION_URL_LABEL, StringUtils.removeEnd(applicationURL, "/"));
    }//from   w w  w . j  a va2 s.co  m
}

From source file:info.magnolia.cms.util.ExceptionUtil.java

/**
 * Translates an exception class name to an english-readable idiom. Example: an instance of AccessDeniedException will be returned as "Access denied".
 *//*from w w w. jav a  2  s. co  m*/
public static String classNameToWords(Exception e) {
    return StringUtils.capitalize(StringUtils.removeEnd(e.getClass().getSimpleName(), "Exception")
            .replaceAll("[A-Z]", " $0").toLowerCase().trim());
}

From source file:edu.cornell.med.icb.goby.alignments.AbstractAlignmentReader.java

/**
 * Return the basename corresponding to the input alignment filename.  Note
 * that if the filename does have the extension known to be a compact alignment
 * the returned value is the original filename
 *
 * @param filename The name of the file to get the basename for
 * @return basename for the alignment file
 *///from w w w .  j  av  a  2s. com
public static String getBasename(final String filename) {
    for (final String ext : FileExtensionHelper.COMPACT_ALIGNMENT_FILE_EXTS) {
        if (StringUtils.endsWith(filename, ext)) {
            return StringUtils.removeEnd(filename, ext);
        }
    }

    // perhaps the input was a basename already.
    return filename;
}

From source file:com.hangum.tadpole.rdb.core.dialog.export.sqltoapplication.application.SQLToAxisjConvert.java

/**
 * sql to string//www  . j a v a  2 s  . co  m
 * 
 * @param userDB
 * @param name
 * @param sql
 * @return
 */
public static String sqlToString(UserDBDAO userDB, String sql, Map options,
        List<AxisjHeaderDAO> listAxisjHeader) {
    String retHtml = "";
    try {
        String STR_TEMPLATE = IOUtils.toString(SQLToAxisjConvert.class.getResource("axis.js.template"));

        QueryExecuteResultDTO queryResult = QueryUtils.executeQuery(userDB, sql, 0, 4);
        Map<Integer, String> columnLabel = queryResult.getColumnLabelName();

        String strHead = "";
        StringBuffer sbGroup = new StringBuffer();
        for (AxisjHeaderDAO dao : listAxisjHeader) {
            sbGroup.append(String.format(GROUP_TEMPLATE, dao.getKey(), dao.getLabel(), dao.getWidth(),
                    AxisjConsts.alignValue[dao.getAlign()], AxisjConsts.sortValue[dao.getSort()],
                    dao.isColHeadTool() ? "true" : "false", dao.getFormatter(), dao.getTooltip(),
                    dao.getDisabled(), dao.getChecked()));
        }
        strHead = StringUtils.removeEnd(sbGroup.toString(), ",");
        // 

        String strBody = "";
        StringBuffer sbData = new StringBuffer();
        TadpoleResultSet tdbResult = queryResult.getDataList();
        for (Map<Integer, Object> resultRow : tdbResult.getData()) {
            sbData.setLength(0);
            for (int i = 0; i < columnLabel.size(); i++) {
                String strColumnLabel = columnLabel.get(i);
                String strColumnValue = "" + resultRow.get(i);
                strColumnValue = StringUtils.replaceEach(strColumnValue,
                        new String[] { ">", "<", "\"", "\r", "\n" },
                        new String[] { "&gt;", "&lt;", "\\\"", "", "\\n" });
                sbData.append(String.format(GROUP_DATA_TEMPLATE, strColumnLabel, "\"" + strColumnValue + "\""));
            }

            strBody += PREFIX_TAB + "{" + StringUtils.removeEnd(sbData.toString(), ",") + "},";
        }
        strBody = StringUtils.removeEnd(strBody, ",");

        retHtml = StringUtils.replaceEach(STR_TEMPLATE, new String[] { "_TDB_TEMPLATE_TITLE_" },
                new String[] { (String) options.get("name") });
        retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_THEME_" },
                new String[] { (String) options.get("theme") });
        retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_FIXEDCOL_" },
                new String[] { (String) options.get("fixedColSeq") });
        retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_FITTOWIDTH_" },
                new String[] { (String) options.get("fitToWidth") });
        retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_HEADALIGN_" },
                new String[] { (String) options.get("colHeadAlign") });
        retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_MERGECELL_" },
                new String[] { (String) options.get("mergeCells") });
        retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_HEIGHT_" },
                new String[] { (String) options.get("height") });
        retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_SORT_" },
                new String[] { (String) options.get("sort") });
        retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_HEADTOOL_" },
                new String[] { (String) options.get("colHeadTool") });
        retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_VIEWMODE_" },
                new String[] { (String) options.get("viewMode") });

        retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_HEAD_" },
                new String[] { strHead });
        retHtml = StringUtils.replaceEach(retHtml, new String[] { "_TDB_TEMPLATE_BODY_" },
                new String[] { strBody });
    } catch (Exception e) {
        logger.error("SQL template exception", e);
    }

    return retHtml;
}

From source file:ips1ap101.lib.core.db.util.DBUtils.java

public static String[] getConstraintMessageKeys(String message) {
    String trimmed = StringUtils/*w w  w .ja  va2s.c  o m*/
            .trimToEmpty(StringUtils.substringAfter(StringUtils.substringBefore(message, WHERE), ERROR));
    if (StringUtils.isNotBlank(trimmed)) {
        String[] tokens = StringUtils.split(trimmed, ';');
        if (tokens != null && tokens.length > 1) {
            String key = tokens[0].trim();
            if (key.matches("^[0-9]{1,3}$")) {
                int length = Integer.valueOf(key);
                if (length == tokens.length - 1) {
                    String string;
                    String[] keys = new String[length];
                    for (int i = 1; i < tokens.length; i++) {
                        key = tokens[i].trim();
                        if (key.endsWith(SUFIJO) && StringUtils.indexOfAny(key, INFIJOS) > 0) {
                            key = StringUtils.removeEnd(key, SUFIJO);
                            string = BundleMensajes.getString(key);
                            keys[i - 1] = isKey(string) ? string : "<" + key + ">";
                        } else {
                            return null;
                        }
                    }
                    return keys;
                }
            }
        }
        String key, string;
        String stripChars = BOMK + EOMK;
        List<String> list = new ArrayList<>();
        Pattern pattern = Pattern.compile("\\" + BOMK + ".*\\" + EOMK);
        Matcher matcher = pattern.matcher(trimmed);
        while (matcher.find()) {
            key = StringUtils.strip(matcher.group(), stripChars);
            if (key.endsWith(SUFIJO) && StringUtils.indexOfAny(key, INFIJOS) > 0) {
                key = StringUtils.removeEnd(key, SUFIJO);
                string = BundleMensajes.getString(key);
                key = isKey(string) ? string : "<" + key + ">";
                list.add(key);
            }
        }
        return (list.isEmpty()) ? null : list.toArray(new String[list.size()]);
    }
    return null;
}