List of usage examples for org.apache.commons.lang.text StrSubstitutor StrSubstitutor
public StrSubstitutor(StrLookup variableResolver)
From source file:com.impetus.ankush2.ganglia.GangliaDeployer.java
public String getGmetadConfigurationContent(String host) throws Exception { String fileContent = null;/*from w ww .j a va 2 s.com*/ String confFileName = (String) advanceConf.get(GangliaConstants.ClusterProperties.SERVER_CONF_FOLDER) + GangliaConstants.ConfigurationFiles.GMOND_CONF; Map<String, Object> configValues = getConfigValueMap(); String udpRecvChannel = "udp_recv_channel {\n port = " + configValues.get("port") + " \n } "; configValues.put("udp_recv_channel", "/*" + udpRecvChannel + "*/"); if (((String) advanceConf.get(GangliaConstants.ClusterProperties.GMETAD_HOST)).equals(host)) { confFileName = (String) advanceConf.get(GangliaConstants.ClusterProperties.SERVER_CONF_FOLDER) + GangliaConstants.ConfigurationFiles.GMETAD_CONF; StringBuffer nodeIpPorts = new StringBuffer(); // Preparing a String of nodeIp:port of gmetad node. nodeIpPorts.append(advanceConf.get(GangliaConstants.ClusterProperties.GMETAD_HOST)) .append(Symbols.STR_COLON); nodeIpPorts.append(advanceConf.get(GangliaConstants.ClusterProperties.GANGLIA_PORT)); // Putting the nodeIpsPorts string in map configValues.put("nodeIpsPorts", nodeIpPorts.toString()); // On gmond nodes other than Gmetad node commenting // udp_recv_channel block configValues.put("udp_recv_channel", udpRecvChannel); } // Reading the content of the template file fileContent = FileUtil.readAsString(new File(confFileName)); // Creating a string substitutor using config values map StrSubstitutor sub = new StrSubstitutor(configValues); // Replacing the config values key found in the file content with // respected values. return sub.replace(fileContent); }
From source file:org.aludratest.impl.log4testing.configuration.ReflectionUtil.java
private static String substituteSystemProperties(String param) { final StrLookup systemLookup = StrLookup.systemPropertiesLookup(); final StrSubstitutor substitutor = new StrSubstitutor(systemLookup); return substitutor.replace(param); }
From source file:org.apache.maven.plugin.cxx.GenerateMojo.java
protected Map<String, String> listResourceFolderContent(String path, Map valuesMap) { String location = getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); final File jarFile = new File(location); HashMap<String, String> resources = new HashMap<String, String>(); StrSubstitutor substitutor = new StrSubstitutor(valuesMap); path = (StringUtils.isEmpty(path)) ? "" : path + "/"; getLog().debug("listResourceFolderContent : " + location + ", sublocation : " + path); if (jarFile.isFile()) { getLog().debug("listResourceFolderContent : jar case"); try {// w w w.ja v a 2s .c o m final JarFile jar = new JarFile(jarFile); final Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { final String name = entries.nextElement().getName(); if (name.startsWith(path)) { String resourceFile = File.separator + name; if (!(resourceFile.endsWith("/") || resourceFile.endsWith("\\"))) { getLog().debug("resource entry = " + resourceFile); String destFile = substitutor.replace(resourceFile); getLog().debug("become entry = " + destFile); resources.put(resourceFile, destFile); } } } jar.close(); } catch (IOException ex) { getLog().error("unable to list jar content : " + ex); } } else { getLog().debug("listResourceFolderContent : file case"); //final URL url = Launcher.class.getResource("/" + path); final URL url = getClass().getResource("/" + path); if (url != null) { try { final File names = new File(url.toURI()); Collection<File> entries = FileUtils.listFiles(names, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); for (File name : entries) { String resourceFile = name.getPath(); if (!(resourceFile.endsWith("/") || resourceFile.endsWith("\\"))) { getLog().debug("resource entry = " + resourceFile); String destFile = substitutor.replace(resourceFile); destFile = destFile.replaceFirst(Pattern.quote(location), "/"); getLog().debug("become entry = " + destFile); resources.put(resourceFile, destFile); } } } catch (URISyntaxException ex) { // never happens } } } return resources; }
From source file:org.apache.maven.surefire.its.fixture.MavenLauncher.java
public OutputValidator executeCurrentGoals() { String userLocalRepo = System.getProperty("user.localRepository"); String testBuildDirectory = System.getProperty("testBuildDirectory"); boolean useInterpolatedSettings = Boolean.getBoolean("useInterpolatedSettings"); try {/* www . j a v a2 s. c o m*/ if (useInterpolatedSettings) { File interpolatedSettings = new File(testBuildDirectory, "interpolated-settings"); if (!interpolatedSettings.exists()) { // hack "a la" invoker plugin to download dependencies from local repo // and not download from central Map<String, String> values = new HashMap<String, String>(1); values.put("localRepositoryUrl", toUrl(userLocalRepo)); StrSubstitutor strSubstitutor = new StrSubstitutor(values); String fileContent = FileUtils.fileRead(new File(testBuildDirectory, "settings.xml")); String filtered = strSubstitutor.replace(fileContent); FileUtils.fileWrite(interpolatedSettings.getAbsolutePath(), filtered); } addCliOption("-s " + interpolatedSettings.getCanonicalPath()); } getVerifier().setCliOptions(cliOptions); getVerifier().executeGoals(goals, envvars); return getValidator(); } catch (IOException e) { throw new SurefireVerifierException(e.getMessage(), e); } catch (VerificationException e) { throw new SurefireVerifierException(e.getMessage(), e); } finally { getVerifier().resetStreams(); } }
From source file:org.apache.maven.surefire.its.fixture.SurefireLauncher.java
public OutputValidator executeCurrentGoals() { String userLocalRepo = System.getProperty("user.localRepository"); String testBuildDirectory = System.getProperty("testBuildDirectory"); boolean useInterpolatedSettings = Boolean.getBoolean("useInterpolatedSettings"); try {//from www .j av a 2s . c o m if (useInterpolatedSettings) { File interpolatedSettings = new File(testBuildDirectory, "interpolated-settings"); if (!interpolatedSettings.exists()) { // hack "a la" invoker plugin to download dependencies from local repo // and not download from central Map<String, String> values = new HashMap<String, String>(1); values.put("localRepositoryUrl", toUrl(userLocalRepo)); StrSubstitutor strSubstitutor = new StrSubstitutor(values); String fileContent = FileUtils.fileRead(new File(testBuildDirectory, "settings.xml")); String filtered = strSubstitutor.replace(fileContent); FileUtils.fileWrite(interpolatedSettings.getAbsolutePath(), filtered); } cliOptions.add("-s " + interpolatedSettings.getCanonicalPath()); } verifier.setCliOptions(cliOptions); verifier.executeGoals(goals, envvars); return surefireVerifier; } catch (IOException e) { throw new SurefireVerifierException(e.getMessage(), e); } catch (VerificationException e) { throw new SurefireVerifierException(e.getMessage(), e); } finally { verifier.resetStreams(); } }
From source file:org.apache.sentry.core.common.utils.PathUtils.java
public static boolean impliesURI(String privilege, String request) { try {/* w w w. java2 s . c om*/ URI privilegeURI = new URI(new StrSubstitutor(System.getProperties()).replace(privilege)); URI requestURI = new URI(request); if (privilegeURI.getScheme() == null || privilegeURI.getPath() == null) { LOGGER.warn("Privilege URI " + request + " is not valid. Either no scheme or no path."); return false; } if (requestURI.getScheme() == null || requestURI.getPath() == null) { LOGGER.warn("Request URI " + request + " is not valid. Either no scheme or no path."); return false; } return PathUtils.impliesURI(privilegeURI, requestURI); } catch (URISyntaxException e) { LOGGER.warn("Request URI " + request + " is not a URI", e); return false; } }
From source file:org.apache.sentry.policy.db.DBWildcardPermission.java
@VisibleForTesting protected static boolean impliesURI(String privilege, String request) { try {/*from w ww. ja v a 2 s .co m*/ URI privilegeURI = new URI(new StrSubstitutor(System.getProperties()).replace(privilege)); URI requestURI = new URI(request); if (privilegeURI.getScheme() == null || privilegeURI.getPath() == null) { LOGGER.warn("Privilege URI " + request + " is not valid. Either no scheme or no path."); return false; } if (requestURI.getScheme() == null || requestURI.getPath() == null) { LOGGER.warn("Request URI " + request + " is not valid. Either no scheme or no path."); return false; } return PathUtils.impliesURI(privilegeURI, requestURI); } catch (URISyntaxException e) { LOGGER.warn("Request URI " + request + " is not a URI", e); return false; } }
From source file:org.apache.sentry.provider.file.WildcardPermission.java
/** * URI is a a special case. For URI's, /a implies /a/b. * Therefore the test is "/a/b".startsWith("/a"); *//*from w w w . j av a 2 s . c o m*/ @VisibleForTesting protected static boolean impliesURI(String policy, String request) { try { URI policyURI = new URI(new StrSubstitutor(System.getProperties()).replace(policy)); URI requestURI = new URI(request); if (policyURI.getScheme() == null || policyURI.getPath() == null) { LOGGER.warn("Policy URI " + policy + " is not valid. Either no scheme or no path."); return false; } if (requestURI.getScheme() == null || requestURI.getPath() == null) { LOGGER.warn("Request URI " + request + " is not valid. Either no scheme or no path."); return false; } // schemes are equal && // request path does not contain relative parts /a/../b && // request path starts with policy path && // authorities (nullable) are equal if (policyURI.getScheme().equals(requestURI.getScheme()) && requestURI.getPath().equals(new URI(request).normalize().getPath()) && requestURI.getPath().startsWith(policyURI.getPath()) && Strings.nullToEmpty(policyURI.getAuthority()) .equals(Strings.nullToEmpty(requestURI.getAuthority()))) { return true; } return false; } catch (URISyntaxException e) { LOGGER.warn("Request URI " + request + " is not a URI", e); return false; } }
From source file:org.apache.usergrid.management.cassandra.ManagementServiceImpl.java
public String emailMsg(Map<String, String> values, String propertyName) { return new StrSubstitutor(values).replace(properties.getProperty(propertyName)); }
From source file:org.apache.usergrid.management.EmailFlowIT.java
private void testProperty(String propertyName, boolean containsSubstitution) { String propertyValue = setup.get(propertyName); assertTrue(propertyName + " was not found", isNotBlank(propertyValue)); LOG.info(propertyName + "=" + propertyValue); if (containsSubstitution) { Map<String, String> valuesMap = new HashMap<String, String>(); valuesMap.put("reset_url", "test-url"); valuesMap.put("organization_name", "test-org"); valuesMap.put("activation_url", "test-url"); valuesMap.put("confirmation_url", "test-url"); valuesMap.put("user_email", "test-email"); valuesMap.put("pin", "test-pin"); StrSubstitutor sub = new StrSubstitutor(valuesMap); String resolvedString = sub.replace(propertyValue); assertNotSame(propertyValue, resolvedString); }/*from w w w .j ava2 s .c o m*/ }