List of usage examples for org.apache.commons.lang.text StrSubstitutor StrSubstitutor
public StrSubstitutor(StrLookup variableResolver)
From source file:org.eclipse.skalli.view.internal.filter.ext.GitGerritFilter.java
@SuppressWarnings("nls") String getScmLocation(GerritServerConfig gerritConfig, String repository, Project project, User user) { Map<String, String> parameters = new HashMap<String, String>(); String protocol = gerritConfig.getProtocol(); if (StringUtils.isBlank(protocol)) { protocol = "git"; }//w w w .j ava 2 s . co m parameters.put("protocol", protocol); parameters.put("host", gerritConfig.getHost()); String port = gerritConfig.getPort(); if (StringUtils.isBlank(port)) { port = Integer.toString(GerritClient.DEFAULT_PORT); } parameters.put("port", port); parameters.put("repository", repository); if (StringUtils.isNotBlank(gerritConfig.getParent())) { parameters.put("parent", gerritConfig.getParent()); } if (StringUtils.isNotBlank(gerritConfig.getBranch())) { parameters.put("branch", gerritConfig.getBranch()); } parameters.put("user", user.getDisplayName()); parameters.put("userId", user.getUserId()); String scmTemplate = gerritConfig.getScmTemplate(); if (StringUtils.isBlank(scmTemplate)) { scmTemplate = DEFAULT_SCM_TEMPLATE; } PropertyLookup propertyLookup = new PropertyLookup(parameters); propertyLookup.putAllProperties(project, ""); propertyLookup.putAllProperties(user, "user"); StrSubstitutor substitutor = new StrSubstitutor(propertyLookup); return substitutor.replace(scmTemplate); }
From source file:org.eclipse.skalli.view.internal.filter.ext.GitGerritFilter.java
@SuppressWarnings("nls") String getDescription(String descriptionTemplate, String baseUrl, Project project, User user, Map<String, String> properties) { Map<String, String> parameters = new HashMap<String, String>(); parameters.putAll(properties);/*w w w. j av a 2 s.c o m*/ parameters.put("user", user.getDisplayName()); parameters.put("userId", user.getUserId()); parameters.put("link", baseUrl + Consts.URL_PROJECTS + "/" + project.getProjectId()); if (StringUtils.isBlank(descriptionTemplate)) { descriptionTemplate = DEFAULT_DESCRIPTION; } PropertyLookup propertyLookup = new PropertyLookup(parameters); propertyLookup.putAllProperties(project, ""); propertyLookup.putAllProperties(user, "user"); StrSubstitutor substitutor = new StrSubstitutor(propertyLookup); return substitutor.replace(descriptionTemplate); }
From source file:org.eclipse.skalli.view.internal.servlet.StaticContentServlet.java
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) *//* w w w. ja va 2s . c o m*/ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String requestURI = request.getRequestURI(); if (requestURI.startsWith("/content/")) { String path = request.getPathInfo(); if (!path.startsWith("/")) { path = "/" + path; } InputStream in = getContent(path); if (in != null) { response.setContentType(getContentType(path)); try { OutputStream out = response.getOutputStream(); IOUtils.copy(in, out); } finally { IOUtils.closeQuietly(in); } return; } } else if (requestURI.startsWith("/schemas/")) { // otherwise check the bundles for a matching schema resource URL schema = RestUtils.findSchemaResource(requestURI); if (schema != null) { response.setContentType(getContentType(requestURI)); InputStream in = schema.openStream(); OutputStream out = response.getOutputStream(); try { resolveIncludes(in, out); } catch (Exception ex) { throw new IOException("Failed to resolve schema resource", ex); } finally { IOUtils.closeQuietly(in); } return; } } else if (requestURI.equals(Consts.URL_SEARCH_PLUGIN)) { URL searchPluginXML = getSearchPluginXML(); if (searchPluginXML != null) { response.setContentType("application/opensearchdescription+xml"); //$NON-NLS-1$ Properties properties = new Properties(); properties.put(Consts.ATTRIBUTE_SEARCH_PLUGIN_TITLE, request.getAttribute(Consts.ATTRIBUTE_SEARCH_PLUGIN_TITLE)); properties.put(Consts.ATTRIBUTE_SEARCH_PLUGIN_DESCRIPTION, request.getAttribute(Consts.ATTRIBUTE_SEARCH_PLUGIN_DESCRIPTION)); properties.put(Consts.ATTRIBUTE_WEBLOCATOR, StringUtils.removeEnd(request.getRequestURL().toString(), requestURI)); InputStream in = searchPluginXML.openStream(); try { String content = IOUtils.toString(in, "UTF-8"); //$NON-NLS-1$ StrSubstitutor subst = new StrSubstitutor(properties); content = subst.replace(content); OutputStream out = response.getOutputStream(); IOUtils.write(content, out, "UTF-8"); //$NON-NLS-1$ } finally { IOUtils.closeQuietly(in); } return; } } response.sendError(HttpServletResponse.SC_NOT_FOUND); }
From source file:org.jobscheduler.dashboard.installer.db.Databases.java
public String getUrl(String serverName, String port, String databaseName) { Map<String, String> valuesMap = new HashMap<String, String>(); valuesMap.put("serverName", serverName); valuesMap.put("port", port); valuesMap.put("databaseName", databaseName); StrSubstitutor sub = new StrSubstitutor(valuesMap); return sub.replace(urlFormat); }
From source file:org.jobscheduler.dashboard.installer.JDBCManager.java
public void createApplicationPropertiesFile(String installPath, CommandLine cmd) throws IOException { Properties valuesMap = new Properties(); valuesMap.put(SERVER_NAME, cmd.getOptionValue(SERVER_NAME)); valuesMap.put("url", Databases.valueOf(cmd.getOptionValue(DB).toUpperCase()).getUrl( cmd.getOptionValue(SERVER_NAME), cmd.getOptionValue(PORT), cmd.getOptionValue(DATABASE_NAME))); valuesMap.put(DB_USER_NAME, cmd.getOptionValue(DB_USER_NAME)); valuesMap.put(DB_USER_PASSWORD, cmd.getOptionValue(DB_USER_PASSWORD)); StrSubstitutor sub = new StrSubstitutor(valuesMap); String applicationJobSchedulerYaml = IOUtils .toString(this.getClass().getResourceAsStream("/application-jobscheduler-template.yml"), "UTF-8"); String translatedApplicationJobSchedulerYaml = sub.replace(applicationJobSchedulerYaml); // Create config directory file File configDir = new File(installPath, "config"); if (!configDir.exists()) configDir.mkdir();/*from www. j a va 2s .co m*/ FileUtils.write(new File(configDir, "application-jobscheduler.yml"), translatedApplicationJobSchedulerYaml); }
From source file:org.klco.email2html.OutputWriter.java
/** * Writes the message to a html file. The name of the HTML file is generated * from the date of the message./* w ww. j a v a2 s . c om*/ * * @param emailMessage * the message to save to a file * @throws IOException * Signals that an I/O exception has occurred. */ public void writeHTML(EmailMessage emailMessage) throws IOException { log.trace("writeHTML"); Map<String, Object> params = emailMessage.toMap(); params.put("attachmentFolder", config.getImagesSubDir() + File.separator + FILE_DATE_FORMAT.format(emailMessage.getSentDate())); if (config.getHookObj() != null) { config.getHookObj().beforeWrite(emailMessage, params); } File messageFolder = new File(outputDir.getAbsolutePath() + File.separator + config.getMessagesSubDir()); if (!messageFolder.exists()) { log.debug("Creating messages folder"); messageFolder.mkdirs(); } StrSubstitutor sub = new StrSubstitutor(params); String fileContent = sub.replace(template); String name = String.format(config.getFileNameFormat(), emailMessage.getSentDate(), toPath(emailMessage.getSubject())); File messageFile = new File( outputDir.getAbsolutePath() + File.separator + config.getMessagesSubDir() + File.separator + name); OutputStream os = null; try { os = new FileOutputStream(messageFile); IOUtils.write(fileContent, new FileOutputStream(messageFile)); log.debug("Writing message to file {}", messageFile.getAbsolutePath()); } finally { IOUtils.closeQuietly(os); } if (config.getHookObj() != null) { config.getHookObj().afterWrite(emailMessage, params, messageFile); } }
From source file:org.kuali.rice.core.impl.config.property.ConfigParserImpl.java
/** * Parses a list of locations//from w w w. ja v a 2 s.c o m * @param params the current parameter map * @param locations a list of locations to parse * @throws IOException */ protected void parse(LinkedHashMap<String, Object> params, String[] locations) throws IOException { StrSubstitutor subs = new StrSubstitutor(new SystemPropertiesDelegatingStrLookup(params)); for (String location : locations) { parse(params, location, subs, 0); } }
From source file:org.kuali.rice.kew.util.Utilities.java
/** * Performs variable substitution on the specified string, replacing variables specified like ${name} * with the value of the corresponding config parameter obtained from the current context Config object. * This version of the method also takes an application id to qualify the parameter. * @param applicationId the application id to use for qualifying the parameter * @param string the string on which to perform variable substitution * @return a string with any variables substituted with configuration parameter values *//*from ww w . j a va 2 s .c o m*/ public static String substituteConfigParameters(String applicationId, String string) { StrSubstitutor sub = new StrSubstitutor(new ParameterStrLookup(applicationId)); return sub.replace(string); }
From source file:org.mule.config.dsl.internal.PropertyPlaceholderImpl.java
/** * @param properties the properties k-v to be loaded * @throws NullPointerException if {@code properties} param is null *///from ww w. jav a 2 s .co m public PropertyPlaceholderImpl(final Properties properties) throws NullPointerException { checkNotNull(properties, "properties"); substitutor = new StrSubstitutor(properties); }
From source file:org.mycore.frontend.cli.MCRCommandLineInterface.java
/** * Expands variables in a command.//from w ww . j a v a 2 s .c om * Replaces any variables in form ${propertyName} to the value defined by {@link MCRConfiguration#getString(String)}. * If the property is not defined not 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(MCRConfiguration.instance().getPropertiesMap()); String expandedCommand = strSubstitutor.replace(command); if (!expandedCommand.equals(command)) { LOGGER.info(command + " --> " + expandedCommand); } return expandedCommand; }