Example usage for org.apache.commons.lang.text StrLookup mapLookup

List of usage examples for org.apache.commons.lang.text StrLookup mapLookup

Introduction

In this page you can find the example usage for org.apache.commons.lang.text StrLookup mapLookup.

Prototype

public static StrLookup mapLookup(Map map) 

Source Link

Document

Returns a lookup which looks up values using a map.

Usage

From source file:com.enonic.cms.framework.util.PropertiesUtil.java

/**
 * Interpolate properties names like ${..}.
 *//*ww  w . j  av  a 2s.  c  o m*/
public static Properties interpolate(final Properties props) {
    Properties target = new Properties();

    Properties source = new Properties();
    source.putAll(System.getProperties());
    source.putAll(props);

    StrLookup lookup = StrLookup.mapLookup(source);
    StrSubstitutor substitutor = new StrSubstitutor(lookup);

    for (Object key : props.keySet()) {
        String value = props.getProperty((String) key);

        try {
            value = substitutor.replace(value);
        } catch (IllegalStateException e) {
            // Do nothing
        }

        target.put(key, value);
    }

    return target;
}

From source file:com.thoughtworks.go.buildsession.BuildVariables.java

public BuildVariables(AgentRuntimeInfo agentRuntimeInfo, Clock clock) {
    this.clock = clock;
    this.staticLookup = StrLookup.mapLookup(map("agent.location", agentRuntimeInfo.getLocation(),
            "agent.hostname", agentRuntimeInfo.getHostName()));
}

From source file:com.thoughtworks.go.buildsession.BuildSessionBasedTestCase.java

protected BuildSession newBuildSession() {
    return new BuildSession("build1", statusReporter, console, StrLookup.mapLookup(buildVariables),
            artifactsRepository, httpService, new TestingClock(), sandbox);
}

From source file:com.adobe.acs.commons.hc.impl.SMTPMailServiceHealthCheck.java

@Override
@SuppressWarnings("squid:S1141")
public Result execute() {
    final FormattingResultLog resultLog = new FormattingResultLog();

    if (messageGatewayService == null) {
        resultLog.critical("MessageGatewayService OSGi service could not be found.");
        resultLog.info(/*from   w w w  .  j a va  2  s.co  m*/
                "Verify the Default Mail Service is active: http://<host>:<port>/system/console/components/com.day.cq.mailer.impl.CqMailingService");
    } else {
        final MessageGateway<SimpleEmail> messageGateway = messageGatewayService.getGateway(SimpleEmail.class);
        if (messageGateway == null) {
            resultLog.critical("The AEM Default Mail Service is INACTIVE, thus e-mails cannot be sent.");
            resultLog.info(
                    "Verify the Default Mail Service is active and configured: http://<host>:<port>/system/console/components/com.day.cq.mailer.DefaultMailService");
            log.warn("Could not retrieve a SimpleEmail Message Gateway");

        } else {
            try {
                List<InternetAddress> emailAddresses = new ArrayList<InternetAddress>();
                emailAddresses.add(new InternetAddress(this.toEmail));
                MailTemplate mailTemplate = new MailTemplate(IOUtils.toInputStream(MAIL_TEMPLATE),
                        CharEncoding.UTF_8);
                SimpleEmail email = mailTemplate.getEmail(StrLookup.mapLookup(Collections.emptyMap()),
                        SimpleEmail.class);

                email.setSubject("AEM E-mail Service Health Check");
                email.setTo(emailAddresses);

                email.setSocketConnectionTimeout(TIMEOUT);
                email.setSocketTimeout(TIMEOUT);
                try {
                    messageGateway.send(email);
                    resultLog.info(
                            "The E-mail Service appears to be working properly. Verify the health check e-mail was sent to [ {} ]",
                            this.toEmail);
                } catch (Exception e) {
                    resultLog.critical(
                            "Failed sending e-mail. Unable to send a test toEmail via the configured E-mail server: "
                                    + e.getMessage(),
                            e);
                    log.warn("Failed to send E-mail for E-mail Service health check", e);
                }

                logMailServiceConfig(resultLog, email);
            } catch (Exception e) {
                resultLog.healthCheckError(
                        "Sling Health check could not formulate a test toEmail: " + e.getMessage(), e);
                log.error("Unable to execute E-mail health check", e);
            }
        }
    }

    return new Result(resultLog);
}

From source file:com.adobe.acs.commons.email.impl.EmailServiceImpl.java

private Email getEmail(final MailTemplate mailTemplate, final Class<? extends Email> mailType,
        final Map<String, String> params) throws EmailException, MessagingException, IOException {

    final Email email = mailTemplate.getEmail(StrLookup.mapLookup(params), mailType);

    if (params.containsKey(EmailServiceConstants.SENDER_EMAIL_ADDRESS)
            && params.containsKey(EmailServiceConstants.SENDER_NAME)) {

        email.setFrom(params.get(EmailServiceConstants.SENDER_EMAIL_ADDRESS),
                params.get(EmailServiceConstants.SENDER_NAME));

    } else if (params.containsKey(EmailServiceConstants.SENDER_EMAIL_ADDRESS)) {
        email.setFrom(params.get(EmailServiceConstants.SENDER_EMAIL_ADDRESS));
    }/* w  w  w.j a va 2s. c o  m*/
    if (connectTimeout > 0) {
        email.setSocketConnectionTimeout(connectTimeout);
    }
    if (soTimeout > 0) {
        email.setSocketTimeout(soTimeout);
    }

    // #1008 setting the subject via the setSubject(..) parameter.
    if (params.containsKey(EmailServiceConstants.SUBJECT)) {
        email.setSubject(params.get(EmailServiceConstants.SUBJECT));
    }

    return email;
}

From source file:nl.isaac.dotcms.plugin.configuration.ConfigurationService.java

/**
 * This method deals with constructing a key for the specified configuration, checking the cache and if it isn't in the cache constructing (and caching) it.
 *
 * @param hostName/* w  w  w . j  ava 2  s . c  om*/
 * @param ipAddress
 * @param sessionId
 * @param pluginName
 * @param configurationLocation
 * @return
 * @throws ConfigurationException
 */
private static CustomConfiguration retrieveFromCacheOrCreateConfiguration(String keyPrefix, String hostName,
        String ipAddress, String sessionId, String pluginName, String configurationLocation)
        throws ConfigurationException {

    if (ConfigurationDotCMSCacheGroupHandler.isFlushed()) {
        clearCache();
        ConfigurationDotCMSCacheGroupHandler.setLoaded();
    }

    String key;
    final String basicKey = keyPrefix + hostName;

    // On Windows the : character is not allowed, replace it with _
    if (ipAddress != null) {
        ipAddress = ipAddress.replace(':', '_');
    }

    if (cacheOnIp) {
        String ipKey = basicKey + '_' + ipAddress + '_' + sessionId;
        if (!ipForwardCache.contains(ipKey)) {
            key = ipKey;
        } else {
            key = basicKey;
        }
    } else {
        key = basicKey;
    }

    Logger.debug(ConfigurationService.class, "Looking up configuration under key: " + key);
    CustomConfiguration conf = serverCache.get(key);

    if (conf != null) {
        return conf;
    }

    Logger.debug(ConfigurationService.class, "Loading configuration for key: " + key);

    Map<String, String> interpolationValues = new HashMap<String, String>();
    final Bundle bundle;

    interpolationValues.put("hostName", hostName);
    if (pluginName != null && pluginName.startsWith("osgi/")) {
        //This is an OSGi plugin
        String[] splitPluginName = pluginName.split("/");
        interpolationValues.put("pluginName", splitPluginName[1]);

        if (splitPluginName.length > 2) {
            long bundleId = Long.valueOf(splitPluginName[2]);
            bundle = OSGIProxyServlet.bundleContext.getBundle(bundleId);
        } else {
            // If we didn't get a bundleId we need to search for it, somewhat slower, but the result is cached
            bundle = searchBundles(splitPluginName[1]);
        }
    } else {
        if (pluginName != null) {
            interpolationValues.put("pluginName", pluginName);
        }
        bundle = null;
    }

    // We only do ip specific things on DEV (and local of course!)
    if (cacheOnIp && ipAddress != null) {
        interpolationValues.put("ClientIPAddress", ipAddress);
    }

    Map<String, StrLookup> interpolators = new HashMap<String, StrLookup>();
    interpolators.put("param", StrLookup.mapLookup(interpolationValues));

    DotCMSFileConfigurationProvider dotCmsProvider = new DotCMSFileConfigurationProvider(hostName);
    Map<String, ConfigurationProvider> providers = new HashMap<String, ConfigurationProvider>();
    providers.put("dotcms", dotCmsProvider);

    OSGiFileConfigurationProvider osgiProvider = new OSGiFileConfigurationProvider(bundle);
    providers.put("osgi", osgiProvider);

    conf = ConfigurationFactory.createConfiguration(key, configurationLocation, interpolators, providers);

    boolean isIpSpecific = false;
    if (cacheOnIp && ipAddress != null) {
        for (FileConfiguration fileConf : conf.getLoadedFileConfigurations()) {
            if (fileConf.getFileName() != null && fileConf.getFileName().contains(ipAddress)) {

                isIpSpecific = true;

                return conf;
            }
        }
    }
    if (isIpSpecific) {
        ConfigurationParameters params = defaultParameters.get();
        if (params != null) {
            params.addConfigurationToSession(key);
        }
    }
    if (cacheOnIp && !isIpSpecific) {
        ipForwardCache.add(key);
        if (serverCache.contains(basicKey)) {
            return serverCache.get(basicKey);
        } else {
            key = basicKey;
        }
    }
    Logger.debug(ConfigurationService.class, "Created a new configuration! " + key);

    serverCache.put(key, conf);

    return conf;
}