Populate data/ hierarchy
[yangtools.git] / data / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / IgnoreWhiteCharsDiffListener.java
diff --git a/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/IgnoreWhiteCharsDiffListener.java b/data/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/IgnoreWhiteCharsDiffListener.java
new file mode 100644 (file)
index 0000000..3dfe836
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.impl;
+
+import org.custommonkey.xmlunit.Difference;
+import org.custommonkey.xmlunit.DifferenceConstants;
+import org.custommonkey.xmlunit.DifferenceListener;
+
+/**
+ * Implementatin of {@link DifferenceListener} ignoring white characters around text elements.
+ *
+ * @author mirehak
+ */
+public class IgnoreWhiteCharsDiffListener implements DifferenceListener {
+
+    @Override
+    public void skippedComparison(org.w3c.dom.Node control,
+            org.w3c.dom.Node test) {
+        // do nothing
+    }
+
+    @Override
+    public int differenceFound(Difference diff) {
+
+        if (diff.getId() == DifferenceConstants.TEXT_VALUE.getId()) {
+            String control = diff.getControlNodeDetail().getValue();
+            if (control != null) {
+                control = control.trim();
+                if (diff.getTestNodeDetail().getValue() != null
+                    && control.equals(diff.getTestNodeDetail().getValue().trim())) {
+                    return
+                        DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
+                }
+            }
+        }
+        return RETURN_ACCEPT_DIFFERENCE;
+    }
+}