Search in sources :

Example 1 with XmlPath

use of io.atlasmap.xml.core.XmlPath in project atlasmap by atlasmap.

the class XmlModule method getCollectionSize.

@Override
public int getCollectionSize(AtlasInternalSession session, Field field) throws AtlasException {
    // TODO could this use FieldReader?
    try {
        Object sourceObject = session.getSourceDocument(getDocId());
        Document document = getDocument((String) sourceObject, false);
        Element parentNode = document.getDocumentElement();
        for (SegmentContext sc : new XmlPath(field.getPath()).getSegmentContexts(false)) {
            if (sc.getPrev() == null) {
                // "/XOA/contact<>/firstName", skip.
                continue;
            }
            String childrenElementName = XmlPath.cleanPathSegment(sc.getSegment());
            String namespaceAlias = XmlPath.getNamespace(sc.getSegment());
            if (namespaceAlias != null && !"".equals(namespaceAlias)) {
                childrenElementName = namespaceAlias + ":" + childrenElementName;
            }
            List<Element> children = XmlIOHelper.getChildrenWithName(childrenElementName, parentNode);
            if (children == null || children.isEmpty()) {
                return 0;
            }
            if (XmlPath.isCollectionSegment(sc.getSegment())) {
                return children.size();
            }
            parentNode = children.get(0);
        }
        return 0;
    } catch (Exception e) {
        throw new AtlasException(e);
    }
}
Also used : XmlPath(io.atlasmap.xml.core.XmlPath) SegmentContext(io.atlasmap.core.AtlasPath.SegmentContext) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) AtlasException(io.atlasmap.api.AtlasException) TransformerException(javax.xml.transform.TransformerException) AtlasConversionException(io.atlasmap.api.AtlasConversionException) AtlasValidationException(io.atlasmap.api.AtlasValidationException) AtlasException(io.atlasmap.api.AtlasException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

AtlasConversionException (io.atlasmap.api.AtlasConversionException)1 AtlasException (io.atlasmap.api.AtlasException)1 AtlasValidationException (io.atlasmap.api.AtlasValidationException)1 SegmentContext (io.atlasmap.core.AtlasPath.SegmentContext)1 XmlPath (io.atlasmap.xml.core.XmlPath)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 SAXException (org.xml.sax.SAXException)1