List of usage examples for org.apache.commons.lang3.text StrSubstitutor StrSubstitutor
public <V> StrSubstitutor(final Map<String, V> valueMap, final String prefix, final String suffix)
From source file:com.rest.samples.getReportFromJasperServerWithSeparateAuthFormatURL.java
public static void main(String[] args) { // TODO code application logic here Map<String, String> params = new HashMap<String, String>(); params.put("host", "10.49.28.3"); params.put("port", "8081"); params.put("reportName", "vencimientos"); params.put("parametros", "feini=2016-09-30&fefin=2016-09-30"); StrSubstitutor sub = new StrSubstitutor(params, "{", "}"); String urlTemplate = "http://{host}:{port}/jasperserver/rest_v2/reports/Reportes/{reportName}.pdf?{parametros}"; String url = sub.replace(urlTemplate); try {// w ww . j av a 2s . c om CredentialsProvider cp = new BasicCredentialsProvider(); cp.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("jasperadmin", "jasperadmin")); CloseableHttpClient hc = HttpClientBuilder.create().setDefaultCredentialsProvider(cp).build(); HttpGet getMethod = new HttpGet(url); getMethod.addHeader("accept", "application/pdf"); HttpResponse res = hc.execute(getMethod); if (res.getStatusLine().getStatusCode() != 200) { throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode()); } InputStream is = res.getEntity().getContent(); OutputStream os = new FileOutputStream(new File("vencimientos.pdf")); int read = 0; byte[] bytes = new byte[2048]; while ((read = is.read(bytes)) != -1) { os.write(bytes, 0, read); } is.close(); os.close(); if (Desktop.isDesktopSupported()) { File pdfFile = new File("vencimientos.pdf"); Desktop.getDesktop().open(pdfFile); } } catch (IOException ex) { Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.spotify.heroic.suggest.elasticsearch.ElasticsearchSuggestUtils.java
public static Function<String, String> variables(final Map<String, String> variables) { return new StrSubstitutor(variables, "{{", "}}")::replace; }
From source file:com.mobilecashout.osprey.util.Substitutor.java
public Substitutor(HashMap<String, String> variables) { values.putAll(variables);/*from w w w . j a v a2 s . c o m*/ for (Map.Entry<String, String> env : System.getenv().entrySet()) { values.put(String.format("env_%s", env.getKey()).toLowerCase(), env.getValue()); } this.substitutor = new StrSubstitutor(values, "{", "}"); }
From source file:com.redhat.developers.helloworld.HelloworldVerticle.java
private String hello(String name) { String configGreeting = ApplicationConfiguration.load(config()).getString("GREETING"); String greeting = configGreeting == null ? "Hello {name} from {hostname} with {version}" : configGreeting; Map<String, String> values = new HashMap<String, String>(); values.put("name", name); values.put("hostname", System.getenv().getOrDefault("HOSTNAME", "unknown")); values.put("version", version); return new StrSubstitutor(values, "{", "}").replace(greeting); }
From source file:com.spotify.heroic.metric.datastax.schema.AbstractCassandraSchema.java
private String loadTemplate(final String path, final Map<String, String> values) throws IOException { final String string; final ClassLoader loader = ManagedSetupConnection.class.getClassLoader(); try (final InputStream is = loader.getResourceAsStream(path)) { if (is == null) { throw new IOException("No such resource: " + path); }//from w ww.jav a 2 s.co m string = CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8)); } return new StrSubstitutor(values, "{{", "}}").replace(string); }
From source file:com.spotify.heroic.metric.datastax.schema.AbstractCassandraSchema.java
private String variables(String cql, Map<String, String> values) { return new StrSubstitutor(values, "{{", "}}").replace(cql); }
From source file:com.qcadoo.mes.deviationCausesReporting.dataProvider.DeviationWithOccurrencesDataProvider.java
private static String prepareTotalOccurrencesForProblemProjection() { Collection<String> subQueries = Collections2.transform(Arrays.asList(DeviationType.values()), new Function<DeviationType, String>() { @Override//from w w w . j a v a 2 s . co m public String apply(final DeviationType deviationType) { DeviationModelDescriber modelDescriber = deviationType.getModelDescriber(); HashMap<String, String> placeholderValues = Maps.newHashMap(); placeholderValues.put("MODEL_PLUGIN", modelDescriber.getModelPlugin()); placeholderValues.put("MODEL_NAME", modelDescriber.getModelName()); placeholderValues.put("REASON_TYPE_FIELD_NAME", modelDescriber.getReasonTypeFieldName()); placeholderValues.put("ORDER_PATH", deviationType.getPathToOrder()); placeholderValues.put("ORDER_STATE", OrderFields.STATE); StrSubstitutor substitutor = new StrSubstitutor(placeholderValues, "${", "}"); return substitutor.replace(PARTIAL_COUNT_SUB_QUERY_TPL).toString(); } }); return StringUtils.join(subQueries, " + "); }
From source file:com.qcadoo.view.api.utils.NumberGeneratorModelHelper.java
private String buildQuery(final String pluginIdentifier, final String modelName, final String numberFieldName, final String prefix) { Map<String, String> placeholderValues = Maps.newHashMap(); placeholderValues.put("PLUGIN_IDENTIFIER", pluginIdentifier); placeholderValues.put("MODEL_NAME", modelName); placeholderValues.put("NUMBER_FIELD", numberFieldName); placeholderValues.put("NUM_PROJECTION_ALIAS", NUM_PROJECTION_ALIAS); String query;// w ww. j a v a 2s .c o m if (StringUtils.isNotEmpty(prefix)) { placeholderValues.put("PREFIX", prefix); int prefixLength = StringUtils.length(prefix); placeholderValues.put("NUMBER_STARTS_AT", String.valueOf(prefixLength + 1)); query = GET_PREFIX_AWARE_NUMBERS_QUERY_TEMPLATE; } else { query = GET_NUMBERS_QUERY_TEMPLATE; } StrSubstitutor substitutor = new StrSubstitutor(placeholderValues, "${", "}"); return substitutor.replace(query).toString(); }
From source file:de.rwth.dbis.acis.bazaar.service.TestBase.java
public ClientResponse test_addUserToDevelopers(BazaarRequestParams params) { MiniClient c = getClient();//from ww w. j av a2 s . co m try { login(c); StrSubstitutor substitutor = new StrSubstitutor(params.getQueryParams(), "{", "}"); ClientResponse result = c.sendRequest("POST", mainPath + substitutor.replace( "projects/{projectId}/components/{componentId}/requirements/{requirementId}/developers"), params.getContentParam()); return result; } catch (Exception e) { e.printStackTrace(); fail("Exception: " + e); } return null; }
From source file:de.rwth.dbis.acis.bazaar.service.TestBase.java
public ClientResponse test_addUserToFollowers(BazaarRequestParams params) { MiniClient c = getClient();/* w w w. jav a 2s . c om*/ try { login(c); StrSubstitutor substitutor = new StrSubstitutor(params.getQueryParams(), "{", "}"); ClientResponse result = c.sendRequest("POST", mainPath + substitutor.replace( "projects/{projectId}/components/{componentId}/requirements/{requirementId}/followers"), params.getContentParam()); return result; } catch (Exception e) { e.printStackTrace(); fail("Exception: " + e); } return null; }