List of usage examples for org.apache.commons.lang.text StrSubstitutor replace
public static String replace(Object source, Map valueMap, String prefix, String suffix)
From source file:org.eclipse.fx.core.internal.TplURLDynamicDataStreamHandler.java
@Override public @Nullable InputStream createDataStream(URL url) { try {/* w w w.j a va2 s . c om*/ URL realURL = new URL(url.getPath()); String data; try (InputStream stream = realURL.openStream()) { data = StrSubstitutor.replace(IOUtils.readToString(stream, Charset.forName("UTF-8")), //$NON-NLS-1$ map(url.getQuery()), "_(", ")"); //$NON-NLS-1$//$NON-NLS-2$ } return new ByteArrayInputStream(data.getBytes()); } catch (IOException e) { LoggerCreator.createLogger(TplURLDynamicDataStreamHandler.class).error("Failed to load real data", e); //$NON-NLS-1$ } return null; }
From source file:org.eclipse.rdf4j.spin.function.spif.BuildString.java
@Override public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length < 1) { throw new ValueExprEvaluationException("Incorrect number of arguments"); }/*from w w w. j a v a 2s. c o m*/ if (!(args[0] instanceof Literal)) { throw new ValueExprEvaluationException("First argument must be a string"); } Literal s = (Literal) args[0]; String tmpl = s.getLabel(); Map<String, String> mappings = new HashMap<String, String>(args.length); for (int i = 1; i < args.length; i++) { mappings.put(Integer.toString(i), args[i].stringValue()); } String newValue = StrSubstitutor.replace(tmpl, mappings, "{?", "}"); return valueFactory.createLiteral(newValue); }
From source file:org.eclipse.rdf4j.spin.function.spif.BuildURI.java
@Override public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException { if (args.length < 1) { throw new ValueExprEvaluationException("Incorrect number of arguments"); }/*from ww w.ja va2 s .c o m*/ if (!(args[0] instanceof Literal)) { throw new ValueExprEvaluationException("First argument must be a string"); } Literal s = (Literal) args[0]; String tmpl = s.getLabel(); Map<String, String> mappings = new HashMap<String, String>(args.length); for (int i = 1; i < args.length; i++) { mappings.put(Integer.toString(i), args[i].stringValue()); } String newValue = StrSubstitutor.replace(tmpl, mappings, "{?", "}"); if (tmpl.charAt(0) == '<' && tmpl.charAt(tmpl.length() - 1) == '>') { return valueFactory.createURI(newValue.substring(1, newValue.length() - 1)); } throw new ValueExprEvaluationException("Invalid URI template: " + tmpl); }
From source file:org.sonar.application.ConfigurationUtils.java
static Properties interpolateVariables(Properties properties, Map<String, String> variables) { Properties result = new Properties(); Enumeration keys = properties.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); String value = (String) properties.get(key); String interpolatedValue = StrSubstitutor.replace(value, variables, "${env:", "}"); result.setProperty(key, interpolatedValue); }//from w ww . j ava 2s . com return result; }
From source file:org.sonar.core.config.ConfigurationUtils.java
public static Properties interpolateVariables(Properties properties, Map<String, String> variables) { Properties result = new Properties(); Enumeration keys = properties.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); String value = (String) properties.get(key); String interpolatedValue = StrSubstitutor.replace(value, variables, "${env:", "}"); result.setProperty(key, interpolatedValue); }/*from w w w. j a v a 2 s .co m*/ return result; }
From source file:org.sonar.core.persistence.AbstractDaoTestCase.java
private void loadOrchestratorSettings(Settings settings) throws URISyntaxException, IOException { String url = settings.getString("orchestrator.configUrl"); URI uri = new URI(url); InputStream input = null;/* ww w . j a v a 2 s .c o m*/ try { if (url.startsWith("file:")) { File file = new File(uri); input = FileUtils.openInputStream(file); } else { HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); int responseCode = connection.getResponseCode(); if (responseCode >= 400) { throw new IllegalStateException("Fail to request: " + uri + ". Status code=" + responseCode); } input = connection.getInputStream(); } Properties props = new Properties(); props.load(input); settings.addProperties(props); for (Map.Entry<String, String> entry : settings.getProperties().entrySet()) { String interpolatedValue = StrSubstitutor.replace(entry.getValue(), System.getenv(), "${", "}"); settings.setProperty(entry.getKey(), interpolatedValue); } } finally { IOUtils.closeQuietly(input); } }
From source file:org.sonar.db.CoreTestDb.java
private void loadOrchestratorSettings(Settings settings) { String url = settings.getString("orchestrator.configUrl"); InputStream input = null;/*from ww w . j av a2s . c o m*/ try { URI uri = new URI(url); if (url.startsWith("file:")) { File file = new File(uri); input = FileUtils.openInputStream(file); } else { HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); int responseCode = connection.getResponseCode(); if (responseCode >= 400) { throw new IllegalStateException("Fail to request: " + uri + ". Status code=" + responseCode); } input = connection.getInputStream(); } Properties props = new Properties(); props.load(input); settings.addProperties(props); for (Map.Entry<String, String> entry : settings.getProperties().entrySet()) { String interpolatedValue = StrSubstitutor.replace(entry.getValue(), System.getenv(), "${", "}"); settings.setProperty(entry.getKey(), interpolatedValue); } } catch (Exception e) { throw new IllegalStateException(e); } finally { IOUtils.closeQuietly(input); } }