List of usage examples for org.apache.commons.lang3.text StrLookup StrLookup
protected StrLookup()
From source file:com.cybernostics.jsp2thymeleaf.api.util.AlternateFormatStrings.java
private static Set<String> getRequiredValuesForFormat(String candidateFormat) { Set<String> requiredVariables = new HashSet<>(); StrSubstitutor ss = SimpleStringTemplateProcessor.getSubstitutor(new StrLookup<String>() { @Override//w w w .j a v a 2s .c o m public String lookup(String key) { final ValueDefaultAndFilter keyDefaultFilter = ValueDefaultAndFilter.parse(key); if (keyDefaultFilter.isRequired()) { requiredVariables.add(keyDefaultFilter.getName()); } return ""; } }); ss.replace(candidateFormat); // do a dummy replace to find out what's needed return requiredVariables; }
From source file:io.fabric8.karaf.core.properties.PlaceholderResolverImpl.java
public PlaceholderResolverImpl() { this.functions = new CopyOnWriteArrayList<>(); this.substitutor = Support.createStrSubstitutor( getSystemPropertyOrEnvVar(PLACEHOLDER_PREFIX, DEFAULT_PLACEHOLDER_PREFIX), getSystemPropertyOrEnvVar(PLACEHOLDER_SUFFIX, DEFAULT_PLACEHOLDER_SUFFIX), new StrLookup<String>() { @Override//from ww w. jav a 2s . co m public String lookup(String value) { return resolve(value); } }); }
From source file:edu.sdsc.scigraph.internal.CypherUtil.java
static String substituteRelationships(String query, final Multimap<String, Object> valueMap) { StrSubstitutor substitutor = new StrSubstitutor(new StrLookup<String>() { @Override/*from www . j a v a2s . c om*/ public String lookup(String key) { return on('|').join(valueMap.get(key)); } }); return substitutor.replace(query); }
From source file:io.scigraph.internal.CypherUtil.java
String substituteRelationships(String query, final Multimap<String, Object> valueMap) { StrSubstitutor substitutor = new StrSubstitutor(new StrLookup<String>() { @Override/* ww w. j a va 2 s . c om*/ public String lookup(String key) { Collection<String> resolvedRelationshipTypes = transform(valueMap.get(key), new Function<Object, String>() { @Override public String apply(Object input) { if (input.toString().matches(".*(\\s).*")) { throw new IllegalArgumentException( "Cypher relationship templates must not contain spaces"); } return curieUtil.getIri(input.toString()).or(input.toString()); } }); return on("|").join(resolvedRelationshipTypes); } }); return substitutor.replace(query); }
From source file:com.haulmont.cuba.web.testsupport.TestContainer.java
protected void initAppProperties() { final Properties properties = new Properties(); List<String> locations = getAppPropertiesFiles(); DefaultResourceLoader resourceLoader = new DefaultResourceLoader(); for (String location : locations) { Resource resource = resourceLoader.getResource(location); if (resource.exists()) { InputStream stream = null; try { stream = resource.getInputStream(); properties.load(stream); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(stream); }//from ww w . ja va 2s . c o m } else { log.warn("Resource " + location + " not found, ignore it"); } } StrSubstitutor substitutor = new StrSubstitutor(new StrLookup() { @Override public String lookup(String key) { String subst = properties.getProperty(key); return subst != null ? subst : System.getProperty(key); } }); for (Object key : properties.keySet()) { String value = substitutor.replace(properties.getProperty((String) key)); appProperties.put((String) key, value); } File dir; dir = new File(appProperties.get("cuba.confDir")); dir.mkdirs(); dir = new File(appProperties.get("cuba.logDir")); dir.mkdirs(); dir = new File(appProperties.get("cuba.tempDir")); dir.mkdirs(); dir = new File(appProperties.get("cuba.dataDir")); dir.mkdirs(); AppContext.setProperty(AppConfig.CLIENT_TYPE_PROP, ClientType.WEB.toString()); }
From source file:co.jirm.orm.writer.SqlWriterStrategy.java
public String replacePropertyPaths(final SqlObjectDefinition<?> definition, final String sql) { StrLookup<String> lookup = new StrLookup<String>() { @Override/* ww w . j a v a 2 s . c o m*/ public String lookup(String key) { Optional<String> p = parameterPathToSql(definition, key); check.state(p.isPresent(), "Invalid object path: {}", key); return p.get(); } }; StrSubstitutor s = new StrSubstitutor(lookup, "{{", "}}", '$'); String result = s.replace(sql); return result; }
From source file:co.jirm.orm.writer.SqlWriterStrategy.java
public String replaceProperties(final SqlObjectDefinition<?> definition, final String sql) { StrLookup<String> lookup = new StrLookup<String>() { @Override/*w ww. j a v a 2 s . c om*/ public String lookup(String key) { Optional<String> sqlName = definition.parameterNameToSql(key); check.state(sqlName.isPresent(), "Property: {} not found in object.", key); return sqlName.get(); } }; StrSubstitutor s = new StrSubstitutor(lookup, "{{", "}}", '$'); String result = s.replace(sql); return result; }
From source file:org.apache.tomee.embedded.Configuration.java
public void loadFromProperties(final Properties config) { // filtering properties with system properties or themself final StrSubstitutor strSubstitutor = new StrSubstitutor(new StrLookup<String>() { @Override/*from w w w . ja va2 s. c o m*/ public String lookup(final String key) { final String property = System.getProperty(key); return property == null ? config.getProperty(key) : null; } }); for (final String key : config.stringPropertyNames()) { final String val = config.getProperty(key); if (val == null || val.trim().isEmpty()) { continue; } final String newVal = strSubstitutor.replace(config.getProperty(key)); if (!val.equals(newVal)) { config.setProperty(key, newVal); } } final String http = config.getProperty("http"); if (http != null) { setHttpPort(Integer.parseInt(http)); } final String https = config.getProperty("https"); if (https != null) { setHttpsPort(Integer.parseInt(https)); } final String stop = config.getProperty("stop"); if (stop != null) { setStopPort(Integer.parseInt(stop)); } final String host = config.getProperty("host"); if (host != null) { setHost(host); } final String dir = config.getProperty("dir"); if (dir != null) { setDir(dir); } final String serverXml = config.getProperty("serverXml"); if (serverXml != null) { setServerXml(serverXml); } final String keepServerXmlAsThis = config.getProperty("keepServerXmlAsThis"); if (keepServerXmlAsThis != null) { setKeepServerXmlAsThis(Boolean.parseBoolean(keepServerXmlAsThis)); } final String quickSession = config.getProperty("quickSession"); if (quickSession != null) { setQuickSession(Boolean.parseBoolean(quickSession)); } final String skipHttp = config.getProperty("skipHttp"); if (skipHttp != null) { setSkipHttp(Boolean.parseBoolean(skipHttp)); } final String ssl = config.getProperty("ssl"); if (ssl != null) { setSsl(Boolean.parseBoolean(ssl)); } final String http2 = config.getProperty("http2"); if (http2 != null) { setHttp2(Boolean.parseBoolean(http2)); } final String deleteBaseOnStartup = config.getProperty("deleteBaseOnStartup"); if (deleteBaseOnStartup != null) { setDeleteBaseOnStartup(Boolean.parseBoolean(deleteBaseOnStartup)); } final String webResourceCached = config.getProperty("webResourceCached"); if (webResourceCached != null) { setWebResourceCached(Boolean.parseBoolean(webResourceCached)); } final String withEjbRemote = config.getProperty("withEjbRemote"); if (withEjbRemote != null) { setWithEjbRemote(Boolean.parseBoolean(withEjbRemote)); } final String deployOpenEjbApp = config.getProperty("deployOpenEjbApp"); if (deployOpenEjbApp != null) { setDeployOpenEjbApp(Boolean.parseBoolean(deployOpenEjbApp)); } final String keystoreFile = config.getProperty("keystoreFile"); if (keystoreFile != null) { setKeystoreFile(keystoreFile); } final String keystorePass = config.getProperty("keystorePass"); if (keystorePass != null) { setKeystorePass(keystorePass); } final String keystoreType = config.getProperty("keystoreType"); if (keystoreType != null) { setKeystoreType(keystoreType); } final String clientAuth = config.getProperty("clientAuth"); if (clientAuth != null) { setClientAuth(clientAuth); } final String keyAlias = config.getProperty("keyAlias"); if (keyAlias != null) { setKeyAlias(keyAlias); } final String sslProtocol = config.getProperty("sslProtocol"); if (sslProtocol != null) { setSslProtocol(sslProtocol); } final String webXml = config.getProperty("webXml"); if (webXml != null) { setWebXml(webXml); } final String tempDir = config.getProperty("tempDir"); if (tempDir != null) { setTempDir(tempDir); } final String customWebResources = config.getProperty("customWebResources"); if (customWebResources != null) { setCustomWebResources(customWebResources); } final String classesFilterType = config.getProperty("classesFilter"); if (classesFilterType != null) { try { setClassesFilter(Filter.class.cast( Thread.currentThread().getContextClassLoader().loadClass(classesFilterType).newInstance())); } catch (final InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new IllegalArgumentException(e); } } final String conf = config.getProperty("conf"); if (conf != null) { setConf(conf); } for (final String prop : config.stringPropertyNames()) { if (prop.startsWith("properties.")) { property(prop.substring("properties.".length()), config.getProperty(prop)); } else if (prop.startsWith("users.")) { user(prop.substring("users.".length()), config.getProperty(prop)); } else if (prop.startsWith("roles.")) { role(prop.substring("roles.".length()), config.getProperty(prop)); } else if (prop.startsWith("connector.")) { // created in container property(prop, config.getProperty(prop)); } else if (prop.equals("realm")) { final ObjectRecipe recipe = new ObjectRecipe(config.getProperty(prop)); for (final String realmConfig : config.stringPropertyNames()) { if (realmConfig.startsWith("realm.")) { recipe.setProperty(realmConfig.substring("realm.".length()), config.getProperty(realmConfig)); } } setRealm(Realm.class.cast(recipe.create())); } else if (prop.equals("login")) { final ObjectRecipe recipe = new ObjectRecipe(LoginConfigBuilder.class.getName()); for (final String nestedConfig : config.stringPropertyNames()) { if (nestedConfig.startsWith("login.")) { recipe.setProperty(nestedConfig.substring("login.".length()), config.getProperty(nestedConfig)); } } loginConfig(LoginConfigBuilder.class.cast(recipe.create())); } else if (prop.equals("securityConstraint")) { final ObjectRecipe recipe = new ObjectRecipe(SecurityConstaintBuilder.class.getName()); for (final String nestedConfig : config.stringPropertyNames()) { if (nestedConfig.startsWith("securityConstraint.")) { recipe.setProperty(nestedConfig.substring("securityConstraint.".length()), config.getProperty(nestedConfig)); } } securityConstaint(SecurityConstaintBuilder.class.cast(recipe.create())); } else if (prop.equals("configurationCustomizer.")) { final String next = prop.substring("configurationCustomizer.".length()); if (next.contains(".")) { continue; } final ObjectRecipe recipe = new ObjectRecipe(properties.getProperty(prop + ".class")); for (final String nestedConfig : config.stringPropertyNames()) { if (nestedConfig.startsWith(prop) && !prop.endsWith(".class")) { recipe.setProperty(nestedConfig.substring(prop.length() + 1 /*dot*/), config.getProperty(nestedConfig)); } } addCustomizer(ConfigurationCustomizer.class.cast(recipe.create())); } } }
From source file:org.epics.archiverappliance.config.StoragePluginURLParser.java
/** * Expands macros in the plugin definition strings. * Checks java.system.properties first (passed in with a -D to the JVM) * Then checks the environment (for example, using export in Linux). * If we are not able to match in either place, we return as is. * // w ww .ja v a 2 s . c o m * For example, if we did <code>export ARCHAPPL_SHORT_TERM_FOLDER=/dev/test</code>, and then used <code>pbraw://${ARCHAPPL_SHORT_TERM_FOLDER}<code> in the policy datastore definition, * these would be expanded into <code>pbraw:///dev/test<code></code> * @param srcURIStr * @return */ private static String expandMacros(String srcURIStr) { StrSubstitutor sub = new StrSubstitutor(new StrLookup<String>() { @Override public String lookup(String name) { String valueFromProps = System.getProperty(name); if (valueFromProps != null) { if (logger.isDebugEnabled()) logger.debug("Resolving " + name + " from system properties into " + valueFromProps); return valueFromProps; } String valueFromEnvironment = System.getenv(name); if (valueFromEnvironment != null) { if (logger.isDebugEnabled()) logger.debug("Resolving " + name + " from system environment into " + valueFromEnvironment); return valueFromEnvironment; } logger.error("Unable to find " + name + " in either the java system properties or the system environment. Returning as is without expanding"); return name; } }); return sub.replace(srcURIStr); }
From source file:org.lucidj.gluon.GluonWriter.java
public GluonWriter(Writer writer) { this.writer = writer; // Initialize our very exclusive macro processor :) macro_subst = new StrSubstitutor(new StrLookup() { @Override//from ww w. j a v a2 s .com public String lookup(String s) { if (s.equals("attr.name")) { return (macro_attr_name); } else if (s.equals("attr.value")) { return (macro_attr_value); } else if (s.equals("attr.operator")) { return (macro_attr_operator); } return (null); } }); }