/** * <p> * Checks whether a class is present at the application's class path. * </p> * <p> * This method works very similarly to {@link #findClass(String)} but will just return {@code true} * or {@code false} depending on whether the class could be found or not. * </p> * * @param className the name of the class to be checked. * @return {@code true} if the class was found (by any class loader), {@code false} if not. * * @since 3.0.3 * */ public static boolean isClassPresent(final String className) { return findClass(className) != null; }
/** * <p> * Checks whether a resource is present at the application's class path. * </p> * <p> * This method works very similarly to {@link #findResource(String)} but will just return {@code true} * or {@code false} depending on whether the resource could be located or not. * </p> * * @param resourceName the name of the resource to be checked. * @return {@code true} if the class was located (by any class loader), {@code false} if not. * * @since 3.0.3 * */ public static boolean isResourcePresent(final String resourceName) { return findResource(resourceName) != null; }
/** * <p> * Obtain a resource by name, throwing an exception if it is not present. * </p> * <p> * First the <em>context class loader</em> will be used. If this class loader is not * able to locate the resource, then the <em>class class loader</em> * ({@code ClassLoaderUtils.class.getClassLoader()}) will be used if it is different from * the thread context one. Last, the System class loader will be tried. * </p> * <p> * This method does never return {@code null}. * </p> * * @param resourceName the name of the resource to be obtained. * @return an input stream on the resource (null never returned). * @throws IOException if the resource could not be located. * * @since 3.0.3 * */ public static InputStream loadResourceAsStream(final String resourceName) throws IOException { final InputStream inputStream = findResourceAsStream(resourceName); if (inputStream != null) { return inputStream; } // No way to obtain that resource, so we must raise an IOException throw new IOException("Could not locate resource '" + resourceName + "' in the application's class path"); }
/** * <p> * Try to obtain a classloader, following these priorities: * </p> * <ol> * <li>If there is a <i>thread context class loader</i>, return it.</li> * <li>Else if there is a class loader related to the class passed as argument, return it.</li> * <li>Else return the <i>system class loader</i>.</li> * </ol> * * @param clazz the class which loader will be obtained in the second step. Can be null (that will * skip that second step). * @return a non-null, safe classloader to use. */ public static ClassLoader getClassLoader(final Class<?> clazz) { // Context class loader can be null final ClassLoader contextClassLoader = getThreadContextClassLoader(); if (contextClassLoader != null) { return contextClassLoader; } if (clazz != null) { // The class loader for a specific class can also be null final ClassLoader clazzClassLoader = getClassClassLoader(clazz); if (clazzClassLoader != null) { return clazzClassLoader; } } // The only class loader we can rely on for not being null is the system one return systemClassLoader; }
final ClassLoader contextClassLoader = getThreadContextClassLoader(); if (contextClassLoader != null) { final InputStream inputStream = contextClassLoader.getResourceAsStream(resourceName); if (!isKnownLeafClassLoader(contextClassLoader)) {
private static Class<?> getClass(final String className) { final ClassLoader classLoader = ClassLoaderUtils.getClassLoader(SpringSecurityVersionUtils.class); try { return Class.forName(className, false, classLoader); } catch (final Throwable t) { return null; } }
private static boolean testClassExistence(final String className) { final ClassLoader classLoader = ClassLoaderUtils.getClassLoader(SpringSecurityVersionUtils.class); try { Class.forName(className, false, classLoader); return true; } catch (final Throwable t) { return false; } }
final ClassLoader contextClassLoader = getThreadContextClassLoader(); if (contextClassLoader != null) { final URL url = contextClassLoader.getResource(resourceName); if (!isKnownLeafClassLoader(contextClassLoader)) {
private static Class<?> getClass(final String className) { final ClassLoader classLoader = ClassLoaderUtils.getClassLoader(SpringSecurityVersionUtils.class); try { return Class.forName(className, false, classLoader); } catch (final Throwable t) { return null; } }
final ClassLoader contextClassLoader = getThreadContextClassLoader(); if (contextClassLoader != null) { try { if (!isKnownLeafClassLoader(contextClassLoader)) {
public Reader reader() throws IOException { final InputStream inputStream; if (this.optionalClassLoader != null) { inputStream = this.optionalClassLoader.getResourceAsStream(this.path); } else { inputStream = ClassLoaderUtils.findResourceAsStream(this.path); } if (inputStream == null) { throw new FileNotFoundException(String.format("ClassLoader resource \"%s\" could not be resolved", this.path)); } if (!StringUtils.isEmptyOrWhitespace(this.characterEncoding)) { return new BufferedReader(new InputStreamReader(new BufferedInputStream(inputStream), this.characterEncoding)); } return new BufferedReader(new InputStreamReader(new BufferedInputStream(inputStream))); }
JacksonStandardJavaScriptSerializer(final String jacksonPrefix) { super(); this.mapper = new ObjectMapper(); this.mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); this.mapper.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); this.mapper.enable(JsonGenerator.Feature.ESCAPE_NON_ASCII); this.mapper.getFactory().setCharacterEscapes(new JacksonThymeleafCharacterEscapes()); this.mapper.setDateFormat(new JacksonThymeleafISO8601DateFormat()); /* * Now try to (conditionally) initialize support for Jackson serialization of JSR310 (java.time) objects, * by making use of the 'jackson-datatype-jsr310' optional dependency. */ final Class<?> javaTimeModuleClass = ClassLoaderUtils.findClass(jacksonPrefix + ".datatype.jsr310.JavaTimeModule"); if (javaTimeModuleClass != null) { // JSR310 support for Jackson is present in classpath try { this.mapper.registerModule((Module)javaTimeModuleClass.newInstance()); this.mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); } catch (final InstantiationException e) { throw new ConfigurationException("Exception while trying to initialize JSR310 support for Jackson", e); } catch (final IllegalAccessException e) { throw new ConfigurationException("Exception while trying to initialize JSR310 support for Jackson", e); } } }
private static boolean testClassExistence(final String className) { final ClassLoader classLoader = ClassLoaderUtils.getClassLoader(SpringSecurityVersionUtils.class); try { Class.forName(className, false, classLoader); return true; } catch (final Throwable t) { return false; } }
private static boolean testClassExistence(final String className) { final ClassLoader classLoader = ClassLoaderUtils.getClassLoader(SpringSecurityVersionUtils.class); try { Class.forName(className, false, classLoader); return true; } catch (final Throwable t) { return false; } }
private static Class<?> getClass(final String className) { final ClassLoader classLoader = ClassLoaderUtils.getClassLoader(SpringSecurityVersionUtils.class); try { return Class.forName(className, false, classLoader); } catch (final Throwable t) { return null; } }
private static boolean testClassExistence(final String className) { final ClassLoader classLoader = ClassLoaderUtils.getClassLoader(SpringSecurityVersionUtils.class); try { Class.forName(className, false, classLoader); return true; } catch (final Throwable t) { return false; } }
private static boolean testClassExistence(final String className) { final ClassLoader classLoader = ClassLoaderUtils.getClassLoader(SpringSecurityVersionUtils.class); try { Class.forName(className, false, classLoader); return true; } catch (final Throwable t) { return false; } }
private static Class<?> getClass(final String className) { final ClassLoader classLoader = ClassLoaderUtils.getClassLoader(SpringSecurityVersionUtils.class); try { return Class.forName(className, false, classLoader); } catch (final Throwable t) { return null; } }
private static boolean testClassExistence(final String className) { final ClassLoader classLoader = ClassLoaderUtils.getClassLoader(SpringSecurityVersionUtils.class); try { Class.forName(className, false, classLoader); return true; } catch (final Throwable t) { return false; } }
private static Class<?> getClass(final String className) { final ClassLoader classLoader = ClassLoaderUtils.getClassLoader(SpringSecurityVersionUtils.class); try { return Class.forName(className, false, classLoader); } catch (final Throwable t) { return null; } }