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:de.awtools.basic.file.AWToolsFileUtils.java

/**
 * Normalisiert einen Pfadausdruck. D.h. aus den Windows-Trenner werden
 * Unix-Trenner, aus /./ wird /. Falls / vorne fehlt, wird dieser
 * vorangestellt. Doppelte // werden durch / ersetzt. Windows
 * Laufwerksbezeichner werden eliminiert.<br/>
 *
 * <b>ACHTUNG:</b> URL wie file://c:/temp werden nicht korrekt verarbeitet,
 * da das // ebenfalls durch / ersetzt wird. 
 *
 * @param fileName Der zu normalisierende Dateiname.
 * @return Der normalisierte Dateiname./*from  w  ww.ja v a2 s  . com*/
 */
public static String normalizePath(final String fileName) {
    // Alle Windows Trenner durch Unix Trenner ersetzen.
    String newFileName = StringUtils.replace(fileName, "\\", WINFILE_SEPERATOR);

    // Alle // durch / ersetzen.
    newFileName = StringUtils.replace(newFileName, "//", WINFILE_SEPERATOR);
    newFileName = StringUtils.replace(newFileName, "///", WINFILE_SEPERATOR);

    // Alle /./ durch / ersetzen. 
    newFileName = StringUtils.replace(newFileName, "/./", WINFILE_SEPERATOR);

    // Startsymbole normalisieren.
    if (newFileName.startsWith("./")) {
        newFileName = StringUtils.replace(newFileName, ".", "", 1);
    }

    if (WINDOWS_ROOT_PATTERN.matcher(newFileName).find()) {
        newFileName = newFileName.substring(2);
    }

    if (!newFileName.startsWith(WINFILE_SEPERATOR)) {
        newFileName = WINFILE_SEPERATOR + newFileName;
    }

    // / Endsymbol bei Verzeichnissen entfernen
    if (newFileName.endsWith(WINFILE_SEPERATOR)) {
        newFileName = StringUtils.removeEnd(newFileName, WINFILE_SEPERATOR);
    }

    return newFileName;
}

From source file:com.cimmyt.model.dao.impl.AbstractDAO.java

/**
 * Find single by values//from w  w  w.j  av a2  s  .  c  om
 * @param clazz
 * @param properties
 * @param values
 * @return
 * @throws Exception
 */
public List<T> findListByValues(T clazz, Object[] properties, Object[] values) throws Exception {

    if (properties.length != values.length) {
        throw new Exception("The number of properties must be the same than the number of values");
    }
    String strClazz = type.getSimpleName();
    StringBuilder builder = new StringBuilder("FROM " + strClazz + " as a" + " WHERE ");
    for (int i = 0; i < values.length; i++) {
        if (values[i] instanceof String) {
            builder.append("a." + properties[i] + " LIKE ?");
        } else {
            builder.append("a." + properties[i] + " = ?");
        }
        builder.append(" AND ");
    }
    String query = builder.toString().trim();
    if (StringUtils.endsWith(query, "AND")) {
        query = StringUtils.removeEnd(query, "AND");
    }
    @SuppressWarnings("unchecked")
    List<T> list = (List<T>) getHibernateTemplate().find(query, values);
    if (list != null && !list.isEmpty()) {
        return list;
    } else {
        return null;
    }
}

From source file:com.egt.ejb.toolkit.ToolKitUtils.java

public static String getLowerCaseEnumOptionIdentifier(String string) {
    if (string == null) {
        return null;
    }//from  w  ww.ja va 2  s .c om
    String s;
    s = STP.getIdentificadorSql(string);
    s = StringUtils.removeStart(s, "_");
    s = StringUtils.removeEnd(s, "_");
    return s.toLowerCase();
}

From source file:net.paoding.rose.web.impl.module.ModulesBuilderImpl.java

private boolean checkController(final XmlWebApplicationContext context, String beanName, ModuleImpl module)
        throws IllegalAccessException {
    AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) context.getBeanFactory()
            .getBeanDefinition(beanName);
    String beanClassName = beanDefinition.getBeanClassName();
    String controllerSuffix = null;
    for (String suffix : RoseConstants.CONTROLLER_SUFFIXES) {
        if (beanClassName.length() > suffix.length() && beanClassName.endsWith(suffix)) {
            if (suffix.length() == 1 && Character
                    .isUpperCase(beanClassName.charAt(beanClassName.length() - suffix.length() - 1))) {
                continue;
            }/* w  w  w.j  a  va  2 s.  c o  m*/
            controllerSuffix = suffix;
            break;
        }
    }
    if (controllerSuffix == null) {
        if (beanDefinition.hasBeanClass()) {
            Class<?> beanClass = beanDefinition.getBeanClass();
            if (beanClass.isAnnotationPresent(Path.class)) {
                throw new IllegalArgumentException(
                        "@" + Path.class.getSimpleName() + " is only allowed in Resource/Controller, "
                                + "is it a Resource/Controller? wrong spelling? : " + beanClassName);
            }
        }
        // ?l?r?uer?or???
        if (beanClassName.endsWith("Controler") || beanClassName.endsWith("Controllor")
                || beanClassName.endsWith("Resouce") || beanClassName.endsWith("Resorce")) {
            // ?throw???
            logger.error("", new IllegalArgumentException(
                    "invalid class name end wrong spelling? : " + beanClassName));
        }
        return false;
    }
    String[] controllerPaths = null;
    if (!beanDefinition.hasBeanClass()) {
        try {
            beanDefinition.resolveBeanClass(Thread.currentThread().getContextClassLoader());
        } catch (ClassNotFoundException e) {
            throw new CannotLoadBeanClassException("", beanName, beanDefinition.getBeanClassName(), e);
        }
    }
    final Class<?> clazz = beanDefinition.getBeanClass();
    final String controllerName = StringUtils.removeEnd(ClassUtils.getShortNameAsProperty(clazz),
            controllerSuffix);
    Path reqMappingAnnotation = clazz.getAnnotation(Path.class);
    if (reqMappingAnnotation != null) {
        controllerPaths = reqMappingAnnotation.value();
    }
    if (controllerPaths != null) {
        // controllerPaths.length==0path?controller
        for (int i = 0; i < controllerPaths.length; i++) {
            if ("#".equals(controllerPaths[i])) {
                controllerPaths[i] = "/" + controllerName;
            } else if (controllerPaths[i].equals("/")) {
                controllerPaths[i] = "";
            } else if (controllerPaths[i].length() > 0 && controllerPaths[i].charAt(0) != '/') {
                controllerPaths[i] = "/" + controllerPaths[i];
            }
            if (controllerPaths[i].length() > 1 && controllerPaths[i].endsWith("/")) {
                if (controllerPaths[i].endsWith("//")) {
                    throw new IllegalArgumentException("invalid path '" + controllerPaths[i]
                            + "' for controller " + beanClassName + ": don't end with more than one '/'");
                }
                controllerPaths[i] = controllerPaths[i].substring(0, controllerPaths[i].length() - 1);
            }
        }
    } else {
        // TODO: ?0.91.0?201007??
        if (controllerName.equals("index") || controllerName.equals("home")
                || controllerName.equals("welcome")) {
            // ??IndexController/HomeController/WelcomeController@Path("")
            throw new IllegalArgumentException("please add @Path(\"\") to " + clazz.getName());
        } else {
            controllerPaths = new String[] { "/" + controllerName };
        }
    }
    // Controller??Context??
    // Context???
    Object controller = context.getBean(beanName);
    module.addController(//
            controllerPaths, clazz, controllerName, controller);
    if (Proxy.isProxyClass(controller.getClass())) {
        if (logger.isDebugEnabled()) {
            logger.debug("module '" + module.getMappingPath() + "': add controller "
                    + Arrays.toString(controllerPaths) + "= proxy of " + clazz.getName());
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("module '" + module.getMappingPath() //
                    + "': add controller " + Arrays.toString(controllerPaths) + "= "
                    + controller.getClass().getName());
        }
    }
    return true;
}

From source file:com.laxser.blitz.web.impl.module.ModulesBuilderImpl.java

private boolean checkController(final XmlWebApplicationContext context, String beanName, ModuleImpl module)
        throws IllegalAccessException {
    AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) context.getBeanFactory()
            .getBeanDefinition(beanName);
    String beanClassName = beanDefinition.getBeanClassName();
    String controllerSuffix = null;
    for (String suffix : BlitzConstants.CONTROLLER_SUFFIXES) {
        if (beanClassName.length() > suffix.length() && beanClassName.endsWith(suffix)) {
            if (suffix.length() == 1 && Character
                    .isUpperCase(beanClassName.charAt(beanClassName.length() - suffix.length() - 1))) {
                continue;
            }/*  w  w  w.j a  v a 2s  . c o m*/
            controllerSuffix = suffix;
            break;
        }
    }
    if (controllerSuffix == null) {
        if (beanDefinition.hasBeanClass()) {
            Class<?> beanClass = beanDefinition.getBeanClass();
            if (beanClass.isAnnotationPresent(Path.class)) {
                throw new IllegalArgumentException(
                        "@" + Path.class.getSimpleName() + " is only allowed in Resource/Controller, "
                                + "is it a Resource/Controller? wrong spelling? : " + beanClassName);
            }
        }
        // ?l?r?uer?or???
        if (beanClassName.endsWith("Controler") || beanClassName.endsWith("Controllor")
                || beanClassName.endsWith("Resouce") || beanClassName.endsWith("Resorce")) {
            // ?throw???
            logger.error("", new IllegalArgumentException(
                    "invalid class name end wrong spelling? : " + beanClassName));
        }
        return false;
    }
    String[] controllerPaths = null;
    if (!beanDefinition.hasBeanClass()) {
        try {
            beanDefinition.resolveBeanClass(Thread.currentThread().getContextClassLoader());
        } catch (ClassNotFoundException e) {
            throw new CannotLoadBeanClassException("", beanName, beanDefinition.getBeanClassName(), e);
        }
    }
    final Class<?> clazz = beanDefinition.getBeanClass();
    final String controllerName = StringUtils.removeEnd(ClassUtils.getShortNameAsProperty(clazz),
            controllerSuffix);
    Path reqMappingAnnotation = clazz.getAnnotation(Path.class);
    if (reqMappingAnnotation != null) {
        controllerPaths = reqMappingAnnotation.value();
    }
    if (controllerPaths != null) {
        // controllerPaths.length==0path?controller
        for (int i = 0; i < controllerPaths.length; i++) {
            if ("#".equals(controllerPaths[i])) {
                controllerPaths[i] = "/" + controllerName;
            } else if (controllerPaths[i].equals("/")) {
                controllerPaths[i] = "";
            } else if (controllerPaths[i].length() > 0 && controllerPaths[i].charAt(0) != '/') {
                controllerPaths[i] = "/" + controllerPaths[i];
            }
            if (controllerPaths[i].length() > 1 && controllerPaths[i].endsWith("/")) {
                if (controllerPaths[i].endsWith("//")) {
                    throw new IllegalArgumentException("invalid path '" + controllerPaths[i]
                            + "' for controller " + beanClassName + ": don't end with more than one '/'");
                }
                controllerPaths[i] = controllerPaths[i].substring(0, controllerPaths[i].length() - 1);
            }
        }
    } else {
        // TODO: ?0.91.0?201007??
        if (controllerName.equals("index") || controllerName.equals("home")
                || controllerName.equals("welcome")) {
            // ??IndexController/HomeController/WelcomeController@Path("")
            throw new IllegalArgumentException("please add @Path(\"\") to " + clazz.getName());
        } else {
            controllerPaths = new String[] { "/" + controllerName };
        }
    }
    // Controller??Context??
    // Context???
    Object controller = context.getBean(beanName);
    module.addController(//
            controllerPaths, clazz, controllerName, controller);
    if (Proxy.isProxyClass(controller.getClass())) {
        if (logger.isDebugEnabled()) {
            logger.debug("module '" + module.getMappingPath() + "': add controller "
                    + Arrays.toString(controllerPaths) + "= proxy of " + clazz.getName());
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("module '" + module.getMappingPath() //
                    + "': add controller " + Arrays.toString(controllerPaths) + "= "
                    + controller.getClass().getName());
        }
    }
    return true;
}

From source file:com.laxser.blitz.scanner.ModuleResourceProviderImpl.java

private void addModuleClass(Local local, FileObject rootObject, FileObject thisFolder, FileObject resource)
        throws IOException {
    String className = rootObject.getName().getRelativeName(resource.getName());
    Assert.isTrue(!className.startsWith("/"));
    className = StringUtils.removeEnd(className, ".class");
    className = className.replace('/', '.');
    ModuleResource module = local.moduleResourceMap.get(thisFolder);
    try {//  w  w w . ja  v  a  2  s .  co m
        // TODO: classloader...
        module.addModuleClass(Class.forName(className));
        if (logger.isDebugEnabled()) {
            logger.debug("module '" + module.getMappingPath() + "': found class, name=" + className);
        }
    } catch (ClassNotFoundException e) {
        logger.error("", e);
    }
}

From source file:eu.annocultor.converters.solr.BuiltinSolrDocumentTagger.java

LookupTimeRule makePeriodLookupRule(String field) throws Exception {
    LookupTimeRule rule = new LookupTimeRule(null, null, eu.annocultor.api.Factory.makeIgnoreGraph(task, ""),
            null, null, "periods", "(no_split_should_ever_happen)", vocabularyOfPeriods) {

        @Override/*  www  .java 2 s  .  c  om*/
        protected void processLookupMatch(TermList terms, String termUri, String subject, DataObject dataObject,
                boolean createTermDefinion) throws Exception {
            // skip it
        }

        // missing years are reported all together
        @Override
        protected void reportMatch(TermList terms) throws Exception {

            for (Term term : terms) {
                if (!term.getLabel().matches("^(\\d\\d\\d\\d)$")) {
                    super.reportMatch(terms);
                    return;
                }
            }

            TermList genericYear = new TermList();
            genericYear.add(new Term("A year of four digits", null,
                    new CodeURI("http://semium.org/time/year/XXXX"), "time"));
            super.reportMatch(genericYear);
        }

        @Override
        protected PairOfStrings splitToStartAndEnd(DataObject converter, String label, Language.Lang lang) {
            return eu.annocultor.converters.europeana.EuropeanaTimeUtils.splitToStartAndEnd(label);
        }

        @Override
        public Triple onInvocation(Triple sourceTriple, DataObject sourceDataObject) throws Exception {

            String termLabel = sourceTriple.getValue().getValue();
            // removing "made" and "printed" used by some providers 
            termLabel = StringUtils.removeEnd(termLabel, " made");
            termLabel = StringUtils.removeEnd(termLabel, " printed");
            termLabel = StringUtils.removeEnd(termLabel, " built");
            termLabel = StringUtils.removeEnd(termLabel, " existed");
            termLabel = StringUtils.removeEnd(termLabel, " written");
            termLabel = StringUtils.removeEnd(termLabel, " photographed");
            termLabel = StringUtils.removeEnd(termLabel, " surveyed");
            termLabel = StringUtils.removeEnd(termLabel, " manufactured");
            termLabel = StringUtils.removeEnd(termLabel, " taken");
            termLabel = StringUtils.removeEnd(termLabel, " first published");
            termLabel = StringUtils.removeEnd(termLabel, " published");
            termLabel = StringUtils.removeEnd(termLabel, " cuttings collected");

            // remove trailing ,, e.g  19 siete,
            termLabel = StringUtils.removeEnd(termLabel, ",");

            return sourceTriple.changeValue(new LiteralValue(termLabel));
        }

    };

    rule.setObjectRule(objectRule);
    rule.setTask(task);
    rule.setSourcePath(new Path(field));
    //        rule.addLabelExtractor(new EuropeanaLabelExtractor(false));
    return rule;
}

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

@Override
public String getComandoSelect(String comando, int limite) {
    return checkClausulaCriterios(StringUtils.removeEnd(comando, ";"));
}

From source file:com.microsoft.alm.plugin.external.commands.Command.java

protected String getFilePath(final String path, final String filename, final String pathRoot) {
    // If the path still has a ':' at the end, remove it
    String folderPath = StringUtils.removeEnd(path, ":");
    // If the path isn't rooted, add in the root
    if (!Path.isAbsolute(folderPath) && StringUtils.isNotEmpty(pathRoot)) {
        folderPath = Path.combine(pathRoot, folderPath);
    }//from   www  .ja  v  a 2  s. c o m

    return Path.combine(folderPath, filename);
}

From source file:com.sinosoft.one.mvc.web.impl.module.ModulesBuilderImpl.java

private boolean checkController(final XmlWebApplicationContext context, String beanName, ModuleImpl module)
        throws IllegalAccessException {
    AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) context.getBeanFactory()
            .getBeanDefinition(beanName);
    String beanClassName = beanDefinition.getBeanClassName();
    String controllerSuffix = null;
    for (String suffix : MvcConstants.CONTROLLER_SUFFIXES) {
        if (beanClassName.length() > suffix.length() && beanClassName.endsWith(suffix)) {
            if (suffix.length() == 1 && Character
                    .isUpperCase(beanClassName.charAt(beanClassName.length() - suffix.length() - 1))) {
                continue;
            }/*from   w  ww .  j  a  v  a2s. c  om*/
            controllerSuffix = suffix;
            break;
        }
    }
    if (controllerSuffix == null) {
        if (beanDefinition.hasBeanClass()) {
            Class<?> beanClass = beanDefinition.getBeanClass();
            if (beanClass.isAnnotationPresent(Path.class)) {
                throw new IllegalArgumentException(
                        "@" + Path.class.getSimpleName() + " is only allowed in Resource/Controller, "
                                + "is it a Resource/Controller? wrong spelling? : " + beanClassName);
            }
        }
        // ?l?r?uer?or???
        if (beanClassName.endsWith("Controler") || beanClassName.endsWith("Controllor")
                || beanClassName.endsWith("Resouce") || beanClassName.endsWith("Resorce")) {
            // ?throw???
            logger.error("", new IllegalArgumentException(
                    "invalid class name end wrong spelling? : " + beanClassName));
        }
        return false;
    }
    String[] controllerPaths = null;
    if (!beanDefinition.hasBeanClass()) {
        try {
            beanDefinition.resolveBeanClass(Thread.currentThread().getContextClassLoader());
        } catch (ClassNotFoundException e) {
            throw new CannotLoadBeanClassException("", beanName, beanDefinition.getBeanClassName(), e);
        }
    }
    final Class<?> clazz = beanDefinition.getBeanClass();
    final String controllerName = StringUtils.removeEnd(ClassUtils.getShortNameAsProperty(clazz),
            controllerSuffix);
    Path reqMappingAnnotation = clazz.getAnnotation(Path.class);
    if (reqMappingAnnotation != null) {
        controllerPaths = reqMappingAnnotation.value();
    }
    if (controllerPaths != null) {
        // controllerPaths.length==0path?controller
        for (int i = 0; i < controllerPaths.length; i++) {
            if ("#".equals(controllerPaths[i])) {
                controllerPaths[i] = "/" + controllerName;
            } else if (controllerPaths[i].equals("/")) {
                controllerPaths[i] = "";
            } else if (controllerPaths[i].length() > 0 && controllerPaths[i].charAt(0) != '/') {
                controllerPaths[i] = "/" + controllerPaths[i];
            }
            if (controllerPaths[i].length() > 1 && controllerPaths[i].endsWith("/")) {
                if (controllerPaths[i].endsWith("//")) {
                    throw new IllegalArgumentException("invalid path '" + controllerPaths[i]
                            + "' for controller " + beanClassName + ": don't end with more than one '/'");
                }
                controllerPaths[i] = controllerPaths[i].substring(0, controllerPaths[i].length() - 1);
            }
        }
    } else {
        // TODO: ?0.91.0?201007??
        if (controllerName.equals("index") || controllerName.equals("home")
                || controllerName.equals("welcome")) {
            // ??IndexController/HomeController/WelcomeController@Path("")
            throw new IllegalArgumentException("please add @Path(\"\") to " + clazz.getName());
        } else {
            controllerPaths = new String[] { "/" + controllerName };
        }
    }
    // Controller??Context??
    // Context???
    Object controller = context.getBean(beanName);
    module.addController(//
            controllerPaths, clazz, controllerName, controller);
    if (Proxy.isProxyClass(controller.getClass())) {
        if (logger.isDebugEnabled()) {
            logger.debug("module '" + module.getMappingPath() + "': add controller "
                    + Arrays.toString(controllerPaths) + "= proxy of " + clazz.getName());
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("module '" + module.getMappingPath() //
                    + "': add controller " + Arrays.toString(controllerPaths) + "= "
                    + controller.getClass().getName());
        }
    }
    return true;
}