use of io.atlasmap.xml.v2.XmlNamespace in project atlasmap by atlasmap.
the class InstanceInspector method mapNamespace.
private void mapNamespace(Node node) {
if (xmlDocument.getXmlNamespaces() == null) {
XmlNamespaces namespaces = new XmlNamespaces();
xmlDocument.setXmlNamespaces(namespaces);
}
XmlNamespace namespace = new XmlNamespace();
namespace.setAlias(node.getPrefix());
namespace.setUri(node.getNamespaceURI());
if (!xmlDocument.getXmlNamespaces().getXmlNamespace().contains(namespace)) {
xmlDocument.getXmlNamespaces().getXmlNamespace().add(namespace);
}
}
use of io.atlasmap.xml.v2.XmlNamespace in project atlasmap by atlasmap.
the class SchemaInspector method populateNamespaces.
private void populateNamespaces() {
for (Entry<String, String> entry : namespaceContext.getNamespaceMap().entrySet()) {
String prefix = entry.getKey();
String uri = entry.getValue();
if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(uri) || AtlasXmlConstants.ATLAS_XML_SCHEMASET_NAMESPACE.equals(uri)) {
continue;
}
if (LOG.isTraceEnabled()) {
LOG.trace("adding a namespace >>> prefix={}, uri={}", prefix, uri);
}
if (xmlDocument.getXmlNamespaces() == null) {
xmlDocument.setXmlNamespaces(new XmlNamespaces());
}
XmlNamespace namespace = new XmlNamespace();
namespace.setAlias(prefix);
namespace.setUri(uri);
xmlDocument.getXmlNamespaces().getXmlNamespace().add(namespace);
}
}
use of io.atlasmap.xml.v2.XmlNamespace in project atlasmap by atlasmap.
the class XmlInstanceInspector method mapNamespace.
private void mapNamespace(Node node) {
if (xmlDocument.getXmlNamespaces() == null) {
XmlNamespaces namespaces = new XmlNamespaces();
xmlDocument.setXmlNamespaces(namespaces);
}
XmlNamespace namespace = new XmlNamespace();
namespace.setAlias(node.getPrefix());
namespace.setUri(node.getNamespaceURI());
if (!xmlDocument.getXmlNamespaces().getXmlNamespace().contains(namespace)) {
xmlDocument.getXmlNamespaces().getXmlNamespace().add(namespace);
}
}
use of io.atlasmap.xml.v2.XmlNamespace in project atlasmap by atlasmap.
the class XmlFieldReaderTest method mockDataSources.
private void mockDataSources(String docId, AtlasInternalSession session) {
AtlasMapping atlasMapping = mock(AtlasMapping.class);
List<DataSource> dataSources = new ArrayList<>();
XmlDataSource xmlDataSource = new XmlDataSource();
xmlDataSource.setId(docId);
xmlDataSource.setDataSourceType(DataSourceType.SOURCE);
XmlNamespaces atlasNamespaces = new XmlNamespaces();
XmlNamespace xmlNamespaceQ = new XmlNamespace();
xmlNamespaceQ.setAlias("q");
xmlNamespaceQ.setUri("http://www.example.com/q/");
XmlNamespace xmlNamespaceX = new XmlNamespace();
xmlNamespaceX.setAlias("");
xmlNamespaceX.setUri("http://www.example.com/x/");
XmlNamespace xmlNamespaceY = new XmlNamespace();
xmlNamespaceY.setAlias("y");
xmlNamespaceY.setUri("http://www.example.com/y/");
atlasNamespaces.getXmlNamespace().add(xmlNamespaceQ);
atlasNamespaces.getXmlNamespace().add(xmlNamespaceX);
atlasNamespaces.getXmlNamespace().add(xmlNamespaceY);
xmlDataSource.setXmlNamespaces(atlasNamespaces);
dataSources.add(xmlDataSource);
when(atlasMapping.getDataSource()).thenReturn(dataSources);
when(session.getMapping()).thenReturn(atlasMapping);
}
use of io.atlasmap.xml.v2.XmlNamespace in project atlasmap by atlasmap.
the class XmlInstanceInspectionTest method testInspectXmlStringWithNamespaces.
@Test
public void testInspectXmlStringWithNamespaces() throws Exception {
final String source = "<x:data xmlns:x=\"http://x.namespace.com/\">\n" + " <x:intField>32000</x:intField>\n" + " <x:longField>12421</x:longField>\n" + " <x:stringField>abc</x:stringField>\n" + " <x:booleanField>true</x:booleanField>\n" + " <x:doubleField>12.0</x:doubleField>\n" + " <x:shortField>1000</x:shortField>\n" + " <x:floatField>234.5f</x:floatField>\n" + " <x:charField>A</x:charField>\n" + "</x:data>";
XmlInspectionService service = new XmlInspectionService();
XmlDocument xmlDocument = service.inspectXmlDocument(source);
assertNotNull(xmlDocument);
assertNotNull(xmlDocument.getFields());
// check for namespace
assertNotNull(xmlDocument.getXmlNamespaces());
XmlNamespace namespace = xmlDocument.getXmlNamespaces().getXmlNamespace().get(0);
assertEquals(1, xmlDocument.getXmlNamespaces().getXmlNamespace().size());
assertNotNull(namespace);
assertEquals("x", namespace.getAlias());
assertEquals("http://x.namespace.com/", namespace.getUri());
assertNotNull(xmlDocument.getFields());
assertEquals(1, xmlDocument.getFields().getField().size());
XmlComplexType root = (XmlComplexType) xmlDocument.getFields().getField().get(0);
assertNotNull(root);
assertEquals(8, root.getXmlFields().getXmlField().size());
// debugFields(xmlDocument.getFields());
}
Aggregations