List of usage examples for org.apache.commons.lang.text StrSubstitutor StrSubstitutor
public StrSubstitutor(Map valueMap, String prefix, String suffix)
From source file:org.craftercms.deployer.git.processor.ShellProcessor.java
@Override public void doProcess(SiteConfiguration siteConfiguration, PublishedChangeSet changeSet) throws PublishingException { checkConfiguration(siteConfiguration); LOGGER.debug("Starting Shell Processor"); ProcessBuilder builder = new ProcessBuilder(); builder.directory(getWorkingDir(workingDir, siteConfiguration.getSiteId())); LOGGER.debug("Working directory is " + workingDir); HashMap<String, String> argumentsMap = buildArgumentsMap(getFileList(changeSet)); if (asSingleCommand) { StrSubstitutor substitutor = new StrSubstitutor(argumentsMap, "%{", "}"); String execComand = substitutor.replace(command); LOGGER.debug("Command to be Executed is " + execComand); builder.command("/bin/bash", "-c", execComand); } else {//from w ww . j a v a2s . c o m Set<String> keys = argumentsMap.keySet(); ArrayList<String> commandAsList = new ArrayList<String>(); commandAsList.add(command.trim()); for (String key : keys) { if (!key.equalsIgnoreCase(INCLUDE_FILTER_PARAM)) { commandAsList.add(argumentsMap.get(key)); } } LOGGER.debug("Command to be Executed is " + StringUtils.join(commandAsList, " ")); builder.command(commandAsList); } builder.environment().putAll(enviroment); builder.redirectErrorStream(true); try { Process process = builder.start(); process.waitFor(); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String str; while ((str = reader.readLine()) != null) { LOGGER.info("PROCESS OUTPUT :" + str); } reader.close(); LOGGER.info("Process Finish with Exit Code " + process.exitValue()); LOGGER.debug("Process Output "); } catch (IOException ex) { LOGGER.error("Error ", ex); } catch (InterruptedException e) { LOGGER.error("Error ", e); } finally { LOGGER.debug("End of Shell Processor"); } }
From source file:org.eurekastreams.server.action.execution.notification.TemplateEmailBuilder.java
/** * Builds the email message from the notification and initial properties. * /* w ww.j av a 2s .c o m*/ * @param notif * Notification for which to build message. * @param invocationProperties * Initial properties to use. * @param inMessage * Email message. * @throws Exception * On error. */ public void build(final NotificationDTO notif, final Map<String, String> invocationProperties, final MimeMessage inMessage) throws Exception { // -- build properties -- Map<String, String> properties = new HashMap<String, String>(); // from system settings SystemSettings systemSettings = systemSettingsMapper.execute(null); properties.put("settings.sitelabel", systemSettings.getSiteLabel()); properties.put("settings.support.email", systemSettings.getSupportEmailAddress()); properties.put("settings.support.phone", systemSettings.getSupportPhoneNumber()); properties.put("settings.support.name", systemSettings.getSupportStreamGroupDisplayName()); properties.put("settings.support.uniqueid", systemSettings.getSupportStreamGroupShortName()); // from upstream builders if (invocationProperties != null) { properties.putAll(invocationProperties); } // from system configuration if (extraProperties != null) { properties.putAll(extraProperties); } // actor if (notif.getActorId() > 0) { properties.put("actor.id", Long.toString(notif.getActorId())); properties.put("actor.accountid", notif.getActorAccountId()); properties.put("actor.name", notif.getActorName()); } // activity if (notif.getActivityId() > 0) { properties.put("activity.id", Long.toString(notif.getActivityId())); String type = activityTypeDisplayNameOverrides.get(notif.getActivityType()); if (type == null) { type = notif.getActivityType().name().toLowerCase(); } properties.put("activity.type", type); } // destination if (notif.getDestinationId() > 0) { properties.put("dest.id", Long.toString(notif.getDestinationId())); properties.put("dest.type", notif.getDestinationType().name()); properties.put("dest.uniqueid", notif.getDestinationUniqueId()); properties.put("dest.name", notif.getDestinationName()); properties.put("dest.page", entityPageNames.get(notif.getDestinationType())); } // auxiliary if (notif.getAuxiliaryType() != null) { properties.put("aux.type", notif.getAuxiliaryType().name()); properties.put("aux.uniqueid", notif.getAuxiliaryUniqueId()); properties.put("aux.name", notif.getAuxiliaryName()); properties.put("aux.page", entityPageNames.get(notif.getAuxiliaryType())); } // -- build email -- // build and set the email parts StrSubstitutor transform = new StrSubstitutor(properties, "$(", ")"); emailer.setSubject(inMessage, transform.replace(subjectTemplate)); emailer.setTextBody(inMessage, transform.replace(textBodyTemplate)); transform.setVariableResolver(new HtmlEncodingLookup(transform.getVariableResolver())); emailer.setHtmlBody(inMessage, transform.replace(htmlBodyTemplate)); // look up recipients and put as email recipients List<PersonModelView> recipients = peopleMapper.execute(notif.getRecipientIds()); if (recipients.size() == 1) { emailer.setTo(inMessage, recipients.get(0).getEmail()); } else { emailer.setBcc(inMessage, EmailerFactory.buildEmailList(recipients)); } }
From source file:org.fenixedu.qubdocs.util.DocsStringUtils.java
/** * Allows variables replacement with configurable prefix and suffix * //from w w w . j a va2 s.com * Usage example using '<' for prefix and '>' for suffix: * - Template: Hello <name> * - Variables: {name=User} * - Result: Hello User * @return */ public static String replaceVariables(final String template, final String prefix, final String suffix, final Map<String, String> variables) { return new StrSubstitutor(variables, prefix, suffix).replace(template); }
From source file:org.obiba.mica.core.service.MailService.java
public String getSubject(String subjectFormat, Map<String, String> ctx, String defaultSubject) { StrSubstitutor sub = new StrSubstitutor(ctx, "${", "}"); String temp = Optional.ofNullable(subjectFormat) // .filter(s -> !s.isEmpty()) // .orElse(defaultSubject);/* w w w . jav a2s .co m*/ return sub.replace(temp); }
From source file:org.trustedanalytics.cfbroker.store.hdfs.helper.HdfsPathTemplateUtils.java
public static StrSubstitutor getSubstitutor(Map<String, String> values) { return new StrSubstitutor(values, VARIABLE_PREFIX, VARIABLE_SUFIX); }
From source file:org.yes.cart.service.customer.impl.DefaultCustomerNameFormatterImpl.java
private String formatNameInternal(final Address address, final String format) { if (address != null) { final Map<String, String> values = new HashMap<String, String>(); 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); }// ww w . j av a2 s . c o m return StringUtils.EMPTY; }
From source file:org.yes.cart.service.customer.impl.DefaultCustomerNameFormatterImpl.java
private String formatNameInternal(final Customer customer, final String format) { if (customer != null) { final Map<String, String> values = new HashMap<String, String>(); 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); }/*from ww w .ja v a2 s . c o m*/ return StringUtils.EMPTY; }
From source file:org.yes.cart.service.order.impl.DefaultOrderAddressFormatterImpl.java
private String formatAddressInternal(final Address address, final String format) { if (address != null) { final Map<String, String> values = new HashMap<String, String>(); values.put("firstname", StringUtils.defaultString(address.getFirstname())); values.put("middlename", StringUtils.defaultString(address.getMiddlename())); values.put("lastname", StringUtils.defaultString(address.getLastname())); values.put("addrline1", StringUtils.defaultString(address.getAddrline1())); values.put("addrline2", StringUtils.defaultString(address.getAddrline2())); values.put("postcode", StringUtils.defaultString(address.getPostcode())); values.put("city", StringUtils.defaultString(address.getCity())); values.put("countrycode", StringUtils.defaultString(address.getCountryCode())); values.put("statecode", StringUtils.defaultString(address.getStateCode())); values.put("phone1", StringUtils.defaultString(address.getPhone1())); values.put("phone2", StringUtils.defaultString(address.getPhone2())); values.put("mobile1", StringUtils.defaultString(address.getMobile1())); values.put("mobile2", StringUtils.defaultString(address.getMobile2())); values.put("email1", StringUtils.defaultString(address.getEmail1())); values.put("email2", StringUtils.defaultString(address.getEmail2())); values.put("custom1", StringUtils.defaultString(address.getCustom1())); values.put("custom2", StringUtils.defaultString(address.getCustom2())); values.put("custom3", StringUtils.defaultString(address.getCustom3())); values.put("custom4", StringUtils.defaultString(address.getCustom4())); return new StrSubstitutor(values, "{{", "}}").replace(format); }/*from w ww. j av a2 s . c om*/ return StringUtils.EMPTY; }