List of usage examples for org.apache.commons.lang.text StrSubstitutor StrSubstitutor
public StrSubstitutor(StrLookup variableResolver)
From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnReplicationCodeFileWriter.java
public String generateZeligSim2Line() { String template = "x.second <- setx(z.out, ${zelig_sim_2})"; StrSubstitutor sub = new StrSubstitutor(valueMap); return sub.replace(template); }
From source file:io.gatling.jenkins.targetenvgraphs.envgraphs.graphite.TrendGraphBuilder.java
protected String fillInTemplate(String template, Map<String, String> values) { if (values == null) return null; StrSubstitutor sub = new StrSubstitutor(values); return sub.replace(template); }
From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnReplicationCodeFileWriter.java
public String generateIndexingLines() { String template = "${dvn_dataframe}<-createvalindex(dtfrm=${dvn_dataframe}, attrname='val.index')\n" + "${dvn_dataframe}<-createvalindex(dtfrm=${dvn_dataframe}, attrname='missval.index')\n"; StrSubstitutor sub = new StrSubstitutor(valueMap); return sub.replace(template); }
From source file:com.sixdimensions.wcm.cq.component.bindings.impl.ComponentBindingsProviderWebConsole.java
/** * Loads the template with the specified name from the classloader and uses * it to templatize the properties using Apache Commons Lang's * StrSubstitutor and writes it to the response. * //from ww w.j av a2 s .c o m * @param res * the response to write to * @param template * the template file to load from the classpath * @param properties * the properties to templatize * @throws IOException */ private void renderBlock(HttpServletResponse res, String templateName, Map<String, String> properties) throws IOException { InputStream is = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); String template = null; try { is = getClass().getClassLoader().getResourceAsStream(templateName); if (is != null) { IOUtils.copy(is, baos); template = baos.toString(); } else { throw new IOException("Unable to load template " + templateName); } } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(baos); } StrSubstitutor sub = new StrSubstitutor(properties); res.getWriter().write(sub.replace(template)); }
From source file:com.appdynamics.monitors.azure.statsCollector.AzureServiceBusStatsCollector.java
private Map<String, String> getStatsFromAzure(Azure azure, String namespaceName, Map<String, String> valueMap, String resourceName, String resourceType) throws IOException { StrSubstitutor strSubstitutor = new StrSubstitutor(valueMap); String statsUrlString = strSubstitutor.replace(STAT_URL); URL statsUrl = new URL(statsUrlString); InputStream is = processGetRequest(statsUrl, azure.getKeyStoreLocation(), azure.getKeyStorePassword()); XStream xstream = new XStream(); xstream.ignoreUnknownElements();// w ww . java 2s .c o m xstream.processAnnotations(MetricValueSetCollection.class); xstream.processAnnotations(MetricValueSet.class); xstream.processAnnotations(MetricValue.class); MetricValueSetCollection metricValueSetCollection = (MetricValueSetCollection) xstream.fromXML(is); return extractMetrics(metricValueSetCollection, namespaceName, resourceType, resourceName); }
From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnReplicationREADMEFileWriter.java
public String generatePtSupportBlock() { String dvnGuidesUrl = ""; String hostName = System.getProperty("dvn.inetAddress"); dvnGuidesUrl = "http://" + hostName + "/guides"; String datausersGuideUrl = dvnGuidesUrl + "/dataverse-user-main.html#finding-and-using-data"; String tabdataGuideUrl = dvnGuidesUrl + "/dataverse-user-main.html#tabular-data"; valueMap.put("datausersGuideUrl", datausersGuideUrl); valueMap.put("tabdataGuideUrl", tabdataGuideUrl); // TODO: -? /*from w w w . j a va 2 s. com*/ // These URLs, for the data guides, should probably be put on the map // in the code that normally calls this class to generate the README // file, where the rest of valueMap is populated. -- L.A., v3.6 StrSubstitutor sub = new StrSubstitutor(valueMap); return sub.replace(supportTemplate); }
From source file:com.haulmont.cuba.core.sys.AppProperties.java
private String handleInterpolation(String value) { StrSubstitutor substitutor = new StrSubstitutor(new StrLookup() { @Override/* w ww .j av a 2 s .c om*/ public String lookup(String key) { String property = getSystemOrAppProperty(key); return property != null ? property : System.getProperty(key); } }); return substitutor.replace(value); }
From source file:com.thinkbiganalytics.feedmgr.nifi.PropertyExpressionResolver.java
/** * Replace any property in the str ${var} with the respective value in the map of vars *//*from w w w. j a va2s. com*/ public String resolveVariables(String str, Map<String, String> vars) { StrSubstitutor ss = new StrSubstitutor(vars); return ss.replace(str); }
From source file:com.dinochiesa.edgecallouts.EditXmlNode.java
private String resolvePropertyValue(String spec, MessageContext msgCtxt) { if (spec.indexOf('{') > -1 && spec.indexOf('}') > -1) { // Replace ALL curly-braced items in the spec string with // the value of the corresponding context variable. TemplateString ts = new TemplateString(spec); Map<String, String> valuesMap = new HashMap<String, String>(); for (String s : ts.variableNames) { valuesMap.put(s, (String) msgCtxt.getVariable(s)); }// w ww . j a v a2 s.c o m StrSubstitutor sub = new StrSubstitutor(valuesMap); String resolvedString = sub.replace(ts.template); return resolvedString; } return spec; }
From source file:com.hiperium.bo.manager.exception.ExceptionManager.java
/** * Verifies if the error exception ID corresponds to a message that need a * parameter exchange.//from www . j a va2 s .c o m * * @param infoExcepcion * the information exception * @param locale * the locale used to format the message * @return the information exception object with the internationalized * message. * @throws javax.persistence.NoResultException * if no result exception in the searching */ private InformationException createMessageParameters(InformationException infoExcepcion, Locale locale) throws NoResultException, InformationException { this.log.debug("createMessageParameters - START"); Map<String, String> var = new HashMap<String, String>(); // POSTGRES INTEGRITY CODES: http://www.postgresql.org/docs/9.1/static/errcodes-appendix.html switch (infoExcepcion.getErrorCode()) { case 23502: // Insert null in a required field var.put(ENTITY_FIELD, infoExcepcion.getMessage().split("\"")[1]); break; case 23503: // Foreign key constraint exception var.put(ENTITY_CHILD, this.findEntityTableName(infoExcepcion, locale)); break; case 23514: // Check constraint exception var.put(ENTITY_FIELD, infoExcepcion.getMessage().split("chk_")[1].split("\"")[0]); break; default: break; } if (!var.isEmpty()) { StrSubstitutor sub = new StrSubstitutor(var); infoExcepcion = new InformationException(sub.replace(infoExcepcion.getMessage())); } this.log.debug("createMessageParameters - END"); return infoExcepcion; }