| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kew.mail; |
| 17 | |
|
| 18 | |
import javax.xml.transform.Templates; |
| 19 | |
import javax.xml.transform.TransformerException; |
| 20 | |
import javax.xml.transform.dom.DOMResult; |
| 21 | |
import javax.xml.transform.dom.DOMSource; |
| 22 | |
import javax.xml.xpath.XPath; |
| 23 | |
import javax.xml.xpath.XPathConstants; |
| 24 | |
import javax.xml.xpath.XPathExpressionException; |
| 25 | |
import javax.xml.xpath.XPathFactory; |
| 26 | |
|
| 27 | |
import org.kuali.rice.kew.exception.WorkflowRuntimeException; |
| 28 | |
import org.kuali.rice.kew.util.XmlHelper; |
| 29 | |
import org.w3c.dom.Document; |
| 30 | |
import org.w3c.dom.Node; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | 0 | public class EmailStyleHelper { |
| 40 | |
|
| 41 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(EmailStyleHelper.class); |
| 42 | |
|
| 43 | |
public EmailContent generateEmailContent(Templates style, Document document) { |
| 44 | 0 | DOMResult result = new DOMResult(); |
| 45 | 0 | if (LOG.isDebugEnabled()) { |
| 46 | 0 | LOG.debug("Input document: " + XmlHelper.jotNode(document.getDocumentElement(), true)); |
| 47 | |
} |
| 48 | |
|
| 49 | |
try { |
| 50 | 0 | style.newTransformer().transform(new DOMSource(document), result); |
| 51 | 0 | } catch (TransformerException te) { |
| 52 | 0 | String message = "Error transforming immediate reminder DOM"; |
| 53 | 0 | LOG.error(message, te); |
| 54 | 0 | throw new WorkflowRuntimeException(message, te); |
| 55 | 0 | } |
| 56 | |
|
| 57 | 0 | Node node = result.getNode(); |
| 58 | |
|
| 59 | 0 | if (LOG.isDebugEnabled()) { |
| 60 | 0 | LOG.debug("Email document: " + XmlHelper.jotNode(document)); |
| 61 | |
} |
| 62 | 0 | XPathFactory xpf = XPathFactory.newInstance(); |
| 63 | 0 | XPath xpath = xpf.newXPath(); |
| 64 | |
try { |
| 65 | 0 | String subject = (String) xpath.evaluate("/email/subject", node, XPathConstants.STRING); |
| 66 | 0 | String body = (String) xpath.evaluate("/email/body", node, XPathConstants.STRING); |
| 67 | |
|
| 68 | 0 | return new EmailContent(subject, body, body.matches("(?msi).*<(\\w+:)?html.*")); |
| 69 | 0 | } catch (XPathExpressionException xpee) { |
| 70 | 0 | throw new WorkflowRuntimeException("Error evaluating generated email content", xpee); |
| 71 | |
} |
| 72 | |
} |
| 73 | |
|
| 74 | |
} |