Example usage for org.springframework.util ClassUtils isPresent

List of usage examples for org.springframework.util ClassUtils isPresent

Introduction

In this page you can find the example usage for org.springframework.util ClassUtils isPresent.

Prototype

public static boolean isPresent(String className, @Nullable ClassLoader classLoader) 

Source Link

Document

Determine whether the Class identified by the supplied name is present and can be loaded.

Usage

From source file:cz.jirutka.spring.exhandler.support.HttpMessageConverterUtils.java

/**
 * Determine whether a JAXB binder is present on the classpath and can be loaded. Will return
 * <tt>false</tt> if either the {@link javax.xml.bind.Binder} or one of its dependencies is not
 * present or cannot be loaded./*from   ww  w . ja va  2 s  .  c o m*/
 */
public static boolean isJaxb2Present() {
    return ClassUtils.isPresent("javax.xml.bind.Binder", CLASSLOADER);
}

From source file:cz.jirutka.spring.exhandler.support.HttpMessageConverterUtils.java

/**
 * Determine whether Jackson 2.x is present on the classpath and can be loaded. Will return
 * <tt>false</tt> if either the {@link com.fasterxml.jackson.databind.ObjectMapper},
 * {@link com.fasterxml.jackson.core.JsonGenerator} or one of its dependencies is not present
 * or cannot be loaded.//from ww w  . ja  va  2 s .com
 */
public static boolean isJackson2Present() {
    return ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", CLASSLOADER)
            && ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", CLASSLOADER);
}

From source file:com.domingosuarez.boot.autoconfigure.jade4j.Jade4JTemplateAvailabilityProvider.java

@Override
public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader,
        ResourceLoader resourceLoader) {
    if (ClassUtils.isPresent("de.neuland.jade4j.spring.template.SpringTemplateLoader", classLoader)) {
        String prefix = environment.getProperty("spring.jade4j.prefix", Jade4JAutoConfiguration.DEFAULT_PREFIX);
        String suffix = environment.getProperty("spring.jade4j.suffix", Jade4JAutoConfiguration.DEFAULT_SUFFIX);
        return resourceLoader.getResource(prefix + view + suffix).exists();
    }//from w  ww  .  j ava  2 s. c  o  m

    return false;
}

From source file:net.alpha.velocity.configuration.VelocityTemplateAvailabilityProvider.java

@Override
public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader,
        ResourceLoader resourceLoader) {
    if (ClassUtils.isPresent("org.apache.velocity.app.VelocityEngine", classLoader)) {
        PropertyResolver resolver = new RelaxedPropertyResolver(environment, "spring.velocity.");
        String loaderPath = resolver.getProperty("resource-loader-path",
                VelocityProperties.DEFAULT_RESOURCE_LOADER_PATH);
        String prefix = resolver.getProperty("prefix", VelocityProperties.DEFAULT_PREFIX);
        String suffix = resolver.getProperty("suffix", VelocityProperties.DEFAULT_SUFFIX);
        return resourceLoader.getResource(loaderPath + prefix + view + suffix).exists();
    }/*from  w ww  .  j a  v  a2 s. com*/
    return false;
}

From source file:jp.gr.java_conf.bufferings.thymeleaf.spring.boot.Thymeleaf3TemplateAvailabilityProvider.java

@Override
public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader,
        ResourceLoader resourceLoader) {
    if (ClassUtils.isPresent("org.thymeleaf.spring4.SpringTemplateEngine", classLoader)
            && ClassUtils.isPresent("org.thymeleaf.Thymeleaf", classLoader)) {
        PropertyResolver resolver = new RelaxedPropertyResolver(environment, "spring.thymeleaf3.");
        String prefix = resolver.getProperty("prefix", Thymeleaf3Properties.DEFAULT_PREFIX);
        String suffix = resolver.getProperty("suffix", Thymeleaf3Properties.DEFAULT_SUFFIX);
        return resourceLoader.getResource(prefix + view + suffix).exists();
    }/*w ww . j  a v  a 2s. co  m*/
    return false;
}

From source file:cz.jirutka.spring.exhandler.support.HttpMessageConverterUtils.java

/**
 * Determine whether Jackson 1.x is present on the classpath and can be loaded. Will return
 * <tt>false</tt> if either the {@link org.codehaus.jackson.map.ObjectMapper},
 * {@link org.codehaus.jackson.JsonGenerator} or one of its dependencies is not present or
 * cannot be loaded.//from  ww w  . ja v a2  s.c om
 */
@Deprecated
public static boolean isJacksonPresent() {
    return ClassUtils.isPresent("org.codehaus.jackson.map.ObjectMapper", CLASSLOADER)
            && ClassUtils.isPresent("org.codehaus.jackson.JsonGenerator", CLASSLOADER);
}

From source file:bootstrap.EnvironmentBootstrapConfiguration.java

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
    if (!environment.getPropertySources().contains(CONFIG_SERVER_BOOTSTRAP)) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("spring.cloud.config.uri",
                "${CONFIG_SERVER_URI:${vcap.services.${PREFIX:}configserver.credentials.uri:http://localhost:8888}}");
        if (ClassUtils.isPresent("org.springframework.cloud.sleuth.zipkin.ZipkinProperties", null)) {
            map.put("spring.zipkin.host",
                    "${ZIPKIN_HOST:${vcap.services.${PREFIX:}zipkin.credentials.host:localhost}}");
            map.put("logging.pattern.console",
                    "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr(${PID:- }){magenta} %clr(---){faint} %clr([trace=%X{X-Trace-Id:-},span=%X{X-Span-Id:-}]){yellow} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex");
            String zipkinHost = environment
                    .resolvePlaceholders("${ZIPKIN_HOST:${vcap.services.${PREFIX:}zipkin.credentials.host:}}");
            if (!"".equals(zipkinHost)) {
                map.put("fleet.zipkin.enabled", "true");
            }/*  w w  w  .  ja va  2s.c  o m*/
        }
        String space = environment.resolvePlaceholders("${vcap.application.space_name:dev}");
        log.info("Spacename: " + space);
        if (space.startsWith("dev")) {
            environment.addActiveProfile("dev");
        }
        map.put("encrypt.failOnError", "false");
        map.put("endpoints.shutdown.enabled", "true");
        map.put("endpoints.restart.enabled", "true");
        environment.getPropertySources().addLast(new MapPropertySource(CONFIG_SERVER_BOOTSTRAP, map));
    }
}

From source file:org.jnap.core.assets.LessAssetsHandler.java

@Override
protected boolean shouldInit() {
    return super.shouldInit()
            && ClassUtils.isPresent("com.asual.lesscss.LessEngine", this.getClass().getClassLoader());
}

From source file:org.grails.datastore.mapping.keyvalue.mapping.config.KeyValueMappingContext.java

/**
 * Constructs a context using the given keyspace
 *
 * @param keyspace The keyspace, this is typically the application name
 *//*from w  w w.j av a  2 s  .  co m*/
public KeyValueMappingContext(String keyspace) {
    Assert.notNull(keyspace, "Argument [keyspace] cannot be null");
    this.keyspace = keyspace;
    initializeDefaultMappingFactory(keyspace);

    if (ClassUtils.isPresent(GROOVY_OBJECT_CLASS, KeyValueMappingContext.class.getClassLoader())) {
        syntaxStrategy = new GormMappingConfigurationStrategy(mappingFactory);
    } else {
        syntaxStrategy = new DefaultMappingConfigurationStrategy(mappingFactory);
    }
}

From source file:org.cloudfoundry.reconfiguration.spring.DataSourceCloudServiceBeanFactoryPostProcessor.java

@Override
protected void filterBeanNames(ConfigurableListableBeanFactory beanFactory, Set<String> beanNames) {
    if (ClassUtils.isPresent(DELEGATING_DATA_SOURCE_CLASS, null)) {
        Set<String> delegatingBeanNames = Sets.asSet(beanFactory.getBeanNamesForType(
                ClassUtils.resolveClassName(DELEGATING_DATA_SOURCE_CLASS, null), true, false));

        beanNames.removeAll(delegatingBeanNames);
    }/*from w  w  w.j a v a  2 s .com*/
}