Search in sources :

Example 1 with XmlNamespace

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);
    }
}
Also used : XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) XmlNamespaces(io.atlasmap.xml.v2.XmlNamespaces)

Example 2 with XmlNamespace

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);
    }
}
Also used : XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) XmlNamespaces(io.atlasmap.xml.v2.XmlNamespaces)

Example 3 with XmlNamespace

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);
    }
}
Also used : XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) XmlNamespaces(io.atlasmap.xml.v2.XmlNamespaces)

Example 4 with XmlNamespace

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);
}
Also used : AtlasMapping(io.atlasmap.v2.AtlasMapping) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) ArrayList(java.util.ArrayList) XmlNamespaces(io.atlasmap.xml.v2.XmlNamespaces) DataSource(io.atlasmap.v2.DataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 5 with XmlNamespace

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());
}
Also used : XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) XmlDocument(io.atlasmap.xml.v2.XmlDocument) Test(org.junit.jupiter.api.Test)

Aggregations

XmlNamespace (io.atlasmap.xml.v2.XmlNamespace)15 XmlDocument (io.atlasmap.xml.v2.XmlDocument)9 Test (org.junit.jupiter.api.Test)9 XmlComplexType (io.atlasmap.xml.v2.XmlComplexType)8 XmlNamespaces (io.atlasmap.xml.v2.XmlNamespaces)6 File (java.io.File)6 XmlField (io.atlasmap.xml.v2.XmlField)5 DataSource (io.atlasmap.v2.DataSource)2 Field (io.atlasmap.v2.Field)2 XmlDataSource (io.atlasmap.xml.v2.XmlDataSource)2 AtlasMapping (io.atlasmap.v2.AtlasMapping)1 XmlFieldWriter (io.atlasmap.xml.core.XmlFieldWriter)1 Restriction (io.atlasmap.xml.v2.Restriction)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1