List of usage examples for org.w3c.dom NamedNodeMap getNamedItem
public Node getNamedItem(String name);
From source file:org.kuali.coeus.propdev.impl.budget.subaward.PropDevPropDevBudgetSubAwardServiceImpl.java
/** * updates the XMl with hashcode for the files *//*from ww w.j a v a2s .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 w w w .j a va 2 s . c o 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.kew.attribute.XMLAttributeUtils.java
public static void establishFieldLookup(Field field, Node lookupNode) { NamedNodeMap quickfinderAttributes = lookupNode.getAttributes(); String businessObjectClass = quickfinderAttributes.getNamedItem("businessObjectClass").getNodeValue(); field.setQuickFinderClassNameImpl(businessObjectClass); Map<String, String> fieldConversionsMap = new HashMap<String, String>(); for (int lcIndex = 0; lcIndex < lookupNode.getChildNodes().getLength(); lcIndex++) { Node fieldConversionsChildNode = lookupNode.getChildNodes().item(lcIndex); if ("fieldConversions".equals(fieldConversionsChildNode.getNodeName())) { for (int fcIndex = 0; fcIndex < fieldConversionsChildNode.getChildNodes().getLength(); fcIndex++) { Node fieldConversionChildNode = fieldConversionsChildNode.getChildNodes().item(fcIndex); if ("fieldConversion".equals(fieldConversionChildNode.getNodeName())) { NamedNodeMap fieldConversionAttributes = fieldConversionChildNode.getAttributes(); String lookupFieldName = fieldConversionAttributes.getNamedItem("lookupFieldName") .getNodeValue(); String localFieldName = fieldConversionAttributes.getNamedItem("localFieldName") .getNodeValue(); fieldConversionsMap.put(lookupFieldName, localFieldName); }//from w w w. ja v a 2s. co m } } } field.setFieldConversions(fieldConversionsMap); }
From source file:org.kuali.rice.kew.attribute.XMLAttributeUtils.java
public static void establishFieldLookup(RemotableAttributeField.Builder fieldBuilder, Node lookupNode) { NamedNodeMap quickfinderAttributes = lookupNode.getAttributes(); Node dataObjectNode = quickfinderAttributes.getNamedItem("dataObjectClass"); if (dataObjectNode == null) { // for legacy compatibility, though businessObjectClass is deprecated dataObjectNode = quickfinderAttributes.getNamedItem("businessObjectClass"); if (dataObjectNode != null) { LOG.warn(//from w ww.j a v a 2s .c o m "Field is using deprecated 'businessObjectClass' instead of 'dataObjectClass' for lookup definition, field name is: " + fieldBuilder.getName()); } else { throw new ConfigurationException("Failed to locate 'dataObjectClass' for lookup definition."); } } String dataObjectClass = dataObjectNode.getNodeValue(); String baseLookupUrl = LookupUtils.getBaseLookupUrl(false); RemotableQuickFinder.Builder quickFinderBuilder = RemotableQuickFinder.Builder.create(baseLookupUrl, dataObjectClass); for (int lcIndex = 0; lcIndex < lookupNode.getChildNodes().getLength(); lcIndex++) { Map<String, String> fieldConversionsMap = new HashMap<String, String>(); Node fieldConversionsChildNode = lookupNode.getChildNodes().item(lcIndex); if ("fieldConversions".equals(fieldConversionsChildNode)) { for (int fcIndex = 0; fcIndex < fieldConversionsChildNode.getChildNodes().getLength(); fcIndex++) { Node fieldConversionChildNode = fieldConversionsChildNode.getChildNodes().item(fcIndex); if ("fieldConversion".equals(fieldConversionChildNode)) { NamedNodeMap fieldConversionAttributes = fieldConversionChildNode.getAttributes(); String lookupFieldName = fieldConversionAttributes.getNamedItem("lookupFieldName") .getNodeValue(); String localFieldName = fieldConversionAttributes.getNamedItem("localFieldName") .getNodeValue(); fieldConversionsMap.put(lookupFieldName, localFieldName); } } } quickFinderBuilder.setFieldConversions(fieldConversionsMap); fieldBuilder.getWidgets().add(quickFinderBuilder); } }
From source file:org.kuali.rice.kew.doctype.DocumentTypeSecurity.java
/** parse <security> XML to populate security object * @throws ParserConfigurationException//from www . ja v a 2 s . c om * @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 List<Row> getRows(Element root, String[] types) { List<Row> rows = new ArrayList<Row>(); XPath xpath = XPathHelper.newXPath(); NodeList fieldNodeList;// w w w.j a va2s .co m try { fieldNodeList = getFields(xpath, root, types); } catch (XPathExpressionException e) { LOG.error("Error evaluating fields expression"); return rows; } if (fieldNodeList != null) { for (int i = 0; i < fieldNodeList.getLength(); i++) { Node field = fieldNodeList.item(i); NamedNodeMap fieldAttributes = field.getAttributes(); List<Field> fields = new ArrayList<Field>(); Field myField = new Field(fieldAttributes.getNamedItem("title").getNodeValue(), "", "", false, fieldAttributes.getNamedItem("name").getNodeValue(), "", false, false, null, ""); String quickfinderService = null; for (int j = 0; j < field.getChildNodes().getLength(); j++) { Node childNode = field.getChildNodes().item(j); if ("value".equals(childNode.getNodeName())) { myField.setPropertyValue(childNode.getFirstChild().getNodeValue()); } else if ("display".equals(childNode.getNodeName())) { List<KeyValue> options = new ArrayList<KeyValue>(); List<String> selectedOptions = new ArrayList<String>(); for (int k = 0; k < childNode.getChildNodes().getLength(); k++) { Node displayChildNode = childNode.getChildNodes().item(k); if ("type".equals(displayChildNode.getNodeName())) { myField.setFieldType( convertTypeToFieldType(displayChildNode.getFirstChild().getNodeValue())); } else if ("meta".equals(displayChildNode.getNodeName())) { // i don't think the rule creation support things in this node. // i don't think the flex Routing report supports things in this node. } else if ("values".equals(displayChildNode.getNodeName())) { NamedNodeMap valuesAttributes = displayChildNode.getAttributes(); String optionValue = ""; // if element is empty then child will be null Node firstChild = displayChildNode.getFirstChild(); if (firstChild != null) { optionValue = firstChild.getNodeValue(); } if (valuesAttributes.getNamedItem("selected") != null) { selectedOptions.add(optionValue); } String title = ""; Node titleAttribute = valuesAttributes.getNamedItem("title"); if (titleAttribute != null) { title = titleAttribute.getNodeValue(); } options.add(new ConcreteKeyValue(optionValue, title)); } } if (!options.isEmpty()) { myField.setFieldValidValues(options); if (!selectedOptions.isEmpty()) { //if (Field.MULTI_VALUE_FIELD_TYPES.contains(myField.getFieldType())) { // String[] newSelectedOptions = new String[selectedOptions.size()]; // int k = 0; // for (Iterator iter = selectedOptions.iterator(); iter.hasNext();) { // String option = (String) iter.next(); // newSelectedOptions[k] = option; // k++; // } // myField.setPropertyValues(newSelectedOptions); //} else { // myField.setPropertyValue((String) selectedOptions.get(0)); //} } } } else if ("lookup".equals(childNode.getNodeName())) { XMLAttributeUtils.establishFieldLookup(myField, childNode); } } fields.add(myField); rows.add(new Row(fields)); } } return rows; }
From source file:org.kuali.rice.kew.rule.xmlrouting.StandardGenericXMLRuleAttribute.java
/** * Performs attribute validation producing a list of errors of the parameterized type T generated by the ErrorGenerator<T> * @throws XPathExpressionException/*ww w . j a v a 2 s . com*/ */ private <T> List<T> validate(Element root, String[] types, Map map, ErrorGenerator<T> errorGenerator) throws XPathExpressionException { List<T> errors = new ArrayList(); XPath xpath = XPathHelper.newXPath(); NodeList nodes = getFields(xpath, root, types); for (int i = 0; i < nodes.getLength(); i++) { Node field = nodes.item(i); NamedNodeMap fieldAttributes = field.getAttributes(); String fieldName = fieldAttributes.getNamedItem("name").getNodeValue(); LOG.debug("evaluating field: " + fieldName); String findValidation = "//routingConfig/" + FIELD_DEF_E + "[@name='" + fieldName + "']/validation"; Node validationNode = (Node) xpath.evaluate(findValidation, root, XPathConstants.NODE); boolean fieldIsRequired = false; if (validationNode != null) { NamedNodeMap validationAttributes = validationNode.getAttributes(); Node reqAttribNode = validationAttributes.getNamedItem("required"); fieldIsRequired = reqAttribNode != null && "true".equalsIgnoreCase(reqAttribNode.getNodeValue()); } String findRegex = "//routingConfig/" + FIELD_DEF_E + "[@name='" + fieldName + "']/validation/regex"; String regex = null; Node regexNode = (Node) xpath.evaluate(findRegex, root, XPathConstants.NODE); if (regexNode != null && regexNode.getFirstChild() != null) { regex = regexNode.getFirstChild().getNodeValue(); if (regex == null) { throw new RuntimeException("Null regex text node"); } } /* else { if (fieldIsRequired) { fieldIsOnlyRequired = true; LOG.debug("Setting empty regex to .+ as field is required"); // NOTE: ok, so technically .+ is not the same as checking merely // for existence, because a field can be extant but "empty" // however this has no relevance to the user as an empty field // is for all intents and purposes non-existent (not-filled-in) // so let's just use this regex to simplify the logic and // pass everything through a regex check regex = ".+"; } else { LOG.debug("Setting empty regex to .* as field is NOT required"); regex = ".*"; } }*/ LOG.debug("regex for field '" + fieldName + "': '" + regex + "'"); String fieldValue = null; if (map != null) { fieldValue = (String) map.get(fieldName); } LOG.debug("field value: " + fieldValue); // fix up non-existent value for regex purposes only if (fieldValue == null) { fieldValue = ""; } if (regex == null) { if (fieldIsRequired) { if (fieldValue.length() == 0) { errors.add(errorGenerator.generateMissingFieldError(field, fieldName, getValidationErrorMessage(xpath, root, fieldName))); } } } else { if (!Pattern.compile(regex).matcher(fieldValue).matches()) { LOG.debug("field value does not match validation regex"); errors.add(errorGenerator.generateInvalidFieldError(field, fieldName, getValidationErrorMessage(xpath, root, fieldName))); } } } return errors; }
From source file:org.kuali.rice.kew.rule.xmlrouting.StandardGenericXMLRuleAttribute.java
public String getDocContent() { XPath xpath = XPathHelper.newXPath(); final String findDocContent = "//routingConfig/xmlDocumentContent"; try {/*from w w w .ja va2 s .co m*/ Node xmlDocumentContent = (Node) xpath.evaluate(findDocContent, getConfigXML(), XPathConstants.NODE); NodeList nodes = getFields(xpath, getConfigXML(), new String[] { "ALL", "REPORT", "RULE" }); // if (nodes == null || nodes.getLength() == 0) { // return ""; // } if (xmlDocumentContent != null && xmlDocumentContent.hasChildNodes()) { // Custom doc content in the routingConfig xml. String documentContent = ""; NodeList customNodes = xmlDocumentContent.getChildNodes(); for (int i = 0; i < customNodes.getLength(); i++) { Node childNode = customNodes.item(i); documentContent += XmlJotter.jotNode(childNode); } for (int i = 0; i < nodes.getLength(); i++) { Node field = nodes.item(i); NamedNodeMap fieldAttributes = field.getAttributes(); String fieldName = fieldAttributes.getNamedItem("name").getNodeValue(); LOG.debug("Replacing field '" + fieldName + "'"); Map map = getParamMap(); String fieldValue = (String) map.get(fieldName); if (map != null && !org.apache.commons.lang.StringUtils.isEmpty(fieldValue)) { LOG.debug("Replacing %" + fieldName + "% with field value: '" + fieldValue + "'"); documentContent = documentContent.replaceAll("%" + fieldName + "%", fieldValue); } else { LOG.debug("Field map is null or fieldValue is empty"); } } return documentContent; } else { // Standard doc content if no doc content is found in the routingConfig xml. StringBuffer documentContent = new StringBuffer("<xmlRouting>"); for (int i = 0; i < nodes.getLength(); i++) { Node field = nodes.item(i); NamedNodeMap fieldAttributes = field.getAttributes(); String fieldName = fieldAttributes.getNamedItem("name").getNodeValue(); Map map = getParamMap(); if (map != null && !org.apache.commons.lang.StringUtils.isEmpty((String) map.get(fieldName))) { documentContent.append("<field name=\""); documentContent.append(fieldName); documentContent.append("\"><value>"); documentContent.append((String) map.get(fieldName)); documentContent.append("</value></field>"); } } documentContent.append("</xmlRouting>"); return documentContent.toString(); } } catch (XPathExpressionException e) { LOG.error("error in getDocContent ", e); throw new RuntimeException("Error trying to find xml content with xpath expression", e); } catch (Exception e) { LOG.error("error in getDocContent attempting to find xml doc content", e); throw new RuntimeException("Error trying to get xml doc content.", e); } }
From source file:org.kuali.rice.kew.rule.xmlrouting.StandardGenericXMLRuleAttribute.java
public List getRuleExtensionValues() { List extensionValues = new ArrayList(); XPath xpath = XPathHelper.newXPath(); try {/*from ww w.j ava2s . co m*/ NodeList nodes = getFields(xpath, getConfigXML(), new String[] { "ALL", "RULE" }); for (int i = 0; i < nodes.getLength(); i++) { Node field = nodes.item(i); NamedNodeMap fieldAttributes = field.getAttributes(); String fieldName = fieldAttributes.getNamedItem("name").getNodeValue(); Map map = getParamMap(); if (map != null && !org.apache.commons.lang.StringUtils.isEmpty((String) map.get(fieldName))) { RuleExtensionValue value = new RuleExtensionValue(); value.setKey(fieldName); value.setValue((String) map.get(fieldName)); extensionValues.add(value); } } } catch (XPathExpressionException e) { LOG.error("error in getRuleExtensionValues ", e); throw new RuntimeException("Error trying to find xml content with xpath expression", e); } return extensionValues; }