List of usage examples for javax.xml.xpath XPathConstants STRING
QName STRING
To view the source code for javax.xml.xpath XPathConstants STRING.
Click Source Link
The XPath 1.0 string data type.
Maps to Java String .
From source file:org.kuali.rice.kew.xml.DocumentTypeXmlParser.java
private DocumentType getDocumentType(boolean isOverwrite, Node documentTypeNode) throws XPathExpressionException, GroupNotFoundException, XmlException, WorkflowException, SAXException, IOException, ParserConfigurationException { DocumentType documentType = null; String documentTypeName = getDocumentTypeNameFromNode(documentTypeNode); DocumentType previousDocumentType = KEWServiceLocator.getDocumentTypeService().findByName(documentTypeName); if (isOverwrite) { // we don't need the isOverwrite value to be passed here because we're only temporarily creating this document type in memory documentType = generateNewDocumentTypeFromExisting(documentTypeName); // export the document type that exists in the database }/* w w w . ja va2 s. co m*/ // if we don't have a valid value for documentType create a brand new instance if (documentType == null) { documentType = new DocumentType(); } documentType.setName(documentTypeName); // set the description on the document type // the description is always taken from the previous document type unless specified in the ingested file String description = null; try { description = (String) getXPath().evaluate("./" + DESCRIPTION, documentTypeNode, XPathConstants.STRING); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type description", xpee); throw xpee; } // if the ingestion has produced a valid value then set it on the document if (StringUtils.isNotBlank(description)) { documentType.setDescription(description); } // at this point we know the ingested value is blank else if (!isOverwrite) { // if this is not an overwrite we need to check the previous document type version for a value to pull forward if (previousDocumentType != null && StringUtils.isNotBlank(previousDocumentType.getDescription())) { // keep the same value from the previous version of the document type from the database description = previousDocumentType.getDescription(); } documentType.setDescription(description); } // set the label on the document type String label = null; try { label = (String) getXPath().evaluate("./" + LABEL, documentTypeNode, XPathConstants.STRING); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type label", xpee); throw xpee; } // if the ingestion has produced a valid value then set it on the document if (StringUtils.isNotBlank(label)) { documentType.setLabel(label); } // at this point we know the ingested value is blank else if (!isOverwrite) { // if this is not an overwrite we need to check the previous document type version for a value to pull forward if (previousDocumentType != null && StringUtils.isNotBlank(previousDocumentType.getLabel())) { // keep the same value from the previous version of the document type from the database label = previousDocumentType.getLabel(); } else { // otherwise set it to undefined label = KewApiConstants.DEFAULT_DOCUMENT_TYPE_LABEL; } documentType.setLabel(label); } // set the post processor class on the document type try { /* * - if the element tag is ingested... take whatever value is given, even if it's empty * - we disregard the isOverwrite because if the element tag does not exist in the ingestion * then the documentType should already carry the value from the previous document type */ if (XmlHelper.pathExists(xpath, "./" + POST_PROCESSOR_NAME, documentTypeNode)) { String postProcessor = (String) getXPath().evaluate("./" + POST_PROCESSOR_NAME, documentTypeNode, XPathConstants.STRING); if (StringUtils.isEmpty(postProcessor)) { documentType.setPostProcessorName(KewApiConstants.POST_PROCESSOR_NON_DEFINED_VALUE); } else { documentType.setPostProcessorName((String) getXPath().evaluate("./" + POST_PROCESSOR_NAME, documentTypeNode, XPathConstants.STRING)); } } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type postProcessorName", xpee); throw xpee; } // set the DocumentTypeAuthorizer try { if (XmlHelper.pathExists(xpath, "./" + AUTHORIZER, documentTypeNode)) { String authorizer = (String) getXPath().evaluate("./" + AUTHORIZER, documentTypeNode, XPathConstants.STRING); if (StringUtils.isNotBlank(authorizer)) { documentType.setAuthorizer(authorizer); } } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type authorizer", xpee); throw xpee; } // set the document handler URL on the document type try { /* * - if the element tag is ingested... take whatever value is given, even if it's empty * - we disregard the isOverwrite because if the element tag does not exist in the ingestion * then the documentType should already carry the value from the previous document type */ if (XmlHelper.pathExists(xpath, "./" + DOC_HANDLER, documentTypeNode)) { documentType.setUnresolvedDocHandlerUrl( (String) getXPath().evaluate("./" + DOC_HANDLER, documentTypeNode, XPathConstants.STRING)); } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type docHandler", xpee); throw xpee; } // set the help definition URL on the document type String helpDefUrl = null; try { helpDefUrl = (String) getXPath().evaluate("./" + HELP_DEFINITION_URL, documentTypeNode, XPathConstants.STRING); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type help definition url", xpee); throw xpee; } // if the ingestion has produced a valid value then set it on the document if (StringUtils.isNotBlank(helpDefUrl)) { documentType.setUnresolvedHelpDefinitionUrl(helpDefUrl); } // at this point we know the ingested value is blank else if (!isOverwrite) { // if this is not an overwrite, we need to check the previous document type version for a value to pull forward if (previousDocumentType != null && StringUtils.isNotBlank(previousDocumentType.getUnresolvedHelpDefinitionUrl())) { // keep the same value from the previous version of the document type from the database helpDefUrl = previousDocumentType.getUnresolvedHelpDefinitionUrl(); } documentType.setUnresolvedHelpDefinitionUrl(helpDefUrl); } // set the doc search help URL on the document type String docSearchHelpUrl = null; try { docSearchHelpUrl = (String) getXPath().evaluate("./" + DOC_SEARCH_HELP_URL, documentTypeNode, XPathConstants.STRING); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type document search help url", xpee); throw xpee; } // if the ingestion has produced a valid value then set it on the document if (StringUtils.isNotBlank(docSearchHelpUrl)) { documentType.setUnresolvedDocSearchHelpUrl(docSearchHelpUrl); } // at this point we know the ingested value is blank else if (!isOverwrite) { // if this is not an overwrite, we need to check the previous document type version for a value to pull forward if (previousDocumentType != null && StringUtils.isNotBlank(previousDocumentType.getUnresolvedDocSearchHelpUrl())) { // keep the same value from the previous version of the document type from the database docSearchHelpUrl = previousDocumentType.getUnresolvedDocSearchHelpUrl(); } documentType.setUnresolvedDocSearchHelpUrl(docSearchHelpUrl); } // set the application id on the document type try { /* * - if the element tag is ingested... take whatever value is given, even if it's empty * - we disregard the isOverwrite because if the element tag does not exist in the ingestion * then the documentType should already carry the value from the previous document type */ if (XmlHelper.pathExists(xpath, "./" + APPLICATION_ID, documentTypeNode)) { documentType.setActualApplicationId((String) getXPath().evaluate("./" + APPLICATION_ID, documentTypeNode, XPathConstants.STRING)); } else if (XmlHelper.pathExists(xpath, "./" + SERVICE_NAMESPACE, documentTypeNode)) { documentType.setActualApplicationId((String) getXPath().evaluate("./" + SERVICE_NAMESPACE, documentTypeNode, XPathConstants.STRING)); LOG.warn(SERVICE_NAMESPACE + " element was set on document type XML but is deprecated and will be removed in a future version, please use " + APPLICATION_ID + " instead."); } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type applicationId", xpee); throw xpee; } // set the notification from address on the document type try { /* * - if the element tag is ingested... take whatever value is given, even if it's empty * - we disregard the isOverwrite because if the element tag does not exist in the ingestion * then the documentType should already carry the value from the previous document type */ if (XmlHelper.pathExists(xpath, "./" + NOTIFICATION_FROM_ADDRESS, documentTypeNode)) { documentType.setActualNotificationFromAddress((String) getXPath() .evaluate("./" + NOTIFICATION_FROM_ADDRESS, documentTypeNode, XPathConstants.STRING)); } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type " + NOTIFICATION_FROM_ADDRESS, xpee); throw xpee; } try { /* * - if the element tag is ingested... take whatever value is given, even if it's empty * - we disregard the isOverwrite because if the element tag does not exist in the ingestion * then the documentType should already carry the value from the previous document type */ if (XmlHelper.pathExists(xpath, "./" + CUSTOM_EMAIL_STYLESHEET, documentTypeNode)) { documentType.setCustomEmailStylesheet((String) getXPath().evaluate("./" + CUSTOM_EMAIL_STYLESHEET, documentTypeNode, XPathConstants.STRING)); } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type " + CUSTOM_EMAIL_STYLESHEET, xpee); throw xpee; } // any ingested document type by default becomes the current document type documentType.setCurrentInd(Boolean.TRUE); // set up the default exception workgroup for the document type String exceptionWg = null; String exceptionWgName = null; String exceptionWgNamespace = null; try { if (XmlHelper.pathExists(xpath, "./" + DEFAULT_EXCEPTION_GROUP_NAME, documentTypeNode)) { exceptionWgName = (String) getXPath().evaluate("./" + DEFAULT_EXCEPTION_GROUP_NAME, documentTypeNode, XPathConstants.STRING); exceptionWgNamespace = (String) getXPath().evaluate( "./" + DEFAULT_EXCEPTION_GROUP_NAME + "/@" + NAMESPACE, documentTypeNode, XPathConstants.STRING); exceptionWg = exceptionWgName; } else { exceptionWg = (String) getXPath().evaluate("./" + DEFAULT_EXCEPTION_WORKGROUP_NAME, documentTypeNode, XPathConstants.STRING); } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type " + DEFAULT_EXCEPTION_GROUP_NAME, xpee); throw xpee; } // we don't need to take the isOverwrite into account here because this ingestion method is a shortcut to use the same workgroup in all route nodes if (StringUtils.isNotBlank(exceptionWg)) { if (StringUtils.isNotBlank(exceptionWgName)) { // Found a "defaultExceptionGroupName" element. // allow core config parameter replacement in documenttype workgroups exceptionWgName = Utilities.substituteConfigParameters(exceptionWgName).trim(); exceptionWgNamespace = Utilities.substituteConfigParameters(exceptionWgNamespace).trim(); } else { // Found a deprecated "defaultExceptionWorkgroupName" element. LOG.warn((new StringBuilder(160)).append("Document Type XML is using deprecated element '") .append(DEFAULT_EXCEPTION_WORKGROUP_NAME).append("', please use '") .append(DEFAULT_EXCEPTION_GROUP_NAME).append("' instead.").toString()); // allow core config parameter replacement in documenttype workgroups exceptionWg = Utilities.substituteConfigParameters(exceptionWg); exceptionWgName = Utilities.parseGroupName(exceptionWg); exceptionWgNamespace = Utilities.parseGroupNamespaceCode(exceptionWg); } Group exceptionGroup = getGroupService().getGroupByNamespaceCodeAndName(exceptionWgNamespace, exceptionWgName); if (exceptionGroup == null) { throw new WorkflowRuntimeException( "Exception workgroup name " + exceptionWgName + " does not exist"); } documentType.setDefaultExceptionWorkgroup(exceptionGroup); defaultExceptionWorkgroup = exceptionGroup; } // set up the active indicator on the document type try { // if the element tag is ingested... take whatever value is given if (XmlHelper.pathExists(xpath, "./" + ACTIVE, documentTypeNode)) { documentType.setActive(Boolean.valueOf( (String) getXPath().evaluate("./" + ACTIVE, documentTypeNode, XPathConstants.STRING))); } // if isOverwrite is false set the default value else if (!isOverwrite) { documentType.setActive(Boolean.TRUE); } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type active flag", xpee); throw xpee; } // check for a parent document type for the ingested document type boolean parentElementExists = false; try { parentElementExists = XmlHelper.pathExists(xpath, "./" + PARENT, documentTypeNode); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type parent", xpee); throw xpee; } /* * - if the element tag is ingested... take whatever value is given * - we disregard the isOverwrite because if the element tag does not exist in the ingestion * then the documentType should already carry the value from the previous document type */ if (parentElementExists) { // the tag was ingested so we'll use whatever the user attempted to set String parentDocumentTypeName = null; try { parentDocumentTypeName = (String) getXPath().evaluate("./" + PARENT, documentTypeNode, XPathConstants.STRING); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type parent", xpee); throw xpee; } DocumentType parentDocumentType = KEWServiceLocator.getDocumentTypeService() .findByName(parentDocumentTypeName); if (parentDocumentType == null) { //throw new XmlException("Invalid parent document type: '" + parentDocumentTypeName + "'"); LOG.info("Parent document type '" + parentDocumentTypeName + "' could not be found; attempting to delay processing of '" + documentTypeName + "'..."); throw new InvalidParentDocTypeException(parentDocumentTypeName, documentTypeName, "Invalid parent document type: '" + parentDocumentTypeName + "'"); } documentType.setDocTypeParentId(parentDocumentType.getDocumentTypeId()); } // set the super user workgroup name on the document type try { /* * - if the element tag is ingested... take whatever value is given * - we disregard the isOverwrite because if the element tag does not exist in the ingestion * then the documentType should already carry the value from the previous document type */ if (XmlHelper.pathExists(xpath, "./" + SUPER_USER_GROUP_NAME, documentTypeNode)) { documentType.setSuperUserWorkgroupNoInheritence( retrieveValidKimGroup("./" + SUPER_USER_GROUP_NAME, documentTypeNode, false)); } else if (XmlHelper.pathExists(xpath, "./" + SUPER_USER_WORKGROUP_NAME, documentTypeNode)) { LOG.warn((new StringBuilder(160)).append("Document Type XML is using deprecated element '") .append(SUPER_USER_WORKGROUP_NAME).append("', please use '").append(SUPER_USER_GROUP_NAME) .append("' instead.").toString()); documentType.setSuperUserWorkgroupNoInheritence( retrieveValidKimGroup("./" + SUPER_USER_WORKGROUP_NAME, documentTypeNode, true)); } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type " + SUPER_USER_GROUP_NAME, xpee); throw xpee; } // set the blanket approve workgroup name on the document type String blanketWorkGroup = null; String blanketGroupName = null; String blanketNamespace = null; String blanketApprovePolicy = null; try { // check if the blanket approve workgroup name element tag was set on the ingested document type and get value if it was if (XmlHelper.pathExists(xpath, "./" + BLANKET_APPROVE_GROUP_NAME, documentTypeNode)) { blanketGroupName = (String) getXPath().evaluate("./" + BLANKET_APPROVE_GROUP_NAME, documentTypeNode, XPathConstants.STRING); blanketNamespace = (String) getXPath().evaluate( "./" + BLANKET_APPROVE_GROUP_NAME + "/@" + NAMESPACE, documentTypeNode, XPathConstants.STRING); blanketWorkGroup = blanketGroupName; } else if (XmlHelper.pathExists(xpath, "./" + BLANKET_APPROVE_WORKGROUP_NAME, documentTypeNode)) { blanketWorkGroup = (String) getXPath().evaluate("./" + BLANKET_APPROVE_WORKGROUP_NAME, documentTypeNode, XPathConstants.STRING); } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type " + BLANKET_APPROVE_GROUP_NAME, xpee); throw xpee; } try { // check if the blanket approve policy element tag was set on the ingested document type and get value if it was if (XmlHelper.pathExists(xpath, "./" + BLANKET_APPROVE_POLICY, documentTypeNode)) { blanketApprovePolicy = (String) getXPath().evaluate("./" + BLANKET_APPROVE_POLICY, documentTypeNode, XPathConstants.STRING); } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type " + BLANKET_APPROVE_POLICY, xpee); throw xpee; } // first check to see if the user ingested both a workgroup name and a policy if (StringUtils.isNotBlank(blanketWorkGroup) && StringUtils.isNotBlank(blanketApprovePolicy)) { throw new XmlException("Only one of the blanket approve xml tags can be set"); } else if (StringUtils.isNotBlank(blanketWorkGroup)) { if (isOverwrite) { // if overwrite mode is on we need to make sure we clear out the blanket approve policy in case that was the previous document type's method documentType.setBlanketApprovePolicy(null); } if (StringUtils.isNotBlank(blanketGroupName)) { // Found a "blanketApproveGroupName" element. documentType.setBlanketApproveWorkgroup( retrieveValidKimGroupUsingGroupNameAndNamespace(blanketGroupName, blanketNamespace)); } else { // Found a deprecated "blanketApproveWorkgroupName" element. LOG.warn((new StringBuilder(160)).append("Document Type XML is using deprecated element '") .append(BLANKET_APPROVE_WORKGROUP_NAME).append("', please use '") .append(BLANKET_APPROVE_GROUP_NAME).append("' instead.").toString()); documentType .setBlanketApproveWorkgroup(retrieveValidKimGroupUsingUnparsedGroupName(blanketWorkGroup)); } } else if (StringUtils.isNotBlank(blanketApprovePolicy)) { if (isOverwrite) { // if overwrite mode is on we need to make sure we clear out the blanket approve workgroup in case that was the previous document type's method documentType.setBlanketApproveWorkgroup(null); } documentType.setBlanketApprovePolicy(blanketApprovePolicy); } // set the reporting workgroup name on the document type try { if (XmlHelper.pathExists(xpath, "./" + REPORTING_GROUP_NAME, documentTypeNode)) { documentType.setReportingWorkgroup( retrieveValidKimGroup("./" + REPORTING_GROUP_NAME, documentTypeNode, false)); } else if (XmlHelper.pathExists(xpath, "./" + REPORTING_WORKGROUP_NAME, documentTypeNode)) { LOG.warn((new StringBuilder(160)).append("Document Type XML is using deprecated element '") .append(REPORTING_WORKGROUP_NAME).append("', please use '").append(REPORTING_GROUP_NAME) .append("' instead.").toString()); documentType.setReportingWorkgroup( retrieveValidKimGroup("./" + REPORTING_WORKGROUP_NAME, documentTypeNode, true)); } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type " + REPORTING_GROUP_NAME, xpee); throw xpee; } // set the routing version on the document type try { /* * - if the element tag is ingested... take whatever value is given * - we disregard the isOverwrite because if the element tag does not exist in the ingestion * then the documentType should already carry the value from the previous document type */ if (XmlHelper.pathExists(xpath, "./" + ROUTING_VERSION, documentTypeNode)) { String version; try { version = (String) getXPath().evaluate("./" + ROUTING_VERSION, documentTypeNode, XPathConstants.STRING); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type routingVersion", xpee); throw xpee; } // verify that the routing version is one of the two valid values if (!(version.equals(KewApiConstants.ROUTING_VERSION_ROUTE_LEVEL) || version.equals(KewApiConstants.ROUTING_VERSION_NODAL))) { throw new WorkflowRuntimeException("Invalid routing version on document type: " + version); } documentType.setRoutingVersion(version); } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type routingVersion", xpee); throw xpee; } // KULRICE-7786: Document Specific Doc Search Application Document Status should be available (and groupable) // on the basic version of search. // // Side-effect: populates the application statuses and categories on the documentType ApplicationDocumentStatusParser.parseValidApplicationStatuses(documentType, documentTypeNode, getXPath()); return documentType; }
From source file:org.kuali.rice.kew.xml.DocumentTypeXmlParser.java
private Group retrieveValidKimGroup(String xpathExpression, Node documentTypeNode, boolean deprecatedGroupElement) throws XPathExpressionException, GroupNotFoundException { String groupName;//w ww . j ava 2s. c o m String groupNamespace = null; try { groupName = (String) getXPath().evaluate(xpathExpression, documentTypeNode, XPathConstants.STRING); // If not using the deprecated "namespaceCode:GroupName" format for group names, obtain the namespace from the element's "namespace" attribute. if (!deprecatedGroupElement) { groupNamespace = (String) getXPath().evaluate(xpathExpression + "/@" + NAMESPACE, documentTypeNode, XPathConstants.STRING); } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type workgroup using xpath expression: " + xpathExpression, xpee); throw xpee; } // Use the appropriate method to retrieve the group, based on whether or not the deprecated "namespaceCode:groupName" naming pattern is in use. return (deprecatedGroupElement) ? retrieveValidKimGroupUsingUnparsedGroupName(groupName) : retrieveValidKimGroupUsingGroupNameAndNamespace(groupName, groupNamespace); }
From source file:org.kuali.rice.kew.xml.DocumentTypeXmlParser.java
private String getDocumentTypeNameFromNode(Node documentTypeNode) throws XPathExpressionException { try {/*from www. java 2s . c o m*/ return (String) getXPath().evaluate("./name", documentTypeNode, XPathConstants.STRING); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type name", xpee); throw xpee; } }
From source file:org.kuali.rice.kew.xml.DocumentTypeXmlParser.java
private RouteNode createRouteNode(RouteNode previousRouteNode, String nodeName, Node routePathNode, Node routeNodesNode, DocumentType documentType, RoutePathContext context) throws XPathExpressionException, XmlException, GroupNotFoundException { if (nodeName == null) return null; Node currentNode;/*w w w .j ava2 s .com*/ context.nodeXPath += "//" + "*[@name = '" + nodeName + "']"; context.nodeQName += nodeName + ":"; try { currentNode = (Node) getXPath().evaluate(context.nodeXPath + "//" + "*[@name = '" + nodeName + "']", routePathNode, XPathConstants.NODE); if (currentNode == null) { findNodeOnXPath(nodeName, context, routePathNode); currentNode = (Node) getXPath().evaluate(context.nodeXPath + "//" + "*[@name = '" + nodeName + "']", routePathNode, XPathConstants.NODE); } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining routePath for routeNode", xpee); throw xpee; } if (currentNode == null) { String message = "Next node '" + nodeName + "' for node '" + previousRouteNode.getRouteNodeName() + "' not found!"; LOG.error(message); throw new XmlException(message); } context.nodeXPath += "//" + "*[@name = '" + nodeName + "']"; context.nodeQName += nodeName + ":"; LOG.debug("nodeQNme:" + context.nodeQName); boolean nodeIsABranch; try { nodeIsABranch = ((Boolean) getXPath().evaluate("self::node()[local-name() = 'branch']", currentNode, XPathConstants.BOOLEAN)).booleanValue(); } catch (XPathExpressionException xpee) { LOG.error("Error testing whether node is a branch", xpee); throw xpee; } if (nodeIsABranch) { throw new XmlException("Next node cannot be a branch node"); } String localName; try { localName = (String) getXPath().evaluate("local-name(.)", currentNode, XPathConstants.STRING); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining node local-name", xpee); throw xpee; } RouteNode currentRouteNode = null; if (nodesMap.containsKey(context.nodeQName)) { currentRouteNode = (RouteNode) nodesMap.get(context.nodeQName); } else { String nodeExpression = ".//*[@name='" + nodeName + "']"; currentRouteNode = makeRouteNodePrototype(localName, nodeName, nodeExpression, routeNodesNode, documentType, context); } if ("split".equalsIgnoreCase(localName)) { getSplitNextNodes(currentNode, routePathNode, currentRouteNode, routeNodesNode, documentType, cloneContext(context)); } if (previousRouteNode != null) { previousRouteNode.getNextNodes().add(currentRouteNode); nodesMap.put(context.previousNodeQName, previousRouteNode); currentRouteNode.getPreviousNodes().add(previousRouteNode); } String nextNodeName = null; boolean hasNextNodeAttrib; try { hasNextNodeAttrib = ((Boolean) getXPath().evaluate(NEXT_NODE_EXP, currentNode, XPathConstants.BOOLEAN)) .booleanValue(); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining node nextNode attrib", xpee); throw xpee; } if (hasNextNodeAttrib) { // if the node has a nextNode but is not a split node, the nextNode is used for its node if (!"split".equalsIgnoreCase(localName)) { try { nextNodeName = (String) getXPath().evaluate(NEXT_NODE_EXP, currentNode, XPathConstants.STRING); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining node nextNode attrib", xpee); throw xpee; } context.previousNodeQName = context.nodeQName; createRouteNode(currentRouteNode, nextNodeName, routePathNode, routeNodesNode, documentType, cloneContext(context)); } else { // if the node has a nextNode but is a split node, the nextNode must be used for that split node's join node nodesMap.put(context.nodeQName, currentRouteNode); } } else { // if the node has no nextNode of its own and is not a join which gets its nextNode from its parent split node if (!"join".equalsIgnoreCase(localName)) { nodesMap.put(context.nodeQName, currentRouteNode); } else { // if join has a parent nextNode (on its split node) and join has not already walked this path boolean parentHasNextNodeAttrib; try { parentHasNextNodeAttrib = ((Boolean) getXPath().evaluate(PARENT_NEXT_NODE_EXP, currentNode, XPathConstants.BOOLEAN)).booleanValue(); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining parent node nextNode attrib", xpee); throw xpee; } if (parentHasNextNodeAttrib && !nodesMap.containsKey(context.nodeQName)) { try { nextNodeName = (String) getXPath().evaluate(PARENT_NEXT_NODE_EXP, currentNode, XPathConstants.STRING); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining parent node nextNode attrib", xpee); throw xpee; } context.previousNodeQName = context.nodeQName; createRouteNode(currentRouteNode, nextNodeName, routePathNode, routeNodesNode, documentType, cloneContext(context)); } else { // if join's parent split node does not have a nextNode nodesMap.put(context.nodeQName, currentRouteNode); } } } // handle nextAppDocStatus route node attribute String nextDocStatusName = null; boolean hasNextDocStatus; try { hasNextDocStatus = ((Boolean) getXPath().evaluate(NEXT_DOC_STATUS_EXP, currentNode, XPathConstants.BOOLEAN)).booleanValue(); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining node nextAppDocStatus attrib", xpee); throw xpee; } if (hasNextDocStatus) { try { nextDocStatusName = (String) getXPath().evaluate(NEXT_DOC_STATUS_EXP, currentNode, XPathConstants.STRING); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining node nextNode attrib", xpee); throw xpee; } //validate against allowable values if defined if (documentType.getValidApplicationStatuses() != null && documentType.getValidApplicationStatuses().size() > 0) { Iterator iter = documentType.getValidApplicationStatuses().iterator(); boolean statusValidated = false; while (iter.hasNext()) { ApplicationDocumentStatus myAppDocStat = (ApplicationDocumentStatus) iter.next(); if (nextDocStatusName.compareToIgnoreCase(myAppDocStat.getStatusName()) == 0) { statusValidated = true; break; } } if (!statusValidated) { XmlException xpee = new XmlException( "AppDocStatus value " + nextDocStatusName + " not allowable."); LOG.error("Error validating nextAppDocStatus name: " + nextDocStatusName + " against acceptable values.", xpee); throw xpee; } } currentRouteNode.setNextDocStatus(nextDocStatusName); } return currentRouteNode; }
From source file:org.kuali.rice.kew.xml.DocumentTypeXmlParser.java
private void getSplitNextNodes(Node splitNode, Node routePathNode, RouteNode splitRouteNode, Node routeNodesNode, DocumentType documentType, RoutePathContext context) throws XPathExpressionException, XmlException, GroupNotFoundException { NodeList splitBranchNodes;/* w ww . j av a 2 s . com*/ try { splitBranchNodes = (NodeList) getXPath().evaluate("./branch", splitNode, XPathConstants.NODESET); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining split node branch", xpee); throw xpee; } String splitQName = context.nodeQName; String splitXPath = context.nodeXPath; for (int i = 0; i < splitBranchNodes.getLength(); i++) { String branchName; try { branchName = (String) getXPath().evaluate("./@name", splitBranchNodes.item(i), XPathConstants.STRING); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining branch name attribute", xpee); throw xpee; } String name; try { name = (String) getXPath().evaluate("./*[1]/@name", splitBranchNodes.item(i), XPathConstants.STRING); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining first split branch node name", xpee); throw xpee; } context.nodeQName = splitQName + branchName + ":"; context.nodeXPath = splitXPath + "//" + "*[@name = '" + branchName + "']"; context.branch = new BranchPrototype(); context.branch.setName(branchName); context.previousNodeQName = splitQName; createRouteNode(splitRouteNode, name, routePathNode, routeNodesNode, documentType, cloneContext(context)); } }
From source file:org.kuali.rice.kew.xml.DocumentTypeXmlParser.java
private RouteNode makeRouteNodePrototype(String nodeTypeName, String nodeName, String nodeExpression, Node routeNodesNode, DocumentType documentType, RoutePathContext context) throws XPathExpressionException, GroupNotFoundException, XmlException { NodeList nodeList;/*from w w w. j av a2s .c om*/ try { nodeList = (NodeList) getXPath().evaluate(nodeExpression, routeNodesNode, XPathConstants.NODESET); } catch (XPathExpressionException xpee) { LOG.error("Error evaluating node expression: '" + nodeExpression + "'"); throw xpee; } if (nodeList.getLength() > 1) { throw new XmlException("More than one node under routeNodes has the same name of '" + nodeName + "'"); } if (nodeList.getLength() == 0) { throw new XmlException("No node definition was found with the name '" + nodeName + "'"); } Node node = nodeList.item(0); RouteNode routeNode = new RouteNode(); // set fields that all route nodes of all types should have defined routeNode.setDocumentType(documentType); routeNode.setRouteNodeName((String) getXPath().evaluate("./@name", node, XPathConstants.STRING)); routeNode.setContentFragment(XmlJotter.jotNode(node)); if (XmlHelper.pathExists(xpath, "./activationType", node)) { routeNode.setActivationType(ActivationTypeEnum .parse((String) getXPath().evaluate("./activationType", node, XPathConstants.STRING)) .getCode()); } else { routeNode.setActivationType(DEFAULT_ACTIVATION_TYPE); } Group exceptionWorkgroup = defaultExceptionWorkgroup; String exceptionWg = null; String exceptionWorkgroupName = null; String exceptionWorkgroupNamespace = null; if (XmlHelper.pathExists(xpath, "./" + EXCEPTION_GROUP_NAME, node)) { exceptionWorkgroupName = Utilities .substituteConfigParameters( (String) getXPath().evaluate("./" + EXCEPTION_GROUP_NAME, node, XPathConstants.STRING)) .trim(); exceptionWorkgroupNamespace = Utilities .substituteConfigParameters((String) getXPath() .evaluate("./" + EXCEPTION_GROUP_NAME + "/@" + NAMESPACE, node, XPathConstants.STRING)) .trim(); } if (org.apache.commons.lang.StringUtils.isEmpty(exceptionWorkgroupName) && XmlHelper.pathExists(xpath, "./" + EXCEPTION_WORKGROUP_NAME, node)) { LOG.warn((new StringBuilder(160)).append("Document Type XML is using deprecated element '") .append(EXCEPTION_WORKGROUP_NAME).append("', please use '").append(EXCEPTION_GROUP_NAME) .append("' instead.").toString()); // for backward compatibility we also need to be able to support exceptionWorkgroupName exceptionWg = Utilities.substituteConfigParameters( (String) getXPath().evaluate("./" + EXCEPTION_WORKGROUP_NAME, node, XPathConstants.STRING)); exceptionWorkgroupName = Utilities.parseGroupName(exceptionWg); exceptionWorkgroupNamespace = Utilities.parseGroupNamespaceCode(exceptionWg); } if (org.apache.commons.lang.StringUtils.isEmpty(exceptionWorkgroupName) && XmlHelper.pathExists(xpath, "./" + EXCEPTION_WORKGROUP, node)) { LOG.warn((new StringBuilder(160)).append("Document Type XML is using deprecated element '") .append(EXCEPTION_WORKGROUP).append("', please use '").append(EXCEPTION_GROUP_NAME) .append("' instead.").toString()); // for backward compatibility we also need to be able to support exceptionWorkgroup exceptionWg = Utilities.substituteConfigParameters( (String) getXPath().evaluate("./" + EXCEPTION_WORKGROUP, node, XPathConstants.STRING)); exceptionWorkgroupName = Utilities.parseGroupName(exceptionWg); exceptionWorkgroupNamespace = Utilities.parseGroupNamespaceCode(exceptionWg); } if (org.apache.commons.lang.StringUtils.isEmpty(exceptionWorkgroupName)) { if (routeNode.getDocumentType().getDefaultExceptionWorkgroup() != null) { exceptionWorkgroupName = routeNode.getDocumentType().getDefaultExceptionWorkgroup().getName(); exceptionWorkgroupNamespace = routeNode.getDocumentType().getDefaultExceptionWorkgroup() .getNamespaceCode(); } } if (org.apache.commons.lang.StringUtils.isNotEmpty(exceptionWorkgroupName) && org.apache.commons.lang.StringUtils.isNotEmpty(exceptionWorkgroupNamespace)) { exceptionWorkgroup = getGroupService().getGroupByNamespaceCodeAndName(exceptionWorkgroupNamespace, exceptionWorkgroupName); if (exceptionWorkgroup == null) { throw new GroupNotFoundException("Could not locate exception workgroup with namespace '" + exceptionWorkgroupNamespace + "' and name '" + exceptionWorkgroupName + "'"); } } else { if (StringUtils.isEmpty(exceptionWorkgroupName) ^ StringUtils.isEmpty(exceptionWorkgroupNamespace)) { throw new GroupNotFoundException("Could not locate exception workgroup with namespace '" + exceptionWorkgroupNamespace + "' and name '" + exceptionWorkgroupName + "'"); } } if (exceptionWorkgroup != null) { routeNode.setExceptionWorkgroupName(exceptionWorkgroup.getName()); routeNode.setExceptionWorkgroupId(exceptionWorkgroup.getId()); } if (((Boolean) getXPath().evaluate("./mandatoryRoute", node, XPathConstants.BOOLEAN)).booleanValue()) { routeNode.setMandatoryRouteInd( Boolean.valueOf((String) getXPath().evaluate("./mandatoryRoute", node, XPathConstants.STRING))); } else { routeNode.setMandatoryRouteInd(Boolean.FALSE); } if (((Boolean) getXPath().evaluate("./finalApproval", node, XPathConstants.BOOLEAN)).booleanValue()) { routeNode.setFinalApprovalInd( Boolean.valueOf((String) getXPath().evaluate("./finalApproval", node, XPathConstants.STRING))); } else { routeNode.setFinalApprovalInd(Boolean.FALSE); } // for every simple child element of the node, store a config parameter of the element name and text content NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node n = children.item(i); if (n instanceof Element) { Element e = (Element) n; String name = e.getNodeName(); String content = getTextContent(e); routeNode.getConfigParams().add(new RouteNodeConfigParam(routeNode, name, content)); } } // make sure a default rule selector is set Map<String, String> cfgMap = Utilities.getKeyValueCollectionAsMap(routeNode.getConfigParams()); if (!cfgMap.containsKey(RouteNode.RULE_SELECTOR_CFG_KEY)) { routeNode.getConfigParams().add(new RouteNodeConfigParam(routeNode, RouteNode.RULE_SELECTOR_CFG_KEY, FlexRM.DEFAULT_RULE_SELECTOR)); } if (((Boolean) getXPath().evaluate("./ruleTemplate", node, XPathConstants.BOOLEAN)).booleanValue()) { String ruleTemplateName = (String) getXPath().evaluate("./ruleTemplate", node, XPathConstants.STRING); RuleTemplateBo ruleTemplate = KEWServiceLocator.getRuleTemplateService() .findByRuleTemplateName(ruleTemplateName); if (ruleTemplate == null) { throw new XmlException("Rule template for node '" + routeNode.getRouteNodeName() + "' not found: " + ruleTemplateName); } routeNode.setRouteMethodName(ruleTemplateName); routeNode.setRouteMethodCode(KewApiConstants.ROUTE_LEVEL_FLEX_RM); } else if (((Boolean) getXPath().evaluate("./routeModule", node, XPathConstants.BOOLEAN)).booleanValue()) { routeNode .setRouteMethodName((String) getXPath().evaluate("./routeModule", node, XPathConstants.STRING)); routeNode.setRouteMethodCode(KewApiConstants.ROUTE_LEVEL_ROUTE_MODULE); } else if (((Boolean) getXPath().evaluate("./peopleFlows", node, XPathConstants.BOOLEAN)).booleanValue()) { routeNode.setRouteMethodCode(KewApiConstants.ROUTE_LEVEL_PEOPLE_FLOW); } else if (((Boolean) getXPath().evaluate("./rulesEngine", node, XPathConstants.BOOLEAN)).booleanValue()) { // validate that the element has at least one of the two required attributes, XML schema does not provide a way for us to // check this so we must do so programatically Element rulesEngineElement = (Element) getXPath().evaluate("./rulesEngine", node, XPathConstants.NODE); String executorName = rulesEngineElement.getAttribute("executorName"); String executorClass = rulesEngineElement.getAttribute("executorClass"); if (StringUtils.isBlank(executorName) && StringUtils.isBlank(executorClass)) { throw new XmlException( "The rulesEngine declaration must have at least one of 'executorName' or 'executorClass' attributes."); } else if (StringUtils.isNotBlank(executorName) && StringUtils.isNotBlank(executorClass)) { throw new XmlException( "Only one of 'executorName' or 'executorClass' may be declared on rulesEngine configuration, but both were declared."); } routeNode.setRouteMethodCode(KewApiConstants.ROUTE_LEVEL_RULES_ENGINE); } String nodeType = null; if (((Boolean) getXPath().evaluate("./type", node, XPathConstants.BOOLEAN)).booleanValue()) { nodeType = (String) getXPath().evaluate("./type", node, XPathConstants.STRING); } else { String localName = (String) getXPath().evaluate("local-name(.)", node, XPathConstants.STRING); if ("start".equalsIgnoreCase(localName)) { nodeType = "org.kuali.rice.kew.engine.node.InitialNode"; } else if ("split".equalsIgnoreCase(localName)) { nodeType = "org.kuali.rice.kew.engine.node.SimpleSplitNode"; } else if ("join".equalsIgnoreCase(localName)) { nodeType = "org.kuali.rice.kew.engine.node.SimpleJoinNode"; } else if ("requests".equalsIgnoreCase(localName)) { nodeType = "org.kuali.rice.kew.engine.node.RequestsNode"; } else if ("process".equalsIgnoreCase(localName)) { nodeType = "org.kuali.rice.kew.engine.node.SimpleSubProcessNode"; } else if (NodeType.ROLE.getName().equalsIgnoreCase(localName)) { nodeType = RoleNode.class.getName(); } } if (org.apache.commons.lang.StringUtils.isEmpty(nodeType)) { throw new XmlException( "Could not determine node type for the node named '" + routeNode.getRouteNodeName() + "'"); } routeNode.setNodeType(nodeType); String localName = (String) getXPath().evaluate("local-name(.)", node, XPathConstants.STRING); if ("split".equalsIgnoreCase(localName)) { context.splitNodeStack.addFirst(routeNode); } else if ("join".equalsIgnoreCase(localName) && context.splitNodeStack.size() != 0) { // join node should have same branch prototype as split node RouteNode splitNode = (RouteNode) context.splitNodeStack.removeFirst(); context.branch = splitNode.getBranch(); } else if (NodeType.ROLE.getName().equalsIgnoreCase(localName)) { routeNode.setRouteMethodName(RoleRouteModule.class.getName()); routeNode.setRouteMethodCode(KewApiConstants.ROUTE_LEVEL_ROUTE_MODULE); } routeNode.setBranch(context.branch); return routeNode; }
From source file:org.kuali.rice.kew.xml.DocumentTypeXmlParser.java
private List getDocumentTypePolicies(NodeList documentTypePolicies, DocumentType documentType) throws XPathExpressionException, XmlException, ParserConfigurationException { List policies = new ArrayList(); Set policyNames = new HashSet(); for (int i = 0; i < documentTypePolicies.getLength(); i++) { DocumentTypePolicy policy = new DocumentTypePolicy(); try {//from w w w . j a v a 2s . c om String policyName = (String) getXPath().evaluate("./name", documentTypePolicies.item(i), XPathConstants.STRING); policy.setPolicyName(org.kuali.rice.kew.api.doctype.DocumentTypePolicy.fromCode(policyName) .getCode().toUpperCase()); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type policy name", xpee); throw xpee; } try { if (((Boolean) getXPath().evaluate("./value", documentTypePolicies.item(i), XPathConstants.BOOLEAN)) .booleanValue()) { policy.setPolicyValue(Boolean.valueOf((String) getXPath().evaluate("./value", documentTypePolicies.item(i), XPathConstants.STRING))); } else { policy.setPolicyValue(Boolean.FALSE); } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type policy value", xpee); throw xpee; } try { String policyStringValue = (String) getXPath().evaluate("./stringValue", documentTypePolicies.item(i), XPathConstants.STRING); if (!StringUtils.isEmpty(policyStringValue)) { policy.setPolicyStringValue(policyStringValue.toUpperCase()); policy.setPolicyValue(Boolean.TRUE); // if DocumentStatusPolicy, check against allowable values if (KewApiConstants.DOCUMENT_STATUS_POLICY .equalsIgnoreCase(org.kuali.rice.kew.api.doctype.DocumentTypePolicy .fromCode(policy.getPolicyName()).getCode())) { boolean found = false; for (int index = 0; index < KewApiConstants.DOCUMENT_STATUS_POLICY_VALUES.length; index++) { if (KewApiConstants.DOCUMENT_STATUS_POLICY_VALUES[index] .equalsIgnoreCase(policyStringValue)) { found = true; break; } } if (!found) { throw new XmlException("Application Document Status string value: " + policyStringValue + " is invalid."); } } } else { //DocumentStatusPolicy requires a <stringValue> tag if (KewApiConstants.DOCUMENT_STATUS_POLICY .equalsIgnoreCase(org.kuali.rice.kew.api.doctype.DocumentTypePolicy .fromCode(policy.getPolicyName()).getCode())) { throw new XmlException("Application Document Status Policy requires a <stringValue>"); } String customConfig = parseDocumentPolicyCustomXMLConfig(documentTypePolicies.item(i)); if (customConfig != null) { policy.setPolicyStringValue(customConfig); } } } catch (XPathExpressionException xpee) { LOG.error("Error obtaining document type policy string value", xpee); throw xpee; } if (!policyNames.add(policy.getPolicyName())) { throw new XmlException( "Policy '" + policy.getPolicyName() + "' has already been defined on this document"); } else { policies.add(policy); } policy.setDocumentType(documentType); } return policies; }
From source file:org.kuali.rice.kew.xml.DocumentTypeXmlParser.java
private List getDocumentTypeAttributes(NodeList documentTypeAttributes, DocumentType documentType) throws XPathExpressionException, WorkflowException { List attributes = new ArrayList(); for (int i = 0; i < documentTypeAttributes.getLength(); i++) { DocumentTypeAttributeBo attribute = new DocumentTypeAttributeBo(); attribute.setDocumentType(documentType); String ruleAttributeName; try {/*from ww w . j a va2 s .c o m*/ ruleAttributeName = (String) getXPath().evaluate("./name", documentTypeAttributes.item(i), XPathConstants.STRING); } catch (XPathExpressionException xpee) { LOG.error("Error obtaining rule attribute name", xpee); throw xpee; } RuleAttribute ruleAttribute = KEWServiceLocator.getRuleAttributeService().findByName(ruleAttributeName); if (ruleAttribute == null) { throw new WorkflowException("Could not find rule attribute: " + ruleAttributeName); } attribute.setDocumentType(documentType); attribute.setRuleAttribute(ruleAttribute); attribute.setOrderIndex(i + 1); attributes.add(attribute); } return attributes; }
From source file:org.kuali.rice.kns.workflow.KualiXMLAttributeImplTest.java
/** * compares the label from the test to the expected, or not expected, value for all of the rule attributes in the file * * <p>The inputSource file should be as close to the production version as possible, as described by the class comments. It * accepts the string to test against as a parameter.</p> * // w w w. j a v a 2 s . co m * @param testString * @param attributeXml * @param configNodeName */ private boolean confirmLabels(String testString, String attributeXml, String configNodeName) { boolean testFailed = false; String theTitle = ""; String theName = ""; String attributeName = ""; try { NodeList tempList = (NodeList) myXPath.evaluate("//ruleAttribute", new InputSource(new StringReader(attributeXml)), XPathConstants.NODESET); for (int i = 0; i < tempList.getLength(); i++) { // loop over ruleattributes Node originalNode = tempList.item(i); Set ruleAttributeFieldDefNames = new HashSet(); Set ruleAttributeFieldDefTitles = new HashSet(); attributeName = (String) myXPath.evaluate(WorkflowUtils.XSTREAM_MATCH_RELATIVE_PREFIX + "name", originalNode, XPathConstants.STRING); Node classNameNode = (Node) myXPath.evaluate( WorkflowUtils.XSTREAM_MATCH_RELATIVE_PREFIX + "className", originalNode, XPathConstants.NODE); if ((classNameNode != null) && (classNameNode.getFirstChild() != null)) { if (LOG.isInfoEnabled()) { LOG.info("Checking attribute with name '" + attributeName + "'"); } KualiXmlAttribute myAttribute = (KualiXmlAttribute) GlobalResourceLoader .getObject(new ObjectDefinition(classNameNode.getFirstChild().getNodeValue())); Node xmlNode = configureRuleAttribute(originalNode, myAttribute); NamedNodeMap fieldDefAttributes = null; String potentialFailMessage = ""; try { NodeList xmlNodeList = (NodeList) myXPath.evaluate("//fieldDef", xmlNode, XPathConstants.NODESET); for (int j = 0; j < xmlNodeList.getLength(); j++) { Node fieldDefXmlNode = xmlNodeList.item(j); fieldDefAttributes = fieldDefXmlNode.getAttributes(); theTitle = fieldDefAttributes.getNamedItem("title").getNodeValue();// Making sure they are clean theName = fieldDefAttributes.getNamedItem("name").getNodeValue(); if (LOG.isDebugEnabled()) { LOG.debug(attributeName); LOG.debug("name=" + theName + " title=" + theTitle); } if (ruleAttributeFieldDefNames.contains(theName)) { // names of fieldDefs inside a single attribute must be unique potentialFailMessage = "Each fieldDef name on a single attribute must be unique and the fieldDef name '" + theName + "' already exists on the attribute '" + attributeName + "'"; Assert.fail(potentialFailMessage); } else { ruleAttributeFieldDefNames.add(theName); } if (testString.equals(KualiXmlAttributeHelper.notFound)) { potentialFailMessage = "Each fieldDef title should be a valid value and currently the title for attribute '" + attributeName + "' is '" + theTitle + "'"; Assert.assertFalse(potentialFailMessage, theTitle.equals(testString)); if (ruleAttributeFieldDefTitles.contains(theTitle)) { /* * Titles of fieldDefs inside a single attribute should be unique in the normal case. Having two * fields with the same label would certainly confuse the user. However, due to the way the * confirmSource test works, all the titles/labels must be the same. So only run this check when * not in the confirmSource test. */ potentialFailMessage = "Each fieldDef title on a single attribute must be unique and the fieldDef title '" + theTitle + "' already exists on the attribute '" + attributeName + "'"; Assert.fail(potentialFailMessage); } else { ruleAttributeFieldDefTitles.add(theTitle); } } else { potentialFailMessage = "For attribute '" + attributeName + "' the title should have been '" + testString + "' but was actually '" + theTitle + "'"; Assert.assertEquals(potentialFailMessage, testString, theTitle); } } } catch (AssertionError afe) { LOG.warn("Assertion Failed for attribute '" + attributeName + "' with error " + potentialFailMessage, afe); testFailed = true; } finally { attributeName = ""; } } else { throw new RuntimeException("Could not find class for attribute named '" + attributeName + "'"); } } } catch (Exception e) { LOG.error("General Exception thrown for attribute '" + attributeName + "'", e); testFailed = true; } return testFailed; }
From source file:org.kuali.rice.krad.devtools.maintainablexml.MaintainableXMLConversionServiceImpl.java
private void transformNode(Document document, Node node, Class<?> currentClass, Map<String, String> propertyMappings) throws ClassNotFoundException, XPathExpressionException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, InstantiationException { for (Node childNode = node.getFirstChild(); childNode != null;) { Node nextChild = childNode.getNextSibling(); String propertyName = childNode.getNodeName(); if (childNode.hasAttributes()) { XPath xpath = XPathFactory.newInstance().newXPath(); Node serializationAttribute = childNode.getAttributes().getNamedItem(SERIALIZATION_ATTRIBUTE); if (serializationAttribute != null && StringUtils.equals(serializationAttribute.getNodeValue(), "custom")) { Node classAttribute = childNode.getAttributes().getNamedItem(CLASS_ATTRIBUTE); if (classAttribute != null && StringUtils.equals(classAttribute.getNodeValue(), "org.kuali.rice.kns.util.TypedArrayList")) { ((Element) childNode).removeAttribute(SERIALIZATION_ATTRIBUTE); ((Element) childNode).removeAttribute(CLASS_ATTRIBUTE); XPathExpression listSizeExpression = xpath.compile("//" + propertyName + "/org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl/default/size/text()"); String size = (String) listSizeExpression.evaluate(childNode, XPathConstants.STRING); List<Node> nodesToAdd = new ArrayList<Node>(); if (StringUtils.isNotBlank(size) && Integer.valueOf(size) > 0) { XPathExpression listTypeExpression = xpath.compile("//" + propertyName + "/org.kuali.rice.kns.util.TypedArrayList/default/listObjectType/text()"); String listType = (String) listTypeExpression.evaluate(childNode, XPathConstants.STRING); XPathExpression listContentsExpression = xpath.compile("//" + propertyName + "/org.apache.ojb.broker.core.proxy.ListProxyDefaultImpl/" + listType); NodeList listContents = (NodeList) listContentsExpression.evaluate(childNode, XPathConstants.NODESET); for (int i = 0; i < listContents.getLength(); i++) { Node tempNode = listContents.item(i); transformClassNode(document, tempNode); nodesToAdd.add(tempNode); }/*from w w w. j av a 2 s .c o m*/ } for (Node removeNode = childNode.getFirstChild(); removeNode != null;) { Node nextRemoveNode = removeNode.getNextSibling(); childNode.removeChild(removeNode); removeNode = nextRemoveNode; } for (Node nodeToAdd : nodesToAdd) { childNode.appendChild(nodeToAdd); } } else { ((Element) childNode).removeAttribute(SERIALIZATION_ATTRIBUTE); XPathExpression mapContentsExpression = xpath.compile("//" + propertyName + "/map/string"); NodeList mapContents = (NodeList) mapContentsExpression.evaluate(childNode, XPathConstants.NODESET); List<Node> nodesToAdd = new ArrayList<Node>(); if (mapContents.getLength() > 0 && mapContents.getLength() % 2 == 0) { for (int i = 0; i < mapContents.getLength(); i++) { Node keyNode = mapContents.item(i); Node valueNode = mapContents.item(++i); Node entryNode = document.createElement("entry"); entryNode.appendChild(keyNode); entryNode.appendChild(valueNode); nodesToAdd.add(entryNode); } } for (Node removeNode = childNode.getFirstChild(); removeNode != null;) { Node nextRemoveNode = removeNode.getNextSibling(); childNode.removeChild(removeNode); removeNode = nextRemoveNode; } for (Node nodeToAdd : nodesToAdd) { childNode.appendChild(nodeToAdd); } } } } if (propertyMappings != null && propertyMappings.containsKey(propertyName)) { String newPropertyName = propertyMappings.get(propertyName); if (StringUtils.isNotBlank(newPropertyName)) { document.renameNode(childNode, null, newPropertyName); propertyName = newPropertyName; } else { // If there is no replacement name then the element needs // to be removed and skip all other processing node.removeChild(childNode); childNode = nextChild; continue; } } if (dateRuleMap != null && dateRuleMap.containsKey(propertyName)) { String newDateValue = dateRuleMap.get(propertyName); if (StringUtils.isNotBlank(newDateValue)) { if (childNode.getTextContent().length() == 10) { childNode.setTextContent(childNode.getTextContent() + " " + newDateValue); } } } if (currentClass != null) { if (childNode.hasChildNodes() && !(Collection.class.isAssignableFrom(currentClass) || Map.class.isAssignableFrom(currentClass))) { Class<?> propertyClass = PropertyUtils.getPropertyType(currentClass.newInstance(), propertyName); if (propertyClass != null && classPropertyRuleMap.containsKey(propertyClass.getName())) { transformNode(document, childNode, propertyClass, this.classPropertyRuleMap.get(propertyClass.getName())); } transformNode(document, childNode, propertyClass, classPropertyRuleMap.get("*")); } } childNode = nextChild; } }