List of usage examples for org.apache.commons.lang StringUtils substringBefore
public static String substringBefore(String str, String separator)
Gets the substring before the first occurrence of a separator.
From source file:org.betaconceptframework.astroboa.util.PropertyPath.java
private String getFirstPath(String path) { String substringBefore = StringUtils.substringBefore(path, CmsConstants.PERIOD_DELIM); return (StringUtils.isBlank(substringBefore) ? null : substringBefore); }
From source file:org.cloudifysource.dsl.utils.IPUtils.java
/** * Chechs if the given address is an IPv6 address. * @param ipAddress IP address//from w ww . j a v a 2 s . co m * @return True is the address represents and IPv6 address, False otherwise */ public static boolean isIPv6Address(final String ipAddress) { boolean isIPv6 = false; String strippedIp = StringUtils.strip(ipAddress, "[]"); if (strippedIp.indexOf(NETWORK_INTERFACE_SEPARATOR) > -1) { strippedIp = StringUtils.substringBefore(strippedIp, NETWORK_INTERFACE_SEPARATOR); } try { IPv6Address.fromString(strippedIp); isIPv6 = true; } catch (IllegalArgumentException e) { //this is not a valid IPv6 address } return isIPv6; }
From source file:org.cloudifysource.dsl.utils.IPUtils.java
/** * Returns a "safe" formatted IP address - IPv4 addresses are not changed, * IPv6 addresses may change - if they include an "interface" section it is removed, * and the address itself is surrounded by brackets ("[]") to allow for port concatenation. * @param ipAddress The ipAddress to handle * @return an IP address, "safe" for concatenation. */// w w w .j a v a2 s .c om public static String getSafeIpAddress(final String ipAddress) { String safeIpAddress; try { String strippedIp = StringUtils.strip(ipAddress, "[]"); strippedIp = StringUtils.substringBefore(strippedIp, NETWORK_INTERFACE_SEPARATOR); IPv6Address.fromString(strippedIp); //verifies this is an IPv6 address safeIpAddress = "[" + strippedIp + "]"; } catch (IllegalArgumentException e) { //this is not a valid IPv6 address, assume this is IPv4 or host name, leave as is safeIpAddress = ipAddress; } return safeIpAddress; }
From source file:org.cloudifysource.esc.driver.provisioning.jclouds.DefaultProvisioningDriver.java
private String getOpenstackLocationByHardwareId(final String hardwareId) { String region = ""; if (hardwareId.indexOf("/") == -1) { logger.info("HardwareId is: " + hardwareId + ". It must be formatted " + "as region / profile id"); throw new IllegalArgumentException( "HardwareId is: " + hardwareId + ". It must be formatted " + "as region / profile id"); }//from w w w. j a v a 2 s .c o m region = StringUtils.substringBefore(hardwareId, "/"); if (StringUtils.isBlank(region)) { logger.info("HardwareId " + hardwareId + " is missing the region name. It must be formatted " + "as region / profile id"); throw new IllegalArgumentException( "HardwareId is: " + hardwareId + ". It must be formatted " + "as region / profile id"); } logger.fine("region: " + region); return region; }
From source file:org.cloudifysource.esc.driver.provisioning.storage.openstack.OpenstackStorageDriver.java
private String getRegionFromHardwareId(final String hardwareId) { String region = ""; if (hardwareId.indexOf("/") == -1) { logger.info("HardwareId is: " + hardwareId + ". It must be formatted " + "as region / profile id"); throw new IllegalArgumentException( "HardwareId is: " + hardwareId + ". It must be formatted " + "as region / profile id"); }//from www .j ava2s. c om region = StringUtils.substringBefore(hardwareId, "/"); if (StringUtils.isBlank(region)) { logger.info("HardwareId " + hardwareId + " is missing the region name. It must be formatted " + "as region / profile id"); throw new IllegalArgumentException( "HardwareId is: " + hardwareId + ". It must be formatted " + "as region / profile id"); } logger.fine("region: " + region); return region; }
From source file:org.cloudifysource.quality.iTests.framework.utils.network.OpenstackNetworkApiHelper.java
public synchronized String getValidSubnetRange(final String basicRange) throws Exception { boolean rangeInConflict = false; int rangesTested = 1; String subnetBasicIP = StringUtils.substringBefore(basicRange, CIDR_SEPARATOR); Set<String> SubnetRangesAlreadyInUse = new HashSet<String>(); // validate the subnet range formatting validateSubnetRangeFormatting(basicRange); // retrieve from the cloud all the subnets already being used by this tenant List<Subnet> existingSubnets = networkClient.getSubnets(); for (Subnet subnet : existingSubnets) { String existingIP = StringUtils.substringBefore(subnet.getCidr(), CIDR_SEPARATOR); SubnetRangesAlreadyInUse.add(existingIP); }//from ww w. j a va 2s . c o m rangeInConflict = SubnetRangesAlreadyInUse.contains(subnetBasicIP); // if the subnet range is already being used - find another free range while (rangeInConflict && rangesTested <= NUM_OF_POSSIBLE_SUBNET_RANGES) { rangesTested++; subnetBasicIP = getNextRange(subnetBasicIP); rangeInConflict = SubnetRangesAlreadyInUse.contains(subnetBasicIP); } if (rangeInConflict) { throw new Exception("Failed to find a valid subnet range based on starting range: " + basicRange); } return subnetBasicIP; }
From source file:org.codehaus.groovy.grails.context.support.PluginAwareResourceBundleMessageSource.java
public void afterPropertiesSet() throws Exception { if (pluginManager == null || localResourceLoader == null) { return;/*w w w.java 2s. co m*/ } for (GrailsPlugin plugin : pluginManager.getAllPlugins()) { for (Resource pluginBundle : getPluginBundles(plugin)) { // If the plugin is an inline plugin, use the abosolute path to the plugin's i18n files. // Otherwise, use the relative path to the plugin from the application's perspective. String basePath; if (isInlinePlugin(plugin)) { basePath = getInlinePluginPath(plugin); } else { basePath = WEB_INF_PLUGINS_PATH.substring(1) + plugin.getFileSystemName(); } final String baseName = StringUtils .substringBefore(FilenameUtils.getBaseName(pluginBundle.getFilename()), "_"); pluginBaseNames.add(basePath + "/grails-app/i18n/" + baseName); } } }
From source file:org.codehaus.groovy.grails.support.DevelopmentResourceLoader.java
/** * Retrieves the real location of a GSP within a Grails project. * @param location The location of the GSP at deployment time * @return The location of the GSP at development time *///from ww w.j av a2 s .c om protected String getRealLocationInProject(String location) { if (new File(location).exists()) { return "file:" + location; } // don't mess with locations that are URLs (in other words, locations that have schemes) if (HAS_SCHEME_PATTERN.matcher(location).matches()) return location; if (!location.startsWith(SLASH)) location = SLASH + location; // don't mess with locations that are URLs (in other words, locations that have schemes) if (HAS_SCHEME_PATTERN.matcher(location).matches()) return location; // If the location (minus the "grails-app/.*" ending so that it matches the key value used in BuildSettings for // the inline plugin map) matches an "inline" plugin, use the location as-is // for the resource location. Otherwise, perform the logic to "normalize" the resource location based on // its relativity to the application (i.e. is it from a non-inline plugin, etc). if (BuildSettingsHolder.getSettings() .isInlinePluginLocation(new File(location.replaceAll(GRAILS_APP_DIR_PATTERN, "")))) { return "file:" + location; } if (!location.startsWith(GrailsResourceUtils.WEB_INF)) { return GrailsResourceUtils.WEB_APP_DIR + location; } final String noWebInf = location.substring(GrailsResourceUtils.WEB_INF.length() + 1); final String defaultPath = "file:" + baseLocation + SLASH + noWebInf; if (!noWebInf.startsWith(PLUGINS_PREFIX)) { return defaultPath; } if (application != null) { BuildSettings settings = BuildSettingsHolder.getSettings(); PluginBuildSettings pluginBuildSettings = org.codehaus.groovy.grails.plugins.GrailsPluginUtils .getPluginBuildSettings(); String pluginPath = StringUtils.substringAfter(noWebInf, SLASH); String pluginName = StringUtils.substringBefore(pluginPath, SLASH); String remainingPath = StringUtils.substringAfter(pluginPath, SLASH); org.codehaus.groovy.grails.io.support.Resource r = pluginBuildSettings.getPluginDirForName(pluginName); if (r != null) { try { return "file:" + r.getFile().getAbsolutePath() + SLASH + remainingPath; } catch (IOException e) { LOG.debug("Unable to locate plugin resource -- returning default path " + defaultPath + ".", e); return defaultPath; } } if (settings != null) { return "file:" + settings.getProjectPluginsDir().getAbsolutePath() + SLASH + pluginName + SLASH + remainingPath; } } return defaultPath; }
From source file:org.codice.alliance.catalog.transformer.mgmp.MgmpTransformer.java
private void addMetacardReleasabilityAndDisseminationControls(String caveatString, MetacardImpl metacard, String releasability, String disseminationControls) { if (caveatString.startsWith(MgmpConstants.RELEASABLE_TO)) { String[] nations = StringUtils.substringAfter(caveatString, MgmpConstants.RELEASABLE_TO + " ") .split(COUNTRY_SEPARATOR); List<String> nationsList = Arrays.asList(nations); metacard.setAttribute(releasability, (Serializable) nationsList); metacard.setAttribute(disseminationControls, MgmpConstants.RELEASABLE_TO); } else if (caveatString.endsWith(MgmpConstants.EYES_ONLY)) { String[] nations = StringUtils.substringBefore(caveatString, " " + MgmpConstants.EYES_ONLY) .split(COUNTRY_SEPARATOR); List<String> nationsList = Arrays.asList(nations); metacard.setAttribute(releasability, (Serializable) nationsList); metacard.setAttribute(disseminationControls, MgmpConstants.EYES_ONLY); } else if (caveatString.endsWith(MgmpConstants.EYES_DISCRETION)) { String[] nations = StringUtils.substringBefore(caveatString, " " + MgmpConstants.EYES_DISCRETION) .split(COUNTRY_SEPARATOR); List<String> nationsList = Arrays.asList(nations); metacard.setAttribute(releasability, (Serializable) nationsList); metacard.setAttribute(disseminationControls, MgmpConstants.EYES_DISCRETION); }/*from w ww. j ava 2 s . c o m*/ }
From source file:org.codice.ddf.registry.source.configuration.SourceConfigurationHandler.java
public synchronized void setBindingTypeFactoryPid(List<String> bindingTypeFactoryPid) { bindingTypeToFactoryPidMap.clear();//from w ww .j ava 2 s . com for (String mapping : bindingTypeFactoryPid) { String bindingType = StringUtils.substringBefore(mapping, "="); String factoryPid = StringUtils.substringAfter(mapping, "="); if (StringUtils.isNotBlank(bindingType) && StringUtils.isNotBlank(factoryPid)) { bindingTypeToFactoryPidMap.put(bindingType, factoryPid); } } }