List of usage examples for org.w3c.dom Element getAttributes
public NamedNodeMap getAttributes();
NamedNodeMap
containing the attributes of this node (if it is an Element
) or null
otherwise. From source file:org.jbpm.bpel.integration.soap.SoapUtil.java
public static void copyNamespaces(SOAPElement target, Element source) throws SOAPException { // easy way out: no attributes if (!source.hasAttributes()) return;/* www . ja va2 s . c om*/ // traverse attributes to discover namespace declarations NamedNodeMap attributes = source.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { Node attribute = attributes.item(i); // is attribute a namespace declaration? if (!BpelConstants.NS_XMLNS.equals(attribute.getNamespaceURI())) continue; // namespace declaration format xmlns:prefix="namespaceURI" | // xmlns="defaultNamespaceURI" String namespaceURI = attribute.getNodeValue(); String prefix = attribute.getLocalName(); // non-default namespace declaration? if (!"xmlns".equals(prefix)) { // BPEL-195: prevent addition matching visible declaration at target if (namespaceURI.equals(target.getNamespaceURI(prefix))) continue; target.addNamespaceDeclaration(prefix, namespaceURI); if (traceEnabled) log.trace("added namespace declaration: " + prefix + "->" + namespaceURI); } // non-empty default namespace declaration else if (namespaceURI.length() > 0) { prefix = XmlUtil.generatePrefix(DEFAULT_NAMESPACE_PREFIX, source); target.addNamespaceDeclaration(prefix, namespaceURI); if (traceEnabled) log.trace("reassigned default namespace declaration: " + prefix + "->" + namespaceURI); } } }
From source file:org.jbpm.bpel.integration.soap.SoapUtil.java
public static void copyAttributes(SOAPElement target, Element source) { // easy way out: no attributes if (!source.hasAttributes()) return;/* w ww . j av a2 s .co m*/ // traverse attributes NamedNodeMap attributes = source.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { Node attribute = attributes.item(i); String namespaceURI = attribute.getNamespaceURI(); // isn't the attribute a namespace declaration? if (BpelConstants.NS_XMLNS.equals(namespaceURI)) continue; String name = attribute.getNodeName(); String value = attribute.getNodeValue(); if (namespaceURI == null) { /* * use the DOM level 1 method as some SAAJ implementations complain when presented a null * namespace URI */ target.setAttribute(name, value); } else target.setAttributeNS(namespaceURI, name, value); if (traceEnabled) log.trace("set attribute: " + name); } }
From source file:org.jbpm.bpel.xml.util.XmlUtil.java
public static void copyNamespaces(final Element target, Element source) { // easy way out: no attributes if (!source.hasAttributes()) return;//from ww w . j av a2s . c o m // traverse attributes to discover namespace declarations NamedNodeMap attributes = source.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { Node attribute = attributes.item(i); // is attribute a namespace declaration? if (!BpelConstants.NS_XMLNS.equals(attribute.getNamespaceURI())) continue; // namespace declaration format // xmlns:prefix="namespaceURI" | xmlns="defaultNamespaceURI" String namespaceURI = attribute.getNodeValue(); String prefix = attribute.getLocalName(); // default namespace declaration? if ("xmlns".equals(prefix)) { // BPEL-195: prevent addition matching visible declaration at target if ("".equals(getPrefix(namespaceURI, target))) continue; addNamespaceDeclaration(target, namespaceURI); if (traceEnabled) log.trace("added default namespace declaration: " + namespaceURI); } else { // BPEL-195: prevent addition matching visible declaration at target if (prefix.equals(getPrefix(namespaceURI, target))) continue; addNamespaceDeclaration(target, namespaceURI, prefix); if (traceEnabled) log.trace("added namespace declaration: " + prefix + "->" + namespaceURI); } } }
From source file:org.jbpm.bpel.xml.util.XmlUtil.java
public static void copyAttributes(Element target, Element source) { // easy way out: no attributes if (!source.hasAttributes()) return;/*www .j a va 2 s .com*/ // traverse attributes NamedNodeMap attributes = source.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { Node sourceAttr = attributes.item(i); String namespaceURI = sourceAttr.getNamespaceURI(); String name = sourceAttr.getNodeName(); // namespace declaration? if (BpelConstants.NS_XMLNS.equals(namespaceURI)) continue; // unqualified? if (namespaceURI == null || namespaceURI.length() == 0) { target.setAttribute(name, sourceAttr.getNodeValue()); if (traceEnabled) log.trace("set attribute: " + name); } // qualified else { Attr targetAttr = target.getOwnerDocument().createAttributeNS(namespaceURI, name); targetAttr.setValue(sourceAttr.getNodeValue()); target.setAttributeNodeNS(targetAttr); ensureNamespaceDeclared(targetAttr, namespaceURI, sourceAttr.getPrefix()); if (traceEnabled) log.trace("set attribute: {" + namespaceURI + '}' + name); } } }
From source file:org.jbpm.bpel.xml.util.XmlUtil.java
private static void findLocalNamespaceDeclarations(Element elem, Map namespaces) { // traverse attributes to discover namespace declarations NamedNodeMap attributes = elem.getAttributes(); for (int i = 0, n = attributes.getLength(); i < n; i++) { Node attribute = attributes.item(i); // is attribute a namespace declaration? if (!BpelConstants.NS_XMLNS.equals(attribute.getNamespaceURI())) continue; // namespace declaration format: // xmlns:prefix="namespaceURI" | xmlns="defaultNamespaceURI" String prefix = attribute.getLocalName(); // exclude default and overriden namespace declarations if ("xmlns".equals(prefix) || namespaces.containsKey(prefix)) continue; String namespaceURI = attribute.getNodeValue(); namespaces.put(prefix, namespaceURI); }/* w w w .j av a 2 s .com*/ }
From source file:org.kepler.moml.KeplerMetadataExtractor.java
/** Get the metadata from an input stream optionally printing output if a parsing error occurs. * @param actorStream the input stream/* www.jav a 2 s . co m*/ * @param printError if true, print a stack trace and error message if a parsing error occurs. */ public static KeplerActorMetadata extractActorMetadata(InputStream actorStream, boolean printError) throws Exception { //if (isTracing) //log.trace("ActorCacheObject(" + actorStream.getClass().getName() //+ ")"); KeplerActorMetadata kam = new KeplerActorMetadata(); ByteArrayOutputStream byteout; try { // Copy 1024 bytes from actorStream to byteout byteout = new ByteArrayOutputStream(); byte[] b = new byte[1024]; int numread = actorStream.read(b, 0, 1024); while (numread != -1) { byteout.write(b, 0, numread); numread = actorStream.read(b, 0, 1024); } kam.setActorString(byteout.toString()); // need to get actor name and id from the string // thus build a DOM representation String nameStr = null; try { //if (isTracing) log.trace(kam.getActorString()); StringReader strR = new StringReader(kam.getActorString()); InputSource xmlIn = new InputSource(strR); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setEntityResolver(new EntityResolver() { public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (MOML_PUBLIC_ID_1.equals(publicId)) { return new InputSource(MoMLParser.class.getResourceAsStream("MoML_1.dtd")); } else { return null; } } }); // TODO // this causes http://bugzilla.ecoinformatics.org/show_bug.cgi?id=4671 // when File => Save Archive w/ wf w/ actor w/ < in the name: Document doc = builder.parse(xmlIn); //if (isTracing) log.trace(doc.toString()); Element rootNode = doc.getDocumentElement(); kam.setRootName(rootNode.getNodeName()); // Get the value of the name attribute of the root node NamedNodeMap nnm = rootNode.getAttributes(); Node namenode = nnm.getNamedItem("name"); nameStr = namenode.getNodeValue(); kam.setName(nameStr); boolean emptyKeplerDocumentation = true; boolean foundKeplerDocumentation = false; boolean foundUserLevelDocumentation = false; boolean foundAuthor = false; // Cycle through the children of the root node NodeList probNodes = rootNode.getChildNodes(); for (int i = 0; i < probNodes.getLength(); i++) { Node child = probNodes.item(i); if (child.hasAttributes()) { NamedNodeMap childAttrs = child.getAttributes(); Node idNode = childAttrs.getNamedItem("name"); if (idNode != null) { // the entityId String nameval = idNode.getNodeValue(); if (nameval.equals(NamedObjId.NAME)) { Node idNode1 = childAttrs.getNamedItem("value"); String idval = idNode1.getNodeValue(); kam.setLsid(new KeplerLSID(idval)); } // the class name if (nameval.equals("class")) { Node idNode3 = childAttrs.getNamedItem("value"); String classname = idNode3.getNodeValue(); kam.setClassName(classname); } // the semantic types if (nameval.startsWith("semanticType")) { Node idNode2 = childAttrs.getNamedItem("value"); String semtype = idNode2.getNodeValue(); kam.addSemanticType(semtype); } // userLevelDocumentation must be contained in KeplerDocumentation if (nameval.equals("userLevelDocumentation")) { log.warn(nameStr + " userLevelDocumentation property should be contained in a KeplerDocumentation property."); } else if (nameval.equals("KeplerDocumentation")) { foundKeplerDocumentation = true; final NodeList keplerDocNodeList = child.getChildNodes(); if (keplerDocNodeList.getLength() > 0) { emptyKeplerDocumentation = false; for (int j = 0; j < keplerDocNodeList.getLength(); j++) { final Node docChildNode = keplerDocNodeList.item(j); final NamedNodeMap docChildNamedNodeMap = docChildNode.getAttributes(); if (docChildNamedNodeMap != null) { final Node docChildChildName = docChildNamedNodeMap .getNamedItem("name"); if (docChildChildName != null) { final String docChildChildNameValue = docChildChildName .getNodeValue(); if (docChildChildNameValue.equals("userLevelDocumentation")) { foundUserLevelDocumentation = true; final String text = docChildNode.getTextContent(); if (text == null || text.trim().isEmpty()) { log.debug(nameStr + " has empty userLevelDocumentation."); } } else if (docChildChildNameValue.equals("author")) { foundAuthor = true; final String text = docChildNode.getTextContent(); if (text == null || text.trim().isEmpty()) { log.debug(nameStr + " has empty author documentation."); } } } } } } } if (nameval.startsWith(COPY_ATTRIBUTE_PREFIX)) { String value = childAttrs.getNamedItem("value").getNodeValue(); kam.addAttribute(nameval, value); } } } } // check documentation if (!foundKeplerDocumentation) { log.debug(nameStr + " is missing KeplerDocumentation."); } else if (emptyKeplerDocumentation) { log.debug(nameStr + " KeplerDocumentation is empty."); } else if (!foundUserLevelDocumentation && !foundAuthor) { log.debug(nameStr + " is missing userLevelDocumentation and author documentation."); } else if (!foundUserLevelDocumentation) { log.debug(nameStr + " is missing userLevelDocumentation."); } else if (!foundAuthor) { log.debug(nameStr + " is missing author documentation."); } } catch (Exception e) { if (printError) { e.printStackTrace(); System.out.println("Error parsing Actor KAR DOM \"" + ((nameStr == null) ? byteout.toString().substring(0, 300) + "..." : nameStr) + "\": " + e.getMessage()); } kam = null; } finally { actorStream.close(); byteout.close(); } } catch (Exception e) { kam = null; throw new Exception("Error extracting Actor Metadata: " + e.getMessage()); } return kam; }
From source file:org.kuali.coeus.propdev.impl.budget.subaward.PropDevPropDevBudgetSubAwardServiceImpl.java
/** * updates the XMl with hashcode for the files */// w w w . j av a 2 s .co 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.coeus.propdev.impl.budget.subaward.PropDevPropDevBudgetSubAwardServiceImpl.java
protected Element copyElementToName(Element element, String tagName) { Element newElement = element.getOwnerDocument().createElement(tagName); NamedNodeMap attrs = element.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node attribute = attrs.item(i); newElement.setAttribute(attribute.getNodeName(), attribute.getNodeValue()); }/* ww w . j a v a2 s. c o m*/ for (int i = 0; i < element.getChildNodes().getLength(); i++) { newElement.appendChild(element.getChildNodes().item(i).cloneNode(true)); } return newElement; }
From source file:org.kuali.kra.proposaldevelopment.budget.service.impl.BudgetSubAwardServiceImpl.java
/** * updates the XMl with hashcode for the files *///from w w w.ja va 2s. 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.doctype.DocumentTypeSecurity.java
/** parse <security> XML to populate security object * @throws ParserConfigurationException/*from ww w. j a va 2s. c o 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); } }