Example usage for org.w3c.dom Node appendChild

List of usage examples for org.w3c.dom Node appendChild

Introduction

In this page you can find the example usage for org.w3c.dom Node appendChild.

Prototype

public Node appendChild(Node newChild) throws DOMException;

Source Link

Document

Adds the node newChild to the end of the list of children of this node.

Usage

From source file:org.jboss.qa.jcontainer.tomcat.TomcatContainer.java

@Override
public void addUser(V user) throws Exception {
    try {/*  www  .  jav  a  2 s  .  c  o  m*/
        final File file = new File(configuration.getDirectory(), "conf" + File.separator + "tomcat-users.xml");
        final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        final Document doc = docBuilder.parse(file);

        // Get the root element
        final Node rootNode = doc.getElementsByTagName("tomcat-users").item(0);

        // Get existing roles
        final NodeList roleNodes = doc.getElementsByTagName("role");
        final List<String> existingRoles = new ArrayList<>();
        for (int i = 0; i < roleNodes.getLength(); i++) {
            existingRoles.add(roleNodes.item(i).getAttributes().getNamedItem("rolename").getNodeValue());
        }

        // Add new roles
        for (String role : user.getRoles()) {
            if (!existingRoles.contains(role)) {
                final Element roleEl = doc.createElement("role");
                roleEl.setAttribute("rolename", role);
                rootNode.appendChild(roleEl);
            }
        }

        // Get existing users
        final NodeList userNodes = doc.getElementsByTagName("user");
        final List<String> existingUsers = new ArrayList<>();
        for (int i = 0; i < userNodes.getLength(); i++) {
            existingUsers.add(userNodes.item(i).getAttributes().getNamedItem("username").getNodeValue());
        }

        final String newRoles = StringUtils.join(user.getRoles(), ",");
        if (!existingUsers.contains(user.getUsername())) { // Add new user
            final Element userEl = doc.createElement("user");
            userEl.setAttribute("username", user.getUsername());
            userEl.setAttribute("password", user.getPassword());
            userEl.setAttribute("roles", newRoles);
            rootNode.appendChild(userEl);
        } else { // Modify existing user
            for (int i = 0; i < userNodes.getLength(); i++) {
                if (user.getUsername()
                        .equals(userNodes.item(i).getAttributes().getNamedItem("username").getNodeValue())) {
                    userNodes.item(i).getAttributes().getNamedItem("password").setNodeValue(user.getPassword());
                    userNodes.item(i).getAttributes().getNamedItem("roles").setNodeValue(newRoles);
                    log.warn("Existing user '{}' was modified", user.getUsername());
                    break;
                }
            }
        }

        // Write the content into xml file
        final TransformerFactory transformerFactory = TransformerFactory.newInstance();
        final Transformer transformer = transformerFactory.newTransformer();
        final DOMSource source = new DOMSource(doc);
        final StreamResult result = new StreamResult(file);
        transformer.transform(source, result);
    } catch (Exception e) {
        log.error("User was not created", e);
    }
}

From source file:org.kalypsodeegree.xml.XMLTools.java

/**
 * copies one node to another node (of a different dom document).
 *//*ww  w  .j  a v a  2 s. c o  m*/
public static Node copyNode(final Node source, final Node dest) {
    // Debug.debugMethodBegin( "XMLTools", "copyNode" );
    if (source.getNodeType() == Node.TEXT_NODE) {
        final Text tn = dest.getOwnerDocument().createTextNode(source.getNodeValue());
        return tn;
    }

    final NamedNodeMap attr = source.getAttributes();

    if (attr != null) {
        for (int i = 0; i < attr.getLength(); i++) {
            ((Element) dest).setAttribute(attr.item(i).getNodeName(), attr.item(i).getNodeValue());
        }
    }

    final NodeList list = source.getChildNodes();

    for (int i = 0; i < list.getLength(); i++) {
        if (!(list.item(i) instanceof Text)) {
            final Element en = dest.getOwnerDocument().createElementNS(list.item(i).getNamespaceURI(),
                    list.item(i).getNodeName());

            if (list.item(i).getNodeValue() != null) {
                en.setNodeValue(list.item(i).getNodeValue());
            }

            final Node n = copyNode(list.item(i), en);
            dest.appendChild(n);
        } else if (list.item(i) instanceof CDATASection) {
            final CDATASection cd = dest.getOwnerDocument().createCDATASection(list.item(i).getNodeValue());
            dest.appendChild(cd);
        } else {
            final Text tn = dest.getOwnerDocument().createTextNode(list.item(i).getNodeValue());
            dest.appendChild(tn);
        }
    }

    // Debug.debugMethodEnd();
    return dest;
}

From source file:org.kalypsodeegree.xml.XMLTools.java

/**
 * inserts a node into a dom element (of a different dom document)
 *///from  w  w  w  .ja  v  a 2s  . c  om
public static Node insertNodeInto(final Node source, final Node dest) {

    Document dDoc = null;
    final Document sDoc = source.getOwnerDocument();

    if (dest instanceof Document) {
        dDoc = (Document) dest;
    } else {
        dDoc = dest.getOwnerDocument();
    }

    if (dDoc.equals(sDoc)) {
        dest.appendChild(source);
    } else {
        final Element element = dDoc.createElementNS(source.getNamespaceURI(), source.getNodeName());
        dest.appendChild(element);

        copyNode(source, element);
    }

    return dest;
}

From source file:org.kie.server.services.jbpm.ui.form.RemoteFormModellerFormProvider.java

protected String attachSubForms(String document, String deploymentId) {
    try {/*from   ww w.  j av a  2  s  . co  m*/
        if (!document.contains(SUB_FORM_TYPE) && !document.contains(MULTI_SUB_FORM_TYPE)) {
            return document;
        }
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();

        Document doc = builder.parse(new ByteArrayInputStream(document.getBytes()));
        NodeList nodes = doc.getElementsByTagName(NODE_FORM);
        Node nodeForm = nodes.item(0);
        NodeList childNodes = nodeForm.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node node = childNodes.item(i);
            if (node.getNodeName().equals(NODE_FIELD)) {

                String fieldType = node.getAttributes().getNamedItem(ATTR_TYPE).getNodeValue();
                if (SUB_FORM_TYPE.equals(fieldType) || MULTI_SUB_FORM_TYPE.equals(fieldType)) {

                    String defaultSubForm = findPropertyValue(node, "defaultSubform");
                    if (defaultSubForm != null) {

                        String subFormContent = formManagerService.getFormByKey(deploymentId, defaultSubForm);

                        if (subFormContent != null) {
                            Document docSubForm = builder
                                    .parse(new ByteArrayInputStream(subFormContent.getBytes()));

                            NodeList nodesSubForm = docSubForm.getElementsByTagName(NODE_FORM);
                            Node nodeFormSubForm = nodesSubForm.item(0);

                            Node imported = doc.importNode(nodeFormSubForm, true);

                            nodeForm.appendChild(imported);
                        }
                    }
                }
            }
        }
        document = asString(doc);
    } catch (Exception ex) {
        logger.error("Error when attaching subform", ex);
    }
    return document;
}

From source file:org.kuali.coeus.propdev.impl.budget.subaward.PropDevPropDevBudgetSubAwardServiceImpl.java

/**
 * updates the XMl with hashcode for the files
 *///from   www. j  ava2s  .  c o m

protected BudgetSubAwards updateXML(byte xmlContents[], Map fileMap, BudgetSubAwards budgetSubAwardBean,
        Budget budget) throws Exception {

    javax.xml.parsers.DocumentBuilderFactory domParserFactory = javax.xml.parsers.DocumentBuilderFactory
            .newInstance();
    javax.xml.parsers.DocumentBuilder domParser = domParserFactory.newDocumentBuilder();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xmlContents);

    org.w3c.dom.Document document = domParser.parse(byteArrayInputStream);
    byteArrayInputStream.close();
    String namespace = null;
    String formName = null;
    if (document != null) {
        Node node;
        Element element = document.getDocumentElement();
        NamedNodeMap map = element.getAttributes();
        String namespaceHolder = element.getNodeName().substring(0, element.getNodeName().indexOf(':'));
        node = map.getNamedItem("xmlns:" + namespaceHolder);
        namespace = node.getNodeValue();
        FormMappingInfo formMappingInfo = formMappingService.getFormInfo(namespace);
        formName = formMappingInfo.getFormName();
        budgetSubAwardBean.setNamespace(namespace);
        budgetSubAwardBean.setFormName(formName);
    }

    String xpathEmptyNodes = "//*[not(node()) and local-name(.) != 'FileLocation' and local-name(.) != 'HashValue']";
    String xpathOtherPers = "//*[local-name(.)='ProjectRole' and local-name(../../.)='OtherPersonnel' and count(../NumberOfPersonnel)=0]";
    removeAllEmptyNodes(document, xpathEmptyNodes, 0);
    removeAllEmptyNodes(document, xpathOtherPers, 1);
    removeAllEmptyNodes(document, xpathEmptyNodes, 0);
    changeDataTypeForNumberOfOtherPersons(document);

    List<String> fedNonFedSubAwardForms = getFedNonFedSubawardForms();
    NodeList budgetYearList = XPathAPI.selectNodeList(document, "//*[local-name(.) = 'BudgetYear']");
    for (int i = 0; i < budgetYearList.getLength(); i++) {
        Node bgtYearNode = budgetYearList.item(i);
        String period = getValue(XPathAPI.selectSingleNode(bgtYearNode, "BudgetPeriod"));
        if (fedNonFedSubAwardForms.contains(namespace)) {
            Element newBudgetYearElement = copyElementToName((Element) bgtYearNode, bgtYearNode.getNodeName());
            bgtYearNode.getParentNode().replaceChild(newBudgetYearElement, bgtYearNode);
        } else {
            Element newBudgetYearElement = copyElementToName((Element) bgtYearNode,
                    bgtYearNode.getNodeName() + period);
            bgtYearNode.getParentNode().replaceChild(newBudgetYearElement, bgtYearNode);
        }
    }

    Node oldroot = document.removeChild(document.getDocumentElement());
    Node newroot = document.appendChild(document.createElement("Forms"));
    newroot.appendChild(oldroot);

    org.w3c.dom.NodeList lstFileName = document.getElementsByTagName("att:FileName");
    org.w3c.dom.NodeList lstFileLocation = document.getElementsByTagName("att:FileLocation");
    org.w3c.dom.NodeList lstMimeType = document.getElementsByTagName("att:MimeType");
    org.w3c.dom.NodeList lstHashValue = document.getElementsByTagName("glob:HashValue");

    org.w3c.dom.Node fileNode, hashNode, mimeTypeNode;
    org.w3c.dom.NamedNodeMap fileNodeMap, hashNodeMap;
    String fileName;
    byte fileBytes[];
    String contentId;
    List attachmentList = new ArrayList();

    for (int index = 0; index < lstFileName.getLength(); index++) {
        fileNode = lstFileName.item(index);

        Node fileNameNode = fileNode.getFirstChild();
        fileName = fileNameNode.getNodeValue();

        fileBytes = (byte[]) fileMap.get(fileName);

        if (fileBytes == null) {
            throw new RuntimeException("FileName mismatch in XML and PDF extracted file");
        }
        String hashVal = grantApplicationHashService.computeAttachmentHash(fileBytes);

        hashNode = lstHashValue.item(index);
        hashNodeMap = hashNode.getAttributes();

        Node temp = document.createTextNode(hashVal);
        hashNode.appendChild(temp);

        hashNode = hashNodeMap.getNamedItem("glob:hashAlgorithm");

        hashNode.setNodeValue(InfastructureConstants.HASH_ALGORITHM);

        fileNode = lstFileLocation.item(index);
        fileNodeMap = fileNode.getAttributes();
        fileNode = fileNodeMap.getNamedItem("att:href");

        contentId = fileNode.getNodeValue();
        String encodedContentId = cleanContentId(contentId);
        fileNode.setNodeValue(encodedContentId);

        mimeTypeNode = lstMimeType.item(0);
        String contentType = mimeTypeNode.getFirstChild().getNodeValue();

        BudgetSubAwardAttachment budgetSubAwardAttachmentBean = new BudgetSubAwardAttachment();
        budgetSubAwardAttachmentBean.setData(fileBytes);
        budgetSubAwardAttachmentBean.setName(encodedContentId);

        budgetSubAwardAttachmentBean.setType(contentType);
        budgetSubAwardAttachmentBean.setBudgetSubAward(budgetSubAwardBean);

        attachmentList.add(budgetSubAwardAttachmentBean);
    }

    budgetSubAwardBean.setBudgetSubAwardAttachments(attachmentList);

    javax.xml.transform.Transformer transformer = javax.xml.transform.TransformerFactory.newInstance()
            .newTransformer();
    transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes");

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(bos);
    javax.xml.transform.dom.DOMSource source = new javax.xml.transform.dom.DOMSource(document);

    transformer.transform(source, result);

    budgetSubAwardBean.setSubAwardXmlFileData(new String(bos.toByteArray()));

    bos.close();

    return budgetSubAwardBean;
}

From source file:org.kuali.kra.proposaldevelopment.budget.service.impl.BudgetSubAwardServiceImpl.java

/**
 * updates the XMl with hashcode for the files
 *//*from   ww w. j  a  va  2 s  .co  m*/

protected BudgetSubAwards updateXML(byte xmlContents[], Map fileMap, BudgetSubAwards budgetSubAwardBean)
        throws Exception {

    javax.xml.parsers.DocumentBuilderFactory domParserFactory = javax.xml.parsers.DocumentBuilderFactory
            .newInstance();
    javax.xml.parsers.DocumentBuilder domParser = domParserFactory.newDocumentBuilder();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xmlContents);

    org.w3c.dom.Document document = domParser.parse(byteArrayInputStream);
    byteArrayInputStream.close();
    String namespace = null;
    if (document != null) {
        Node node;
        String formName;
        Element element = document.getDocumentElement();
        NamedNodeMap map = element.getAttributes();
        String namespaceHolder = element.getNodeName().substring(0, element.getNodeName().indexOf(':'));
        node = map.getNamedItem("xmlns:" + namespaceHolder);
        namespace = node.getNodeValue();
        FormMappingInfo formMappingInfo = new FormMappingLoader().getFormInfo(namespace);
        formName = formMappingInfo.getFormName();
        budgetSubAwardBean.setNamespace(namespace);
        budgetSubAwardBean.setFormName(formName);
    }

    String xpathEmptyNodes = "//*[not(node()) and local-name(.) != 'FileLocation' and local-name(.) != 'HashValue']";
    String xpathOtherPers = "//*[local-name(.)='ProjectRole' and local-name(../../.)='OtherPersonnel' and count(../NumberOfPersonnel)=0]";
    removeAllEmptyNodes(document, xpathEmptyNodes, 0);
    removeAllEmptyNodes(document, xpathOtherPers, 1);
    removeAllEmptyNodes(document, xpathEmptyNodes, 0);
    changeDataTypeForNumberOfOtherPersons(document);

    List<String> fedNonFedSubAwardForms = getFedNonFedSubawardForms();
    NodeList budgetYearList = XPathAPI.selectNodeList(document, "//*[local-name(.) = 'BudgetYear']");
    for (int i = 0; i < budgetYearList.getLength(); i++) {
        Node bgtYearNode = budgetYearList.item(i);
        String period = getValue(XPathAPI.selectSingleNode(bgtYearNode, "BudgetPeriod"));
        if (fedNonFedSubAwardForms.contains(namespace)) {
            Element newBudgetYearElement = copyElementToName((Element) bgtYearNode, bgtYearNode.getNodeName());
            bgtYearNode.getParentNode().replaceChild(newBudgetYearElement, bgtYearNode);
        } else {
            Element newBudgetYearElement = copyElementToName((Element) bgtYearNode,
                    bgtYearNode.getNodeName() + period);
            bgtYearNode.getParentNode().replaceChild(newBudgetYearElement, bgtYearNode);
        }
    }

    Node oldroot = document.removeChild(document.getDocumentElement());
    Node newroot = document.appendChild(document.createElement("Forms"));
    newroot.appendChild(oldroot);

    org.w3c.dom.NodeList lstFileName = document.getElementsByTagName("att:FileName");
    org.w3c.dom.NodeList lstFileLocation = document.getElementsByTagName("att:FileLocation");
    org.w3c.dom.NodeList lstMimeType = document.getElementsByTagName("att:MimeType");
    org.w3c.dom.NodeList lstHashValue = document.getElementsByTagName("glob:HashValue");

    if ((lstFileName.getLength() != lstFileLocation.getLength())
            || (lstFileLocation.getLength() != lstHashValue.getLength())) {
        //            throw new RuntimeException("Tag occurances mismatch in XML File");
    }

    org.w3c.dom.Node fileNode, hashNode, mimeTypeNode;
    org.w3c.dom.NamedNodeMap fileNodeMap, hashNodeMap;
    String fileName;
    byte fileBytes[];
    String contentId;
    List attachmentList = new ArrayList();

    for (int index = 0; index < lstFileName.getLength(); index++) {
        fileNode = lstFileName.item(index);

        Node fileNameNode = fileNode.getFirstChild();
        fileName = fileNameNode.getNodeValue();

        fileBytes = (byte[]) fileMap.get(fileName);

        if (fileBytes == null) {
            throw new RuntimeException("FileName mismatch in XML and PDF extracted file");
        }
        String hashVal = GrantApplicationHash.computeAttachmentHash(fileBytes);

        hashNode = lstHashValue.item(index);
        hashNodeMap = hashNode.getAttributes();

        Node temp = document.createTextNode(hashVal);
        hashNode.appendChild(temp);

        hashNode = hashNodeMap.getNamedItem("glob:hashAlgorithm");

        hashNode.setNodeValue(S2SConstants.HASH_ALGORITHM);

        fileNode = lstFileLocation.item(index);
        fileNodeMap = fileNode.getAttributes();
        fileNode = fileNodeMap.getNamedItem("att:href");

        contentId = fileNode.getNodeValue();
        String encodedContentId = cleanContentId(contentId);
        fileNode.setNodeValue(encodedContentId);

        mimeTypeNode = lstMimeType.item(0);
        String contentType = mimeTypeNode.getFirstChild().getNodeValue();

        BudgetSubAwardAttachment budgetSubAwardAttachmentBean = new BudgetSubAwardAttachment();
        budgetSubAwardAttachmentBean.setAttachment(fileBytes);
        budgetSubAwardAttachmentBean.setContentId(encodedContentId);

        budgetSubAwardAttachmentBean.setContentType(contentType);
        budgetSubAwardAttachmentBean.setBudgetId(budgetSubAwardBean.getBudgetId());
        budgetSubAwardAttachmentBean.setSubAwardNumber(budgetSubAwardBean.getSubAwardNumber());

        attachmentList.add(budgetSubAwardAttachmentBean);
    }

    budgetSubAwardBean.setBudgetSubAwardAttachments(attachmentList);

    javax.xml.transform.Transformer transformer = javax.xml.transform.TransformerFactory.newInstance()
            .newTransformer();
    transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes");

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(bos);
    javax.xml.transform.dom.DOMSource source = new javax.xml.transform.dom.DOMSource(document);

    transformer.transform(source, result);

    budgetSubAwardBean.setSubAwardXmlFileData(new String(bos.toByteArray()));

    bos.close();

    return budgetSubAwardBean;
}

From source file:org.kuali.rice.core.api.util.xml.XmlHelper.java

public static void appendXml(Node parentNode, String xml)
        throws SAXException, IOException, ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(false);// w ww .  ja v  a2  s.  c  o m
    org.w3c.dom.Document xmlDocument = factory.newDocumentBuilder()
            .parse(new InputSource(new StringReader(xml)));
    org.w3c.dom.Element xmlDocumentElement = xmlDocument.getDocumentElement();
    Node importedNode = parentNode.getOwnerDocument().importNode(xmlDocumentElement, true);
    parentNode.appendChild(importedNode);
}

From source file:org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl.java

protected static void addObjectXML(Document doc, Object o, Node node, String name) throws Exception {
    Element element = XmlHelper.propertiesToXml(doc, o, name);

    if (LOG.isDebugEnabled()) {
        LOG.debug(XmlJotter.jotNode(element));
    }//from   w  w  w. j  av  a2  s . c  om

    if (node == null) {
        node = doc;
    }

    node.appendChild(element);
}

From source file:org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl.java

/**
 * This method is used to add the given {@link ActionItem} to the given {@link org.w3c.dom.Document} in a summarized
 * form for use in weekly or daily type reminder e-mails.
 *
 * @param doc - Document to have the ActionItem added to
 * @param actionItem - the action item being added
 * @param user - the current user/*from   w ww.j ava  2s  . co  m*/
 * @param node - the node object to add the actionItem XML to (defaults to the doc variable if null is passed in)
 * @throws Exception
 */
protected void addSummarizedActionItem(Document doc, ActionItem actionItem, Person user, Node node,
        DocumentRouteHeaderValue routeHeader) throws Exception {
    if (node == null) {
        node = doc;
    }

    Element root = doc.createElement("summarizedActionItem");

    // add in all items from action list as preliminary default dataset
    addTextElement(doc, root, "documentId", actionItem.getDocumentId());
    addTextElement(doc, root, "docName", actionItem.getDocName());
    addCDataElement(doc, root, "docLabel", actionItem.getDocLabel());
    addCDataElement(doc, root, "docTitle", actionItem.getDocTitle());
    //DocumentRouteHeaderValue routeHeader = getRouteHeader(actionItem);
    addTextElement(doc, root, "docRouteStatus", routeHeader.getDocRouteStatus());
    addCDataElement(doc, root, "routeStatusLabel", routeHeader.getRouteStatusLabel());
    addTextElement(doc, root, "actionRequestCd", actionItem.getActionRequestCd());
    addTextElement(doc, root, "actionRequestLabel",
            CodeTranslator.getActionRequestLabel(actionItem.getActionRequestCd()));
    addDelegatorElement(doc, root, actionItem);
    addTimestampElement(doc, root, "createDate", routeHeader.getCreateDate());
    addWorkgroupRequestElement(doc, root, actionItem);
    if (actionItem.getDateTimeAssigned() != null)
        addTimestampElement(doc, root, "dateAssigned", actionItem.getDateTimeAssigned().toDate());

    node.appendChild(root);
}

From source file:org.kuali.rice.kew.mail.service.impl.StyleableEmailContentServiceImpl.java

/**
 * This method generates an {@link EmailContent} object using the given parameters.  Part of this operation includes
 * serializing the given {@link ActionItem} to XML. The following objects and methods are included in the serialization:
 *
 * <ul>/* w ww.  j  a  v  a 2  s  .c  o m*/
 * <li>{@link Person}</li>
 * <li>{@link Person#getPrincipalName()}</li>
 * <li>{@link DocumentRouteHeaderValue}</li>
 * <li>{@link DocumentRouteHeaderValue#getInitiatorUser()}</li>
 * <li>{@link DocumentRouteHeaderValue#getDocumentType()}</li>
 * <li>{@link Person}</li>
 * </ul>
 *
 * @param user - the current user
 * @param actionItem - the action item being added
 * @param documentType - the document type that the custom email style sheet will come from
 * @param node - the node object to add the actionItem XML to (defaults to the doc variable if null is passed in)
 * @throws Exception
 */
@Override
public EmailContent generateImmediateReminder(Person user, ActionItem actionItem, DocumentType documentType) {
    if (user != null) {
        LOG.info("Starting generation of immediate email reminder...");
        LOG.info("Action Id: " + actionItem.getId() + ";  ActionRequestId: " + actionItem.getActionRequestId()
                + ";  Action Item Principal Id: " + actionItem.getPrincipalId());
        LOG.info("User Principal Id: " + user.getPrincipalId());
        // change style name based on documentType when configurable email style on document is implemented...
        String styleSheet = documentType.getCustomEmailStylesheet();
        LOG.debug(documentType.getName() + " style: " + styleSheet);
        if (styleSheet == null) {
            styleSheet = globalEmailStyleSheet;
        }

        LOG.info("generateImmediateReminder using style sheet: " + styleSheet + " for Document Type "
                + documentType.getName());
        // return generateReminderForActionItems(user, actionItems, "immediateReminder", styleSheet);
        DocumentBuilder db = getDocumentBuilder(false);
        Document doc = db.newDocument();
        Element element = doc.createElement("immediateReminder");
        setStandardAttributes(element);
        doc.appendChild(element);

        try {
            addObjectXML(doc, user, element, "user");
            // addActionItem(doc, actionItem, user, node);
            Node node = element;
            if (node == null) {
                node = doc;
            }

            Element root = doc.createElement("actionItem");
            // append the custom body and subject if they exist
            try {
                CustomEmailAttribute customEmailAttribute = getCustomEmailAttribute(user, actionItem);
                if (customEmailAttribute != null) {
                    String customBody = customEmailAttribute.getCustomEmailBody();
                    if (!org.apache.commons.lang.StringUtils.isEmpty(customBody)) {
                        Element bodyElement = doc.createElement("customBody");
                        bodyElement.appendChild(doc.createTextNode(customBody));
                        root.appendChild(bodyElement);
                    }
                    String customEmailSubject = customEmailAttribute.getCustomEmailSubject();
                    if (!org.apache.commons.lang.StringUtils.isEmpty(customEmailSubject)) {
                        Element subjectElement = doc.createElement("customSubject");
                        subjectElement.appendChild(doc.createTextNode(customEmailSubject));
                        root.appendChild(subjectElement);
                    }
                }
            } catch (Exception e) {
                LOG.error("Error when checking for custom email body and subject.", e);
            }
            Person person = KimApiServiceLocator.getPersonService().getPerson(actionItem.getPrincipalId());
            DocumentRouteHeaderValue header = getRouteHeader(actionItem);
            // keep adding stuff until we have all the xml we need to formulate the message :/
            addObjectXML(doc, actionItem, root, "actionItem");
            addObjectXML(doc, person, root, "actionItemPerson");
            addTextElement(doc, root, "actionItemPrincipalId", person.getPrincipalId());
            addTextElement(doc, root, "actionItemPrincipalName", person.getPrincipalName());
            addDocumentHeaderXML(doc, header, root, "doc");
            addObjectXML(doc, header.getInitiatorPrincipal(), root, "docInitiator");
            addTextElement(doc, root, "docInitiatorDisplayName", header.getInitiatorDisplayName());
            addObjectXML(doc, header.getDocumentType(), root, "documentType");

            node.appendChild(root);
        } catch (Exception e) {
            String message = "Error generating immediate reminder XML for action item: " + actionItem;
            LOG.error(message, e);
            throw new WorkflowRuntimeException(e);
        }
        LOG.info("Leaving generation of immeidate email reminder...");
        return generateEmailContent(styleSheet, doc);
    }
    LOG.info("Skipping generation of immediate email reminder due to the user being null");
    return null;
}