use of org.springframework.core.io.ResourceLoader in project webapp by elimu-ai.
the class EPubParagraphExtractionHelperTest method testExtractParagraphsFromChapterFile_FIL_LRA_7f877260_ch13.
@Test
public void testExtractParagraphsFromChapterFile_FIL_LRA_7f877260_ch13() throws IOException {
ResourceLoader resourceLoader = new ClassRelativeResourceLoader(EPubParagraphExtractionHelper.class);
Resource resource = resourceLoader.getResource("fil-lra-7f877260-ec7c-4970-b6e2-2ee41231d96d.epub_Page_13.xhtml");
File xhtmlFile = resource.getFile();
logger.debug("xhtmlFile: " + xhtmlFile);
List<String> storyBookParagraphs = EPubParagraphExtractionHelper.extractParagraphsFromChapterFile(xhtmlFile);
assertThat(storyBookParagraphs.size(), is(1));
assertThat(storyBookParagraphs.get(0), is("\"Nagmumuni-muni lang,\" sabi niya."));
}
use of org.springframework.core.io.ResourceLoader in project geronimo-xbean by apache.
the class XBeanNamespaceHandler method resolveBeanClass.
protected Class resolveBeanClass(AbstractBeanDefinition bd, String beanName) {
if (bd.hasBeanClass()) {
return bd.getBeanClass();
}
try {
ResourceLoader rl = parserContext.getReaderContext().getResourceLoader();
ClassLoader cl = rl != null ? rl.getClassLoader() : null;
if (cl == null) {
cl = parserContext.getReaderContext().getReader().getBeanClassLoader();
}
if (cl == null) {
cl = Thread.currentThread().getContextClassLoader();
}
if (cl == null) {
cl = getClass().getClassLoader();
}
return bd.resolveBeanClass(cl);
} catch (ClassNotFoundException ex) {
throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanName, "Bean class [" + bd.getBeanClassName() + "] not found", ex);
} catch (NoClassDefFoundError err) {
throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanName, "Class that bean class [" + bd.getBeanClassName() + "] depends on not found", err);
}
}
use of org.springframework.core.io.ResourceLoader in project spring-framework by spring-projects.
the class FreeMarkerConfigurerTests method freeMarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath.
@Test
@SuppressWarnings("rawtypes")
public void freeMarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath() throws Exception {
FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean();
fcfb.setTemplateLoaderPath("file:/mydir");
Properties settings = new Properties();
settings.setProperty("localized_lookup", "false");
fcfb.setFreemarkerSettings(settings);
fcfb.setResourceLoader(new ResourceLoader() {
@Override
public Resource getResource(String location) {
if (!("file:/mydir".equals(location) || "file:/mydir/test".equals(location))) {
throw new IllegalArgumentException(location);
}
return new ByteArrayResource("test".getBytes(), "test");
}
@Override
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
});
fcfb.afterPropertiesSet();
assertThat(fcfb.getObject(), instanceOf(Configuration.class));
Configuration fc = fcfb.getObject();
Template ft = fc.getTemplate("test");
assertEquals("test", FreeMarkerTemplateUtils.processTemplateIntoString(ft, new HashMap()));
}
use of org.springframework.core.io.ResourceLoader in project spring-boot by spring-projects.
the class ConfigFileApplicationListenerTests method loadCustomResource.
@Test
public void loadCustomResource() throws Exception {
this.application.setResourceLoader(new ResourceLoader() {
@Override
public Resource getResource(final String location) {
if (location.equals("classpath:/custom.properties")) {
return new ByteArrayResource("the.property: fromcustom".getBytes(), location) {
@Override
public String getFilename() {
return location;
}
};
}
return null;
}
@Override
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
});
this.initializer.setSearchNames("custom");
this.initializer.postProcessEnvironment(this.environment, this.application);
String property = this.environment.getProperty("the.property");
assertThat(property).isEqualTo("fromcustom");
}
use of org.springframework.core.io.ResourceLoader in project webapp by elimu-ai.
the class Mailer method sendHtmlWithButton.
public static void sendHtmlWithButton(String to, String cc, String from, String subject, String title, String text, String buttonText, String buttonUrl) {
logger.info("sendHtmlWithButton");
if (to.contains(",")) {
to = to.replace(",", "");
}
if (to.contains(":")) {
to = to.replace(":", "");
}
JavaMailSenderImpl javaMailSenderImpl = new JavaMailSenderImpl();
String smtpHost = ConfigHelper.getProperty("smtp.host");
javaMailSenderImpl.setHost(smtpHost);
MimeMessage mimeMessage = javaMailSenderImpl.createMimeMessage();
try {
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);
mimeMessageHelper.setFrom(from);
mimeMessageHelper.setTo(to);
if (StringUtils.isNotBlank(cc)) {
mimeMessageHelper.setCc(cc);
}
mimeMessageHelper.setBcc(ADMIN_EMAIL);
mimeMessageHelper.setSubject(subject);
String html = "";
ResourceLoader resourceLoader = new ClassRelativeResourceLoader(Mailer.class);
logger.info("Loading file email_template_button.html...");
Resource resource = resourceLoader.getResource("email_template_button.html");
InputStream inputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
try {
inputStream = resource.getInputStream();
inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
bufferedReader = new BufferedReader(inputStreamReader);
String line;
while ((line = bufferedReader.readLine()) != null) {
if (line.contains("${subject}")) {
line = line.replace("${subject}", subject);
}
if (line.contains("${title}")) {
line = line.replace("${title}", title);
}
if (line.contains("${text}")) {
line = line.replace("${text}", text);
}
if (line.contains("${buttonText}")) {
line = line.replace("${buttonText}", buttonText);
}
if (line.contains("${buttonUrl}")) {
line = line.replace("${buttonUrl}", buttonUrl);
}
html += line;
}
} catch (IOException ex) {
logger.error(null, ex);
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
logger.error(null, e);
}
}
if (inputStreamReader != null) {
try {
inputStreamReader.close();
} catch (IOException e) {
logger.error(null, e);
}
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
logger.error(null, e);
}
}
}
mimeMessageHelper.setText(text, html);
logger.info("Sending MIME message to " + to + " with subject \"" + subject + "\"...");
logger.info("title: " + title);
logger.info("text: " + text);
logger.info("buttonText: " + buttonText);
logger.info("buttonUrl: " + buttonUrl);
if (EnvironmentContextLoaderListener.env != Environment.DEV) {
javaMailSenderImpl.send(mimeMessage);
}
} catch (MessagingException ex) {
logger.error(null, ex);
}
}
Aggregations