org.apache.commons.lang.text.StrSubstitutor Java Examples

The following examples show how to use org.apache.commons.lang.text.StrSubstitutor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LDAPEmbeddedServer.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private void importLdif() throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    map.put("hostname", this.bindHost);
    if (this.ldapSaslPrincipal != null) {
        map.put("ldapSaslPrincipal", this.ldapSaslPrincipal);
    }

    // Find LDIF file on filesystem or classpath ( if it's like classpath:ldap/users.ldif )
    InputStream is = FindFile.findFile(ldifFile);
    if (is == null) {
        throw new IllegalStateException("LDIF file not found on classpath or on file system. Location was: " + ldifFile);
    }

    final String ldifContent = StrSubstitutor.replace(StreamUtil.readString(is), map);
    log.info("Content of LDIF: " + ldifContent);
    final SchemaManager schemaManager = directoryService.getSchemaManager();

    importLdifContent(directoryService, ldifContent);
}
 
Example #2
Source File: TemplateTUDSCR.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String fillDocument(String document, SlrProjectMetainformation metainformation, DataProvider dataProvider,
		Map<Term, String> mainDimensions) {
	Map<String, String> valuesMap = new HashMap<String, String>();
	valuesMap.put(SLRVARIABLE_TITLE, metainformation.getTitle());
	valuesMap.put(SLRVARIABLE_ABSTRACT, metainformation.getProjectAbstract());
	valuesMap.put(SLRVARIABLE_KEYWORDS, metainformation.getKeywords());
	valuesMap.put(SLRVARIABLE_AUTHORS, this.generateAuthorSection(metainformation));
	valuesMap.put(SLRVARIABLE_TAXONOMYDESCRIPTION, metainformation.getTaxonomyDescription());
	valuesMap.put(SLRVARIABLE_STATISTICS, this.generateStatistics(dataProvider));
	
	double imageToTextWidthFactor = 1;
	valuesMap.put(SLRVARIABLE_DIMENSIONCHARTS, this.generateDimensionCharts(mainDimensions, imageToTextWidthFactor));

	StrSubstitutor sub = new StrSubstitutor(valuesMap);
	String resolvedString = sub.replace(document);

	return resolvedString;
}
 
Example #3
Source File: TemplatePlainArticle.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String fillDocument(String document, SlrProjectMetainformation metainformation, DataProvider dataProvider,
		Map<Term, String> mainDimensions) {
	Map<String, String> valuesMap = new HashMap<String, String>();
	valuesMap.put(SLRVARIABLE_TITLE, metainformation.getTitle());
	valuesMap.put(SLRVARIABLE_ABSTRACT, metainformation.getProjectAbstract());
	valuesMap.put(SLRVARIABLE_KEYWORDS, metainformation.getKeywords());
	valuesMap.put(SLRVARIABLE_AUTHORS, this.generateAuthorSection(metainformation));
	valuesMap.put(SLRVARIABLE_TAXONOMYDESCRIPTION, metainformation.getTaxonomyDescription());
	valuesMap.put(SLRVARIABLE_STATISTICS, this.generateStatistics(dataProvider));
	
	double imageToTextWidthFactor = 1;
	valuesMap.put(SLRVARIABLE_DIMENSIONCHARTS, this.generateDimensionCharts(mainDimensions, imageToTextWidthFactor));

	StrSubstitutor sub = new StrSubstitutor(valuesMap);
	String resolvedString = sub.replace(document);

	return resolvedString;
}
 
Example #4
Source File: BDDDefinitionHelper.java    From qaf with MIT License 6 votes vote down vote up
public static String replaceParams(String stepCall, Map<String, Object> context) {
	stepCall = convertPrameter(stepCall);
	//don't resolve quoted parameters.
	stepCall = stepCall.replace("\"${", "\"<%{").replace("'${", "'<%{");
	//qaf#321 
	StrLookup lookup = new StrLookup() {
		public String lookup(String var) {

			Object prop = context.get(var);
			if(prop==null) {
				prop = getBundle().getSubstitutor().getVariableResolver().lookup(var);
			}
			return (prop != null) ? JSONUtil.toString(prop) : null;
		}
	};		
	StrSubstitutor interpol = new StrSubstitutor(lookup);
	stepCall = interpol.replace(stepCall);
	
	stepCall = stepCall.replace( "\"<%{","\"${").replace( "'<%{","'${");
	return stepCall;
}
 
Example #5
Source File: ScenarioExecutionStateTest.java    From zerocode with Apache License 2.0 6 votes vote down vote up
protected String createStepWith(String stepName) {
    Map<String, String> parammap = new HashMap<>();

    parammap.put("STEP.NAME", stepName);
    parammap.put("STEP.REQUEST", "{\n" +
            "    \"customer\": {\n" +
            "        \"firstName\": \"FIRST_NAME\"\n" +
            "    }\n" +
            "}");
    parammap.put("STEP.RESPONSE", "{\n" +
            "    \"id\" : 10101\n" +
            "}");

    StrSubstitutor sub = new StrSubstitutor(parammap);

    return sub.replace((new StepExecutionState()).getRequestResponseState());
}
 
Example #6
Source File: MetaDataScanner.java    From qaf with MIT License 6 votes vote down vote up
/**
 * 
 * @param xmlTest
 * @param parameter
 * @return
 */
public static String getParameter(XmlTest xmlTest, String parameter) {
	String paramValue = "";

	boolean overrideUsingSystemProp = System.getProperties().containsKey(parameter);

	Map<String, String> context = xmlTest.getAllParameters();
	context.keySet().removeAll(System.getProperties().keySet());

	if (overrideUsingSystemProp) {
		paramValue = System.getProperty(parameter);
	} else if (context.containsKey(parameter)) {
		paramValue = context.get(parameter);
	} else if (getBundle().containsKey(parameter)) {
		try {
			// unresolved value
			paramValue = (String) getBundle().configurationAt(parameter).getRoot().getValue();
		} catch (Exception e) {
			paramValue = getBundle().getString(parameter, "");
		}
	}
	paramValue = StrSubstitutor.replace(paramValue, context);
	paramValue = getBundle().getSubstitutor().replace(paramValue);
	return paramValue;
}
 
Example #7
Source File: TemplateIEEEconf.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String fillDocument(String document, SlrProjectMetainformation metainformation, DataProvider dataProvider,
		Map<Term, String> mainDimensions) {
	Map<String, String> valuesMap = new HashMap<String, String>();
	valuesMap.put(SLRVARIABLE_TITLE, metainformation.getTitle());
	valuesMap.put(SLRVARIABLE_ABSTRACT, metainformation.getProjectAbstract());
	valuesMap.put(SLRVARIABLE_KEYWORDS, metainformation.getKeywords());
	valuesMap.put(SLRVARIABLE_AUTHORS, this.generateAuthorSection(metainformation));
	valuesMap.put(SLRVARIABLE_STATISTICS, this.generateStatistics(dataProvider));
	valuesMap.put(SLRVARIABLE_TAXONOMYDESCRIPTION, metainformation.getTaxonomyDescription());
	
	double imageToTextWidthFactor = 0.4;
	valuesMap.put(SLRVARIABLE_DIMENSIONCHARTS, this.generateDimensionCharts(mainDimensions, imageToTextWidthFactor));

	StrSubstitutor sub = new StrSubstitutor(valuesMap);
	String resolvedString = sub.replace(document);

	return resolvedString;
}
 
Example #8
Source File: TemplateSpringerLncs.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String fillDocument(String document, SlrProjectMetainformation metainformation, DataProvider dataProvider,
		Map<Term, String> mainDimensions) {
	Map<String, String> valuesMap = new HashMap<String, String>();
	valuesMap.put(SLRVARIABLE_TITLE, metainformation.getTitle());
	valuesMap.put(SLRVARIABLE_ABSTRACT, metainformation.getProjectAbstract());
	valuesMap.put(SLRVARIABLE_KEYWORDS, metainformation.getKeywords());
	valuesMap.put(SLRVARIABLE_AUTHORS, this.generateAuthorSection(metainformation));
	valuesMap.put(SLRVARIABLE_STATISTICS, this.generateStatistics(dataProvider));
	valuesMap.put(SLRVARIABLE_TAXONOMYDESCRIPTION, metainformation.getTaxonomyDescription());
	
	double imageToTextWidthFactor = 0.8;
	valuesMap.put(SLRVARIABLE_DIMENSIONCHARTS, this.generateDimensionCharts(mainDimensions, imageToTextWidthFactor));

	StrSubstitutor sub = new StrSubstitutor(valuesMap);
	String resolvedString = sub.replace(document);

	return resolvedString;
}
 
Example #9
Source File: LoggingConfigurator.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * This method selects a filepath of an appender.
 * 
 * @param appender The appender name
 * @param replaceVariables If true all variables(${var}) in the file path
 *        will be substituted
 * 
 * @return The log file path
 */
public String getFile(String appender, boolean replaceVariables) {
	String result = null;
	Element elem = xml.getChild("appender", "name", appender);
	if (elem != null) {
		List childs = elem.getChildren("param");
		Iterator children = childs.iterator();

		while (children.hasNext()) {
			Element child = (Element) children.next();

			if (child.getAttributeValue("name").equals("File")) {
				result = child.getAttributeValue("value");
			}
		}

		if (replaceVariables) {
			result = StrSubstitutor.replaceSystemProperties(result);
		}
	}

	return result;
}
 
Example #10
Source File: TemplateACMSigplanConf.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String fillDocument(String document, SlrProjectMetainformation metainformation, DataProvider dataProvider,
		Map<Term, String> mainDimensions) {
	Map<String, String> valuesMap = new HashMap<String, String>();
	valuesMap.put(SLRVARIABLE_TITLE, metainformation.getTitle());
	valuesMap.put(SLRVARIABLE_ABSTRACT, metainformation.getProjectAbstract());
	valuesMap.put(SLRVARIABLE_KEYWORDS, metainformation.getKeywords());
	valuesMap.put(SLRVARIABLE_AUTHORS, this.generateAuthorSection(metainformation));
	valuesMap.put(SLRVARIABLE_STATISTICS, this.generateStatistics(dataProvider));
	valuesMap.put(SLRVARIABLE_TAXONOMYDESCRIPTION, metainformation.getTaxonomyDescription());
	
	double imageToTextWidthFactor = 0.4;
	valuesMap.put(SLRVARIABLE_DIMENSIONCHARTS, this.generateDimensionCharts(mainDimensions, imageToTextWidthFactor));

	StrSubstitutor sub = new StrSubstitutor(valuesMap);
	String resolvedString = sub.replace(document);

	return resolvedString;
}
 
Example #11
Source File: EmailFlowIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
private void testProperty( String propertyName, boolean containsSubstitution ) {
    String propertyValue = setup.get( propertyName );
    assertTrue( propertyName + " was not found", isNotBlank( propertyValue ) );
    logger.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 );
    }
}
 
Example #12
Source File: PathUtils.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
public static boolean impliesURI(String privilege, String request) {
  try {
    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;
  }
}
 
Example #13
Source File: CustomIuv.java    From govpay with GNU General Public License v3.0 5 votes vote down vote up
public String buildPrefix(Applicazione applicazione, String prefix, Map<String, String> values) {
	if(prefix == null) return "";
	
	StrSubstitutor sub = new StrSubstitutor(values, "%(", ")");
	String result = sub.replace(prefix);

	return result;
}
 
Example #14
Source File: I18nLabelBuilder.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String toString() {
	if (this.label != null && this.params != null && !this.params.isEmpty()) {
		StrSubstitutor strSub = new StrSubstitutor(this.params);
		this.label = strSub.replace(this.label);
	}
	return this.label;
}
 
Example #15
Source File: SwaggerServlet.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public String loadTempate( String template ) {
    String templateString = readClasspathFileAsString( template );
    Map<String, String> valuesMap = new HashMap<String, String>();
    String basePath = properties != null ? properties.getProperty( "usergrid.api.url.base", SWAGGER_BASE_PATH ) :
                      SWAGGER_BASE_PATH;
    valuesMap.put( "basePath", basePath );
    StrSubstitutor sub = new StrSubstitutor( valuesMap );
    return sub.replace( templateString );
}
 
Example #16
Source File: KylinConfigBase.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param propertyKeys the collection of the properties; if null will return all properties
 * @return properties which contained in propertyKeys
 */
protected Properties getProperties(Collection<String> propertyKeys) {
    Map<String, String> envMap = System.getenv();
    StrSubstitutor sub = new StrSubstitutor(envMap);

    Properties filteredProperties = new Properties();
    for (Entry<Object, Object> entry : this.properties.entrySet()) {
        if (propertyKeys == null || propertyKeys.contains(entry.getKey())) {
            filteredProperties.put(entry.getKey(), sub.replace((String) entry.getValue()));
        }
    }
    return filteredProperties;
}
 
Example #17
Source File: Generator.java    From RIBs with Apache License 2.0 5 votes vote down vote up
/**
 * @return the source for the generated file.
 */
public final String generate() {
  StrSubstitutor substitutor = new StrSubstitutor(templateValuesMap);
  String newFile = substitutor.replace(templateString);
  System.out.println(newFile);
  return newFile;
}
 
Example #18
Source File: MCRCommandLineInterface.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Expands variables in a command.
 * Replaces any variables in form ${propertyName} to the value defined by
 * {@link MCRConfiguration2#getString(String)}.
 * If the property is not defined no variable replacement takes place.
 * @param command a CLI command that should be expanded
 * @return expanded command
 */
public static String expandCommand(final String command) {
    StrSubstitutor strSubstitutor = new StrSubstitutor(MCRConfiguration2.getPropertiesMap());
    String expandedCommand = strSubstitutor.replace(command);
    if (!expandedCommand.equals(command)) {
        LOGGER.info("{} --> {}", command, expandedCommand);
    }
    return expandedCommand;
}
 
Example #19
Source File: FaultCommandInjector.java    From GomJabbar with Apache License 2.0 5 votes vote down vote up
private String formatCommand(final String command, final Target target) {
  Map<Object, Object> valuesMap = new HashMap<>();
  valuesMap.put("host", target.getHost());
  valuesMap.put("module", target.getModule());
  valuesMap.putAll(System.getProperties());

  return new StrSubstitutor(valuesMap).replace(command);
}
 
Example #20
Source File: StringTemplate.java    From waterdrop with Apache License 2.0 5 votes vote down vote up
/**
 * @param timeFormat example : "yyyy-MM-dd HH:mm:ss"
 * */
public static String substitute(String str, String timeFormat) {

    final SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
    final String formatteddDate = sdf.format(new Date());

    final Map valuesMap = new HashMap();
    valuesMap.put("uuid", UUID.randomUUID().toString());
    valuesMap.put("now", formatteddDate);
    valuesMap.put(timeFormat, formatteddDate);
    final StrSubstitutor sub = new StrSubstitutor(valuesMap);
    return sub.replace(str);
}
 
Example #21
Source File: RangerPolicyEnginePerformanceTest.java    From ranger with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void chartResults() throws IOException {
	// row: policies
	// column: concurrency
	// value: average
	LineChart chart = buildChart(parsePerformanceTable());
	String chartMarkup = StrSubstitutor.replace(RangerPolicyFactory.readResourceFile("/testdata/performance-chart.template"), ImmutableMap.of("data", chart.toJson()));
	Files.write(chartMarkup, new File("target", "performance-chart.html"), Charsets.UTF_8);
}
 
Example #22
Source File: KylinConfigBase.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * @param propertyKeys the collection of the properties; if null will return all properties
 * @return properties which contained in propertyKeys
 */
protected Properties getProperties(Collection<String> propertyKeys) {
    Map<String, String> envMap = System.getenv();
    StrSubstitutor sub = new StrSubstitutor(envMap);

    Properties filteredProperties = new Properties();
    for (Entry<Object, Object> entry : this.properties.entrySet()) {
        if (propertyKeys == null || propertyKeys.contains(entry.getKey())) {
            filteredProperties.put(entry.getKey(), sub.replace((String) entry.getValue()));
        }
    }
    return filteredProperties;
}
 
Example #23
Source File: ScenarioExecutionState.java    From zerocode with Apache License 2.0 5 votes vote down vote up
public String getResolvedScenarioState() {
    final String commaSeparatedStepResults = getAllStepsInStringList().stream()
            .map(i -> i)
            .collect(Collectors.joining(", "));
    paramMap.put("STEP_REQUEST_RESPONSE_SECTION", commaSeparatedStepResults);

    return (new StrSubstitutor(paramMap)).replace(scenarioStateTemplate);
}
 
Example #24
Source File: TokenUtils.java    From zerocode with Apache License 2.0 5 votes vote down vote up
public static String resolveKnownTokens(String requestJsonOrAnyString) {
    Map<String, Object> paramMap = new HashMap<>();

    final List<String> testCaseTokens = getTestCaseTokens(requestJsonOrAnyString);
    testCaseTokens.stream().distinct().forEach(runTimeToken -> {
        populateParamMap(paramMap, runTimeToken);
    });

    StrSubstitutor sub = new StrSubstitutor(paramMap);

    return sub.replace(requestJsonOrAnyString);
}
 
Example #25
Source File: StringSubstitutorTest.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testStringSubstitution() throws MalformedURLException {
	Map<String, String> subMap = new HashMap<>();
	String afterChange = "afterChange";
	subMap.put(SlrLatexTemplate.SLRVARIABLE_ABSTRACT, afterChange);

	String dontChangeMeString = "dontChangeMe";
	String oldString = "${" + SlrLatexTemplate.SLRVARIABLE_ABSTRACT + "}" + "," + dontChangeMeString;

	StrSubstitutor sub = new StrSubstitutor(subMap);
	String newString = sub.replace(oldString);

	assertFalse(newString.contains(SlrLatexTemplate.SLRVARIABLE_ABSTRACT));
	assertTrue(newString.contains(dontChangeMeString));
}
 
Example #26
Source File: StepExecutionStateTest.java    From zerocode with Apache License 2.0 5 votes vote down vote up
@Test
public void willHaveReqResp_resolved() throws Exception {

    Map<String, String> parammap = new HashMap<>();

    parammap.put("STEP.NAME", "Step-1");
    parammap.put("STEP.REQUEST", "{\n" +
            "    \"customer\": {\n" +
            "        \"firstName\": \"FIRST_NAME\"\n" +
            "    }\n" +
            "}");
    parammap.put("STEP.RESPONSE", "{\n" +
            "    \"id\" : 10101\n" +
            "}");

    StrSubstitutor sub = new StrSubstitutor(parammap);
    String resolvedString = sub.replace(stepExecutionState.getRequestResponseState());

    JSONAssert.assertEquals(String.format("{%s}", resolvedString), "{\n" +
            "    \"Step-1\": {\n" +
            "        \"request\": {\n" +
            "            \"customer\": {\n" +
            "                \"firstName\": \"FIRST_NAME\"\n" +
            "            }\n" +
            "        },\n" +
            "        \"response\": {\n" +
            "            \"id\": 10101\n" +
            "        }\n" +
            "    }\n" +
            "}", true);
}
 
Example #27
Source File: DefaultCustomerNameFormatterImpl.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
private String formatNameInternal(final Customer customer, final String format) {
    if (customer != null) {

        final Map<String, String> values = new HashMap<>();
        values.put("salutation", StringUtils.defaultString(customer.getSalutation()));
        values.put("firstname", StringUtils.defaultString(customer.getFirstname()));
        values.put("middlename", StringUtils.defaultString(customer.getMiddlename()));
        values.put("lastname", StringUtils.defaultString(customer.getLastname()));

        return new StrSubstitutor(values, "{{", "}}").replace(format);

    }
    return StringUtils.EMPTY;
}
 
Example #28
Source File: JweDecryptorCallout.java    From iloveapis2015-jwt-jwe-jws with Apache License 2.0 5 votes vote down vote up
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));
        }
        StrSubstitutor sub = new StrSubstitutor(valuesMap);
        String resolvedString = sub.replace(ts.template);
        return resolvedString;
    }
    return spec;
}
 
Example #29
Source File: JweEncryptorCallout.java    From iloveapis2015-jwt-jwe-jws with Apache License 2.0 5 votes vote down vote up
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));
        }
        StrSubstitutor sub = new StrSubstitutor(valuesMap);
        String resolvedString = sub.replace(ts.template);
        return resolvedString;
    }
    return spec;
}
 
Example #30
Source File: DefaultCustomerNameFormatterImpl.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
private String formatNameInternal(final Address address, final String format) {
    if (address != null) {

        final Map<String, String> values = new HashMap<>();
        values.put("salutation", StringUtils.defaultString(address.getSalutation()));
        values.put("firstname", StringUtils.defaultString(address.getFirstname()));
        values.put("middlename", StringUtils.defaultString(address.getMiddlename()));
        values.put("lastname", StringUtils.defaultString(address.getLastname()));

        return new StrSubstitutor(values, "{{", "}}").replace(format);

    }
    return StringUtils.EMPTY;
}