use of org.springframework.core.io.ClassRelativeResourceLoader in project webapp by elimu-ai.
the class EPubMetadataExtractionHelperTest method testExtractTitleFromOpfFile_FIL_LETS_READ_ASIA_0acfe340.
@Test
public void testExtractTitleFromOpfFile_FIL_LETS_READ_ASIA_0acfe340() throws IOException {
ResourceLoader resourceLoader = new ClassRelativeResourceLoader(EPubMetadataExtractionHelper.class);
Resource resource = resourceLoader.getResource("fil-lra-0acfe340-6116-4f8a-a45d-c925c8a1fd0e.epub_content.opf");
File opfFile = resource.getFile();
logger.debug("opfFile: " + opfFile);
String title = EPubMetadataExtractionHelper.extractTitleFromOpfFile(opfFile);
assertThat(title, is("Hindi na Ako natatakot!"));
String description = EPubMetadataExtractionHelper.extractDescriptionFromOpfFile(opfFile);
assertThat(description, is("Ang batang si Marah, mag-isang lumabas sa dilim. Matatakot kaya siya?"));
}
use of org.springframework.core.io.ClassRelativeResourceLoader in project webapp by elimu-ai.
the class EPubMetadataExtractionHelperTest method testExtractTitleFromOpfFile_FIL_LETS_READ_ASIA_627f64f8.
@Test
public void testExtractTitleFromOpfFile_FIL_LETS_READ_ASIA_627f64f8() throws IOException {
ResourceLoader resourceLoader = new ClassRelativeResourceLoader(EPubMetadataExtractionHelper.class);
Resource resource = resourceLoader.getResource("fil-lra-627f64f8-a002-4c0f-8bb6-3701ce5fcf19.epub_content.opf");
File opfFile = resource.getFile();
logger.debug("opfFile: " + opfFile);
String title = EPubMetadataExtractionHelper.extractTitleFromOpfFile(opfFile);
assertThat(title, is("Si Pusa at si Aso at ang Sumbrero"));
String description = EPubMetadataExtractionHelper.extractDescriptionFromOpfFile(opfFile);
assertThat(description, is("Mayroong mga bagong sumbrero sina Pusa at Aso! Ngunit ano ang kanilang gagawin pagkatapos tangayin ng malakas na hangin ang kani-kaniyang sumbrero sa tubig? Sana, mayroon silang kaibigan na nauuhaw."));
}
use of org.springframework.core.io.ClassRelativeResourceLoader 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.ClassRelativeResourceLoader 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);
}
}
use of org.springframework.core.io.ClassRelativeResourceLoader in project webapp by elimu-ai.
the class Mailer method sendHtml.
public static void sendHtml(String to, String cc, String from, String subject, String title, String text) {
logger.info("sendPlainText");
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.html...");
Resource resource = resourceLoader.getResource("email_template.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);
} else if (line.contains("${title}")) {
line = line.replace("${title}", title);
} else if (line.contains("${text}")) {
line = line.replace("${text}", text);
}
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);
if (EnvironmentContextLoaderListener.env != Environment.DEV) {
javaMailSenderImpl.send(mimeMessage);
}
} catch (MessagingException ex) {
logger.error(null, ex);
}
}
Aggregations