@Beta /** for transitioning away from LocationDefinition */ public static String unwrapLegacyWrappedReference(String id) { return Strings.removeFromStart(id, NAME+":"); } }
protected String getLocalType(String type) { return Strings.removeFromStart(type, prefix).trim(); }
@Deprecated public static String fixLocation(String locationId) { if (locationId.startsWith("/locations/") || locationId.startsWith("/v1/locations/")) { log.warn("REST API using legacy URI syntax for location: "+locationId); locationId = Strings.removeFromStart(locationId, "/v1/locations/"); locationId = Strings.removeFromStart(locationId, "/locations/"); } return locationId; }
/** Parse and return the ID returned from a Docker command. */ public static String checkId(String input) { // Remove hash type from start and convert to lowercase String imageId = Strings.removeFromStart(Strings.trim(input).toLowerCase(Locale.ENGLISH), SHA_256); boolean prefix = input.startsWith(SHA_256); if (imageId.length() == 64 && DOCKERFILE_CHARACTERS.matchesAllOf(imageId)) { return (prefix ? SHA_256 : "") + imageId; } else { throw new IllegalStateException("Invalid image ID returned: " + imageId); } }
/** Records an {@link AbstractEntityAdjunct#HIGHLIGHT_NAME_LAST_ACTION} with the given message, * formatted with arguments entity and either 'added', 'changed', or 'removed'. * Can be overridden to be no-op if caller wants to manage their own such highlights, * or to provide further information. See also {@link #defaultHighlightAction(EventType, Entity)}. */ protected void defaultHighlightAction(EventType type, Entity entity, String formattedMessage) { highlightAction(String.format(formattedMessage, entity, Strings.removeFromStart(type.toString().toLowerCase(), "entity_")), null); }
/** * Look for keys with <code>configPrefix</code> in <code>configBag</code> and * those which have <code>configPrefix</code> are added in <code>destinationBucket</code> but without <code>configPrefix</code>. * @param configPrefix prefix to look for * @param configBag keys to look in * @param destinationBucket should not be an ImmutableMap */ public static void addUnprefixedConfigKeyInConfigBack(String configPrefix, ConfigBag configBag, Map<String, Object> destinationBucket) { for (Map.Entry<ConfigKey<?>, ?> entry : configBag.getAllConfigAsConfigKeyMap().entrySet()) { String keyName = entry.getKey().getName(); if (keyName.startsWith(configPrefix)) { destinationBucket.put(Strings.removeFromStart(keyName, configPrefix), entry.getValue()); } } } }
public String getClassLoaderDir(String resourceInThatDir) { resourceInThatDir = Strings.removeFromStart(resourceInThatDir, "/"); URL resourceUrl = getLoader().getResource(resourceInThatDir); if (resourceUrl==null) throw new NoSuchElementException("Resource ("+resourceInThatDir+") not found"); URL containerUrl = getContainerUrl(resourceUrl, resourceInThatDir); if (!"file".equals(containerUrl.getProtocol())) throw new IllegalStateException("Resource ("+resourceInThatDir+") not on file system (at "+containerUrl+")"); //convert from file: URL to File File file; try { file = new File(containerUrl.toURI()); } catch (URISyntaxException e) { throw new IllegalStateException("Resource ("+resourceInThatDir+") found at invalid URI (" + containerUrl + ")", e); } if (!file.exists()) throw new IllegalStateException("Context class url substring ("+containerUrl+") not found on filesystem"); return file.getPath(); }
public void testRemoveFromStart2() { assertEquals(Strings.removeFromStart("xyz", "x"), "yz"); assertEquals(Strings.removeFromStart("xyz", "."), "xyz"); assertEquals(Strings.removeFromStart("http://foo.com", "http://"), "foo.com"); }
public void testRemoveFromStart() { assertEquals(Strings.removeFromStart("", "foo"), ""); assertEquals(Strings.removeFromStart(null, "foo"), null); assertEquals(Strings.removeFromStart("foobar", "foo"), "bar"); assertEquals(Strings.removeFromStart("foo", "bar"), "foo"); }
@Override public HttpExecutor getHttpExecutor(Map<?, ?> props) { HttpExecutor httpExecutor; String httpExecutorClass = (String) props.get(HTTP_EXECUTOR_CLASS_CONFIG); if (httpExecutorClass != null) { Map<String,Object> httpExecutorProps = MutableMap.of(); Map<?, ?> executorProps = Maps.filterKeys(props, StringPredicates.isStringStartingWith(HTTP_EXECUTOR_CLASS_CONFIG_PREFIX)); if (executorProps.size() > 0) { for (Entry<?, ?> entry: executorProps.entrySet()) { String keyName = Strings.removeFromStart((String)entry.getKey(), HTTP_EXECUTOR_CLASS_CONFIG_PREFIX); httpExecutorProps.put(keyName, entry.getValue()); } } try { httpExecutor = (HttpExecutor) new ClassLoaderUtils(getClass()).loadClass(httpExecutorClass).getConstructor(Map.class).newInstance(httpExecutorProps); } catch (Exception e) { throw Exceptions.propagate(e); } } else { LOG.info(HTTP_EXECUTOR_CLASS_CONFIG + " parameter not provided. Using the default implementation " + HttpExecutorImpl.class.getName()); httpExecutor = HttpExecutorImpl.newInstance(); } return httpExecutor; } }
@Override public TemplateModel get(String key) throws TemplateModelException { if (map==null) return null; try { if (map.containsKey(key)) return wrapAsTemplateModel( map.get(key) ); Map<String,Object> result = MutableMap.of(); for (Map.Entry<?,?> entry: map.entrySet()) { String k = Strings.toString(entry.getKey()); if (k.startsWith(key+".")) { String k2 = Strings.removeFromStart(k, key+"."); result.put(k2, entry.getValue()); } } if (!result.isEmpty()) return wrapAsTemplateModel( result ); } catch (Exception e) { Exceptions.propagateIfFatal(e); throw new IllegalStateException("Error accessing config '"+key+"'"+": "+e, e); } return null; }
@Override public LocationSpec<? extends Location> newLocationSpecFromString(String spec, Map<?, ?> locationFlags, LocationRegistry registry) { String name = spec; ConfigBag lfBag = ConfigBag.newInstance(locationFlags).putIfAbsent(LocationInternal.ORIGINAL_SPEC, name); name = Strings.removeFromStart(spec, getPrefix()+":"); if (name.toLowerCase().startsWith(NAMED+":")) { // since 0.7.0 log.warn("Deprecated use of 'named:' prefix with wrong case ("+spec+"); support may be removed in future versions"); name = spec.substring( (NAMED+":").length() ); } LocationDefinition ld = registry.getDefinedLocationByName(name); if (ld==null) throw new NoSuchElementException("No named location defined matching '"+name+"'"); return registry.getLocationSpec(ld, lfBag.getAllConfig()).get(); }
public PerUserEntitlementManager(BrooklynProperties properties) { this(load(properties, properties.getConfig(DEFAULT_MANAGER))); Set<ConfigKey<?>> users = properties.findKeysPresent(ConfigPredicates.nameStartsWith(PER_USER_ENTITLEMENTS_CONFIG_PREFIX+".")); for (ConfigKey<?> key: users) { if (key.getName().equals(DEFAULT_MANAGER.getName())) continue; String user = Strings.removeFromStart(key.getName(), PER_USER_ENTITLEMENTS_CONFIG_PREFIX+"."); addUser(user, load(properties, Strings.toString(properties.getConfig(key)))); } log.info(getClass().getSimpleName()+" created with "+perUserManagers.size()+" user"+Strings.s(perUserManagers)+" and " + "default "+defaultManager+" (users: "+perUserManagers+")"); }
String oldPackage = "brooklyn.web.console.security."; if (className.startsWith(oldPackage)) { className = Strings.removeFromStart(className, oldPackage); className = DelegatingSecurityProvider.class.getPackage().getName() + "." + className; clazz = (Class<? extends SecurityProvider>) clu.loadClass(className);
String keyName = entry.getKey().getName(); if (keyName.startsWith(WinRmTool.BROOKLYN_CONFIG_KEY_PREFIX)) { keyName = Strings.removeFromStart(keyName, WinRmTool.BROOKLYN_CONFIG_KEY_PREFIX); include = true; keyName = Strings.removeFromStart(keyName, WINRM_TOOL_CLASS_PROPERTIES_PREFIX); include = true;
String match = yamlExtract.withOriginalIndentation(true).withKeyIncluded(true).getMatchedYamlTextOrWarn(); if (match!=null) { if (rootItemYaml.startsWith(match)) rootItemYaml = Strings.removeFromStart(rootItemYaml, match); else rootItemYaml = Strings.replaceAllNonRegex(rootItemYaml, "\n"+match, "");
@Override protected String generateNewIdOfLength(ConfigBag setup, int len) { Object context = setup.peek(CloudLocationConfig.CALLER_CONTEXT); Entity entity = null; if (context instanceof Entity) { entity = (Entity) context; } String template = setup.get(MACHINE_NAME_TEMPLATE); String processed; if (entity == null) { processed = TemplateProcessor.processTemplateContents(template, setup.get(EXTRA_SUBSTITUTIONS)); } else { processed = TemplateProcessor.processTemplateContents(template, (EntityInternal)entity, setup.get(EXTRA_SUBSTITUTIONS)); } processed = Strings.removeFromStart(processed, "#ftl\n"); return sanitize(processed); }
@Override public void applyYamlPrimitive(PlanInterpretationNode node) { if (node.matchesLiteral("$sample:foo")) node.setNewValue("bar").exclude(); if (node.matchesPrefix("$sample:caps:")) { node.setNewValue(Strings.removeFromStart(node.getNewValue().toString(), "$sample:caps:").toUpperCase()).exclude(); } }
result.add(p); } else { result.add(Strings.removeFromStart(p, subsequentLineIndentationToRemoveS));
ld = mgmt.getLocationRegistry().getDefinedLocationByName(Strings.removeFromStart(spec, "named:")); if (ld==null) ld = mgmt.getLocationRegistry().getDefinedLocationById(lp.getId()); if (ld!=null) {