List of usage examples for org.apache.commons.lang.text StrSubstitutor replace
public static String replace(Object source, Map valueMap)
From source file:org.mortbay.jetty.load.generator.jenkins.result.LoadResultProjectAction.java
public static List<RunInformations> searchRunInformations(String jettyVersion, ElasticHost elasticHost, int maxResult) throws IOException { String originalJettyVersion = jettyVersion; // jettyVersion 9.4.9* //in case jettyVersion is 9.4.9.v20180320 we need to replace with 9.4.9* if (StringUtils.contains(jettyVersion, 'v')) { jettyVersion = StringUtils.substringBeforeLast(jettyVersion, ".v"); }//w w w.j a v a 2 s.com // FIXME investigate elastic but query such 9.4.10-SNAPSHOT doesn't work... // so using 9.4.10* then filter response back.... if (StringUtils.contains(jettyVersion, "-SNAPSHOT")) { jettyVersion = StringUtils.substringBeforeLast(jettyVersion, "-SNAPSHOT"); } // in case of 9.4.11-NO-LOGGER-SNAPSHOT still not working with elastic // here we must have only number or . so remove everything else StringBuilder versionQuery = new StringBuilder(); CharacterIterator ci = new StringCharacterIterator(jettyVersion); for (char c = ci.first(); c != CharacterIterator.DONE; c = ci.next()) { if (NumberUtils.isCreatable(Character.toString(c)) || c == '.') { versionQuery.append(c); } } jettyVersion = versionQuery.toString() + "*"; try (ElasticResultStore elasticResultStore = elasticHost.buildElasticResultStore(); // InputStream inputStream = LoadResultProjectAction.class .getResourceAsStream("/versionResult.json")) { String versionResultQuery = IOUtils.toString(inputStream); Map<String, String> map = new HashMap<>(1); map.put("jettyVersion", jettyVersion); map.put("maxResult", Integer.toString(maxResult)); versionResultQuery = StrSubstitutor.replace(versionResultQuery, map); String results = elasticResultStore.search(versionResultQuery); List<LoadResult> loadResults = ElasticResultStore .map(new HttpContentResponse(null, results.getBytes(), null, null)); List<RunInformations> runInformations = // loadResults.stream() // .filter(loadResult -> StringUtils.equalsIgnoreCase(originalJettyVersion, // loadResult.getServerInfo().getJettyVersion())) // .map(loadResult -> new RunInformations( loadResult.getServerInfo().getJettyVersion() + ":" + loadResult.getServerInfo().getGitHash(), // loadResult.getCollectorInformations(), StringUtils.lowerCase(loadResult.getTransport())) // .jettyVersion(loadResult.getServerInfo().getJettyVersion()) // .estimatedQps(LoadTestResultBuildAction.estimatedQps( LoadTestResultBuildAction.getLoaderConfig(loadResult))) // .serverInfo(loadResult.getServerInfo())) // .collect(Collectors.toList()); Collections.sort(runInformations, Comparator.comparing(o -> o.getStartTimeStamp())); return runInformations; } }
From source file:org.nuxeo.launcher.config.ConfigurationGenerator.java
/** * Gets the Java options with 'nuxeo.*' properties substituted. It enables * usage of property like ${nuxeo.log.dir} inside JAVA_OPTS. * * @return the java options string.// www .ja v a 2 s .c o m */ protected String getJavaOpts(String key, String value) { return StrSubstitutor.replace(System.getProperty(key, value), getUserConfig()); }
From source file:org.picketlink.test.integration.federation.saml.util.JBoss7Util.java
/** * Replace variables in PicketLink configurations files with given values and set ${hostname} variable from system property: * node0/*from w w w .jav a 2 s . c om*/ * * @param stream Stream to perform replacement on. The stream is expected to be a text file in UTF-8 encoding * @param deploymentName Value of property <code>deployment</code> in replacement * @param bindingType Value of property <code>bindingType</code> in replacement * @param idpContextPath Value of property <code>idpContextPath</code> in replacement * @return Contents of the input stream with replaced values */ public static String propertiesReplacer(InputStream stream, String deploymentName, String bindingType, String idpContextPath) { String hostname = getHostname(); final Map<String, String> map = new HashMap<String, String>(); String content = ""; map.put("hostname", hostname); map.put("deployment", deploymentName); map.put("bindingType", bindingType); map.put("idpContextPath", idpContextPath); try { content = StrSubstitutor.replace(IOUtils.toString(stream, "UTF-8"), map); } catch (IOException ex) { String message = "Cannot find or modify input stream, error: " + ex.getMessage(); throw new RuntimeException(ex); } return content; }
From source file:org.sonar.server.platform.db.migration.sql.RenameColumnsBuilderTest.java
@Theory public void checkSQL_results(@FromDataPoints("database") DatabaseAndResult database, @FromDataPoints("columnDef") ColumnDef columnDef) { String oldColumnName = "old_" + randomAlphabetic(6).toLowerCase(); String tableName = "table_" + randomAlphabetic(6).toLowerCase(); List<String> result = new RenameColumnsBuilder(database.getDialect(), tableName) .renameColumn(oldColumnName, columnDef).build(); Map<String, String> parameters = new HashMap<>(); parameters.put("table_name", tableName); parameters.put("old_column_name", oldColumnName); parameters.put("new_column_name", NEW_COLUMN_NAME); parameters.put("column_def", columnDef.generateSqlType(database.getDialect())); String expectedResult = StrSubstitutor.replace(database.getTemplateSql(), parameters); assertThat(result).containsExactlyInAnyOrder(expectedResult); }
From source file:org.springframework.security.kerberos.test.MiniKdc.java
private void initKDCServer() throws Exception { String orgName = conf.getProperty(ORG_NAME); String orgDomain = conf.getProperty(ORG_DOMAIN); String bindAddress = conf.getProperty(KDC_BIND_ADDRESS); final Map<String, String> map = new HashMap<String, String>(); map.put("0", orgName.toLowerCase()); map.put("1", orgDomain.toLowerCase()); map.put("2", orgName.toUpperCase()); map.put("3", orgDomain.toUpperCase()); map.put("4", bindAddress); ClassLoader cl = Thread.currentThread().getContextClassLoader(); InputStream is1 = cl.getResourceAsStream("minikdc.ldiff"); SchemaManager schemaManager = ds.getSchemaManager(); LdifReader reader = null;//from w w w . j a v a 2 s . c o m try { final String content = StrSubstitutor.replace(IOUtils.toString(is1), map); reader = new LdifReader(new StringReader(content)); for (LdifEntry ldifEntry : reader) { ds.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry())); } } finally { IOUtils.closeQuietly(reader); IOUtils.closeQuietly(is1); } kdc = new KdcServer(); kdc.setDirectoryService(ds); // transport String transport = conf.getProperty(TRANSPORT); if (transport.trim().equals("TCP")) { kdc.addTransports(new TcpTransport(bindAddress, port, 3, 50)); } else if (transport.trim().equals("UDP")) { kdc.addTransports(new UdpTransport(port)); } else { throw new IllegalArgumentException("Invalid transport: " + transport); } kdc.setServiceName(conf.getProperty(INSTANCE)); kdc.getConfig().setMaximumRenewableLifetime(Long.parseLong(conf.getProperty(MAX_RENEWABLE_LIFETIME))); kdc.getConfig().setMaximumTicketLifetime(Long.parseLong(conf.getProperty(MAX_TICKET_LIFETIME))); kdc.getConfig().setPaEncTimestampRequired(false); kdc.start(); StringBuilder sb = new StringBuilder(); InputStream is2 = cl.getResourceAsStream("minikdc-krb5.conf"); BufferedReader r = null; try { r = new BufferedReader(new InputStreamReader(is2, Charsets.UTF_8)); String line = r.readLine(); while (line != null) { sb.append(line).append("{3}"); line = r.readLine(); } } finally { IOUtils.closeQuietly(r); IOUtils.closeQuietly(is2); } krb5conf = new File(workDir, "krb5.conf").getAbsoluteFile(); FileUtils.writeStringToFile(krb5conf, MessageFormat.format(sb.toString(), getRealm(), getHost(), Integer.toString(getPort()), System.getProperty("line.separator"))); System.setProperty("java.security.krb5.conf", krb5conf.getAbsolutePath()); System.setProperty("sun.security.krb5.debug", conf.getProperty(DEBUG, "false")); // refresh the config Class<?> classRef; if (System.getProperty("java.vendor").contains("IBM")) { classRef = Class.forName("com.ibm.security.krb5.internal.Config"); } else { classRef = Class.forName("sun.security.krb5.Config"); } Method refreshMethod = classRef.getMethod("refresh", new Class[0]); refreshMethod.invoke(classRef, new Object[0]); LOG.info("MiniKdc listening at port: {}", getPort()); LOG.info("MiniKdc setting JVM krb5.conf to: {}", krb5conf.getAbsolutePath()); }
From source file:org.unitils.core.config.UserPropertiesFactory.java
/** * Expands all property place holders to actual values. For example * suppose you have a property defined as follows: root.dir=/usr/home * Expanding following ${root.dir}/someSubDir * will then give following result: /usr/home/someSubDir * * @param properties The properties, not null *//*from w w w .j a va 2s.c om*/ protected void expandPropertyValues(Properties properties) { for (Object key : properties.keySet()) { Object value = properties.get(key); try { String expandedValue = StrSubstitutor.replace(value, properties); properties.put(key, expandedValue); } catch (Exception e) { throw new UnitilsException("Could not expand property value for key " + key + " and value " + value, e); } } }
From source file:org.unitils.core.ConfigurationLoader.java
/** * Expands all property place holders to actual values. For example * suppose you have a property defined as follows: root.dir=/usr/home * Expanding following ${root.dir}/somesubdir * will then give following result: /usr/home/somesubdir * * @param properties The properties, not null *///from w ww . java 2 s .c om protected void expandPropertyValues(Properties properties) { for (Object key : properties.keySet()) { Object value = properties.get(key); try { String expandedValue = StrSubstitutor.replace(value, properties); properties.put(key, expandedValue); } catch (Exception e) { throw new UnitilsException( "Unable to load unitils configuration. Could not expand property value for key: " + key + ", value " + value, e); } } }
From source file:org.wildfly.test.integration.security.picketlink.idm.util.LdapServerSetupTask.java
@CreateDS(name = "JBossDS-LdapServerSetupTask", factory = org.jboss.as.test.integration.ldap.InMemoryDirectoryServiceFactory.class, partitions = { @CreatePartition(name = "jboss", suffix = "dc=jboss,dc=org", contextEntry = @ContextEntry(entryLdif = "dn: dc=jboss,dc=org\n" + "dc: jboss\n" + "objectClass: top\n" + "objectClass: domain\n\n"), indexes = { @CreateIndex(attribute = "objectClass"), @CreateIndex(attribute = "dc"), @CreateIndex(attribute = "ou") }) }, additionalInterceptors = { KeyDerivationInterceptor.class }) @CreateLdapServer(transports = { @CreateTransport(protocol = "LDAP", port = LDAP_PORT), @CreateTransport(protocol = "LDAPS", port = LDAPS_PORT) }, certificatePassword = "secret") //@formatter:on/*from ww w.j ava 2s . c o m*/ public void startLdapServer(final String hostname) throws Exception, IOException, ClassNotFoundException, FileNotFoundException { final Map<String, String> map = new HashMap<String, String>(); map.put("hostname", NetworkUtils.formatPossibleIpv6Address(hostname)); directoryService = DSAnnotationProcessor.getDirectoryService(); final String ldifContent = StrSubstitutor.replace(IOUtils.toString( LdapServerSetupTask.class.getResourceAsStream("picketlink-idm-tests.ldif"), "UTF-8"), map); final SchemaManager schemaManager = directoryService.getSchemaManager(); try { for (LdifEntry ldifEntry : new LdifReader(IOUtils.toInputStream(ldifContent))) { directoryService.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry())); } } catch (Exception e) { throw e; } final ManagedCreateLdapServer createLdapServer = new ManagedCreateLdapServer( (CreateLdapServer) AnnotationUtils.getInstance(CreateLdapServer.class)); FileOutputStream fos = new FileOutputStream(KEYSTORE_FILE); IOUtils.copy(getClass().getResourceAsStream(KEYSTORE_FILENAME), fos); fos.close(); createLdapServer.setKeyStore(KEYSTORE_FILE.getAbsolutePath()); fixTransportAddress(createLdapServer, hostname); ldapServer = ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService); ldapServer.start(); }
From source file:org.xmlactions.action.Action.java
/** * Process the page replacing any actions and / or markers. TODO add the * markers replacement code. e.g. add code to replace ${...}; * /*from ww w .j a v a 2 s .c o m*/ * @param execContext * @return the processedPage result. * @throws IOException * , NestedPagerException, ClassNotFoundException, * InstantiationException, IllegalAccessException, * InvocationTargetException, NoSuchMethodException */ public String processPage(IExecContext execContext) throws IOException, NestedActionException, ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, BadXMLException { String pageName = StrSubstitutor.replace(getPageName(), execContext); String loadedPage = loadPage(getRootPath(), pageName); String page = processPage(execContext, loadedPage); // === // Handle stacked page insert intos. // === boolean continueProcessing = true; while (continueProcessing == true) { StackedPage stackedPage = StackedPage.getAndRemoveFirstStackedPage(execContext); if (stackedPage != null) { if (stackedPage.isRemove_html()) { page = Html.removeOuterHtml(page); } execContext.put(stackedPage.getKey(), page); Action action = new Action(stackedPage.getPath(), stackedPage.getPage(), stackedPage.getNamespace()); page = action.processPage(execContext); } else { continueProcessing = false; } } Html html = new Html(); page = html.removeOuterJsonOrXml(page); if (html.getContentType() != null) { execContext.put(ExecContext.CONTENT_TYPE_KEY, html.getContentType()); } return page; }
From source file:org.xmlactions.action.Action.java
public String processPage(IExecContext execContext, String page) throws IOException, NestedActionException, ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, BadXMLException { if (StringUtils.isNotBlank(page)) { Map<String, Object> map = XMLUtils.findNameSpaces(page); List<String> pageNameSpaces = (List<String>) map.get(XMLUtils.MAP_KEY_URIS); addNameSpaces(pageNameSpaces);/*from w w w . j a v a 2 s . c om*/ String actionMapName = (String) map.get(XMLUtils.MAP_KEY_XMLNS); List<ReplacementMarker> markers = findMarkers(page, getNameSpaces(), execContext, actionMapName); String newPage = replaceMarkers(execContext, page, markers); Object noStrSubst = execContext.get(ActionConst.NO_STR_SUBST); if (noStrSubst != null) { //execContext.put(ActionConst.NO_STR_SUBST, (Object) null); newPage = newPage.toString(); } else { newPage = StrSubstitutor.replace(newPage.toString(), execContext); } Html html = new Html(); newPage = html.removeOuterJsonOrXml(newPage); if (html.getContentType() != null) { execContext.put(ExecContext.CONTENT_TYPE_KEY, html.getContentType()); } return newPage; } return page; }