Coverage Report - org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
StyleableEmailContentServiceImpl
0%
0/230
0%
0/46
2.909
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  *
 4  
  *
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.opensource.org/licenses/ecl2.php
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 package org.kuali.rice.kew.mail.service.impl;
 19  
 
 20  
 import org.apache.commons.lang.StringUtils;
 21  
 import org.apache.log4j.Logger;
 22  
 import org.kuali.rice.core.api.style.StyleService;
 23  
 import org.kuali.rice.core.mail.EmailContent;
 24  
 import org.kuali.rice.core.util.RiceConstants;
 25  
 import org.kuali.rice.core.util.xml.XmlHelper;
 26  
 import org.kuali.rice.core.util.xml.XmlJotter;
 27  
 import org.kuali.rice.kew.actionitem.ActionItem;
 28  
 import org.kuali.rice.kew.api.WorkflowRuntimeException;
 29  
 import org.kuali.rice.kew.doctype.bo.DocumentType;
 30  
 import org.kuali.rice.kew.feedback.web.FeedbackForm;
 31  
 import org.kuali.rice.kew.mail.CustomEmailAttribute;
 32  
 import org.kuali.rice.kew.mail.EmailStyleHelper;
 33  
 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
 34  
 import org.kuali.rice.kew.routeheader.service.RouteHeaderService;
 35  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 36  
 import org.kuali.rice.kew.user.UserUtils;
 37  
 import org.kuali.rice.kew.util.KEWConstants;
 38  
 import org.kuali.rice.kim.api.identity.principal.Principal;
 39  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 40  
 import org.kuali.rice.kim.bo.Person;
 41  
 import org.kuali.rice.krad.util.GlobalVariables;
 42  
 import org.springframework.core.io.DefaultResourceLoader;
 43  
 import org.w3c.dom.Document;
 44  
 import org.w3c.dom.Element;
 45  
 import org.w3c.dom.Node;
 46  
 
 47  
 import javax.xml.parsers.DocumentBuilder;
 48  
 import javax.xml.parsers.DocumentBuilderFactory;
 49  
 import javax.xml.parsers.ParserConfigurationException;
 50  
 import javax.xml.transform.Templates;
 51  
 import javax.xml.transform.TransformerConfigurationException;
 52  
 import javax.xml.transform.TransformerException;
 53  
 import javax.xml.transform.TransformerFactory;
 54  
 import javax.xml.transform.dom.DOMSource;
 55  
 import javax.xml.transform.stream.StreamResult;
 56  
 import javax.xml.transform.stream.StreamSource;
 57  
 import java.io.StringWriter;
 58  
 import java.sql.Timestamp;
 59  
 import java.util.Collection;
 60  
 import java.util.Map;
 61  
 
 62  
 
 63  
 
 64  
 /**
 65  
  * EmailContentService that serves EmailContent customizable via XSLT style sheets
 66  
  * The global email style name is: kew.email.style
 67  
  * If this style is not found, the resource 'defaultEmailStyle.xsl' will be retrieved
 68  
  * relative to this class.
 69  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 70  
  */
 71  0
 public class StyleableEmailContentServiceImpl extends BaseEmailContentServiceImpl {
 72  0
     private static final Logger LOG = Logger.getLogger(StyleableEmailContentServiceImpl.class);
 73  
 
 74  0
     protected final String DEFAULT_EMAIL_STYLESHEET_RESOURCE_LOC = "defaultEmailStyle.xsl";
 75  
 
 76  
     protected StyleService styleService;
 77  0
     protected EmailStyleHelper styleHelper = new EmailStyleHelper();
 78  0
     protected String globalEmailStyleSheet = KEWConstants.EMAIL_STYLESHEET_NAME;
 79  
 
 80  
     protected RouteHeaderService routeHeaderService;
 81  
 
 82  
     public void setStyleService(StyleService styleService) {
 83  0
         this.styleService = styleService;
 84  0
     }
 85  
 
 86  
     public void setGlobalEmailStyleSheet(String globalEmailStyleSheet) {
 87  0
         this.globalEmailStyleSheet = globalEmailStyleSheet;
 88  0
     }
 89  
 
 90  
     protected static DocumentBuilder getDocumentBuilder(boolean coalesce) {
 91  
         try {
 92  0
             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 93  0
             dbf.setCoalescing(coalesce);
 94  0
             return dbf.newDocumentBuilder();
 95  0
         } catch (ParserConfigurationException e) {
 96  0
             String message = "Error constructing document builder";
 97  0
             LOG.error(message, e);
 98  0
             throw new WorkflowRuntimeException(message, e);
 99  
         }
 100  
     }
 101  
 
 102  
     protected static void addObjectXML(Document doc, Object o, Node node, String name) throws Exception {
 103  0
         Element element = XmlHelper.propertiesToXml(doc, o, name);
 104  
 
 105  0
         if (LOG.isDebugEnabled()) {
 106  0
             LOG.debug(XmlJotter.jotNode(element));
 107  
         }
 108  
 
 109  0
         if (node == null) {
 110  0
             node = doc;
 111  
         }
 112  
 
 113  0
         node.appendChild(element);
 114  0
     }
 115  
 
 116  
     protected static void addTextElement(Document doc, Element baseElement, String elementName, Object elementData) {
 117  0
         Element element = doc.createElement(elementName);
 118  0
         String dataValue = "";
 119  0
         if (elementData != null) {
 120  0
                 dataValue = elementData.toString();
 121  
         }
 122  0
         element.appendChild(doc.createTextNode(dataValue));
 123  0
         baseElement.appendChild(element);
 124  0
     }
 125  
 
 126  
     protected static void addCDataElement(Document doc, Element baseElement, String elementName, Object elementData) {
 127  0
         Element element = doc.createElement(elementName);
 128  0
         String dataValue = "";
 129  0
         if (elementData != null) {
 130  0
             dataValue = elementData.toString();
 131  
         }
 132  0
         element.appendChild(doc.createCDATASection(dataValue));
 133  0
         baseElement.appendChild(element);
 134  0
     }
 135  
 
 136  
     protected static void addTimestampElement(Document doc, Element baseElement, String elementName, Timestamp elementData) {
 137  0
         addTextElement(doc, baseElement, elementName, RiceConstants.getDefaultDateFormat().format(elementData));
 138  0
     }
 139  
 
 140  
     protected static void addDelegatorElement(Document doc, Element baseElement, ActionItem actionItem) {
 141  0
         Element delegatorElement = doc.createElement("delegator");
 142  0
         if ( (actionItem.getDelegatorWorkflowId() != null) && (actionItem.getDelegatorWorkflowId() != null) ) {
 143  
             // add empty delegator element
 144  0
             baseElement.appendChild(delegatorElement);
 145  0
             return;
 146  
         }
 147  0
         String delegatorType = "";
 148  0
         String delegatorId = "";
 149  0
         String delegatorDisplayValue = "";
 150  0
         if (actionItem.getDelegatorWorkflowId() != null) {
 151  0
             delegatorType = "user";
 152  0
             delegatorId = actionItem.getDelegatorWorkflowId();
 153  0
             Principal delegator = KimApiServiceLocator.getIdentityService().getPrincipal(delegatorId);
 154  
             
 155  0
             if (delegator == null) {
 156  0
                     LOG.error("Cannot find user for id " + delegatorId);
 157  0
                     delegatorDisplayValue = "USER NOT FOUND";
 158  
             } else {
 159  0
                     delegatorDisplayValue = UserUtils.getTransposedName(GlobalVariables.getUserSession(), delegator);
 160  
             }
 161  0
         } else if (actionItem.getDelegatorWorkflowId() != null) {
 162  0
             delegatorType = "workgroup";
 163  0
             delegatorId = actionItem.getDelegatorGroupId().toString();
 164  0
             delegatorDisplayValue = KimApiServiceLocator.getGroupService().getGroup(actionItem.getDelegatorGroupId()).getName();
 165  
         }
 166  0
         delegatorElement.setAttribute("type", delegatorType);
 167  
         // add the id element
 168  0
         Element idElement = doc.createElement("id");
 169  0
         idElement.appendChild(doc.createTextNode(delegatorId));
 170  0
         delegatorElement.appendChild(idElement);
 171  
         // add the display value element
 172  0
         Element displayValElement = doc.createElement("displayValue");
 173  0
         displayValElement.appendChild(doc.createTextNode(delegatorDisplayValue));
 174  0
         delegatorElement.appendChild(displayValElement);
 175  0
         baseElement.appendChild(delegatorElement);
 176  0
     }
 177  
 
 178  
     protected static void addWorkgroupRequestElement(Document doc, Element baseElement, ActionItem actionItem) {
 179  0
         Element workgroupElement = doc.createElement("workgroupRequest");
 180  0
         if (actionItem.isWorkgroupItem()) {
 181  
             // add the id element
 182  0
             Element idElement = doc.createElement("id");
 183  0
             idElement.appendChild(doc.createTextNode(actionItem.getGroupId()));
 184  0
             workgroupElement.appendChild(idElement);
 185  
             // add the display value element
 186  0
             Element displayValElement = doc.createElement("displayValue");
 187  0
             displayValElement.appendChild(doc.createTextNode(actionItem.getGroupId()));
 188  0
             workgroupElement.appendChild(displayValElement);
 189  
         }
 190  0
         baseElement.appendChild(workgroupElement);
 191  0
     }
 192  
 
 193  
     /**
 194  
      * This method is used to add the given {@link ActionItem} to the given {@link org.w3c.dom.Document} in a summarized
 195  
      * form for use in weekly or daily type reminder e-mails.
 196  
      *
 197  
      * @param doc - Document to have the ActionItem added to
 198  
      * @param actionItem - the action item being added
 199  
      * @param user - the current user
 200  
      * @param node - the node object to add the actionItem XML to (defaults to the doc variable if null is passed in)
 201  
      * @throws Exception
 202  
      */
 203  
     protected void addSummarizedActionItem(Document doc, ActionItem actionItem, Person user, Node node, DocumentRouteHeaderValue routeHeader) throws Exception {
 204  0
         if (node == null) {
 205  0
             node = doc;
 206  
         }
 207  
 
 208  0
         Element root = doc.createElement("summarizedActionItem");
 209  
 
 210  
         // add in all items from action list as preliminary default dataset
 211  0
         addTextElement(doc, root, "documentId", actionItem.getDocumentId());
 212  0
         addTextElement(doc, root, "docName", actionItem.getDocName());
 213  0
         addCDataElement(doc, root, "docLabel", actionItem.getDocLabel());
 214  0
         addCDataElement(doc, root, "docTitle", actionItem.getDocTitle());
 215  
         //DocumentRouteHeaderValue routeHeader = getRouteHeader(actionItem);
 216  0
         addTextElement(doc, root, "docRouteStatus", routeHeader.getDocRouteStatus());
 217  0
         addCDataElement(doc, root, "routeStatusLabel", routeHeader.getRouteStatusLabel());
 218  0
         addTextElement(doc, root, "actionRequestCd", actionItem.getActionRequestCd());
 219  0
         addTextElement(doc, root, "actionRequestLabel", actionItem.getActionRequestLabel());
 220  0
         addDelegatorElement(doc, root, actionItem);
 221  0
         addTimestampElement(doc, root, "createDate", routeHeader.getCreateDate());
 222  0
         addWorkgroupRequestElement(doc, root, actionItem);
 223  0
         addTimestampElement(doc, root, "dateAssigned", actionItem.getDateAssigned());
 224  
 
 225  0
         node.appendChild(root);
 226  0
     }
 227  
 
 228  
     public DocumentRouteHeaderValue getRouteHeader(ActionItem actionItem) {
 229  0
             if (routeHeaderService == null) {
 230  0
                     routeHeaderService = KEWServiceLocator.getRouteHeaderService();
 231  
             }
 232  0
         return routeHeaderService.getRouteHeader(actionItem.getDocumentId());
 233  
     }
 234  
 
 235  
     protected Map<String,DocumentRouteHeaderValue> getRouteHeaders(Collection<ActionItem> actionItems) {
 236  0
             if (routeHeaderService == null) {
 237  0
                     routeHeaderService = KEWServiceLocator.getRouteHeaderService();
 238  
             }
 239  0
             return routeHeaderService.getRouteHeadersForActionItems(actionItems);
 240  
     }
 241  
     
 242  
     protected static String transform(Templates style, Document doc) {
 243  0
         StringWriter writer = new StringWriter();
 244  0
         StreamResult result = new StreamResult(writer);
 245  
 
 246  
         try {
 247  0
             style.newTransformer().transform(new DOMSource(doc), result);
 248  0
             return writer.toString();
 249  0
         } catch (TransformerException te) {
 250  0
             String message = "Error transforming DOM";
 251  0
             LOG.error(message, te);
 252  0
             throw new WorkflowRuntimeException(message, te);
 253  
         }
 254  
     }
 255  
 
 256  
     /**
 257  
      * This method retrieves the style from the system using the given name. If none is found the default style xsl file
 258  
      * defined by {@link #DEFAULT_EMAIL_STYLESHEET_RESOURCE_LOC} is used.
 259  
      *
 260  
      * @param styleName
 261  
      * @return a valid {@link javax.xml.transform.Templates} using either the given styleName or the default xsl style file
 262  
      */
 263  
     protected Templates getStyle(String styleName) {
 264  0
         Templates style = null;
 265  
         try {
 266  0
             style = styleService.getStyleAsTranslet(styleName);
 267  0
         } catch (TransformerConfigurationException tce) {
 268  0
             String message = "Error obtaining style '" + styleName + "', using default";
 269  0
             LOG.error(message, tce);
 270  
             // throw new WorkflowRuntimeException("Error obtaining style '" + styleName + "'", tce);
 271  0
         }
 272  
 
 273  0
         if (style == null) {
 274  0
             LOG.warn("Could not find specified style, " + styleName + ", using default");
 275  
             try {
 276  
 
 277  0
                 style = TransformerFactory.newInstance().newTemplates(new StreamSource(new DefaultResourceLoader().getResource("classpath:org/kuali/rice/kew/mail/" + DEFAULT_EMAIL_STYLESHEET_RESOURCE_LOC).getInputStream()));
 278  0
             } catch (Exception tce) {
 279  0
                 String message = "Error obtaining default style from resource: " + DEFAULT_EMAIL_STYLESHEET_RESOURCE_LOC;
 280  0
                 LOG.error(message, tce);
 281  0
                 throw new WorkflowRuntimeException("Error obtaining style '" + styleName + "'", tce);
 282  0
             }
 283  
         }
 284  0
         return style;
 285  
     }
 286  
 
 287  
     protected EmailContent generateEmailContent(String styleName, Document doc) {
 288  0
         Templates style = getStyle(styleName);
 289  0
         return styleHelper.generateEmailContent(style, doc);
 290  
     }
 291  
 
 292  
     protected EmailContent generateReminderForActionItems(Person user, Collection<ActionItem> actionItems, String name, String style) {
 293  0
         DocumentBuilder db = getDocumentBuilder(false);
 294  0
         Document doc = db.newDocument();
 295  0
         Element element = doc.createElement(name);
 296  0
         Map<String,DocumentRouteHeaderValue> routeHeaders = getRouteHeaders(actionItems);
 297  
         
 298  0
         setStandardAttributes(element);
 299  0
         doc.appendChild(element);
 300  
 
 301  
         try {
 302  0
             addObjectXML(doc, user, element, "user");
 303  0
             for (ActionItem actionItem: actionItems) {
 304  
                 try {
 305  0
                     addSummarizedActionItem(doc, actionItem, user, element, routeHeaders.get(actionItem.getDocumentId()));
 306  0
                 } catch (Exception e) {
 307  0
                     String message = "Error generating XML for action item: " + actionItem;
 308  0
                     LOG.error(message, e);
 309  0
                     throw new WorkflowRuntimeException(e);
 310  0
                 }
 311  
             }
 312  
 
 313  0
         } catch (Exception e) {
 314  0
             String message = "Error generating XML for action items: " + actionItems;
 315  0
             LOG.error(message, e);
 316  0
             throw new WorkflowRuntimeException(e);
 317  0
         }
 318  
 
 319  0
         return generateEmailContent(style, doc);
 320  
     }
 321  
 
 322  
     protected void setStandardAttributes(Element e) {
 323  0
         e.setAttribute("env", getDeploymentEnvironment());
 324  0
         e.setAttribute("applicationEmailAddress", getApplicationEmailAddress());
 325  0
         e.setAttribute("actionListUrl", getActionListUrl());
 326  0
         e.setAttribute("preferencesUrl", getPreferencesUrl());
 327  0
     }
 328  
 
 329  
     /**
 330  
      * This method generates an {@link EmailContent} object using the given parameters.  Part of this operation includes
 331  
      * serializing the given {@link ActionItem} to XML. The following objects and methods are included in the serialization:
 332  
      *
 333  
      * <ul>
 334  
      * <li>{@link Person}</li>
 335  
      * <li>{@link Person#getPrincipalName()}</li>
 336  
      * <li>{@link DocumentRouteHeaderValue}</li>
 337  
      * <li>{@link DocumentRouteHeaderValue#getInitiatorUser()}</li>
 338  
      * <li>{@link DocumentRouteHeaderValue#getDocumentType()}</li>
 339  
      * <li>{@link Person}</li>
 340  
      * </ul>
 341  
      *
 342  
      * @param user - the current user
 343  
      * @param actionItem - the action item being added
 344  
      * @param documentType - the document type that the custom email style sheet will come from
 345  
      * @param node - the node object to add the actionItem XML to (defaults to the doc variable if null is passed in)
 346  
      * @throws Exception
 347  
      */
 348  
     @Override
 349  
         public EmailContent generateImmediateReminder(Person user, ActionItem actionItem, DocumentType documentType) {
 350  
             
 351  0
             LOG.info("Starting generation of immediate email reminder...");
 352  0
             LOG.info("Action Id: " + actionItem.getActionItemId() + 
 353  
                              ";  ActionRequestId: " + actionItem.getActionRequestId() + 
 354  
                              ";  Action Item Principal Name: " + actionItem.getPerson().getPrincipalName());
 355  0
             LOG.info("User Principal Name: " + user.getPrincipalName());
 356  
         // change style name based on documentType when configurable email style on document is implemented...
 357  0
         String styleSheet = documentType.getCustomEmailStylesheet();
 358  0
         LOG.debug(documentType.getName() + " style: " + styleSheet);
 359  0
         if (styleSheet == null) {
 360  0
             styleSheet = globalEmailStyleSheet;
 361  
         }
 362  
 
 363  0
         LOG.info("generateImmediateReminder using style sheet: "+ styleSheet + " for Document Type " + documentType.getName());
 364  
 //        return generateReminderForActionItems(user, actionItems, "immediateReminder", styleSheet);
 365  0
         DocumentBuilder db = getDocumentBuilder(false);
 366  0
         Document doc = db.newDocument();
 367  0
         Element element = doc.createElement("immediateReminder");
 368  0
         setStandardAttributes(element);
 369  0
         doc.appendChild(element);
 370  
 
 371  
         try {
 372  0
             addObjectXML(doc, user, element, "user");
 373  
 //            addActionItem(doc, actionItem, user, node);
 374  0
             Node node = element;
 375  0
             if (node == null) {
 376  0
                 node = doc;
 377  
             }
 378  
 
 379  0
             Element root = doc.createElement("actionItem");
 380  
             // append the custom body and subject if they exist
 381  
             try {
 382  0
                 CustomEmailAttribute customEmailAttribute = getCustomEmailAttribute(user, actionItem);
 383  0
                 if (customEmailAttribute != null) {
 384  0
                     String customBody = customEmailAttribute.getCustomEmailBody();
 385  0
                     if (!org.apache.commons.lang.StringUtils.isEmpty(customBody)) {
 386  0
                         Element bodyElement = doc.createElement("customBody");
 387  0
                         bodyElement.appendChild(doc.createTextNode(customBody));
 388  0
                         root.appendChild(bodyElement);
 389  
                     }
 390  0
                     String customEmailSubject = customEmailAttribute.getCustomEmailSubject();
 391  0
                     if (!org.apache.commons.lang.StringUtils.isEmpty(customEmailSubject)) {
 392  0
                         Element subjectElement = doc.createElement("customSubject");
 393  0
                         subjectElement.appendChild(doc.createTextNode(customEmailSubject));
 394  0
                         root.appendChild(subjectElement);
 395  
                     }
 396  
                 }
 397  0
             } catch (Exception e) {
 398  0
                 LOG.error("Error when checking for custom email body and subject.", e);
 399  0
             }
 400  0
             Person person = actionItem.getPerson();
 401  0
             DocumentRouteHeaderValue header = getRouteHeader(actionItem);
 402  
             // keep adding stuff until we have all the xml we need to formulate the message :/
 403  0
             addObjectXML(doc, actionItem, root, "actionItem");
 404  0
             addObjectXML(doc, person, root, "actionItemPerson");
 405  0
             addTextElement(doc, root, "actionItemPrincipalId", person.getPrincipalId());
 406  0
             addTextElement(doc, root, "actionItemPrincipalName", person.getPrincipalName());
 407  0
             addDocumentHeaderXML(doc, header, root, "doc");
 408  0
             addObjectXML(doc, header.getInitiatorPrincipal(), root, "docInitiator");
 409  0
             addTextElement(doc, root, "docInitiatorDisplayName", header.getInitiatorDisplayName());
 410  0
             addObjectXML(doc, header.getDocumentType(), root, "documentType");
 411  
 
 412  0
             node.appendChild(root);
 413  0
         } catch (Exception e) {
 414  0
             String message = "Error generating immediate reminder XML for action item: " + actionItem;
 415  0
             LOG.error(message, e);
 416  0
             throw new WorkflowRuntimeException(e);
 417  0
         }
 418  0
         LOG.info("Leaving generation of immeidate email reminder...");
 419  
             /**
 420  
              * End IU customization
 421  
              */
 422  0
         return generateEmailContent(styleSheet, doc);
 423  
     }
 424  
     
 425  
     /**
 426  
      * This method handles converting the DocumentRouteHeaderValue into an XML representation.  The reason we can't just use
 427  
      * propertiesToXml like we have elsewhere is because the doc header has a String attached to it that has the XML document
 428  
      * content in it.  The default serialization of this will serialize this as a String so we will end up with escaped XML
 429  
      * in our output which we won't be able to process with the email stylesheet.  So we need to read the xml content from
 430  
      * the document and parse it into a DOM object so it can be appended to our output.
 431  
      */
 432  
     protected void addDocumentHeaderXML(Document document, DocumentRouteHeaderValue documentHeader, Node node, String elementName) throws Exception {
 433  0
             Element element = XmlHelper.propertiesToXml(document, documentHeader, elementName);
 434  
             // now we need to "fix" the xml document content because it's going to be in there as escaped XML
 435  0
             Element docContentElement = (Element)element.getElementsByTagName("docContent").item(0);
 436  0
             String documentContent = docContentElement.getTextContent();
 437  
             
 438  0
             if (!StringUtils.isBlank(documentContent) && documentContent.startsWith("<")) {
 439  0
                     Document documentContentXML = XmlHelper.readXml(documentContent);
 440  0
                     Element documentContentElement = documentContentXML.getDocumentElement();
 441  0
                     documentContentElement = (Element)document.importNode(documentContentElement, true);
 442  
             
 443  
                     // remove the old, bad text content
 444  0
                     docContentElement.removeChild(docContentElement.getFirstChild());
 445  
             
 446  
                     // replace with actual XML
 447  0
                     docContentElement.appendChild(documentContentElement);
 448  0
             } else {
 449  
                     // in this case it means that the XML is encrypted, unfortunately, we have no way to decrypt it since
 450  
                     // the key is stored in the client application.  We will just include the doc content since none of our
 451  
                     // current IU clients will be using this feature right away
 452  
 
 453  
                     // remove the old, bad text content
 454  0
                     docContentElement.removeChild(docContentElement.getFirstChild());
 455  
             }
 456  
             
 457  0
             if (LOG.isDebugEnabled()) {
 458  0
             LOG.debug(XmlJotter.jotNode(element));
 459  
         }
 460  
 
 461  0
         node.appendChild(element);
 462  0
     }
 463  
 
 464  
     @Override
 465  
         public EmailContent generateWeeklyReminder(Person user, Collection<ActionItem> actionItems) {
 466  0
         return generateReminderForActionItems(user, actionItems, "weeklyReminder", globalEmailStyleSheet);
 467  
     }
 468  
 
 469  
     @Override
 470  
         public EmailContent generateDailyReminder(Person user, Collection<ActionItem> actionItems) {
 471  0
         return generateReminderForActionItems(user, actionItems, "dailyReminder", globalEmailStyleSheet);
 472  
     }
 473  
 
 474  
     @Override
 475  
         public EmailContent generateFeedback(FeedbackForm form) {
 476  0
         DocumentBuilder db = getDocumentBuilder(true);
 477  0
         Document doc = db.newDocument();
 478  0
         String styleSheet = globalEmailStyleSheet;
 479  
 
 480  
         // if the doc type is specified, see if that doc has a custom email stylesheet and use it
 481  
         // NOTE: do we need to do this for feedback? presumably feedback will be going back to admins
 482  
         /*String docTypeName = form.getDocumentType();
 483  
         if (!StringUtils.isBlank(docTypeName)) {
 484  
             DocumentType docType = KEWServiceLocator.getDocumentTypeService().findByName(docTypeName);
 485  
             if (docType == null) {
 486  
                 LOG.error("User specified document type '" + docTypeName + "' in feedback form, but the document type was not found in the system");
 487  
             } else {
 488  
                 if (docType.getCustomEmailStylesheet() != null) {
 489  
                     styleSheet = docType.getCustomEmailStylesheet();
 490  
                 }
 491  
             }
 492  
         }*/
 493  0
         LOG.info("form: " + form.getDocumentId());
 494  
         try {
 495  0
             addObjectXML(doc, form, null, "feedback");
 496  0
         } catch (Exception e) {
 497  0
             String message = "Error generating XML for feedback form: " + form;
 498  0
             LOG.error(message, e);
 499  0
             throw new WorkflowRuntimeException(message, e);
 500  0
         }
 501  0
         setStandardAttributes(doc.getDocumentElement());
 502  
 
 503  0
         return generateEmailContent(styleSheet, doc);
 504  
     }
 505  
 }