private String getTemplatePath(final String template) { final boolean renderAsHtml = (ClassLoaderUtils.getResource(EMAIL_TEMPLATES + "html/" + template, this.getClass()) != null); final String prefix = (renderAsHtml) ? "html/" : "text/"; return EMAIL_TEMPLATES + prefix + template; }
public static File getTestResource(String path) throws URISyntaxException { return new File(ClassLoaderUtils.getResource(path, TestUtils.class).toURI()); } }
/** * This is a convenience method to load a resource as a stream. * <p> * The algorithm used to find the resource is given in getResource() * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object */ public static InputStream getResourceAsStream(String resourceName, Class callingClass) { URL url = getResource(resourceName, callingClass); try { return url != null ? url.openStream() : null; } catch (IOException e) { return null; } } }
/** * This is a convenience method to load a resource as a stream. * * The algorithm used to find the resource is given in getResource() * * @param resourceName The name of the resource to load * @param callingClass The Class object of the calling object */ public static InputStream getResourceAsStream(String resourceName, Class callingClass) { URL url = getResource(resourceName, callingClass); try { return url != null ? url.openStream() : null; } catch (IOException e) { return null; } }
public String getEntityEngineXmlPath() { try { return ClassLoaderUtils.getResource(EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME, getClass()).toExternalForm(); } catch (final Exception e) { log.error("Could not load " + EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME + " path " + e.getMessage(), e); return "Could not load " + EntityConfigUtil.ENTITY_ENGINE_XML_FILENAME + " path. Exception " + e.getMessage(); } }
private void exceptionHandling(final Writer writer, Exception e, final String templateDirectory, String template) throws IOException { if (e instanceof ResourceNotFoundException) { log.error("ResourceNotFoundException occurred whilst loading resource " + template); URL templateUrl = ClassLoaderUtils.getResource(templateDirectory + template, this.getClass()); if (templateUrl == null) { throw new VelocityException("Could not find template '" + templateDirectory + template + "' ensure it is in the classpath."); } writer.write("Could not locate resource " + templateDirectory + template); } else if (e instanceof MethodInvocationException) { Throwable t = ((MethodInvocationException) e).getWrappedThrowable(); log.error("MethodInvocationException occurred getting message body from Velocity: " + t, t); writer.write(getErrorMessageForException(e)); } else { log.error("Exception getting message body from Velocity: " + e, e); writer.write(getErrorMessageForException(e)); } }
@Override public Configuration get() { try { final Configuration configuration = new DefaultConfiguration(); configuration.load(ClassLoaderUtils.getResource("osworkflow.xml", getClass())); // This is here because there is a concurrency bug in osworkflow such that the configuration // does not safely initialize its GenericDelegator. If we do not "prime" the reference to the // delegator then you can run into issues where you get a null pointer when concurrently trying // to create issues. DO NOT REMOVE THIS BLOCK OF CODE!! try { configuration.getWorkflowStore(); return configuration; } catch (StoreException e) { throw new DataAccessException(e); } } catch (FactoryException e) { log.error("Error loading OSWorkflow Configuration: " + e, e); throw new InfrastructureException("Error loading osworkflow.xml file: " + e, e); } } }
final URL entityEngineURL = ClassLoaderUtils.getResource("entityengine.xml", getClass()); logMsg.outputProperty("Loading entityengine.xml from", entityEngineURL.toString());