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

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

Introduction

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

Prototype

public static String removeEnd(final String str, final String remove) 

Source Link

Document

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

A null source string will return null .

Usage

From source file:nl.vpro.jcr.criteria.query.xpath.utils.XPathTextUtils.java

public static String toXPath(String path) {
    if (!isValidNodePath(path)) {
        throw new IllegalArgumentException("Path " + path + " is not a valid JCR node path");
    }//from  w  ww. jav  a 2s. c  om

    if (path.equals("/")) {
        return Criterion.ALL_ELEMENTS;
    }

    return encodeDigitsInPath(Criterion.JCR_ROOT + StringUtils.removeEnd(path, "/") + "//*");
}

From source file:org.alfresco.dataprep.CMISUtil.java

/**
 * Get the node ref for a item by path// w  w  w  .java  2s  .  co m
 * @param session the session
 * @param pathToContent String path to item (e.g. /Sites/siteId/documentLibrary/doc.txt)
 * @return String node ref of the item
 */
public String getNodeRefByPath(Session session, String pathToContent) {
    if (StringUtils.isEmpty(pathToContent)) {
        throw new CmisRuntimeException("Path to content is missing");
    }
    try {
        if (!StringUtils.startsWith(pathToContent, "/")) {
            pathToContent = "/" + pathToContent;
        }
        if (StringUtils.endsWith(pathToContent, "/")) {
            pathToContent = StringUtils.removeEnd(pathToContent, "/");
        }
        CmisObject content = session.getObjectByPath(pathToContent);
        return content.getId().split(";")[0];
    } catch (CmisObjectNotFoundException nf) {
        return "";
    }
}

From source file:org.alfresco.dataprep.CMISUtil.java

/**
 * Get cmis object by path/*from   www.  j a v  a 2 s  .c  o m*/
 * 
 * @param session {@link Session} the session
 * @param pathToItem String path to item
 * @return CmisObject cmis object
 */
public CmisObject getCmisObject(final Session session, String pathToItem) {
    try {
        if (!StringUtils.startsWith(pathToItem, "/")) {
            pathToItem = "/" + pathToItem;
        }
        if (StringUtils.endsWith(pathToItem, "/")) {
            pathToItem = StringUtils.removeEnd(pathToItem, "/");
        }
        if (pathToItem.isEmpty()) {
            // set root folder
            pathToItem = "/";
        }
        return session.getObjectByPath(pathToItem);
    } catch (CmisObjectNotFoundException nf) {
        throw new CmisRuntimeException("Path doesn't exist " + pathToItem);
    }
}

From source file:org.alfresco.dataprep.CMISUtil.java

/**
 * Get cmis object by path/*w ww  . jav  a2s. co  m*/
 * 
 * @param userName String user name
 * @param password String user password
 * @param pathToItem String path to item
 * @return CmisObject cmis object
 */
public CmisObject getCmisObject(final String userName, final String password, String pathToItem) {
    try {
        if (!StringUtils.startsWith(pathToItem, "/")) {
            pathToItem = "/" + pathToItem;
        }
        if (StringUtils.endsWith(pathToItem, "/")) {
            pathToItem = StringUtils.removeEnd(pathToItem, "/");
        }
        Session session = getCMISSession(userName, password);
        return session.getObjectByPath(pathToItem);
    } catch (CmisObjectNotFoundException nf) {
        throw new CmisRuntimeException("Path doesn't exist " + pathToItem);
    }
}

From source file:org.alfresco.selenium.FetchUtil.java

/**
 * Parses file paths to URLs.//from w  w  w  . j av  a  2 s. c  o m
 * @param files collection of paths
 * @param baseUrl Site domain URL, http://localhost:8080
 * @param currentURL the driver.getCurrentUrl() value 
 * @return Collection of URL
 */
public static List<String> parseURL(List<String> files, final String baseUrl, final String currentURL) {
    if (null == baseUrl || baseUrl.isEmpty()) {
        throw new IllegalArgumentException("Site domain url is required");
    }
    if (null == currentURL || currentURL.isEmpty()) {
        throw new IllegalArgumentException("Current WebDriver url is required");
    }
    if (files == null || files.isEmpty()) {
        return Collections.emptyList();
    }
    //Strip tail "/"
    String base = StringUtils.removeEnd(baseUrl, URL_PATH_SEPARATOR);
    List<String> urls = new ArrayList<String>();
    for (String url : files) {
        //replace amp&; with &
        url = url.replaceAll("&amp;", "&");
        if (!url.startsWith("http")) {
            if (url.startsWith(".")) {
                String relativePath = url.startsWith("..") ? url.substring(2) : url.substring(1);
                urls.add(currentURL + relativePath);
            } else {
                //Check if / is needed as we striped / from the base url.
                String path = url.startsWith(URL_PATH_SEPARATOR) ? base + url : base + URL_PATH_SEPARATOR + url;
                urls.add(path);
            }
        } else {
            urls.add(url);
        }
    }
    return urls;
}

From source file:org.apache.cassandra.locator.PropertyFileSnitch.java

public void reloadConfiguration(boolean isUpdate) throws ConfigurationException {
    HashMap<InetAddress, String[]> reloadedMap = new HashMap<>();
    String[] reloadedDefaultDCRack = null;

    Properties properties = new Properties();
    try (InputStream stream = getClass().getClassLoader().getResourceAsStream(SNITCH_PROPERTIES_FILENAME)) {
        properties.load(stream);/*from ww  w  . j  a v a2  s  .c  o  m*/
    } catch (Exception e) {
        throw new ConfigurationException("Unable to read " + SNITCH_PROPERTIES_FILENAME, e);
    }

    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();

        if ("default".equals(key)) {
            String[] newDefault = value.split(":");
            if (newDefault.length < 2)
                reloadedDefaultDCRack = new String[] { "default", "default" };
            else
                reloadedDefaultDCRack = new String[] { newDefault[0].trim(), newDefault[1].trim() };
        } else {
            InetAddress host;
            String hostString = StringUtils.remove(key, '/');
            try {
                host = InetAddress.getByName(hostString);
            } catch (UnknownHostException e) {
                throw new ConfigurationException("Unknown host " + hostString, e);
            }
            String[] token = value.split(":");
            if (token.length < 2)
                token = new String[] { "default", "default" };
            else
                token = new String[] { token[0].trim(), token[1].trim() };
            reloadedMap.put(host, token);
        }
    }
    if (reloadedDefaultDCRack == null && !reloadedMap.containsKey(FBUtilities.getBroadcastAddress()))
        throw new ConfigurationException(String.format(
                "Snitch definitions at %s do not define a location for "
                        + "this node's broadcast address %s, nor does it provides a default",
                SNITCH_PROPERTIES_FILENAME, FBUtilities.getBroadcastAddress()));

    if (isUpdate && !livenessCheck(reloadedMap, reloadedDefaultDCRack))
        return;

    if (logger.isTraceEnabled()) {
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<InetAddress, String[]> entry : reloadedMap.entrySet())
            sb.append(entry.getKey()).append(':').append(Arrays.toString(entry.getValue())).append(", ");
        logger.trace("Loaded network topology from property file: {}",
                StringUtils.removeEnd(sb.toString(), ", "));
    }

    defaultDCRack = reloadedDefaultDCRack;
    endpointMap = reloadedMap;
    if (StorageService.instance != null) // null check tolerates circular dependency; see CASSANDRA-4145
    {
        if (isUpdate)
            StorageService.instance.updateTopology();
        else
            StorageService.instance.getTokenMetadata().invalidateCachedRings();
    }

    if (gossipStarted)
        StorageService.instance.gossipSnitchInfo();
}

From source file:org.apache.cxf.jaxrs.openapi.OpenApiCustomizer.java

public OpenAPIConfiguration customize(final OpenAPIConfiguration configuration) {
    if (configuration == null) {
        return configuration;
    }//from w  w w . j  a  v a2s . c  o  m

    if (dynamicBasePath) {
        final MessageContext ctx = createMessageContext();

        // If the JAX-RS application with custom path is defined, it might be present twice, in the 
        // request URI as well as in each resource operation URI. To properly represent server URL, 
        // the application path should be removed from it.
        final String url = StringUtils.removeEnd(
                StringUtils.substringBeforeLast(ctx.getUriInfo().getRequestUri().toString(), "/"),
                applicationPath);

        final Collection<Server> servers = configuration.getOpenAPI().getServers();
        if (servers == null || servers.stream().noneMatch(s -> s.getUrl().equalsIgnoreCase(url))) {
            configuration.getOpenAPI().setServers(Collections.singletonList(new Server().url(url)));
        }
    }

    return configuration;
}

From source file:org.apache.falcon.catalog.CatalogPartitionHandler.java

protected List<String> getDynamicPartitions(Path path, Path staticPath) {
    String dynPart = path.toUri().getPath().substring(staticPath.toString().length());
    dynPart = StringUtils.removeStart(dynPart, "/");
    dynPart = StringUtils.removeEnd(dynPart, "/");
    if (StringUtils.isEmpty(dynPart)) {
        return new ArrayList<String>();
    }/*from   w  ww .  j ava  2s .  c om*/
    return Arrays.asList(dynPart.split("/"));
}

From source file:org.apache.falcon.extensions.mirroring.hdfs.HdfsMirroringExtension.java

@Override
public Properties getAdditionalProperties(final Properties extensionProperties) throws FalconException {
    Properties additionalProperties = new Properties();

    // Add default properties if not passed
    String distcpMaxMaps = extensionProperties.getProperty(HdfsMirroringExtensionProperties.MAX_MAPS.getName());
    if (StringUtils.isBlank(distcpMaxMaps)) {
        additionalProperties.put(HdfsMirroringExtensionProperties.MAX_MAPS.getName(), "1");
    }/*from  w ww. jav  a 2 s  .  co m*/

    String distcpMapBandwidth = extensionProperties
            .getProperty(HdfsMirroringExtensionProperties.MAP_BANDWIDTH_IN_MB.getName());
    if (StringUtils.isBlank(distcpMapBandwidth)) {
        additionalProperties.put(HdfsMirroringExtensionProperties.MAP_BANDWIDTH_IN_MB.getName(), "100");
    }

    // Construct fully qualified hdfs src path
    String srcPaths = extensionProperties.getProperty(HdfsMirroringExtensionProperties.SOURCE_DIR.getName());
    StringBuilder absoluteSrcPaths = new StringBuilder();
    String sourceClusterName = extensionProperties
            .getProperty(HdfsMirroringExtensionProperties.SOURCE_CLUSTER.getName());

    // Since source cluster get read interface
    Cluster srcCluster = ClusterHelper.getCluster(sourceClusterName);
    if (srcCluster == null) {
        throw new FalconException("Cluster entity " + sourceClusterName + " not found");
    }
    String srcClusterEndPoint = ClusterHelper.getReadOnlyStorageUrl(srcCluster);

    if (StringUtils.isNotBlank(srcPaths)) {
        String[] paths = srcPaths.split(COMMA_SEPARATOR);

        for (String path : paths) {
            StringBuilder srcpath = new StringBuilder(srcClusterEndPoint);
            srcpath.append(path.trim());
            srcpath.append(COMMA_SEPARATOR);
            absoluteSrcPaths.append(srcpath);
        }
    }

    additionalProperties.put(HdfsMirroringExtensionProperties.SOURCE_DIR.getName(),
            StringUtils.removeEnd(absoluteSrcPaths.toString(), COMMA_SEPARATOR));

    // add sourceClusterFS and targetClusterFS
    additionalProperties.put(HdfsMirroringExtensionProperties.SOURCE_CLUSTER_FS_WRITE_ENDPOINT.getName(),
            ClusterHelper.getStorageUrl(srcCluster));

    String targetClusterName = extensionProperties
            .getProperty(HdfsMirroringExtensionProperties.TARGET_CLUSTER.getName());

    Cluster targetCluster = ClusterHelper.getCluster(targetClusterName);
    if (targetCluster == null) {
        throw new FalconException("Cluster entity " + targetClusterName + " not found");
    }
    additionalProperties.put(HdfsMirroringExtensionProperties.TARGET_CLUSTER_FS_WRITE_ENDPOINT.getName(),
            ClusterHelper.getStorageUrl(targetCluster));
    return additionalProperties;
}

From source file:org.apache.falcon.recipe.HdfsReplicationRecipeTool.java

@Override
public Properties getAdditionalSystemProperties(final Properties recipeProperties) {
    Properties additionalProperties = new Properties();

    // Construct fully qualified hdfs src path
    String srcPaths = recipeProperties
            .getProperty(HdfsReplicationRecipeToolOptions.REPLICATION_SOURCE_DIR.getName());
    StringBuilder absoluteSrcPaths = new StringBuilder();
    String srcFsPath = recipeProperties.getProperty(
            HdfsReplicationRecipeToolOptions.REPLICATION_SOURCE_CLUSTER_FS_WRITE_ENDPOINT.getName());
    if (StringUtils.isNotEmpty(srcFsPath)) {
        srcFsPath = StringUtils.removeEnd(srcFsPath, File.separator);
    }/*ww  w .j  a  va 2s  . co  m*/
    if (StringUtils.isNotEmpty(srcPaths)) {
        String[] paths = srcPaths.split(COMMA_SEPARATOR);

        for (String path : paths) {
            StringBuilder srcpath = new StringBuilder(srcFsPath);
            srcpath.append(path.trim());
            srcpath.append(COMMA_SEPARATOR);
            absoluteSrcPaths.append(srcpath);
        }
    }

    additionalProperties.put(HdfsReplicationRecipeToolOptions.REPLICATION_SOURCE_DIR.getName(),
            StringUtils.removeEnd(absoluteSrcPaths.toString(), COMMA_SEPARATOR));
    return additionalProperties;
}