@Test public void testWriteNewNodeWithAttrToDocumentComplex() throws Exception { this.seedDocument = new String( Files.readAllBytes(Paths.get("src/test/resources/complex_example_write_attr.xml"))); writeValue("/orders/order[2]/id[2]", "54554555"); writeValue("/orders/order[2]/id[2]/@custId", "c"); checkResultFromFile("complex_example.xml"); }
private void writeValue(Element parentNode, XmlSegmentContext segment, Field field) throws AtlasException { if (LOG.isDebugEnabled()) { LOG.debug("Writing field value in parent node '{}', parentNode: {}", segment, xmlHelper.writeDocumentToString(true, parentNode)); } String value = convertValue(field); if (segment.isAttribute()) { if (this.enableAttributeNamespaces) { if (LOG.isDebugEnabled()) { LOG.debug("Attribute namespaces are enabled, determining namespace."); } String namespaceAlias = null; String namespaceUri = null; if (segment.getNamespace() != null) { namespaceAlias = segment.getNamespace(); namespaceUri = this.namespaces.get(namespaceAlias); LOG.debug("Parsed namespace alias '{}', from segment '{}', namespaceUri: {}", namespaceAlias, segment, namespaceUri); } if (!this.ignoreMissingNamespaces && namespaceUri == null) { throw new AtlasException(String.format( "Cannot find namespace URI for attribute: '%s', available namespaces: %s", segment, this.namespaces)); } if (namespaceUri != null) { parentNode.setAttributeNS(namespaceUri, namespaceAlias + ":" + segment.getName(), value); } else { parentNode.setAttribute(segment.getName(), value); } } else { parentNode.setAttribute(segment.getName(), value); } } else { parentNode.setTextContent(value); } if (LOG.isDebugEnabled()) { LOG.debug("Parent node after value written: {}", xmlHelper.writeDocumentToString(true, parentNode)); } }
XmlFieldWriter extends XmlFieldTransformer implements AtlasFieldWriter { private void writeValue(Element parentNode, XmlSegmentContext segment, Field field) throws AtlasException { if (LOG.isDebugEnabled()) { LOG.debug("Writing field value in parent node '{}', parentNode: {}", segment, xmlHelper.writeDocumentToString(true, parentNode)); } String value = convertValue(field); if (segment.isAttribute()) { if (this.enableAttributeNamespaces) { if (LOG.isDebugEnabled()) { LOG.debug("Attribute namespaces are enabled, determining namespace."); } String namespaceAlias = null; String namespaceUri = null; if (segment.getNamespace() != null) { namespaceAlias = segment.getNamespace(); namespaceUri = this.namespaces.get(namespaceAlias); LOG.debug("Parsed namespace alias '{}', from segment '{}', namespaceUri: {}", namespaceAlias, segment, namespaceUri); } if (!this.ignoreMissingNamespaces && namespaceUri == null) { throw new AtlasException(String.format( "Cannot find namespace URI for attribute: '%s', available namespaces: %s", segment, this.namespaces)); } if (namespaceUri != null) { parentNode.setAttributeNS(namespaceUri, namespaceAlias + ":" + segment.getName(), value); } else { parentNode.setAttribute(segment.getName(), value); } } else { parentNode.setAttribute(segment.getName(), value); } } else { parentNode.setTextContent(value); } if (LOG.isDebugEnabled()) { LOG.debug("Parent node after value written: {}", xmlHelper.writeDocumentToString(true, parentNode)); } } }
XmlFieldWriter extends XmlFieldTransformer implements AtlasFieldWriter { private void writeValue(Element parentNode, XmlSegmentContext segment, Field field) throws AtlasException { if (LOG.isDebugEnabled()) { LOG.debug("Writing field value in parent node '{}', parentNode: {}", segment, xmlHelper.writeDocumentToString(true, parentNode)); } String value = convertValue(field); if (segment.isAttribute()) { if (this.enableAttributeNamespaces) { if (LOG.isDebugEnabled()) { LOG.debug("Attribute namespaces are enabled, determining namespace."); } String namespaceAlias = null; String namespaceUri = null; if (segment.getNamespace() != null) { namespaceAlias = segment.getNamespace(); namespaceUri = this.namespaces.get(namespaceAlias); LOG.debug("Parsed namespace alias '{}', from segment '{}', namespaceUri: {}", namespaceAlias, segment, namespaceUri); } if (!this.ignoreMissingNamespaces && namespaceUri == null) { throw new AtlasException(String.format( "Cannot find namespace URI for attribute: '%s', available namespaces: %s", segment, this.namespaces)); } if (namespaceUri != null) { parentNode.setAttributeNS(namespaceUri, namespaceAlias + ":" + segment.getName(), value); } else { parentNode.setAttribute(segment.getName(), value); } } else { parentNode.setAttribute(segment.getName(), value); } } else { parentNode.setTextContent(value); } if (LOG.isDebugEnabled()) { LOG.debug("Parent node after value written: {}", xmlHelper.writeDocumentToString(true, parentNode)); } } XmlFieldWriter();  XmlFieldWriter(ClassLoader classLoader, Map<String, String> namespaces, String seedDocument); }
XmlFieldWriter extends XmlFieldTransformer implements AtlasFieldWriter { private void writeValue(Element parentNode, XmlSegmentContext segment, Field field) throws AtlasException { if (LOG.isDebugEnabled()) { LOG.debug("Writing field value in parent node '{}', parentNode: {}", segment, xmlHelper.writeDocumentToString(true, parentNode)); } String value = convertValue(field); if (segment.isAttribute()) { if (this.enableAttributeNamespaces) { if (LOG.isDebugEnabled()) { LOG.debug("Attribute namespaces are enabled, determining namespace."); } String namespaceAlias = null; String namespaceUri = null; if (segment.getNamespace() != null) { namespaceAlias = segment.getNamespace(); namespaceUri = this.namespaces.get(namespaceAlias); LOG.debug("Parsed namespace alias '{}', from segment '{}', namespaceUri: {}", namespaceAlias, segment, namespaceUri); } if (!this.ignoreMissingNamespaces && namespaceUri == null) { throw new AtlasException(String.format( "Cannot find namespace URI for attribute: '%s', available namespaces: %s", segment, this.namespaces)); } if (namespaceUri != null) { parentNode.setAttributeNS(namespaceUri, namespaceAlias + ":" + segment.getName(), value); } else { parentNode.setAttribute(segment.getName(), value); } } else { parentNode.setAttribute(segment.getName(), value); } } else { parentNode.setTextContent(value); } if (LOG.isDebugEnabled()) { LOG.debug("Parent node after value written: {}", xmlHelper.writeDocumentToString(true, parentNode)); } } XmlFieldWriter();  XmlFieldWriter(ClassLoader classLoader, Map<String, String> namespaces, String seedDocument); @Override void write(AtlasInternalSession session); Document getDocument(); boolean isEnableElementNamespaces(); void setEnableElementNamespaces(boolean enableElementNamespaces); boolean isEnableAttributeNamespaces(); void setEnableAttributeNamespaces(boolean enableAttributeNamespaces); boolean isIgnoreMissingNamespaces(); void setIgnoreMissingNamespaces(boolean ignoreMissingNamespaces); }
XmlFieldWriter extends XmlFieldTransformer implements AtlasFieldWriter { private void writeValue(Element parentNode, XmlSegmentContext segment, Field field) throws AtlasException { if (LOG.isDebugEnabled()) { LOG.debug("Writing field value in parent node '{}', parentNode: {}", segment, xmlHelper.writeDocumentToString(true, parentNode)); } String value = convertValue(field); if (segment.isAttribute()) { if (this.enableAttributeNamespaces) { if (LOG.isDebugEnabled()) { LOG.debug("Attribute namespaces are enabled, determining namespace."); } String namespaceAlias = null; String namespaceUri = null; if (segment.getNamespace() != null) { namespaceAlias = segment.getNamespace(); namespaceUri = this.namespaces.get(namespaceAlias); LOG.debug("Parsed namespace alias '{}', from segment '{}', namespaceUri: {}", namespaceAlias, segment, namespaceUri); } if (!this.ignoreMissingNamespaces && namespaceUri == null) { throw new AtlasException(String.format( "Cannot find namespace URI for attribute: '%s', available namespaces: %s", segment, this.namespaces)); } if (namespaceUri != null) { parentNode.setAttributeNS(namespaceUri, namespaceAlias + ":" + segment.getName(), value); } else { parentNode.setAttribute(segment.getName(), value); } } else { parentNode.setAttribute(segment.getName(), value); } } else { parentNode.setTextContent(value); } if (LOG.isDebugEnabled()) { LOG.debug("Parent node after value written: {}", xmlHelper.writeDocumentToString(true, parentNode)); } } XmlFieldWriter();  XmlFieldWriter(ClassLoader classLoader, Map<String, String> namespaces, String seedDocument); @Override void write(AtlasInternalSession session); Document getDocument(); boolean isEnableElementNamespaces(); void setEnableElementNamespaces(boolean enableElementNamespaces); boolean isEnableAttributeNamespaces(); void setEnableAttributeNamespaces(boolean enableAttributeNamespaces); boolean isIgnoreMissingNamespaces(); void setIgnoreMissingNamespaces(boolean ignoreMissingNamespaces);  }