Search in sources :

Example 1 with MailException

use of oap.mail.MailException in project oap by oaplatform.

the class XmlMessageParser method parse.

public Message parse(String content) {
    try {
        SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
        SaxMessageParser handler = new SaxMessageParser();
        parser.parse(new ByteArrayInputStream(content.getBytes(UTF_8)), handler);
        return handler.getMessage();
    } catch (ParserConfigurationException | SAXException | IOException e) {
        throw new MailException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) MailException(oap.mail.MailException) SAXException(org.xml.sax.SAXException)

Example 2 with MailException

use of oap.mail.MailException in project oap by oaplatform.

the class VelocityTemplateTransformer method transform.

public synchronized String transform(Template template) {
    try {
        VelocityContext context = new VelocityContext();
        Map<String, Object> parameters = template.getParameters();
        for (String key : parameters.keySet()) context.put(key, parameters.get(key));
        StringWriter writer = new StringWriter();
        engine.evaluate(context, writer, "mail", template.getContent());
        writer.close();
        return writer.toString();
    } catch (ParseErrorException | MethodInvocationException | ResourceNotFoundException | IOException e) {
        throw new MailException(e);
    }
}
Also used : StringWriter(java.io.StringWriter) VelocityContext(org.apache.velocity.VelocityContext) ParseErrorException(org.apache.velocity.exception.ParseErrorException) MethodInvocationException(org.apache.velocity.exception.MethodInvocationException) IOException(java.io.IOException) MailException(oap.mail.MailException) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException)

Aggregations

IOException (java.io.IOException)2 MailException (oap.mail.MailException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringWriter (java.io.StringWriter)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 SAXParser (javax.xml.parsers.SAXParser)1 VelocityContext (org.apache.velocity.VelocityContext)1 MethodInvocationException (org.apache.velocity.exception.MethodInvocationException)1 ParseErrorException (org.apache.velocity.exception.ParseErrorException)1 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)1 SAXException (org.xml.sax.SAXException)1