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.google.gdt.eclipse.designer.uibinder.editor.UiBinderPairResourceProvider.java

/**
 * @return the ui.xml {@link IFile} for given Java one.
 *//* www.j  ava 2  s.c  o m*/
private IFile getUIFile(IFile javaFile) throws Exception {
    IProject project = javaFile.getProject();
    IJavaProject javaProject = JavaCore.create(project);
    // prepare form name
    String javaFormName = StringUtils.removeEnd(javaFile.getName(), ".java");
    // prepare package name
    String packageName;
    {
        IFolder folder = (IFolder) javaFile.getParent();
        IPackageFragment packageFragmentJava = (IPackageFragment) JavaCore.create(folder);
        packageName = packageFragmentJava.getElementName();
    }
    // try to find ui.xml file in package with same name
    for (IPackageFragmentRoot packageFragmentRoot : javaProject.getPackageFragmentRoots()) {
        IPackageFragment packageFragment = packageFragmentRoot.getPackageFragment(packageName);
        if (packageFragment.exists()) {
            for (Object object : packageFragment.getNonJavaResources()) {
                if (object instanceof IFile) {
                    IFile uiFile = (IFile) object;
                    String uiFileName = uiFile.getName();
                    if (StringUtils.endsWithIgnoreCase(uiFileName, ".ui.xml")) {
                        String uiFormName = StringUtils.removeEndIgnoreCase(uiFileName, ".ui.xml");
                        if (uiFormName.equals(javaFormName)) {
                            return uiFile;
                        }
                    }
                }
            }
        }
    }
    // no ui.xml file
    return null;
}

From source file:io.apiman.gateway.vertx.connector.HttpConnector.java

/**
 * Construct an {@link HttpConnector} instance. The {@link #resultHandler} must remain exclusive to a
 * given instance.// w  ww.  j a va2 s . com
 *
 * @param vertx a vertx
 * @param service a service
 * @param request a request with fields filled
 * @param resultHandler a handler, called when reading is permitted
 */
public HttpConnector(Vertx vertx, Container container, Service service, ServiceRequest request,
        IAsyncResultHandler<IServiceConnectionResponse> resultHandler) {
    this.vertx = vertx;
    this.logger = container.logger();
    this.serviceRequest = request;
    this.resultHandler = resultHandler;
    this.exceptionHandler = new ExceptionHandler();

    URL serviceEndpoint = parseServiceEndpoint(service);

    serviceHost = serviceEndpoint.getHost();
    servicePort = serviceEndpoint.getPort();
    servicePath = StringUtils.removeEnd(serviceEndpoint.getPath(), "/"); //$NON-NLS-1$

    doConnection();
}

From source file:gov.nih.nci.cacisweb.user.CacisUserService.java

public void updateUser(CacisUser cacisUser) throws UsernameNotFoundException {
    try {//from w w w .  j  a va2s . c o m
        log.debug("Updating user...");
        String userProperty = CaCISUtil.getProperty(cacisUser.getUsername());
        if (userProperty == null) {
            log.error("User Not Found");
            throw new UsernameNotFoundException("User Not Found");
        }
        String userPropertyValue = cacisUser.getPassword() + "," + cacisUser.isAccountNonLocked() + ","
                + cacisUser.getFailedLoginAttempts() + "," + cacisUser.getLockOutTime() + ",";
        for (GrantedAuthority grantedAuthority : cacisUser.getAuthorities()) {
            userPropertyValue += grantedAuthority.getAuthority() + ",";
        }
        userPropertyValue = StringUtils.removeEnd(userPropertyValue, ",");
        log.debug("New User Property Value: " + userPropertyValue);
        CaCISUtil.setProperty(cacisUser.getUsername(), userPropertyValue);
    } catch (CaCISWebException e) {
        log.error("User update failed: " + e.getMessage());
        throw new UsernameNotFoundException("User update failed: " + e.getMessage());
    }
}

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

/**
 * Create a new instance of this class.//from ww w .jav  a  2s  .  co m
 * 
 * @param xmlFile
 *          the definition file of this proxy.
 * @throws IOException
 *           If some other I/O error occurs
 * @throws SAXException
 *           If some XML parse error occurs
 */
public Proxy(File xmlFile) throws IOException, SAXException {
    final XmlParser parser = new XmlParser();
    final Node config = parser.parse(new FileInputStream(xmlFile));
    xmlName = StringUtils.removeEnd(xmlFile.getName().toLowerCase(), ".xml");
    name = config.getAttribute("name");
    encoding = config.getAttribute("encoding");
    language = config.getAttribute("language");
    home = config.getAttribute("home");

    final List<?> pictures = config.get("pictures").getNodes("picture");
    for (int i = 0; i < pictures.size(); i++) {
        final Node pictureStream = (Node) pictures.get(i);
        this.pictures.add(
                new PictureConfiguration(new UrlTokenizer(pictureStream), pictureStream.getAttribute("base")));
    }

    // read private aliases
    final Node aliases = config.get("alias");
    this.aliases = new HashMap<String, Map<String, String>>();
    if (aliases != null) {
        List<Node> nodes = aliases.getNodes("alias");
        for (int i = nodes.size(); i-- > 0;) {
            final Node alias = nodes.get(i);
            Map<String, String> nameSpace = this.aliases.get(alias.getAttribute("property"));
            if (nameSpace == null) {
                nameSpace = new HashMap<String, String>();
                this.aliases.put(alias.getAttribute("property"), nameSpace);
            }
            nameSpace.put(alias.getAttribute("local-value").toLowerCase(), alias.getAttribute("ref"));
        }
    }

    // read streams configurations
    Node dataConfig = config.get("data");
    Node streamConfig = dataConfig.get("streams");
    if (streamConfig != null) {
        streamBaseUrl = streamConfig.getAttribute("base");
        final List<Node> streamsNode = streamConfig.getNodes("stream");
        streams = new ArrayList<UrlTokenizer>(streamsNode.size());
        for (int i = 0; i < streamsNode.size(); i++) {
            streams.add(new UrlTokenizer(streamsNode.get(i)));
        }
        if (streams.isEmpty()) {
            throw new RuntimeException("At least one stream configuration must be defined");
        }

        // read properties configurations
        final List<Node> nodes = dataConfig.get("properties").getNodes("property");
        properties = new ArrayList<PropertyConfig>(nodes.size());
        for (int i = 0; i < nodes.size(); i++) {
            properties.add(new PropertyProxyConfig(nodes.get(i)));
        }
    } else {
        streams = new ArrayList<UrlTokenizer>(0);
        properties = new ArrayList<PropertyConfig>(0);
    }
}

From source file:com.hangum.tadpole.rdb.core.editors.main.utils.TableToDataUtils.java

/**
 * table row data/*from  w  w  w .j  ava  2 s  .c o m*/
 * 
 * @param tableResult
 * @param mapColumns
 * @param mapColumnType
 * @return
 */
public static TableColumnDAO getTableRowData(Table tableResult, Map<Integer, Object> mapColumns,
        Map<Integer, Integer> mapColumnType) {
    TableColumnDAO columnDao = new TableColumnDAO();
    String strNullValue = GetPreferenceGeneral.getResultNull();
    columnDao.setName(PublicTadpoleDefine.DEFINE_TABLE_COLUMN_BASE_ZERO);
    columnDao.setType(PublicTadpoleDefine.DEFINE_TABLE_COLUMN_BASE_ZERO_TYPE);

    for (int j = 1; j < tableResult.getColumnCount(); j++) {
        Object columnObject = mapColumns.get(j);
        boolean isNumberType = RDBTypeToJavaTypeUtils.isNumberType(mapColumnType.get(j));
        if (isNumberType) {
            String strText = ""; //$NON-NLS-1$

            // if select value is null can 
            if (columnObject == null)
                strText = strNullValue;
            else
                strText = columnObject.toString();
            columnDao.setCol_value(columnDao.getCol_value() + strText + PublicTadpoleDefine.DELIMITER_DBL);
        } else if ("BLOB".equalsIgnoreCase(columnDao.getData_type())) { //$NON-NLS-1$
            // ignore blob type
        } else {
            String strText = ""; //$NON-NLS-1$

            // if select value is null can 
            if (columnObject == null) {
                strText = strNullValue;
                columnDao.setCol_value(columnDao.getCol_value() + strText + PublicTadpoleDefine.DELIMITER_DBL);
            } else {
                strText = columnObject.toString();
                columnDao.setCol_value(columnDao.getCol_value() + SQLUtil.makeQuote(strText)
                        + PublicTadpoleDefine.DELIMITER_DBL);
            }

        }
    }
    columnDao.setCol_value(
            StringUtils.removeEnd("" + columnDao.getCol_value(), PublicTadpoleDefine.DELIMITER_DBL));

    return columnDao;
}

From source file:com.sinosoft.one.mvc.scanning.MvcScanner.java

public List<ResourceRef> getJarOrClassesFolderResources(String[] scope) throws IOException {
    if (logger.isInfoEnabled()) {
        logger.info("[findFiles] start to found classes folders " + "or mvcd jar files by scope:"
                + Arrays.toString(scope));
    }/*from   w w w.j a va  2  s  .  com*/
    List<ResourceRef> resources;
    if (scope == null) {
        resources = new LinkedList<ResourceRef>();
        if (logger.isDebugEnabled()) {
            logger.debug("[findFiles] call 'classesFolder'");
        }
        resources.addAll(getClassesFolderResources());
        //
        if (logger.isDebugEnabled()) {
            logger.debug("[findFiles] exits from 'classesFolder'");
            logger.debug("[findFiles] call 'jarFile'");
        }
        resources.addAll(getJarResources());
        if (logger.isDebugEnabled()) {
            logger.debug("[findFiles] exits from 'jarFile'");
        }
    } else if (scope.length == 0) {
        return new ArrayList<ResourceRef>();
    } else {
        resources = new LinkedList<ResourceRef>();
        for (String scopeEntry : scope) {
            String packagePath = scopeEntry.replace('.', '/');
            Resource[] packageResources = resourcePatternResolver.getResources("classpath*:" + packagePath);
            for (Resource pkgResource : packageResources) {
                String uri = pkgResource.getURI().toString();
                uri = StringUtils.removeEnd(uri, "/");
                packagePath = StringUtils.removeEnd(packagePath, "/");
                uri = StringUtils.removeEnd(uri, packagePath);
                int beginIndex = uri.lastIndexOf("file:");
                if (beginIndex == -1) {
                    beginIndex = 0;
                } else {
                    beginIndex += "file:".length();
                }
                int endIndex = uri.lastIndexOf('!');
                if (endIndex == -1) {
                    endIndex = uri.length();
                }
                String path = uri.substring(beginIndex, endIndex);
                Resource folder = new FileSystemResource(path);
                ResourceRef ref = ResourceRef.toResourceRef(folder);
                if (!resources.contains(ref)) {
                    resources.add(ref);
                    if (logger.isDebugEnabled()) {
                        logger.debug(
                                "[findFiles] found classes folders " + "or mvcd jar files by scope:" + ref);
                    }
                }
            }
        }
    }
    //
    if (logger.isInfoEnabled()) {
        logger.info("[findFiles] found " + resources.size() + " classes folders " + "or mvcd jar files : "
                + resources);
    }

    return resources;
}

From source file:com.gzj.tulip.load.RoseScanner.java

public List<ResourceRef> getJarOrClassesFolderResources(String[] scope) throws IOException {
    if (logger.isInfoEnabled()) {
        logger.info("[findFiles] start to found classes folders " + "or rosed jar files by scope:"
                + Arrays.toString(scope));
    }//from   w w w .ja  v a 2s  . c o m
    List<ResourceRef> resources;
    if (scope == null) {
        resources = new LinkedList<ResourceRef>();
        if (logger.isDebugEnabled()) {
            logger.debug("[findFiles] call 'classesFolder'");
        }
        resources.addAll(getClassesFolderResources());
        //
        if (logger.isDebugEnabled()) {
            logger.debug("[findFiles] exits from 'classesFolder'");
            logger.debug("[findFiles] call 'jarFile'");
        }
        resources.addAll(getJarResources());
        if (logger.isDebugEnabled()) {
            logger.debug("[findFiles] exits from 'jarFile'");
        }
    } else if (scope.length == 0) {
        return new ArrayList<ResourceRef>();
    } else {
        resources = new LinkedList<ResourceRef>();
        for (String scopeEntry : scope) {
            String packagePath = scopeEntry.replace('.', '/');
            Resource[] packageResources = resourcePatternResolver.getResources("classpath*:" + packagePath);
            for (Resource pkgResource : packageResources) {
                String uri = pkgResource.getURI().toString();
                uri = StringUtils.removeEnd(uri, "/");
                packagePath = StringUtils.removeEnd(packagePath, "/");
                uri = StringUtils.removeEnd(uri, packagePath);
                int beginIndex = uri.lastIndexOf("file:");
                if (beginIndex == -1) {
                    beginIndex = 0;
                } else {
                    beginIndex += "file:".length();
                }
                int endIndex = uri.lastIndexOf('!');
                if (endIndex == -1) {
                    endIndex = uri.length();
                }
                String path = uri.substring(beginIndex, endIndex);
                Resource folder = new FileSystemResource(path);
                ResourceRef ref = ResourceRef.toResourceRef(folder);
                if (!resources.contains(ref)) {
                    resources.add(ref);
                    if (logger.isDebugEnabled()) {
                        logger.debug(
                                "[findFiles] found classes folders " + "or rosed jar files by scope:" + ref);
                    }
                }
            }
        }
    }
    //
    if (logger.isInfoEnabled()) {
        logger.info("[findFiles] found " + resources.size() + " classes folders " + "or rosed jar files : "
                + resources);
    }

    return resources;
}

From source file:com.netease.flume.taildirSource.TailFile.java

private Event readEvent(boolean backoffWithoutNL, boolean addByteOffset) throws IOException {
    Long posTmp = raf.getFilePointer();
    String line = readLine();//  ww  w.j a va  2s.  com
    if (line == null) {
        return null;
    }
    if (backoffWithoutNL && !line.endsWith(LINE_SEP)) {
        logger.debug("Backing off in file without newline: " + path + ", inode: " + inode + ", pos: "
                + raf.getFilePointer());
        raf.seek(posTmp);
        return null;
    }

    String lineSep = LINE_SEP;
    if (line.endsWith(LINE_SEP_WIN)) {
        lineSep = LINE_SEP_WIN;
    }
    Event event = EventBuilder.withBody(StringUtils.removeEnd(line, lineSep), Charsets.UTF_8);
    if (addByteOffset == true) {
        event.getHeaders().put(BYTE_OFFSET_HEADER_KEY, posTmp.toString());
    }
    return event;
}

From source file:com.laxser.blitz.scanning.BlitzScanner.java

public List<ResourceRef> getJarOrClassesFolderResources(String[] scope) throws IOException {
    if (logger.isInfoEnabled()) {
        logger.info("[findFiles] start to found classes folders " + "or blitzd jar files by scope:"
                + Arrays.toString(scope));
    }/*from  ww w . j  a  v a  2s  .c  o m*/
    List<ResourceRef> resources;
    if (scope == null) {
        resources = new LinkedList<ResourceRef>();
        if (logger.isDebugEnabled()) {
            logger.debug("[findFiles] call 'classesFolder'");
        }
        resources.addAll(getClassesFolderResources());
        //
        if (logger.isDebugEnabled()) {
            logger.debug("[findFiles] exits from 'classesFolder'");
            logger.debug("[findFiles] call 'jarFile'");
        }
        resources.addAll(getJarResources());
        if (logger.isDebugEnabled()) {
            logger.debug("[findFiles] exits from 'jarFile'");
        }
    } else if (scope.length == 0) {
        return new ArrayList<ResourceRef>();
    } else {
        resources = new LinkedList<ResourceRef>();
        for (String scopeEntry : scope) {
            String packagePath = scopeEntry.replace('.', '/');
            Resource[] packageResources = resourcePatternResolver.getResources("classpath*:" + packagePath);
            for (Resource pkgResource : packageResources) {
                String uri = pkgResource.getURI().toString();
                uri = StringUtils.removeEnd(uri, "/");
                packagePath = StringUtils.removeEnd(packagePath, "/");
                uri = StringUtils.removeEnd(uri, packagePath);
                int beginIndex = uri.lastIndexOf("file:");
                if (beginIndex == -1) {
                    beginIndex = 0;
                } else {
                    beginIndex += "file:".length();
                }
                int endIndex = uri.lastIndexOf('!');
                if (endIndex == -1) {
                    endIndex = uri.length();
                }
                String path = uri.substring(beginIndex, endIndex);
                Resource folder = new FileSystemResource(path);
                ResourceRef ref = ResourceRef.toResourceRef(folder);
                if (!resources.contains(ref)) {
                    resources.add(ref);
                    if (logger.isDebugEnabled()) {
                        logger.debug(
                                "[findFiles] found classes folders " + "or blitzd jar files by scope:" + ref);
                    }
                }
            }
        }
    }
    //
    if (logger.isInfoEnabled()) {
        logger.info("[findFiles] found " + resources.size() + " classes folders " + "or blitzd jar files : "
                + resources);
    }

    return resources;
}

From source file:com.hangum.tadpole.engine.restful.RESTfulAPIUtils.java

/**
 * Return SQL Paramter//from   ww w  .  j  a v a2s  .  c o  m
 * 
 * @param strSQL
 * @return
 */
public static String getParameter(String strSQL) {
    String strArguments = "";
    OracleStyleSQLNamedParameterUtil oracleNamedParamUtil = OracleStyleSQLNamedParameterUtil.getInstance();
    oracleNamedParamUtil.parse(strSQL);
    Map<Integer, String> mapIndex = oracleNamedParamUtil.getMapIndexToName();
    if (!mapIndex.isEmpty()) {
        for (String strParam : mapIndex.values()) {
            strArguments += String.format("%s={%s_value}&", strParam, strParam);
        }
        strArguments = StringUtils.removeEnd(strArguments, "&");

    } else {
        strArguments = "";//1={FirstParameter}&2={SecondParameter}";
    }

    return strArguments;
}