Example usage for javax.xml.xpath XPathConstants STRING

List of usage examples for javax.xml.xpath XPathConstants STRING

Introduction

In this page you can find the example usage for javax.xml.xpath XPathConstants STRING.

Prototype

QName STRING

To view the source code for javax.xml.xpath XPathConstants STRING.

Click Source Link

Document

The XPath 1.0 string data type.

Maps to Java String .

Usage

From source file:org.kuali.rice.edl.impl.components.WorkflowDocumentState.java

public static boolean isEditable(EDLContext edlContext, List actions) {
    boolean editable = false;
    editable = listContainsItems(actions, UserAction.EDITABLE_ACTIONS);
    // reset editable flag to true if edoclite specifies <param name="alwaysEditable">true</param>
    Document edlDom = EdlServiceLocator.getEDocLiteService()
            .getDefinitionXml(edlContext.getEdocLiteAssociation());
    // use xpath to check for attribute value on Config param element.
    XPath xpath = edlContext.getXpath();
    String xpathExpression = "//config/param[@name='alwaysEditable']";
    try {/*  w  ww  .j  a va2  s .co  m*/
        String match = (String) xpath.evaluate(xpathExpression, edlDom, XPathConstants.STRING);
        if (!StringUtils.isBlank(match) && match.equals("true")) {
            return true;
        }
    } catch (XPathExpressionException e) {
        throw new WorkflowRuntimeException("Unable to evaluate xpath expression " + xpathExpression, e);
    }

    return editable;
}

From source file:org.kuali.rice.ken.xpath.XPathTest.java

@Test
public void testXPathWithPlainDOM() throws Exception {
    Document doc = getDocument(false, false);
    XPath xpath = getXPath(null);
    String channelName = (String) xpath.evaluate("/notification/channel", doc.getDocumentElement(),
            XPathConstants.STRING);
    assertEquals("Test Channel #1", channelName);
}

From source file:org.kuali.rice.ken.xpath.XPathTest.java

@Test
public void testXPathWithNamespaceAwareDOM() throws Exception {
    Document doc = getDocument(true, false);
    XPath xpath = getXPath(null);
    String channelName = (String) xpath.evaluate("/nreq:notification/nreq:channel", doc.getDocumentElement(),
            XPathConstants.STRING);
    assertEquals("Test Channel #1", channelName);
}

From source file:org.kuali.rice.ken.xpath.XPathTest.java

@Test
public void testXPathWithValidatedDOMFixedNamespace() throws Exception {
    LOG.debug("TEST");
    Document doc = getDocument(true, true);
    LOG.info("Default namespace: " + doc.lookupNamespaceURI(null));
    XPath xpath = getXPath(null);
    String channelName = (String) xpath.evaluate("/nreq:notification/nreq:channel", doc.getDocumentElement(),
            XPathConstants.STRING);
    assertEquals("Test Channel #1", channelName);
}

From source file:org.kuali.rice.ken.xpath.XPathTest.java

@Test
public void testXPathWithValidatedDOMDocNamespace() throws Exception {
    LOG.debug("TEST");
    Document doc = getDocument(true, true);
    LOG.info("Default namespace: " + doc.lookupNamespaceURI(null));
    LOG.info("default prefix: " + doc.lookupPrefix(doc.lookupNamespaceURI(null)));
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(Util.getNotificationNamespaceContext(doc));
    String channelName = (String) xpath.evaluate("/nreq:notification/nreq:channel", doc.getDocumentElement(),
            XPathConstants.STRING);
    assertEquals("Test Channel #1", channelName);
}

From source file:org.kuali.rice.kew.docsearch.xml.StandardGenericXMLSearchableAttribute.java

@Override
public List<DocumentAttribute> extractDocumentAttributes(ExtensionDefinition extensionDefinition,
        DocumentWithContent documentWithContent) {
    List<DocumentAttribute> searchStorageValues = new ArrayList<DocumentAttribute>();
    String fullDocumentContent = documentWithContent.getDocumentContent().getFullContent();
    if (StringUtils.isBlank(documentWithContent.getDocumentContent().getFullContent())) {
        LOG.warn("Empty Document Content found for document id: "
                + documentWithContent.getDocument().getDocumentId());
        return searchStorageValues;
    }/*  w  w  w. j  av a  2  s .  c o  m*/
    Document document;
    try {
        document = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new InputSource(new BufferedReader(new StringReader(fullDocumentContent))));
    } catch (Exception e) {
        LOG.error("error parsing docContent: " + documentWithContent.getDocumentContent(), e);
        throw new RuntimeException(
                "Error trying to parse docContent: " + documentWithContent.getDocumentContent(), e);
    }
    XMLSearchableAttributeContent content = new XMLSearchableAttributeContent(
            getConfigXML(extensionDefinition));
    List<XMLSearchableAttributeContent.FieldDef> fields;
    try {
        fields = content.getFieldDefList();
    } catch (XPathExpressionException xpee) {
        throw new RuntimeException("Error parsing searchable attribute content", xpee);
    } catch (ParserConfigurationException pce) {
        throw new RuntimeException("Error parsing searchable attribute content", pce);
    }
    XPath xpath = XPathHelper.newXPath(document);
    for (XMLSearchableAttributeContent.FieldDef field : fields) {
        if (StringUtils.isNotEmpty(field.fieldEvaluationExpr)) {
            List<String> values = new ArrayList<String>();
            try {
                LOG.debug("Trying to retrieve node set with expression: '" + field.fieldEvaluationExpr + "'.");
                NodeList searchValues = (NodeList) xpath.evaluate(field.fieldEvaluationExpr,
                        document.getDocumentElement(), XPathConstants.NODESET);
                // being that this is the standard xml attribute we will return the key with an empty value
                // so we can find it from a doc search using this key
                for (int j = 0; j < searchValues.getLength(); j++) {
                    Node searchValue = searchValues.item(j);
                    if (searchValue.getFirstChild() != null
                            && (StringUtils.isNotEmpty(searchValue.getFirstChild().getNodeValue()))) {
                        values.add(searchValue.getFirstChild().getNodeValue());
                    }
                }
            } catch (XPathExpressionException e) {
                LOG.debug("Could not retrieve node set with expression: '" + field.fieldEvaluationExpr
                        + "'. Trying string return type.");
                //try for a string being returned from the expression.  This
                //seems like a poor way to determine our expression return type but
                //it's all I can come up with at the moment.
                try {
                    String searchValue = (String) xpath.evaluate(field.fieldEvaluationExpr,
                            document.getDocumentElement(), XPathConstants.STRING);
                    if (StringUtils.isNotBlank(searchValue)) {
                        values.add(searchValue);
                    }
                } catch (XPathExpressionException xpee) {
                    LOG.error("Error retrieving string with expression: '" + field.fieldEvaluationExpr + "'",
                            xpee);
                    throw new RuntimeException(
                            "Error retrieving string with expression: '" + field.fieldEvaluationExpr + "'",
                            xpee);
                }
            }

            // remove any nulls
            values.removeAll(Collections.singleton(null));
            // being that this is the standard xml attribute we will return the key with an empty value
            // so we can find it from a doc search using this key
            if (values.isEmpty()) {
                values.add(null);
            }
            for (String value : values) {
                DocumentAttribute searchableValue = this
                        .setupSearchableAttributeValue(field.searchDefinition.dataType, field.name, value);
                if (searchableValue != null) {
                    searchStorageValues.add(searchableValue);
                }
            }
        }
    }
    return searchStorageValues;
}

From source file:org.kuali.rice.kew.doctype.DocumentTypeSecurity.java

/** parse <security> XML to populate security object
 * @throws ParserConfigurationException//from   w  w w  .  j av a 2  s . co  m
 * @throws IOException
 * @throws SAXException */
public DocumentTypeSecurity(String standardApplicationId, String documentTypeSecurityXml) {
    try {
        if (org.apache.commons.lang.StringUtils.isEmpty(documentTypeSecurityXml)) {
            return;
        }

        InputSource inputSource = new InputSource(
                new BufferedReader(new StringReader(documentTypeSecurityXml)));
        Element securityElement = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputSource)
                .getDocumentElement();

        String active = (String) xpath.evaluate("./@active", securityElement, XPathConstants.STRING);
        if (org.apache.commons.lang.StringUtils.isEmpty(active) || "true".equals(active.toLowerCase())) {
            // true is the default
            this.setActive(Boolean.valueOf(true));
        } else {
            this.setActive(Boolean.valueOf(false));
        }

        // there should only be one <initiator> tag
        NodeList initiatorNodes = (NodeList) xpath.evaluate("./initiator", securityElement,
                XPathConstants.NODESET);
        if (initiatorNodes != null && initiatorNodes.getLength() > 0) {
            Node initiatorNode = initiatorNodes.item(0);
            String value = initiatorNode.getTextContent();
            if (org.apache.commons.lang.StringUtils.isEmpty(value) || value.toLowerCase().equals("true")) {
                this.setInitiatorOk(Boolean.valueOf(true));
            } else {
                this.initiatorOk = Boolean.valueOf(false);
            }
        }

        // there should only be one <routeLogAuthenticated> tag
        NodeList routeLogAuthNodes = (NodeList) xpath.evaluate("./routeLogAuthenticated", securityElement,
                XPathConstants.NODESET);
        if (routeLogAuthNodes != null && routeLogAuthNodes.getLength() > 0) {
            Node routeLogAuthNode = routeLogAuthNodes.item(0);
            String value = routeLogAuthNode.getTextContent();
            if (org.apache.commons.lang.StringUtils.isEmpty(value) || value.toLowerCase().equals("true")) {
                this.routeLogAuthenticatedOk = Boolean.valueOf(true);
            } else {
                this.routeLogAuthenticatedOk = Boolean.valueOf(false);
            }
        }

        NodeList searchableAttributeNodes = (NodeList) xpath.evaluate("./searchableAttribute", securityElement,
                XPathConstants.NODESET);
        if (searchableAttributeNodes != null && searchableAttributeNodes.getLength() > 0) {
            for (int i = 0; i < searchableAttributeNodes.getLength(); i++) {
                Node searchableAttributeNode = searchableAttributeNodes.item(i);
                String name = (String) xpath.evaluate("./@name", searchableAttributeNode,
                        XPathConstants.STRING);
                String idType = (String) xpath.evaluate("./@idType", searchableAttributeNode,
                        XPathConstants.STRING);
                if (!org.apache.commons.lang.StringUtils.isEmpty(name)
                        && !org.apache.commons.lang.StringUtils.isEmpty(idType)) {
                    KeyValue searchableAttribute = new ConcreteKeyValue(name, idType);
                    searchableAttributes.add(searchableAttribute);
                }
            }
        }

        NodeList workgroupNodes = (NodeList) xpath.evaluate("./workgroup", securityElement,
                XPathConstants.NODESET);
        if (workgroupNodes != null && workgroupNodes.getLength() > 0) {
            LOG.warn(
                    "Document Type Security XML is using deprecated element 'workgroup', please use 'groupName' instead.");
            for (int i = 0; i < workgroupNodes.getLength(); i++) {
                Node workgroupNode = workgroupNodes.item(i);
                String value = workgroupNode.getTextContent().trim();
                if (!org.apache.commons.lang.StringUtils.isEmpty(value)) {
                    value = Utilities.substituteConfigParameters(value);
                    String namespaceCode = Utilities.parseGroupNamespaceCode(value);
                    String groupName = Utilities.parseGroupName(value);
                    Group groupObject = KimApiServiceLocator.getGroupService()
                            .getGroupByNamespaceCodeAndName(namespaceCode, groupName);
                    if (groupObject == null) {
                        throw new WorkflowException("Could not find group: " + value);
                    }
                    workgroups.add(groupObject);
                }
            }
        }

        NodeList groupNodes = (NodeList) xpath.evaluate("./groupName", securityElement, XPathConstants.NODESET);
        if (groupNodes != null && groupNodes.getLength() > 0) {
            for (int i = 0; i < groupNodes.getLength(); i++) {
                Node groupNode = groupNodes.item(i);
                if (groupNode.getNodeType() == Node.ELEMENT_NODE) {
                    String groupName = groupNode.getTextContent().trim();
                    if (!org.apache.commons.lang.StringUtils.isEmpty(groupName)) {
                        groupName = Utilities.substituteConfigParameters(groupName).trim();
                        String namespaceCode = Utilities.substituteConfigParameters(
                                ((Element) groupNode).getAttribute(XmlConstants.NAMESPACE)).trim();
                        Group groupObject = KimApiServiceLocator.getGroupService()
                                .getGroupByNamespaceCodeAndName(namespaceCode, groupName);

                        if (groupObject != null) {
                            workgroups.add(groupObject);
                        } else {
                            LOG.warn("Could not find group with name '" + groupName + "' and namespace '"
                                    + namespaceCode + "' which was defined on Document Type security");
                        }
                        //                if (groupObject == null) {
                        //                  throw new WorkflowException("Could not find group with name '" + groupName + "' and namespace '" + namespaceCode + "'");
                        //                }

                    }
                }
            }
        }

        NodeList permissionNodes = (NodeList) xpath.evaluate("./permission", securityElement,
                XPathConstants.NODESET);
        if (permissionNodes != null && permissionNodes.getLength() > 0) {
            for (int i = 0; i < permissionNodes.getLength(); i++) {
                Node permissionNode = permissionNodes.item(i);
                if (permissionNode.getNodeType() == Node.ELEMENT_NODE) {
                    SecurityPermissionInfo securityPermission = new SecurityPermissionInfo();
                    securityPermission
                            .setPermissionName(
                                    Utilities
                                            .substituteConfigParameters(
                                                    ((Element) permissionNode).getAttribute(XmlConstants.NAME))
                                            .trim());
                    securityPermission
                            .setPermissionNamespaceCode(Utilities
                                    .substituteConfigParameters(
                                            ((Element) permissionNode).getAttribute(XmlConstants.NAMESPACE))
                                    .trim());
                    if (!StringUtils.isEmpty(securityPermission.getPermissionName())
                            && !StringUtils.isEmpty(securityPermission.getPermissionNamespaceCode())) {
                        //get details and qualifications
                        if (permissionNode.hasChildNodes()) {
                            NodeList permissionChildNodes = permissionNode.getChildNodes();
                            for (int j = 0; j < permissionChildNodes.getLength(); j++) {
                                Node permissionChildNode = permissionChildNodes.item(j);
                                if (permissionChildNode.getNodeType() == Node.ELEMENT_NODE) {
                                    String childAttributeName = Utilities.substituteConfigParameters(
                                            ((Element) permissionChildNode).getAttribute(XmlConstants.NAME))
                                            .trim();
                                    String childAttributeValue = permissionChildNode.getTextContent().trim();
                                    if (!StringUtils.isEmpty(childAttributeValue)) {
                                        childAttributeValue = Utilities
                                                .substituteConfigParameters(childAttributeValue).trim();
                                    }
                                    if (!StringUtils.isEmpty(childAttributeValue)) {
                                        childAttributeValue = Utilities
                                                .substituteConfigParameters(childAttributeValue).trim();
                                    }
                                    if (permissionChildNode.getNodeName().trim().equals("permissionDetail")) {
                                        securityPermission.getPermissionDetails().put(childAttributeName,
                                                childAttributeValue);
                                    }
                                    if (permissionChildNode.getNodeName().trim().equals("qualification")) {
                                        securityPermission.getQualifications().put(childAttributeName,
                                                childAttributeValue);
                                    }
                                }
                            }
                        }

                        //if ( KimApiServiceLocator.getPermissionService().isPermissionDefined(securityPermission.getPermissionNamespaceCode(), securityPermission.getPermissionName(), securityPermission.getPermissionDetails())) {
                        permissions.add(securityPermission);
                        //} else {
                        //  LOG.warn("Could not find permission with name '" + securityPermission.getPermissionName() + "' and namespace '" + securityPermission.getPermissionNamespaceCode() + "' which was defined on Document Type security");
                        //}
                    }
                }
            }
        }

        NodeList roleNodes = (NodeList) xpath.evaluate("./role", securityElement, XPathConstants.NODESET);
        if (roleNodes != null && roleNodes.getLength() > 0) {
            for (int i = 0; i < roleNodes.getLength(); i++) {
                Element roleElement = (Element) roleNodes.item(i);
                String value = roleElement.getTextContent().trim();
                String allowedValue = roleElement.getAttribute("allowed");
                if (StringUtils.isBlank(allowedValue)) {
                    allowedValue = "true";
                }
                if (!org.apache.commons.lang.StringUtils.isEmpty(value)) {
                    if (Boolean.parseBoolean(allowedValue)) {
                        allowedRoles.add(value);
                    } else {
                        disallowedRoles.add(value);
                    }
                }
            }
        }

        NodeList attributeNodes = (NodeList) xpath.evaluate("./securityAttribute", securityElement,
                XPathConstants.NODESET);
        if (attributeNodes != null && attributeNodes.getLength() > 0) {
            for (int i = 0; i < attributeNodes.getLength(); i++) {
                Element attributeElement = (Element) attributeNodes.item(i);
                NamedNodeMap elemAttributes = attributeElement.getAttributes();
                // can be an attribute name or an actual classname
                String attributeOrClassName = null;
                String applicationId = standardApplicationId;
                if (elemAttributes.getNamedItem("name") != null) {
                    // found a name attribute so find the class name
                    String extensionName = elemAttributes.getNamedItem("name").getNodeValue().trim();
                    this.securityAttributeExtensionNames.add(extensionName);
                } else if (elemAttributes.getNamedItem("class") != null) {
                    // class name defined
                    String className = elemAttributes.getNamedItem("class").getNodeValue().trim();
                    this.securityAttributeClassNames.add(className);
                } else {
                    throw new WorkflowException(
                            "Cannot find attribute 'name' or attribute 'class' for securityAttribute Node");
                }
            }
        }
    } catch (Exception err) {
        throw new WorkflowRuntimeException(err);
    }
}

From source file:org.kuali.rice.kew.rule.xmlrouting.StandardGenericXMLRuleAttribute.java

private String getValidationErrorMessage(XPath xpath, Element root, String fieldName)
        throws XPathExpressionException {
    String findErrorMessage = "//routingConfig/" + FIELD_DEF_E + "[@name='" + fieldName
            + "']/validation/message";
    return (String) xpath.evaluate(findErrorMessage, root, XPathConstants.STRING);
}

From source file:org.kuali.rice.kew.xml.DocumentTypeXmlParser.java

/**
 * Parses all document types, both standard and routing.
 * //  w w  w  . j  a  v  a 2 s  .c  o m
 * @param routeDocument The DOM document to parse.
 * @return A list containing the desired document types.
 */
private List<DocumentType> parseAllDocumentTypes(Document routeDocument) throws SAXException, IOException,
        ParserConfigurationException, XPathExpressionException, WorkflowException, GroupNotFoundException {
    // A mapping from the names of uninitialized parent doc types to the child nodes that depend on the parent doc.
    Map<String, List<DocTypeNode>> pendingChildDocs = new HashMap<String, List<DocTypeNode>>();
    // A mapping from the names of uninitialized parent doc types to the names of the dependent children.
    Map<String, List<String>> pendingChildNames = new HashMap<String, List<String>>();
    // A stack containing Iterators over the various lists of unprocessed nodes; this allows for faster parent-child resolution
    // without having to use recursion.
    List<Iterator<DocTypeNode>> docInitStack = new ArrayList<Iterator<DocTypeNode>>();
    // The first List of document types.
    List<DocTypeNode> initialList = new ArrayList<DocTypeNode>();

    List<DocumentType> docTypeBeans = new ArrayList<DocumentType>();

    // Acquire the "standard" and "routing" document types.
    xpath = XPathHelper.newXPath();
    NodeList initialNodes = (NodeList) getXPath().evaluate(
            "/" + DATA_ELEMENT + "/" + DOCUMENT_TYPES + "/" + DOCUMENT_TYPE, routeDocument,
            XPathConstants.NODESET);
    // Take each NodeList's nodes and insert them into a List implementation.
    for (int j = 0; j < initialNodes.getLength(); j++) {
        Node documentTypeNode = initialNodes.item(j);
        boolean docIsStandard = true;
        try {
            String xpathModeExpression = "./@" + DOCUMENT_TYPE_OVERWRITE_MODE;
            if (XmlHelper.pathExists(xpath, xpathModeExpression, documentTypeNode)) {
                String overwriteMode = (String) getXPath().evaluate(xpathModeExpression, documentTypeNode,
                        XPathConstants.STRING);
                docIsStandard = !StringUtils.equalsIgnoreCase("true", overwriteMode);
            }
        } catch (XPathExpressionException xpee) {
            LOG.error("Error trying to check for '" + DOCUMENT_TYPE_OVERWRITE_MODE
                    + "' attribute on document type element", xpee);
            throw xpee;
        }
        initialList.add(new DocTypeNode(documentTypeNode, docIsStandard));
    }

    // The current size of the stack.
    int stackLen = 0;
    // The current document type node.
    DocTypeNode currDocNode = null;
    // The current Iterator instance.
    Iterator<DocTypeNode> currentIter = initialList.iterator();

    // Keep looping until all Iterators are complete or an uncaught exception is thrown.
    while (stackLen >= 0) {
        // Determine the action to take based on whether there are remaining nodes in the present iterator.
        if (currentIter.hasNext()) {
            // If the current iterator still has more nodes, process the next one.
            String newParentName = null;
            currDocNode = currentIter.next();
            // Initialize the document, and catch any child initialization problems.
            try {
                // Take appropriate action based on whether the document is a standard one or a routing one.
                DocumentType docType = parseDocumentType(!currDocNode.isStandard, currDocNode.docNode);
                // Insert into appropriate position in the final list, based on the doc type's location in the XML file's list.
                docTypeBeans.add(docType);
                // Store the document's name for reference.
                newParentName = docType.getName();
            } catch (InvalidParentDocTypeException exc) {
                // If the parent document has not been processed yet, then store the child document.
                List<DocTypeNode> tempList = null;
                List<String> tempStrList = null;
                String parentName = exc.getParentName();
                String childName = exc.getChildName();
                if (parentName == null || childName == null) { // Make sure the parent & child documents' names are defined.
                    throw exc;
                }
                tempList = pendingChildDocs.get(parentName);
                tempStrList = pendingChildNames.get(parentName);
                if (tempList == null) { // Initialize a new child document list if necessary.
                    tempList = new ArrayList<DocTypeNode>();
                    tempStrList = new ArrayList<String>();
                    pendingChildDocs.put(parentName, tempList);
                    pendingChildNames.put(parentName, tempStrList);
                }
                tempList.add(currDocNode);
                tempStrList.add(childName);
            }

            // Check for any delayed child documents that are dependent on the current document.
            List<DocTypeNode> childrenToProcess = pendingChildDocs.remove(newParentName);
            pendingChildNames.remove(newParentName);
            if (childrenToProcess != null) {
                LOG.info("'" + newParentName + "' has children that were delayed; now processing them...");
                // If there are any pending children, push the old Iterator onto the stack and process the new Iterator on the next
                // iteration of the loop.
                stackLen++;
                docInitStack.add(currentIter);
                currentIter = childrenToProcess.iterator();
            }
        } else {
            // If the current Iterator has reached its end, discard it and pop the next one (if any) from the stack.
            stackLen--;
            currentIter = ((stackLen >= 0) ? docInitStack.remove(stackLen) : null);
        }
    }

    // Throw an error if there are still any uninitialized child documents.
    if (pendingChildDocs.size() > 0) {
        StringBuilder errMsg = new StringBuilder("Invalid parent document types: ");
        // Construct the error message.
        for (Iterator<String> unknownParents = pendingChildNames.keySet().iterator(); unknownParents
                .hasNext();) {
            String currParent = unknownParents.next();
            errMsg.append("Invalid parent doc type '").append(currParent)
                    .append("' is needed by child doc types ");
            for (Iterator<String> failedChildren = pendingChildNames.get(currParent).iterator(); failedChildren
                    .hasNext();) {
                String currChild = failedChildren.next();
                errMsg.append('\'').append(currChild).append((failedChildren.hasNext()) ? "', " : "'; ");
            }
        }
        // Throw the exception.
        throw new InvalidParentDocTypeException(null, null, errMsg.toString());
    }

    return docTypeBeans;
}

From source file:org.kuali.rice.kew.xml.DocumentTypeXmlParser.java

private void parseStructure(boolean isOverwrite, Node documentTypeNode, DocumentType documentType,
        RoutePathContext context) throws XPathExpressionException, XmlException, GroupNotFoundException {
    // TODO have a validation function that takes an xpath statement and blows chunks if that
    // statement returns false
    boolean hasRoutePathsElement = false;
    try {/*ww  w.  j  av a  2  s.c o  m*/
        hasRoutePathsElement = XmlHelper.pathExists(xpath, "./" + ROUTE_PATHS, documentTypeNode);
    } catch (XPathExpressionException xpee) {
        LOG.error("Error obtaining document type " + ROUTE_PATHS, xpee);
        throw xpee;
    }
    boolean hasRouteNodesElement = false;
    try {
        hasRouteNodesElement = XmlHelper.pathExists(xpath, "./" + ROUTE_NODES, documentTypeNode);
    } catch (XPathExpressionException xpee) {
        LOG.error("Error obtaining document type " + ROUTE_NODES, xpee);
        throw xpee;
    }

    // check to see if we're in overwrite mode
    if (isOverwrite) {
        // since we're in overwrite mode, if we don't have a routeNodes element or a routePaths element we simply return
        if (!hasRouteNodesElement && !hasRoutePathsElement) {
            return;
        }
        // if we have route nodes and route paths we're going to overwrite all existing processes so we can clear the current list
        else if (hasRouteNodesElement && hasRoutePathsElement) {
            documentType.setProcesses(new ArrayList());
        }
        // check to see if we have one but not the other element of routePaths and routeNodes
        else if (!hasRouteNodesElement || !hasRoutePathsElement) {
            // throw an exception since an ingestion can only have neither or both of the routePaths and routeNodes elements
            throw new XmlException(
                    "A overwriting document type ingestion can not have only one of the " + ROUTE_PATHS
                            + " and " + ROUTE_NODES + " elements.  Either both or neither should be defined.");
        }
    }

    NodeList processNodes;

    try {
        if (XmlHelper.pathExists(xpath, "./" + ROUTE_PATHS + "/" + ROUTE_PATH, documentTypeNode)) {
            processNodes = (NodeList) getXPath().evaluate("./" + ROUTE_PATHS + "/" + ROUTE_PATH,
                    documentTypeNode, XPathConstants.NODESET);
        } else {
            if (hasRoutePathsElement) {
                createEmptyProcess(documentType);
            }
            return;
        }
    } catch (XPathExpressionException xpee) {
        LOG.error("Error obtaining document type routePaths", xpee);
        throw xpee;
    }

    createProcesses(processNodes, documentType);

    NodeList nodeList = null;
    try {
        nodeList = (NodeList) getXPath().evaluate("./" + ROUTE_PATHS + "/" + ROUTE_PATH + "/start",
                documentTypeNode, XPathConstants.NODESET);
    } catch (XPathExpressionException xpee) {
        LOG.error("Error obtaining document type routePath start", xpee);
        throw xpee;
    }
    if (nodeList.getLength() > 1) {
        throw new XmlException("More than one start node is present in route path");
    } else if (nodeList.getLength() == 0) {
        throw new XmlException("No start node is present in route path");
    }
    try {
        nodeList = (NodeList) getXPath().evaluate(".//" + ROUTE_NODES, documentTypeNode,
                XPathConstants.NODESET);
    } catch (XPathExpressionException xpee) {
        LOG.error("Error obtaining document type routeNodes", xpee);
        throw xpee;
    }
    if (nodeList.getLength() > 1) {
        throw new XmlException("More than one routeNodes node is present in documentType node");
    } else if (nodeList.getLength() == 0) {
        throw new XmlException("No routeNodes node is present in documentType node");
    }
    Node routeNodesNode = nodeList.item(0);
    checkForOrphanedRouteNodes(documentTypeNode, routeNodesNode);

    // passed validation.
    nodesMap = new HashMap();
    for (int index = 0; index < processNodes.getLength(); index++) {
        Node processNode = processNodes.item(index);
        String startName;
        try {
            startName = (String) getXPath().evaluate("./start/@name", processNode, XPathConstants.STRING);
        } catch (XPathExpressionException xpee) {
            LOG.error("Error obtaining routePath start name attribute", xpee);
            throw xpee;
        }
        String processName = KewApiConstants.PRIMARY_PROCESS_NAME;
        if (org.apache.commons.lang.StringUtils.isEmpty(startName)) {
            try {
                startName = (String) getXPath().evaluate("./@" + INITIAL_NODE, processNode,
                        XPathConstants.STRING);
            } catch (XPathExpressionException xpee) {
                LOG.error("Error obtaining routePath initialNode attribute", xpee);
                throw xpee;
            }
            try {
                processName = (String) getXPath().evaluate("./@" + PROCESS_NAME, processNode,
                        XPathConstants.STRING);
            } catch (XPathExpressionException xpee) {
                LOG.error("Error obtaining routePath processName attribute", xpee);
                throw xpee;
            }
            if (org.apache.commons.lang.StringUtils.isEmpty(startName)) {
                throw new XmlException("Invalid routePath: no initialNode attribute defined!");
            }
        }
        RouteNode routeNode = createRouteNode(null, startName, processNode, routeNodesNode, documentType,
                context);
        if (routeNode != null) {
            ProcessDefinitionBo process = documentType.getNamedProcess(processName);
            process.setInitialRouteNode(routeNode);
        }
    }

}